Attributes.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using OTS.WinFormsUI.Docking;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace OTSPartA_STDEditor
  7. {
  8. public partial class Attributes : DockContent
  9. {
  10. public Form_Main m_MainForm = null;
  11. /// <summary>
  12. /// [颜色:16进制转成RGB]
  13. /// </summary>
  14. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  15. /// <returns></returns>
  16. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  17. {
  18. try
  19. {
  20. if (strHxColor.Length == 0)
  21. {//如果为空
  22. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  23. }
  24. else
  25. {//转换颜色
  26. 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));
  27. }
  28. }
  29. catch
  30. {//设为白色
  31. return System.Drawing.Color.FromArgb(255, 255, 204);
  32. }
  33. }
  34. public static string colorRGBtoHx16(int R, int G, int B)
  35. {
  36. return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  37. }
  38. private void clickEvent_Click(object sender, EventArgs e)
  39. {
  40. SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
  41. int i = context.Position.Row;
  42. int j = context.Position.Column;
  43. /// 保证鼠标点击的GRID行和列是有效的
  44. if (i >= 0 && j >= 0)
  45. {
  46. ColorDialog cd = new ColorDialog();
  47. cd.FullOpen = true;//自定义颜色界面打开
  48. DialogResult result = cd.ShowDialog();
  49. if (result == DialogResult.OK)
  50. {
  51. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  52. view.BackColor = cd.Color;
  53. Grid_Attributes[i, j].View = view;
  54. m_MainForm.ChangeSTDRulesLISTBackColor();
  55. }
  56. }
  57. Grid_Attributes.Refresh();
  58. }
  59. private void EditorEvent_EditEnded(object sender, EventArgs e)
  60. {
  61. SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
  62. m_MainForm.ChangeSTDRuleName(Convert.ToString( Grid_Attributes[context.Position.Row, context.Position.Column].Value));
  63. }
  64. private class MyHeader : SourceGrid.Cells.ColumnHeader
  65. {
  66. public MyHeader(object value) : base(value)
  67. {
  68. SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
  69. view.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
  70. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  71. //view.BackColor = Color.Green;
  72. //view.ForeColor= Color.Red;
  73. View = view;
  74. //自带排序true;不实现排序false
  75. AutomaticSortEnabled = false;
  76. }
  77. }
  78. public Attributes(Form_Main mainForm)
  79. {
  80. InitializeComponent();
  81. m_MainForm = mainForm;
  82. }
  83. private void Attributes_Load(object sender, EventArgs e)
  84. {
  85. m_MainForm.lan = new Language(this);
  86. Grid_Attributes.Redim(13, 2);
  87. if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "ZH")
  88. {
  89. //SourceGrid.Cells.ColumnHeader head1 = new SourceGrid.Cells.ColumnHeader("通用属性");
  90. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("通用属性 ", typeof(string));
  91. //head1.AutomaticSortEnabled = false;
  92. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  93. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("规则名称 ", typeof(string));
  94. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("颜色", typeof(string));
  95. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("是否元素分析 ", typeof(string));
  96. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("硬度(HV)", typeof(string));
  97. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("密度(g/m³)", typeof(string));
  98. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("导电性(S/m)", typeof(string));
  99. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("Video", typeof(string));
  100. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("化学式", typeof(string));
  101. Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("元素", typeof(string));
  102. Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("分组名称", typeof(string));
  103. }
  104. else
  105. {
  106. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("General Properties", typeof(string));
  107. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  108. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("RuleName ", typeof(string));
  109. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("Color", typeof(string));
  110. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("IfElementAnalysis", typeof(string));
  111. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("Hardness", typeof(string));
  112. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("Density", typeof(string));
  113. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("Conductivity", typeof(string));
  114. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("Video", typeof(string));
  115. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("Formula", typeof(string));
  116. Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("Element", typeof(string));
  117. Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("GroupName", typeof(string));
  118. }
  119. Grid_Attributes[1, 1] = new SourceGrid.Cells.Cell(" ", typeof(int));
  120. Grid_Attributes[2, 1] = new SourceGrid.Cells.Cell(" ", typeof(string));
  121. Grid_Attributes[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  122. Grid_Attributes[4, 1] = new SourceGrid.Cells.CheckBox(null, true);
  123. Grid_Attributes[5, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  124. Grid_Attributes[6, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  125. Grid_Attributes[7, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  126. Grid_Attributes[8, 1] = new SourceGrid.Cells.Cell("", typeof(int));
  127. Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  128. Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  129. Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  130. Grid_Attributes[0, 0].ColumnSpan = 2;
  131. Grid_Attributes.AutoStretchColumnsToFitWidth = true;
  132. Grid_Attributes.Columns[0].Width = 195;
  133. Grid_Attributes.Columns[1].Width = 195;
  134. for (int i=0;i<10;i++)
  135. {
  136. Grid_Attributes.Rows[i].Height = 25;
  137. }
  138. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  139. view.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
  140. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  141. view.BackColor = Color.LightGray;
  142. Grid_Attributes[0, 0].View = view;
  143. SourceGrid.Cells.Controllers.CustomEvents EditorEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  144. EditorEvent.EditEnded += new EventHandler(EditorEvent_EditEnded);
  145. Grid_Attributes[2, 1].AddController(EditorEvent);
  146. SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  147. clickEvent.Click += new EventHandler(clickEvent_Click);
  148. Grid_Attributes[3,1].AddController(clickEvent);
  149. Grid_Attributes[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  150. Grid_Attributes[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  151. Grid_Attributes[3, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  152. Grid_Attributes[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  153. Grid_Attributes[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  154. Grid_Attributes[2, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  155. Grid_Attributes[3, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  156. Grid_Attributes[4, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  157. Grid_Attributes[5, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  158. Grid_Attributes[6, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  159. Grid_Attributes[7, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  160. Grid_Attributes[8, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  161. Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  162. Grid_Attributes[10, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  163. AddSTDGroupsToAttribute();
  164. Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
  165. }
  166. public void SetDatatoGrid_Attributes(STDdata ddata)
  167. {
  168. STDdata sTDdata = ddata;
  169. Grid_Attributes[1, 1].Value = sTDdata.STDId;
  170. Grid_Attributes[2, 1].Value = sTDdata.StrName;
  171. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  172. view.BackColor = colorHx16toRGB(sTDdata.Color);
  173. Grid_Attributes[3, 1].View = view;
  174. Grid_Attributes[4, 1].Value = Convert.ToBoolean(sTDdata.IfElementAnalysis);
  175. Grid_Attributes[5, 1].Value = sTDdata.Hardness;
  176. Grid_Attributes[6, 1].Value = sTDdata.Density;
  177. Grid_Attributes[7, 1].Value = sTDdata.Electrical_conductivity;
  178. Grid_Attributes[8, 1].Value = int.Parse(sTDdata.BSE);
  179. Grid_Attributes[9, 1].Value = sTDdata.Formula;
  180. Grid_Attributes[10, 1].Value = sTDdata.Element;
  181. Grid_Attributes[11, 1].Value = m_MainForm._sTDEditor.GroupIdDictionaryFromId[sTDdata.GroupId];
  182. Grid_Attributes.Refresh();
  183. }
  184. public void SetDatatoGrid_AttributesByReferenceLibrary(STDdata sTDdata)
  185. {
  186. Grid_Attributes[1, 1].Value = "";
  187. Grid_Attributes[2, 1].Value = sTDdata.StrName;
  188. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  189. view.BackColor = colorHx16toRGB(sTDdata.Color);
  190. Grid_Attributes[3, 1].View = view;
  191. Grid_Attributes[4, 1].Value = Convert.ToBoolean(sTDdata.IfElementAnalysis);
  192. Grid_Attributes[5, 1].Value = sTDdata.Hardness;
  193. Grid_Attributes[6, 1].Value = sTDdata.Density;
  194. Grid_Attributes[7, 1].Value = sTDdata.Electrical_conductivity;
  195. Grid_Attributes[8, 1].Value = int.Parse(sTDdata.BSE);
  196. Grid_Attributes[9, 1].Value = sTDdata.Formula;
  197. Grid_Attributes[10, 1].Value = sTDdata.Element;
  198. Grid_Attributes[11, 1].Value = m_MainForm._sTDEditor.GroupIdDictionaryFromId[sTDdata.GroupId];
  199. Grid_Attributes.Refresh();
  200. }
  201. public void AddSTDGroupsToAttribute()
  202. {
  203. List<string> ss = new List<string>();
  204. foreach (var item in m_MainForm._sTDEditor.GroupDictionary)
  205. {
  206. ss.Add(item.Value.name.ToString());
  207. }
  208. SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
  209. GroupIdCBBox.StandardValues = ss;
  210. GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.Focus;
  211. Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("Default", GroupIdCBBox);
  212. GroupIdCBBox.Control.DropDownStyle = ComboBoxStyle.DropDownList; //设置下拉框为不可以编辑的状态
  213. ComboBox winFormsCombo = GroupIdCBBox.Control;
  214. winFormsCombo.SelectedValueChanged += (sender, e) =>
  215. {
  216. if(winFormsCombo.Text=="")
  217. {
  218. return;
  219. }
  220. int Groupid = m_MainForm._sTDEditor.GroupIdDictionaryFromName[winFormsCombo.Text];
  221. m_MainForm.m_STDRuleslist.AdjustTreenodeByGroup(Groupid);
  222. };
  223. }
  224. }
  225. }