Attributes.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using OTS.WinFormsUI.Docking;
  2. using SpectrumSTDEditor.BaseClass;
  3. using System;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace SpectrumSTDEditor
  7. {
  8. public partial class Attributes : DockContent
  9. {
  10. public Form_Main m_MainForm = null;
  11. private void clickEvent_Click(object sender, EventArgs e)
  12. {
  13. SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
  14. int i = context.Position.Row;
  15. int j = context.Position.Column;
  16. /// 保证鼠标点击的GRID行和列是有效的
  17. if (i >= 0 && j >= 0)
  18. {
  19. ColorDialog cd = new ColorDialog();
  20. cd.FullOpen = true;//自定义颜色界面打开
  21. DialogResult result = cd.ShowDialog();
  22. if (result == DialogResult.OK)
  23. {
  24. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  25. view.BackColor = cd.Color;
  26. Grid_Attributes[i, j].View = view;
  27. m_MainForm.ChangeSTDRulesLISTBackColor();
  28. }
  29. }
  30. Grid_Attributes.Refresh();
  31. }
  32. private void EditorEvent_EditEnded(object sender, EventArgs e)
  33. {
  34. SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
  35. //if(Grid_Attributes[context.Position.Row, context.Position.Column].Value==null)
  36. //{
  37. // MessageBox.Show("The name of rule cannot be null!", "warnning");
  38. // return;
  39. //}
  40. m_MainForm.ChangeSTDRuleName(Convert.ToString( Grid_Attributes[context.Position.Row, context.Position.Column].Value));
  41. }
  42. private class MyHeader : SourceGrid.Cells.ColumnHeader
  43. {
  44. public MyHeader(object value) : base(value)
  45. {
  46. SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
  47. view.Font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
  48. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft;
  49. //view.BackColor = Color.Green;
  50. //view.ForeColor= Color.Red;
  51. View = view;
  52. //自带排序true;不实现排序false
  53. AutomaticSortEnabled = false;
  54. }
  55. }
  56. public Attributes(Form_Main mainForm)
  57. {
  58. InitializeComponent();
  59. m_MainForm = mainForm;
  60. }
  61. private void Attributes_Load(object sender, EventArgs e)
  62. {
  63. m_MainForm.lan = new Language(this);
  64. Grid_Attributes.Redim(10, 2);
  65. if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "ZH")
  66. {
  67. //SourceGrid.Cells.ColumnHeader head1 = new SourceGrid.Cells.ColumnHeader("通用属性");
  68. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("通用属性 ", typeof(string));
  69. //head1.AutomaticSortEnabled = false;
  70. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  71. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("规则名称 ", typeof(string));
  72. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("中文名称 ", typeof(string));
  73. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("颜色", typeof(string));
  74. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("硬度(HV)", typeof(string));
  75. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("密度(g/m³)", typeof(string));
  76. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("Video", typeof(string));
  77. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("化学式", typeof(string));
  78. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("元素", typeof(string));
  79. }
  80. else
  81. {
  82. Grid_Attributes[0, 0] = new SourceGrid.Cells.Cell("General Properties", typeof(string));
  83. Grid_Attributes[1, 0] = new SourceGrid.Cells.Cell("STDId ", typeof(string));
  84. Grid_Attributes[2, 0] = new SourceGrid.Cells.Cell("RuleName ", typeof(string));
  85. Grid_Attributes[3, 0] = new SourceGrid.Cells.Cell("ChineseName ", typeof(string));
  86. Grid_Attributes[4, 0] = new SourceGrid.Cells.Cell("Color", typeof(string));
  87. Grid_Attributes[5, 0] = new SourceGrid.Cells.Cell("Hardness", typeof(string));
  88. Grid_Attributes[6, 0] = new SourceGrid.Cells.Cell("Density", typeof(string));
  89. Grid_Attributes[7, 0] = new SourceGrid.Cells.Cell("Video", typeof(string));
  90. Grid_Attributes[8, 0] = new SourceGrid.Cells.Cell("Formula", typeof(string));
  91. Grid_Attributes[9, 0] = new SourceGrid.Cells.Cell("Element", typeof(string));
  92. }
  93. Grid_Attributes[1, 1] = new SourceGrid.Cells.Cell(" ", typeof(int));
  94. Grid_Attributes[2, 1] = new SourceGrid.Cells.Cell(" ", typeof(string));
  95. Grid_Attributes[3, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  96. Grid_Attributes[4, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  97. Grid_Attributes[5, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  98. Grid_Attributes[6, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  99. Grid_Attributes[7, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  100. Grid_Attributes[8, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  101. Grid_Attributes[9, 1] = new SourceGrid.Cells.Cell("", typeof(string));
  102. Grid_Attributes[0, 0].ColumnSpan = 2;
  103. Grid_Attributes.AutoStretchColumnsToFitWidth = true;
  104. Grid_Attributes.Columns[0].Width = this.Width / 2 - 30;
  105. Grid_Attributes.Columns[1].Width = this.Width / 2 + 30;
  106. for (int i=0;i<10;i++)
  107. {
  108. Grid_Attributes.Rows[i].Height = 25;
  109. }
  110. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  111. view.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
  112. view.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  113. view.BackColor = Color.LightGray;
  114. Grid_Attributes[0, 0].View = view;
  115. SourceGrid.Cells.Controllers.CustomEvents EditorEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  116. EditorEvent.EditEnded += new EventHandler(EditorEvent_EditEnded);
  117. Grid_Attributes[2, 1].AddController(EditorEvent);
  118. SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
  119. clickEvent.Click += new EventHandler(clickEvent_Click);
  120. Grid_Attributes[4,1].AddController(clickEvent);
  121. Grid_Attributes[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  122. Grid_Attributes[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  123. Grid_Attributes[4, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  124. Grid_Attributes[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  125. Grid_Attributes[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  126. Grid_Attributes[2, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  127. Grid_Attributes[3, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  128. Grid_Attributes[4, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  129. Grid_Attributes[5, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  130. Grid_Attributes[6, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  131. Grid_Attributes[7, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  132. Grid_Attributes[8, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  133. Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  134. Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
  135. //SourceGrid.Position po = new SourceGrid.Position(1, 0);
  136. //Grid_Attributes[1, 0].Grid.Select();
  137. //Grid_Attributes.Selection.Focus(po, true);
  138. }
  139. public void SetDatatoGrid_Attributes(int STDId)
  140. {
  141. Grid_Attributes[1, 1].Value = STDId;
  142. Grid_Attributes[2, 1].Value = m_MainForm.STDDictionary[STDId].StrName;
  143. Grid_Attributes[3, 1].Value = m_MainForm.STDDictionary[STDId].ChineseName;
  144. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  145. view.BackColor = shareFunction.string10ToColor(m_MainForm.STDDictionary[STDId].Color);
  146. Grid_Attributes[4, 1].View = view;
  147. Grid_Attributes[5, 1].Value = m_MainForm.STDDictionary[STDId].Hardness;
  148. Grid_Attributes[6, 1].Value = m_MainForm.STDDictionary[STDId].Density;
  149. Grid_Attributes[7, 1].Value = m_MainForm.STDDictionary[STDId].BSE;
  150. Grid_Attributes[8, 1].Value = m_MainForm.STDDictionary[STDId].Formula;
  151. Grid_Attributes[9, 1].Value = m_MainForm.STDDictionary[STDId].Element;
  152. //SourceGrid.Position po = new SourceGrid.Position(1, 0);
  153. //Grid_Attributes[1, 0].Grid.Select();
  154. //Grid_Attributes.Selection.Focus(po, true);
  155. Grid_Attributes.Refresh();
  156. }
  157. public void SetDatatoGrid_Attributes(STDdata sTDdata)
  158. {
  159. Grid_Attributes[1, 1].Value = "";
  160. Grid_Attributes[2, 1].Value = sTDdata.StrName;
  161. Grid_Attributes[3, 1].Value = sTDdata.ChineseName;
  162. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  163. view.BackColor = shareFunction.string10ToColor(sTDdata.Color);
  164. Grid_Attributes[4, 1].View = view;
  165. Grid_Attributes[5, 1].Value = sTDdata.Hardness;
  166. Grid_Attributes[6, 1].Value = sTDdata.Density;
  167. Grid_Attributes[7, 1].Value = sTDdata.BSE;
  168. Grid_Attributes[8, 1].Value = sTDdata.Formula;
  169. Grid_Attributes[9, 1].Value = sTDdata.Element;
  170. Grid_Attributes.Refresh();
  171. }
  172. }
  173. }