Attributes.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_ConstantsEditor2 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. /// <summary>
  40. /// [颜色:RGB转成16进制]
  41. /// </summary>
  42. /// <param name="R">红 int</param>
  43. /// <param name="G">绿 int</param>
  44. /// <param name="B">蓝 int</param>
  45. /// <returns></returns>
  46. public static string colorRGBtoHx16(int R, int G, int B)
  47. {
  48. return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  49. }
  50. private void clickEvent_Click(object sender, EventArgs e)
  51. {
  52. SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
  53. int i = context.Position.Row;
  54. int j = context.Position.Column;
  55. /// 保证鼠标点击的GRID行和列是有效的
  56. if (i >= 0 && j >= 0)
  57. {
  58. ColorDialog cd = new ColorDialog();
  59. cd.FullOpen = true;//自定义颜色界面打开
  60. DialogResult result = cd.ShowDialog();
  61. if (result == DialogResult.OK)
  62. {
  63. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  64. view.BackColor = cd.Color;
  65. Grid_Attributes[i, j].View = view;
  66. m_MainForm.ChangeSTDRulesLISTBackColor();
  67. }
  68. }
  69. Grid_Attributes.Refresh();
  70. }
  71. private void EditorEvent_EditEnded(object sender, EventArgs e)
  72. {
  73. SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
  74. m_MainForm.ChangeSTDRuleName(Grid_Attributes[context.Position.Row, context.Position.Column].Value.ToString());
  75. }
  76. private class MyHeader : SourceGrid.Cells.ColumnHeader
  77. {
  78. public MyHeader(object value) : base(value)
  79. {
  80. SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
  81. view.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
  82. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  83. //view.BackColor = Color.Green;
  84. //view.ForeColor= Color.Red;
  85. View = view;
  86. //自带排序true;不实现排序false
  87. AutomaticSortEnabled = false;
  88. }
  89. }
  90. public Attributes(Form_ConstantsEditor2 mainForm)
  91. {
  92. InitializeComponent();
  93. m_MainForm = mainForm;
  94. }
  95. private void Attributes_Load(object sender, EventArgs e)
  96. {
  97. m_MainForm.lan = new Language(this);
  98. Grid_Attributes.Redim(12, 2);
  99. if (m_MainForm.lan.GetNameTable("Form_ConstantsEditor2")["language"].ToString() == "ZH")
  100. {
  101. //SourceGrid.Cells.ColumnHeader head1 = new SourceGrid.Cells.ColumnHeader("通用属性");
  102. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("通用属性 ", typeof(string));
  103. //head1.AutomaticSortEnabled = false;
  104. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  105. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("规则名称 ", typeof(string));
  106. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("颜色", typeof(string));
  107. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("硬度", typeof(string));
  108. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("密度", typeof(string));
  109. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("导电性", typeof(string));
  110. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("BSE", typeof(string));
  111. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("化学式", typeof(string));
  112. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("元素", typeof(string));
  113. Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("分组名称", typeof(string));
  114. }
  115. else
  116. {
  117. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("General Properties", typeof(string));
  118. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  119. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("RuleName ", typeof(string));
  120. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("Color", typeof(string));
  121. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("Hardness", typeof(string));
  122. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("Density", typeof(string));
  123. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("Conductivity", typeof(string));
  124. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("BSE", typeof(string));
  125. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("Formula", typeof(string));
  126. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("Element", typeof(string));
  127. Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("GroupName", typeof(string));
  128. }
  129. Grid_Attributes[1, 1] = new SourceGrid.Cells.Cell(" ", typeof(int));
  130. Grid_Attributes[2, 1] = new SourceGrid.Cells.Cell(" ", typeof(string));
  131. Grid_Attributes[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  132. Grid_Attributes[4, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  133. Grid_Attributes[5, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  134. Grid_Attributes[6, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  135. Grid_Attributes[7, 1] = new SourceGrid.Cells.Cell("", typeof(int));
  136. Grid_Attributes[8, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  137. Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  138. //Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  139. Grid_Attributes[0, 0].ColumnSpan = 2;
  140. Grid_Attributes.AutoStretchColumnsToFitWidth = true;
  141. Grid_Attributes.Columns[0].Width = 195;
  142. Grid_Attributes.Columns[1].Width = 195;
  143. for (int i=0;i<10;i++)
  144. {
  145. Grid_Attributes.Rows[i].Height = 25;
  146. }
  147. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  148. view.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
  149. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  150. view.BackColor = Color.LightGray;
  151. Grid_Attributes[0, 0].View = view;
  152. SourceGrid.Cells.Controllers.CustomEvents EditorEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  153. EditorEvent.EditEnded += new EventHandler(EditorEvent_EditEnded);
  154. Grid_Attributes[2, 1].AddController(EditorEvent);
  155. SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  156. clickEvent.Click += new EventHandler(clickEvent_Click);
  157. Grid_Attributes[3,1].AddController(clickEvent);
  158. Grid_Attributes[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  159. Grid_Attributes[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  160. Grid_Attributes[3, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  161. Grid_Attributes[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  162. Grid_Attributes[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  163. Grid_Attributes[2, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  164. Grid_Attributes[3, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  165. Grid_Attributes[4, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  166. Grid_Attributes[5, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  167. Grid_Attributes[6, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  168. Grid_Attributes[7, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  169. Grid_Attributes[8, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  170. Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  171. Grid_Attributes[10, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  172. Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
  173. //SourceGrid.Position po = new SourceGrid.Position(1, 0);
  174. //Grid_Attributes[1, 0].Grid.Select();
  175. //Grid_Attributes.Selection.Focus(po, true);
  176. }
  177. public void SetDatatoGrid_Attributes(int STDId)
  178. {
  179. Grid_Attributes[1, 1].Value = STDId;
  180. Grid_Attributes[2, 1].Value = m_MainForm.STDDictionary[STDId].StrName;
  181. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  182. view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[STDId].Color);
  183. Grid_Attributes[3, 1].View = view;
  184. Grid_Attributes[4, 1].Value = m_MainForm.STDDictionary[STDId].Hardness;
  185. Grid_Attributes[5, 1].Value = m_MainForm.STDDictionary[STDId].Density;
  186. Grid_Attributes[6, 1].Value = m_MainForm.STDDictionary[STDId].Electrical_conductivity;
  187. Grid_Attributes[7, 1].Value = int.Parse(m_MainForm.STDDictionary[STDId].BSE);
  188. Grid_Attributes[8, 1].Value = m_MainForm.STDDictionary[STDId].Formula;
  189. Grid_Attributes[9, 1].Value = m_MainForm.STDDictionary[STDId].Element;
  190. m_MainForm.AddSTDGroupsToAttribute();
  191. Grid_Attributes[10, 1].Value = m_MainForm.GroupIdDictionaryFromId[int.Parse(m_MainForm.STDDictionary[STDId].GroupId)];
  192. //SourceGrid.Position po = new SourceGrid.Position(1, 0);
  193. //Grid_Attributes[1, 0].Grid.Select();
  194. //Grid_Attributes.Selection.Focus(po, true);
  195. Grid_Attributes.Refresh();
  196. }
  197. }
  198. }