using GeoSigma.SigmaDrawerStyle; using SigmaDrawerElement; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing; using System.Drawing.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; using WorkData; using WorkData.Entity; namespace GeoSigma.SigmaDrawerElement { public partial class FrmTrackCommonDataSetData : Form { public DataItems m_trackDataItems = new DataItems(); class CTableInfo { public string chsTable { get; set; } public string engTable { get; set; } } List m_tablesList = new List(); class CColumnInfo { public string chsName { get; set; } public string engName { get; set; } } BindingList m_columnInfoList = new BindingList(); class CShowMode { public string chsName { get; set; } public string engName { get; set; } } List m_showModeList = new List(); class CDepthMode { public string chsName { get; set; } public string engName { get; set; } } BindingList m_DepthModeList = new BindingList(); class CSymbolShowAreaType { public string chsName { get; set; } public string engName { get; set; } } List m_SymbolAreaList = new List(); class CColorShowAreaType { public string chsName { get; set; } public string engName { get; set; } } List m_ColorAreaList = new List(); public class CFontInfo { public string fontName { get; set; } public float size { get; set; } public System.Drawing.Color color { get; set; } public string Display => $"{fontName},{size:F1}pt,{color.Name}"; } public class CDataItemProp : INotifyPropertyChanged { private bool _bSel; private string _name; private string _showContent; private string _symbolRect; private string _width; private CFontInfo _fontInfo; private int sn = 0; //private string _colorRect; public bool Sel { get => _bSel; set { _bSel = value; OnPropertyChanged(); } } public string Name { get => _name; set { _name = value;OnPropertyChanged(); } } public int Sn { get => sn; set { sn = value; OnPropertyChanged(); } } public string ShowContent { get => _showContent; set { _showContent = value; OnPropertyChanged(); } } public string SymbolRect { get => _symbolRect; set { _symbolRect = value; OnPropertyChanged(); } } //public string ColorRect //{ // get => _colorRect; // set { _colorRect = value; OnPropertyChanged(); } //} public string width { get => _width; set { _width = value; OnPropertyChanged(); } } public CFontInfo fontInfo { get => _fontInfo; set { _fontInfo = value; OnPropertyChanged(); } } public string FontDisplay => fontInfo?.Display ?? "未设置"; public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } } BindingList m_dataList = new BindingList(); public FrmTrackCommonDataSetData(DataItems tDataItems) { InitializeComponent(); dataGridView1.AutoGenerateColumns = false; DataGridViewCheckBoxColumn colSelect = new DataGridViewCheckBoxColumn(); colSelect.HeaderText = "选择"; colSelect.Name = "Sel"; colSelect.DataPropertyName = "Sel"; colSelect.Width = 50; this.dataGridView1.Columns.Add(colSelect); this.dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "位置顺序", Name = "Sn", DataPropertyName = "Sn", Width = 80 } ); this.dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "字段名", Name = "Name", DataPropertyName = "Name", Width = 80 } ); m_showModeList = new List { new CShowMode{ chsName ="文本",engName = "Text"}, new CShowMode{ chsName ="符号",engName = "Symbol"}, new CShowMode{ chsName ="符号+文本",engName = "Symbol+Text"}, new CShowMode{ chsName ="颜色",engName = "Color"}, new CShowMode{ chsName ="颜色+文本",engName = "Color+Text"}, }; DataGridViewComboBoxColumn colShow = new DataGridViewComboBoxColumn(); colShow.HeaderText = "显示样式"; colShow.Name = "ShowContent"; colShow.DataPropertyName = "ShowContent"; colShow.Width = 110; colShow.DataSource = m_showModeList; // 下拉选项 colShow.DisplayMember = "chsName"; colShow.ValueMember = "engName"; dataGridView1.Columns.Add(colShow); m_SymbolAreaList = new List { new CSymbolShowAreaType{ chsName="行宽度", engName="Row"}, new CSymbolShowAreaType{ chsName="列宽度", engName="Column"}, new CSymbolShowAreaType{chsName ="符号在左" ,engName="Left"}, new CSymbolShowAreaType{chsName ="符号在右" ,engName="Right"}, }; DataGridViewComboBoxColumn SymbolAreaShow = new DataGridViewComboBoxColumn(); SymbolAreaShow.HeaderText = "符号颜色区域"; SymbolAreaShow.Name = "SymbolRect"; SymbolAreaShow.DataPropertyName = "SymbolRect"; SymbolAreaShow.Width = 100; SymbolAreaShow.DataSource = m_SymbolAreaList; // 下拉选项 SymbolAreaShow.DisplayMember = "chsName"; SymbolAreaShow.ValueMember = "engName"; dataGridView1.Columns.Add(SymbolAreaShow); //m_ColorAreaList = new List //{ // new CColorShowAreaType{ chsName="", engName=""}, // new CColorShowAreaType{ chsName="行宽度", engName="Row"}, // new CColorShowAreaType{ chsName="列宽度", engName="Column"}, //}; //DataGridViewComboBoxColumn ColorAreaShow = new DataGridViewComboBoxColumn(); //ColorAreaShow.HeaderText = "颜色区域"; //ColorAreaShow.Name = "ColorRect"; //ColorAreaShow.DataPropertyName = "ColorRect"; //ColorAreaShow.Width = 90; //ColorAreaShow.DataSource = m_ColorAreaList; // 下拉选项 //ColorAreaShow.DisplayMember = "chsName"; //ColorAreaShow.ValueMember = "engName"; //dataGridView1.Columns.Add(ColorAreaShow); this.dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "宽度", Name = "width", DataPropertyName="width", Width = 70 } ); var buttonColumn = new DataGridViewButtonColumn { Name = "btnSetFont", HeaderText = "设置字体", Text = "选择字体", UseColumnTextForButtonValue = true, Width = 80 }; dataGridView1.Columns.Add(buttonColumn); var fontDisplayColumn = new DataGridViewTextBoxColumn { Name = "colFontDisplay", HeaderText = "字体", DataPropertyName = "FontDisplay", ReadOnly = true, Width = 200 }; dataGridView1.Columns.Add(fontDisplayColumn); dataGridView1.DataSource = m_dataList; // CTableInfo tTableInfo = null; foreach (var(engName,chsName) in tableInfoQuery.TableDescriptionMap) { CTableInfo tTableInfo = new CTableInfo(); tTableInfo.chsTable = chsName; tTableInfo.engTable = engName; m_tablesList.Add(tTableInfo); } /* CTableInfo tTableInfo = new CTableInfo(); tTableInfo.chsTable = DBHelp.GetTableDescription(); tTableInfo.engTable = DBHelp.GetTableName(); m_tablesList.Add(tTableInfo); tTableInfo = new CTableInfo(); tTableInfo.chsTable = DBHelp.GetTableDescription(); tTableInfo.engTable = DBHelp.GetTableName(); m_tablesList.Add(tTableInfo); tTableInfo = new CTableInfo(); tTableInfo.chsTable = DBHelp.GetTableDescription(); tTableInfo.engTable = DBHelp.GetTableName(); m_tablesList.Add(tTableInfo); tTableInfo = new CTableInfo(); tTableInfo.chsTable = DBHelp.GetTableDescription(); tTableInfo.engTable = DBHelp.GetTableName(); m_tablesList.Add(tTableInfo); tTableInfo = new CTableInfo(); tTableInfo.chsTable = DBHelp.GetTableDescription(); tTableInfo.engTable = DBHelp.GetTableName(); m_tablesList.Add(tTableInfo); */ comboBoxTable.DataSource = m_tablesList; comboBoxTable.DisplayMember = "chsTable"; comboBoxTable.ValueMember = "engTable"; comboBoxDepthMode.DataSource = m_DepthModeList; comboBoxDepthMode.ValueMember = "engName"; comboBoxDepthMode.DisplayMember = "chsName"; m_trackDataItems.SetValue(tDataItems); var selitem = m_tablesList.FirstOrDefault(t => t.engTable == m_trackDataItems.RefTableId); if (selitem != null) { comboBoxTable.SelectedItem = selitem; ListTableColumn(selitem.engTable); } } private void comboBoxTable_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxTable.SelectedItem is CTableInfo tabinfo) { if (tabinfo.engTable == DBHelp.GetTableName()) { m_DepthModeList.Clear(); CDepthMode tdepthMode = new CDepthMode(); tdepthMode.chsName = "一类砂岩顶底"; tdepthMode.engName = "FirstTopBottom"; m_DepthModeList.Add(tdepthMode); tdepthMode = new CDepthMode(); tdepthMode.chsName = "二类砂岩顶底"; tdepthMode.engName = "SecondTopBottom"; m_DepthModeList.Add(tdepthMode); tdepthMode = new CDepthMode(); tdepthMode.chsName = "纯有效顶底"; tdepthMode.engName = "PureEffectiveTopBottom"; m_DepthModeList.Add(tdepthMode); tdepthMode = new CDepthMode(); tdepthMode.chsName = "视有效顶底"; tdepthMode.engName = "ViewEffectiveTopBottom"; m_DepthModeList.Add(tdepthMode); } else { m_DepthModeList.Clear(); CDepthMode tdepthMode = new CDepthMode(); tdepthMode.chsName = "顶底深"; tdepthMode.engName = "TopBottom"; m_DepthModeList.Add(tdepthMode); } ListTableColumn(tabinfo.engTable); } } void ListTableColumn(string tableName) { List colList = tableInfoQuery.getListTableColumn(tableName); if (colList != null) { // dataGridView1.Rows.Clear(); m_dataList.Clear(); bool bSelectInit = false; if (tableName == m_trackDataItems.RefTableId) { bSelectInit = true; // 选中了原有的井就设置,根据传入参数设置选择列 comboBoxDepthMode.SelectedValue = m_trackDataItems.DepthSegmentMode; } for (int i = 0; i < colList.Count; i++) { if (colList[i].ColumnDescription == "" || colList[i].ColumnDescription == null) continue; if (colList[i].DbColumnName == "ID" || colList[i].DbColumnName == "XHID" || colList[i].DbColumnName == null || colList[i].DbColumnName == "CWID" || colList[i].DbColumnName == "Well") continue; bool bSel = false; string show = "Text"; string strSymbolRect = "Column"; string strWidth = "1"; string colorRect = ""; CFontInfo fontInfo = new CFontInfo(); fontInfo.size = 40; fontInfo.fontName = "Times New Roman"; fontInfo.color = Color.Black; int sn = 0; if (bSelectInit) { for (int j = 0; j < m_trackDataItems.DataItem.Count; j++) { if (colList[i].DbColumnName == m_trackDataItems.DataItem[j].RefColId) { bSel = true; show = m_trackDataItems.DataItem[j].ShowContent; strSymbolRect = m_trackDataItems.DataItem[j].SymbolRect; strWidth = m_trackDataItems.DataItem[j].WidthAllocation.ToString("F2"); //colorRect = m_trackDataItems.DataItem[j].ColorRect; fontInfo.size = m_trackDataItems.DataItem[j].TextSize; fontInfo.fontName = m_trackDataItems.DataItem[j].TextFace; fontInfo.color = ColorTranslator2.FromHtml(m_trackDataItems.DataItem[j].TextColor); sn = m_trackDataItems.DataItem[j].sn; break; } } } CDataItemProp dataItemProp = new CDataItemProp { Sel = bSel,Name = colList[i].ColumnDescription ,ShowContent = show ,SymbolRect =strSymbolRect,/*ColorRect= colorRect,*/width = strWidth, fontInfo = fontInfo, Sn =sn }; m_dataList.Add(dataItemProp); //dataItemProp.Sel = bSel; // bSel,colList[i].ColumnDescription,show,strSymbolRect,strWidth,fontInfo}); // dataGridView1.Rows.Add(bSel, colList[i].ColumnDescription, show, strSymbolRect, strWidth,fontInfo); } } } private void btnOK_Click(object sender, EventArgs e) { string selTable = ""; string selDepthMode = ""; if (comboBoxTable.SelectedItem != null) { if (comboBoxTable.SelectedItem is CTableInfo tableinfo) { selTable = tableinfo.engTable; } } if (comboBoxDepthMode.SelectedItem != null) { if (comboBoxDepthMode.SelectedItem is CDepthMode tMode) { selDepthMode = tMode.engName; } } m_trackDataItems.RefTableId = selTable; m_trackDataItems.DepthSegmentMode = selDepthMode; m_trackDataItems.DataItem.Clear(); foreach(CDataItemProp itemprop in m_dataList) { if(itemprop.Sel == true) { DataItem titem = new DataItem(); titem.ColType = "Text"; titem.TextRect = "Full"; titem.RefColId = tableInfoQuery.getColumnNameFromChsName(selTable, itemprop.Name); titem.ShowContent = itemprop.ShowContent; titem.SymbolRect = itemprop.SymbolRect; titem.TextFace = itemprop.fontInfo.fontName; titem.TextSize = itemprop.fontInfo.size; titem.TextColor = ColorTranslator2.ToHtml(itemprop.fontInfo.color); titem.sn = itemprop.Sn; // titem.ColorRect = itemprop.ColorRect; if (!Double.TryParse(itemprop.width, out double width)) { width = 1.0; } titem.WidthAllocation = width; int i = 0; for( i = 0; i< m_trackDataItems.DataItem.Count; i++) { if(titem.sn < m_trackDataItems.DataItem[i].sn) { m_trackDataItems.DataItem.Insert(i,titem); break; } } if(i >= m_trackDataItems.DataItem.Count) m_trackDataItems.DataItem.Add(titem); } } } private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) return; if (dataGridView1.Columns[e.ColumnIndex].Name == "btnSetFont") { var item = (CDataItemProp)dataGridView1.Rows[e.RowIndex].DataBoundItem; var currentFontInfo = item.fontInfo; using (var fontDialog = new FontDialog()) { try { var Font = new Font(currentFontInfo.fontName, currentFontInfo.size/2.8f); fontDialog.Font = Font; } catch { // 防止无效字体名 fontDialog.Font = new Font("宋体", 40/2.8f); } //if (currentFont != null) // fontDialog.Font = font; fontDialog.Color = currentFontInfo.color; fontDialog.ShowColor = true; if (fontDialog.ShowDialog() == DialogResult.OK) { // 更新数据源 //var item = (CFontInfo)dataGridView1.Rows[e.RowIndex].DataBoundItem; currentFontInfo.fontName = fontDialog.Font.Name; currentFontInfo.size = fontDialog.Font.Size*2.8f; currentFontInfo.color = fontDialog.Color; // 触发界面刷新(BindingList 会自动更新,如果没更新可手动 Refresh) dataGridView1.InvalidateRow(e.RowIndex); } } } } } }