Attributes.cs 13 KB

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