123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- using OTS.WinFormsUI.Docking;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSPartA_STDEditor
- {
- public partial class Attributes : DockContent
- {
- public Form_Main m_MainForm = null;
- /// <summary>
- /// [颜色:16进制转成RGB]
- /// </summary>
- /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
- /// <returns></returns>
- public static System.Drawing.Color colorHx16toRGB(string strHxColor)
- {
- try
- {
- if (strHxColor.Length == 0)
- {//如果为空
- return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
- }
- else
- {//转换颜色
- return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
- }
- }
- catch
- {//设为白色
- return System.Drawing.Color.FromArgb(255, 255, 204);
- }
- }
- /// <summary>
- /// [颜色:RGB转成16进制]
- /// </summary>
- /// <param name="R">红 int</param>
- /// <param name="G">绿 int</param>
- /// <param name="B">蓝 int</param>
- /// <returns></returns>
- public static string colorRGBtoHx16(int R, int G, int B)
- {
- return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
- }
- private void clickEvent_Click(object sender, EventArgs e)
- {
- SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
- int i = context.Position.Row;
- int j = context.Position.Column;
- /// 保证鼠标点击的GRID行和列是有效的
- if (i >= 0 && j >= 0)
- {
- ColorDialog cd = new ColorDialog();
- cd.FullOpen = true;//自定义颜色界面打开
- DialogResult result = cd.ShowDialog();
- if (result == DialogResult.OK)
- {
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = cd.Color;
- Grid_Attributes[i, j].View = view;
- m_MainForm.ChangeSTDRulesLISTBackColor();
- }
- }
- Grid_Attributes.Refresh();
- }
- private void EditorEvent_EditEnded(object sender, EventArgs e)
- {
- SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
- //if(Grid_Attributes[context.Position.Row, context.Position.Column].Value==null)
- //{
- // MessageBox.Show("The name of rule cannot be null!", "warnning");
- // return;
- //}
- m_MainForm.ChangeSTDRuleName(Convert.ToString( Grid_Attributes[context.Position.Row, context.Position.Column].Value));
- }
- private class MyHeader : SourceGrid.Cells.ColumnHeader
- {
- public MyHeader(object value) : base(value)
- {
- SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
- view.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
- view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
- //view.BackColor = Color.Green;
- //view.ForeColor= Color.Red;
- View = view;
- //自带排序true;不实现排序false
- AutomaticSortEnabled = false;
- }
- }
- public Attributes(Form_Main mainForm)
- {
- InitializeComponent();
- m_MainForm = mainForm;
- }
- private void Attributes_Load(object sender, EventArgs e)
- {
- m_MainForm.lan = new Language(this);
- Grid_Attributes.Redim(13, 2);
- if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "ZH")
- {
- //SourceGrid.Cells.ColumnHeader head1 = new SourceGrid.Cells.ColumnHeader("通用属性");
- Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("通用属性 ", typeof(string));
- //head1.AutomaticSortEnabled = false;
- Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
- Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("规则名称 ", typeof(string));
- Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("颜色", typeof(string));
- Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("是否元素分析 ", typeof(string));
- Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("硬度(HV)", typeof(string));
- Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("密度(g/m³)", typeof(string));
- Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("导电性(S/m)", typeof(string));
- Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("Video", typeof(string));
- Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("化学式", typeof(string));
- Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("元素", typeof(string));
- Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("分组名称", typeof(string));
- }
- else
- {
- Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("General Properties", typeof(string));
- Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
- Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("RuleName ", typeof(string));
- Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("Color", typeof(string));
- Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("IfElementAnalysis", typeof(string));
- Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("Hardness", typeof(string));
- Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("Density", typeof(string));
- Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("Conductivity", typeof(string));
- Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("Video", typeof(string));
- Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("Formula", typeof(string));
- Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("Element", typeof(string));
- Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("GroupName", typeof(string));
- }
- Grid_Attributes[1, 1] = new SourceGrid.Cells.Cell(" ", typeof(int));
- Grid_Attributes[2, 1] = new SourceGrid.Cells.Cell(" ", typeof(string));
- Grid_Attributes[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[4, 1] = new SourceGrid.Cells.CheckBox(null, true);
- Grid_Attributes[5, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[6, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[7, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[8, 1] = new SourceGrid.Cells.Cell("", typeof(int));
- Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("", typeof(string));
- Grid_Attributes[0, 0].ColumnSpan = 2;
- Grid_Attributes.AutoStretchColumnsToFitWidth = true;
- Grid_Attributes.Columns[0].Width = 195;
- Grid_Attributes.Columns[1].Width = 195;
- for (int i=0;i<10;i++)
- {
- Grid_Attributes.Rows[i].Height = 25;
- }
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
- view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
- view.BackColor = Color.LightGray;
- Grid_Attributes[0, 0].View = view;
- SourceGrid.Cells.Controllers.CustomEvents EditorEvent = new SourceGrid.Cells.Controllers.CustomEvents();
- EditorEvent.EditEnded += new EventHandler(EditorEvent_EditEnded);
- Grid_Attributes[2, 1].AddController(EditorEvent);
- SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
- clickEvent.Click += new EventHandler(clickEvent_Click);
- Grid_Attributes[3,1].AddController(clickEvent);
- Grid_Attributes[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[3, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[2, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[3, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[4, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[5, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[6, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[7, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[8, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- Grid_Attributes[10, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
- AddSTDGroupsToAttribute();
- Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
- //SourceGrid.Position po = new SourceGrid.Position(1, 0);
- //Grid_Attributes[1, 0].Grid.Select();
- //Grid_Attributes.Selection.Focus(po, true);
- }
- public void SetDatatoGrid_Attributes(int STDId)
- {
- STDdata sTDdata = m_MainForm._sTDEditor.STDDictionary[STDId];
- Grid_Attributes[1, 1].Value = STDId;
- Grid_Attributes[2, 1].Value = sTDdata.StrName;
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = colorHx16toRGB(sTDdata.Color);
- Grid_Attributes[3, 1].View = view;
- Grid_Attributes[4, 1].Value = Convert.ToBoolean(sTDdata.IfElementAnalysis);
- Grid_Attributes[5, 1].Value = sTDdata.Hardness;
- Grid_Attributes[6, 1].Value = sTDdata.Density;
- Grid_Attributes[7, 1].Value = sTDdata.Electrical_conductivity;
- Grid_Attributes[8, 1].Value = int.Parse(sTDdata.BSE);
- Grid_Attributes[9, 1].Value = sTDdata.Formula;
- Grid_Attributes[10, 1].Value = sTDdata.Element;
- //m_MainForm.AddSTDGroupsToAttribute();
- Grid_Attributes[11, 1].Value = m_MainForm._sTDEditor.GroupIdDictionaryFromId[sTDdata.GroupId];
- //SourceGrid.Position po = new SourceGrid.Position(1, 0);
- //Grid_Attributes[1, 0].Grid.Select();
- //Grid_Attributes.Selection.Focus(po, true);
- Grid_Attributes.Refresh();
- }
- public void SetDatatoGrid_AttributesByReferenceLibrary(STDdata sTDdata)
- {
- Grid_Attributes[1, 1].Value = "";
- Grid_Attributes[2, 1].Value = sTDdata.StrName;
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = colorHx16toRGB(sTDdata.Color);
- Grid_Attributes[3, 1].View = view;
- Grid_Attributes[4, 1].Value = Convert.ToBoolean(sTDdata.IfElementAnalysis);
- Grid_Attributes[5, 1].Value = sTDdata.Hardness;
- Grid_Attributes[6, 1].Value = sTDdata.Density;
- Grid_Attributes[7, 1].Value = sTDdata.Electrical_conductivity;
- Grid_Attributes[8, 1].Value = int.Parse(sTDdata.BSE);
- Grid_Attributes[9, 1].Value = sTDdata.Formula;
- Grid_Attributes[10, 1].Value = sTDdata.Element;
- //m_MainForm.AddSTDGroupsToAttribute();
- Grid_Attributes[11, 1].Value = m_MainForm._sTDEditor.GroupIdDictionaryFromId[sTDdata.GroupId];
- //SourceGrid.Position po = new SourceGrid.Position(1, 0);
- //Grid_Attributes[1, 0].Grid.Select();
- //Grid_Attributes.Selection.Focus(po, true);
- Grid_Attributes.Refresh();
- }
- public void AddSTDGroupsToAttribute()
- {
- List<string> ss = new List<string>();
- foreach (var item in m_MainForm._sTDEditor.GroupDictionary)
- {
- ss.Add(item.Value.name.ToString());
- }
- SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
- GroupIdCBBox.StandardValues = ss;
- GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.Focus;
- Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("Default", GroupIdCBBox);
- GroupIdCBBox.Control.DropDownStyle = ComboBoxStyle.DropDownList; //设置下拉框为不可以编辑的状态
- ComboBox winFormsCombo = GroupIdCBBox.Control;
- winFormsCombo.SelectedValueChanged += (sender, e) =>
- {
- if(winFormsCombo.Text=="")
- {
- return;
- }
- int Groupid = m_MainForm._sTDEditor.GroupIdDictionaryFromName[winFormsCombo.Text];
- m_MainForm.m_STDRuleslist.AdjustTreenodeByGroup(Groupid);
- };
- }
- }
- }
|