Attributes.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. /// <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. //if(Grid_Attributes[context.Position.Row, context.Position.Column].Value==null)
  75. //{
  76. // MessageBox.Show("The name of rule cannot be null!", "warnning");
  77. // return;
  78. //}
  79. m_MainForm.ChangeSTDRuleName(Convert.ToString( Grid_Attributes[context.Position.Row, context.Position.Column].Value));
  80. }
  81. private class MyHeader : SourceGrid.Cells.ColumnHeader
  82. {
  83. public MyHeader(object value) : base(value)
  84. {
  85. SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
  86. view.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
  87. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  88. //view.BackColor = Color.Green;
  89. //view.ForeColor= Color.Red;
  90. View = view;
  91. //自带排序true;不实现排序false
  92. AutomaticSortEnabled = false;
  93. }
  94. }
  95. public Attributes(Form_Main mainForm)
  96. {
  97. InitializeComponent();
  98. m_MainForm = mainForm;
  99. }
  100. private void Attributes_Load(object sender, EventArgs e)
  101. {
  102. m_MainForm.lan = new Language(this);
  103. Grid_Attributes.Redim(13, 2);
  104. if (m_MainForm.lan.GetNameTable("Form_ConstantsEditor2")["language"].ToString() == "ZH")
  105. {
  106. //SourceGrid.Cells.ColumnHeader head1 = new SourceGrid.Cells.ColumnHeader("通用属性");
  107. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("通用属性 ", typeof(string));
  108. //head1.AutomaticSortEnabled = false;
  109. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  110. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("规则名称 ", typeof(string));
  111. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("颜色", typeof(string));
  112. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("是否元素分析 ", typeof(string));
  113. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("硬度", typeof(string));
  114. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("密度", typeof(string));
  115. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("导电性", typeof(string));
  116. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("BSE", typeof(string));
  117. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("化学式", typeof(string));
  118. Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("元素", typeof(string));
  119. Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("分组名称", typeof(string));
  120. }
  121. else
  122. {
  123. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("General Properties", typeof(string));
  124. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  125. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("RuleName ", typeof(string));
  126. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("Color", typeof(string));
  127. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("IfElementAnalysis", typeof(string));
  128. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("Hardness", typeof(string));
  129. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("Density", typeof(string));
  130. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("Conductivity", typeof(string));
  131. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("BSE", typeof(string));
  132. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("Formula", typeof(string));
  133. Grid_Attributes[10, 0] = new SourceGrid.Cells.Cell("Element", typeof(string));
  134. Grid_Attributes[11, 0] = new SourceGrid.Cells.Cell("GroupName", typeof(string));
  135. }
  136. Grid_Attributes[1, 1] = new SourceGrid.Cells.Cell(" ", typeof(int));
  137. Grid_Attributes[2, 1] = new SourceGrid.Cells.Cell(" ", typeof(string));
  138. Grid_Attributes[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  139. Grid_Attributes[4, 1] = new SourceGrid.Cells.CheckBox(null, true);
  140. Grid_Attributes[5, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  141. Grid_Attributes[6, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  142. Grid_Attributes[7, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  143. Grid_Attributes[8, 1] = new SourceGrid.Cells.Cell("", typeof(int));
  144. Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  145. Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  146. Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  147. Grid_Attributes[0, 0].ColumnSpan = 2;
  148. Grid_Attributes.AutoStretchColumnsToFitWidth = true;
  149. Grid_Attributes.Columns[0].Width = 195;
  150. Grid_Attributes.Columns[1].Width = 195;
  151. for (int i=0;i<10;i++)
  152. {
  153. Grid_Attributes.Rows[i].Height = 25;
  154. }
  155. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  156. view.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
  157. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  158. view.BackColor = Color.LightGray;
  159. Grid_Attributes[0, 0].View = view;
  160. SourceGrid.Cells.Controllers.CustomEvents EditorEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  161. EditorEvent.EditEnded += new EventHandler(EditorEvent_EditEnded);
  162. Grid_Attributes[2, 1].AddController(EditorEvent);
  163. SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  164. clickEvent.Click += new EventHandler(clickEvent_Click);
  165. Grid_Attributes[3,1].AddController(clickEvent);
  166. Grid_Attributes[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  167. Grid_Attributes[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  168. Grid_Attributes[3, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  169. Grid_Attributes[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  170. Grid_Attributes[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  171. Grid_Attributes[2, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  172. Grid_Attributes[3, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  173. Grid_Attributes[4, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  174. Grid_Attributes[5, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  175. Grid_Attributes[6, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  176. Grid_Attributes[7, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  177. Grid_Attributes[8, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  178. Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  179. Grid_Attributes[10, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  180. Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
  181. //SourceGrid.Position po = new SourceGrid.Position(1, 0);
  182. //Grid_Attributes[1, 0].Grid.Select();
  183. //Grid_Attributes.Selection.Focus(po, true);
  184. }
  185. public void SetDatatoGrid_Attributes(int STDId)
  186. {
  187. Grid_Attributes[1, 1].Value = STDId;
  188. Grid_Attributes[2, 1].Value = m_MainForm.STDDictionary[STDId].StrName;
  189. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  190. view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[STDId].Color);
  191. Grid_Attributes[3, 1].View = view;
  192. Grid_Attributes[4, 1].Value = Convert.ToBoolean(m_MainForm.STDDictionary[STDId].IfElementAnalysis);
  193. Grid_Attributes[5, 1].Value = m_MainForm.STDDictionary[STDId].Hardness;
  194. Grid_Attributes[6, 1].Value = m_MainForm.STDDictionary[STDId].Density;
  195. Grid_Attributes[7, 1].Value = m_MainForm.STDDictionary[STDId].Electrical_conductivity;
  196. Grid_Attributes[8, 1].Value = int.Parse(m_MainForm.STDDictionary[STDId].BSE);
  197. Grid_Attributes[9, 1].Value = m_MainForm.STDDictionary[STDId].Formula;
  198. Grid_Attributes[10, 1].Value = m_MainForm.STDDictionary[STDId].Element;
  199. //m_MainForm.AddSTDGroupsToAttribute();
  200. Grid_Attributes[11, 1].Value = m_MainForm.GroupIdDictionaryFromId[int.Parse(m_MainForm.STDDictionary[STDId].GroupId)];
  201. //SourceGrid.Position po = new SourceGrid.Position(1, 0);
  202. //Grid_Attributes[1, 0].Grid.Select();
  203. //Grid_Attributes.Selection.Focus(po, true);
  204. Grid_Attributes.Refresh();
  205. }
  206. }
  207. }