STDRuleslist.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. using OTS.WinFormsUI.Docking;
  2. using SourceGrid;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace OTSPartA_STDEditor
  13. {
  14. public partial class STDRuleslist : DockContent
  15. {
  16. public int PreRow = 1;//之前选中的位置
  17. public Form_Main m_MainForm = null;
  18. ValueChangedEvent m_ValueChangedEvent = null;//单元格内容改变事件
  19. public STDRuleslist(Form_Main mainForm)
  20. {
  21. InitializeComponent();
  22. m_MainForm = mainForm;
  23. m_ValueChangedEvent = new ValueChangedEvent(this);
  24. }
  25. System.Collections.Hashtable table_STDRuleslist;
  26. private void STDRuleslist_Load(object sender, EventArgs e)
  27. {
  28. m_MainForm.lan = new Language(this);
  29. table_STDRuleslist = m_MainForm.lan.GetNameTable("Attributes");
  30. Grid_Minerals.Redim(m_MainForm.STDDictionary.Count + 1, 2);
  31. SourceGrid.Cells.ColumnHeader head1 = null;
  32. if (m_MainForm.lan.GetNameTable("Form_ConstantsEditor2")["language"].ToString() == "EN")
  33. {
  34. head1 = new SourceGrid.Cells.ColumnHeader("Rule Name");
  35. }
  36. else
  37. {
  38. head1 = new SourceGrid.Cells.ColumnHeader("规则名称");
  39. }
  40. Grid_Minerals[0, 0] = head1;
  41. SourceGrid.Cells.ColumnHeader head2 = null;
  42. if (m_MainForm.lan.GetNameTable("Form_ConstantsEditor2")["language"].ToString() == "EN")
  43. {
  44. head2 = new SourceGrid.Cells.ColumnHeader("Color");
  45. }
  46. else
  47. {
  48. head2 = new SourceGrid.Cells.ColumnHeader("颜色");
  49. }
  50. Grid_Minerals[0, 1] = head2;
  51. SourceGrid.Cells.Views.ColumnHeader boldHeader = new SourceGrid.Cells.Views.ColumnHeader();
  52. boldHeader.Font = new Font("Microsoft YaHei UI", 11, FontStyle.Bold);
  53. boldHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  54. Grid_Minerals[0, 0].View = boldHeader;
  55. Grid_Minerals[0, 1].View = boldHeader;
  56. Grid_Minerals.Rows.SetHeight(0, 25);
  57. head1.AutomaticSortEnabled = false;
  58. head2.AutomaticSortEnabled = false;
  59. Grid_Minerals.Selection.EnableMultiSelection = false;
  60. Grid_Minerals.AutoStretchColumnsToFitWidth = true;
  61. Grid_Minerals.Columns[0].Width = this.Width/2-10;
  62. Grid_Minerals.Columns[1].Width = this.Width/2-20;
  63. int i = 1;
  64. foreach (KeyValuePair<int, STDdata> kv in m_MainForm.STDDictionary)
  65. {
  66. Grid_Minerals[i, 0] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
  67. Grid_Minerals.Rows[i].Height = 25;
  68. Grid_Minerals[i, 0].Tag = kv.Key;
  69. Grid_Minerals[i, 1] = new SourceGrid.Cells.Cell();
  70. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  71. view.BackColor = colorHx16toRGB(kv.Value.Color);
  72. Grid_Minerals[i, 1].View = view;
  73. i++;
  74. }
  75. Grid_Minerals.Controller.AddController(m_ValueChangedEvent);
  76. Grid_Minerals.FixedRows = 1;// 第一行是列标题不可以滚动
  77. Grid_Minerals.Selection.FocusStyle = FocusStyle.None;
  78. button_UpOrder.Enabled = false;
  79. button_DownOrder.Enabled = false;
  80. }
  81. /// <summary>
  82. /// [颜色:16进制转成RGB]
  83. /// </summary>
  84. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  85. /// <returns></returns>
  86. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  87. {
  88. try
  89. {
  90. if (strHxColor.Length == 0)
  91. {//如果为空
  92. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  93. }
  94. else
  95. {//转换颜色
  96. 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));
  97. }
  98. }
  99. catch
  100. {//设为白色
  101. return System.Drawing.Color.FromArgb(255, 255, 204);
  102. }
  103. }
  104. private void MineralsGrid_Click(object sender, EventArgs e)
  105. {
  106. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  107. ls_gd.Focus();
  108. int i = ls_gd.Selection.ActivePosition.Row;
  109. int j = ls_gd.Selection.ActivePosition.Column;
  110. //string jj =m_MainForm.m_Attributes.Grid_Attributes[10, 1].Value.ToString();
  111. /// 保证鼠标点击的GRID行和列是有效的
  112. if (i >= 0 && j >= 0)
  113. {
  114. //规则名称不为空
  115. if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
  116. {
  117. if (m_MainForm.CheckAttributes() && m_MainForm.Checktextbox_STDEditor())
  118. {
  119. m_MainForm.SaveDataOfSelRule(PreRow, 0);
  120. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[i, 0].Tag.ToString()));
  121. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  122. PreRow = i;
  123. }
  124. else
  125. {
  126. Position pos = new Position(PreRow, 0);
  127. Grid_Minerals.Selection.Focus(pos, true);
  128. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  129. }
  130. }
  131. else
  132. {
  133. Position pos = new Position(PreRow, 0);
  134. Grid_Minerals.Selection.Focus(pos, true);
  135. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  136. }
  137. }
  138. SetOrderButtonsStatus();
  139. }
  140. /// <summary>
  141. /// 新建
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void ToolStripMenuItem_New_Click(object sender, EventArgs e)
  146. {
  147. int i = Grid_Minerals.Selection.ActivePosition.Row;
  148. int j = Grid_Minerals.Selection.ActivePosition.Column;
  149. /// 保证鼠标点击的GRID行和列是有效的
  150. if (i >= 0 && j >= 0)
  151. {
  152. //规则名称不为空
  153. if (Grid_Minerals[i, j].Value.ToString().Replace(" ", "").Trim() != "")
  154. {
  155. if (m_MainForm.CheckAttributes())
  156. {
  157. if (m_MainForm.Checktextbox_STDEditor())
  158. {
  159. m_MainForm.SaveDataOfSelRule(i, j);
  160. int STDId = m_MainForm.AddSTDDictionaryItem();
  161. AddNewRow(STDId, "NewRuleName", Color.Gray);
  162. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  163. }
  164. }
  165. }
  166. }
  167. else
  168. {
  169. int STDId = m_MainForm.AddSTDDictionaryItem();
  170. AddNewRow(STDId, "NewRuleName", Color.Gray);
  171. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  172. }
  173. //SetOrderButtonsStatus();
  174. }
  175. public void AddNewRow(int STDId, string RuleName, Color color)
  176. {
  177. Grid_Minerals.Rows.Insert(Grid_Minerals.Rows.Count);
  178. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
  179. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag = STDId;
  180. Grid_Minerals.Rows[Grid_Minerals.Rows.Count - 1].Height = 25;
  181. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1] = new SourceGrid.Cells.Cell();
  182. //Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  183. m_MainForm.STDDictionary[STDId].StrName = RuleName;
  184. m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
  185. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  186. view.BackColor = color;
  187. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1].View = view;
  188. Position pos = new Position(Grid_Minerals.Rows.Count - 1, 0);
  189. Grid_Minerals.Selection.Focus(pos, true);
  190. PreRow = Grid_Minerals.Rows.Count - 1;
  191. SetOrderButtonsStatus();
  192. }
  193. void Grid_MineralsDelRow()
  194. {
  195. int x = Grid_Minerals.Selection.ActivePosition.Row;
  196. if (x > 0)
  197. {
  198. m_MainForm.RemoveSTDDictionaryItem((int)Grid_Minerals[x, 0].Tag);
  199. m_MainForm.m_SubMidWindow.m_STDEditor.DelSTDXray((int)Grid_Minerals[x, 0].Tag);
  200. Grid_Minerals.Rows.Remove(x);
  201. if (Grid_Minerals.RowsCount > 1)
  202. {
  203. if (x != Grid_Minerals.RowsCount)
  204. {
  205. Position pos = new Position(x, 0);
  206. Grid_Minerals.Selection.Focus(pos, true);
  207. Grid_Minerals[x, 0].Grid.Select();
  208. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[x, 0].Tag.ToString()));
  209. PreRow = x;
  210. }
  211. else
  212. {
  213. Position pos = new Position(x - 1, 0);
  214. Grid_Minerals.Selection.Focus(pos, true);
  215. Grid_Minerals[x - 1, 0].Grid.Select();
  216. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[x - 1, 0].Tag.ToString()));
  217. PreRow = x - 1;
  218. }
  219. }
  220. else
  221. {
  222. m_MainForm.SetNull();
  223. PreRow = -1;
  224. }
  225. }
  226. else
  227. {
  228. MessageBox.Show("There is no rule to delete!", "Tip");
  229. }
  230. SetOrderButtonsStatus();
  231. }
  232. private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
  233. {
  234. Grid_MineralsDelRow();
  235. }
  236. public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
  237. {
  238. protected STDRuleslist m_parentWnd = null;
  239. public ValueChangedEvent(STDRuleslist parentWnd)
  240. {
  241. m_parentWnd = parentWnd;
  242. }
  243. public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
  244. {
  245. base.OnValueChanged(sender, e);
  246. if (sender.Value != null&& sender.Value.ToString().Replace(" ", "").Trim() != "")
  247. {
  248. m_parentWnd.ChangeStrName(sender.Position.Row, sender.Value.ToString());
  249. }
  250. else
  251. {
  252. m_parentWnd.ChangeStrName(sender.Position.Row, "NewRuleName");
  253. m_parentWnd.Grid_Minerals[sender.Position.Row,0].Value = "NewRuleName";
  254. }
  255. }
  256. }
  257. public void ChangeStrName(int RowNum, string NewStrName)
  258. {
  259. m_MainForm.ChangeStrName(RowNum, NewStrName);
  260. }
  261. private void Grid_Minerals_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  262. {
  263. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  264. ls_gd.Focus();
  265. int i = ls_gd.Selection.ActivePosition.Row;
  266. int j = ls_gd.Selection.ActivePosition.Column;
  267. if(i==-1)
  268. {
  269. return;
  270. }
  271. if (e.KeyCode == Keys.Up)
  272. {
  273. /// 保证鼠标点击的GRID行和列是有效的
  274. if (i >= 2 && j >= 0)
  275. {
  276. //规则名称不为空
  277. if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
  278. {
  279. if (m_MainForm.CheckAttributes() && m_MainForm.Checktextbox_STDEditor())
  280. {
  281. m_MainForm.SaveDataOfSelRule(i, 0);
  282. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[i - 1, 0].Tag.ToString()));
  283. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  284. PreRow = i;
  285. if (i == 2)
  286. {
  287. button_UpOrder.Enabled = false;
  288. }
  289. if (i == ls_gd.RowsCount - 1)
  290. {
  291. button_DownOrder.Enabled = true;
  292. }
  293. }
  294. else
  295. {
  296. Position pos = new Position(i + 1, 0);
  297. Grid_Minerals.Selection.Focus(pos, true);
  298. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  299. }
  300. }
  301. else
  302. {
  303. Position pos = new Position(i + 1, 0);
  304. Grid_Minerals.Selection.Focus(pos, true);
  305. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  306. }
  307. }
  308. }
  309. if (e.KeyCode == Keys.Down)
  310. {
  311. if (i < ls_gd.RowsCount - 1 && j >= 0)
  312. {
  313. //规则名称不为空
  314. if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
  315. {
  316. if (m_MainForm.CheckAttributes()&& m_MainForm.Checktextbox_STDEditor())
  317. {
  318. m_MainForm.SaveDataOfSelRule(i, 0);
  319. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[i + 1, 0].Tag.ToString()));
  320. PreRow = i;
  321. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  322. if (i == 1)
  323. {
  324. button_UpOrder.Enabled = true;
  325. }
  326. if (i == ls_gd.RowsCount - 2)
  327. {
  328. button_DownOrder.Enabled = false;
  329. }
  330. }
  331. else
  332. {
  333. Position pos = new Position(i - 1, 0);
  334. Grid_Minerals.Selection.Focus(pos, true);
  335. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  336. }
  337. }
  338. else
  339. {
  340. Position pos = new Position(i - 1, 0);
  341. Grid_Minerals.Selection.Focus(pos, true);
  342. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  343. }
  344. }
  345. }
  346. if (e.KeyCode == Keys.Delete)
  347. {
  348. Grid_MineralsDelRow();
  349. }
  350. }
  351. public int ChangeSTDRulesLISTBackColor()
  352. {
  353. if (Grid_Minerals.RowsCount > 1)
  354. {
  355. Position pos = new Position(1, 0);
  356. Grid_Minerals[1, 0].Grid.Select();
  357. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View.BackColor = m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor;
  358. m_MainForm.STDDictionary[(int)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag].Color= Attributes.colorRGBtoHx16(m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
  359. Grid_Minerals.Refresh();
  360. return (int)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag;
  361. }
  362. else
  363. {
  364. return -1;
  365. }
  366. }
  367. private void MenuStrip_STDRulelist_Resize(object sender, EventArgs e)
  368. {
  369. }
  370. private void button_UpOrder_Click(object sender, EventArgs e)
  371. {
  372. Grid_Minerals.Focus(true);
  373. int selrow = Grid_Minerals.Selection.ActivePosition.Row;
  374. int id = (int)Grid_Minerals[selrow, 0].Tag;
  375. int id2 = (int)Grid_Minerals[selrow - 1, 0].Tag;
  376. string sname = Grid_Minerals[selrow, 0].Value.ToString();
  377. Grid_Minerals[selrow, 0].Value = Grid_Minerals[selrow - 1, 0].Value;
  378. Grid_Minerals[selrow, 0].Tag = id2;
  379. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  380. view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id2].Color);
  381. Grid_Minerals[selrow, 1].View = view;
  382. Grid_Minerals[selrow - 1, 0].Value = sname;
  383. Grid_Minerals[selrow - 1, 0].Tag = id;
  384. SourceGrid.Cells.Views.Cell view2 = new SourceGrid.Cells.Views.Cell();
  385. view2.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id].Color);
  386. Grid_Minerals[selrow - 1, 1].View = view2;
  387. m_MainForm.STDDictionary[id].StrName = Grid_Minerals[selrow - 1, 0].Value.ToString();
  388. m_MainForm.STDDictionary[id2].StrName = Grid_Minerals[selrow, 0].Value.ToString();
  389. Position pos = new Position(selrow - 1, 0);
  390. Grid_Minerals[selrow - 1, 0].Grid.Select();
  391. Grid_Minerals.Selection.Focus(pos, true);
  392. PreRow = selrow - 1;
  393. button_DownOrder.Enabled = true;
  394. if (selrow - 1 == 1)
  395. {
  396. button_UpOrder.Enabled = false;
  397. }
  398. m_MainForm.IsModified = true;
  399. //m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[selrow-1, 0].Tag.ToString()));
  400. }
  401. private void button_DownOrder_Click(object sender, EventArgs e)
  402. {
  403. Grid_Minerals.Focus(true);
  404. int selrow = Grid_Minerals.Selection.ActivePosition.Row;
  405. int id = (int)Grid_Minerals[selrow, 0].Tag;
  406. int id2 = (int)Grid_Minerals[selrow + 1, 0].Tag;
  407. string sname = Grid_Minerals[selrow, 0].Value.ToString();
  408. Grid_Minerals[selrow, 0].Value = Grid_Minerals[selrow + 1, 0].Value;
  409. Grid_Minerals[selrow, 0].Tag = id2;
  410. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  411. view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id2].Color);
  412. Grid_Minerals[selrow, 1].View = view;
  413. Grid_Minerals[selrow + 1, 0].Value = sname;
  414. Grid_Minerals[selrow + 1, 0].Tag = id;
  415. SourceGrid.Cells.Views.Cell view2 = new SourceGrid.Cells.Views.Cell();
  416. view2.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id].Color);
  417. Grid_Minerals[selrow + 1, 1].View = view2;
  418. m_MainForm.STDDictionary[id].StrName = Grid_Minerals[selrow + 1, 0].Value.ToString();
  419. m_MainForm.STDDictionary[id2].StrName = Grid_Minerals[selrow, 0].Value.ToString();
  420. Position pos = new Position(selrow + 1, 0);
  421. Grid_Minerals[selrow + 1, 0].Grid.Select();
  422. Grid_Minerals.Selection.Focus(pos, true);
  423. PreRow = selrow + 1;
  424. button_UpOrder.Enabled = true;
  425. if (selrow + 1 == Grid_Minerals.RowsCount - 1)
  426. {
  427. button_DownOrder.Enabled = false;
  428. }
  429. #region 添加修改stdid顺序 ,由于需求改变只完成一部分(差相应修改能谱部分)
  430. //DialogResult result=MessageBox.Show("检测到顺序已修改,是否调整STDId?", "提示",MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  431. //if (result == DialogResult.Yes)
  432. //{
  433. // ChangeSTDidFromNum changeSTDidFromNum = new ChangeSTDidFromNum();
  434. // DialogResult res=changeSTDidFromNum.ShowDialog();
  435. // {
  436. // if (res == DialogResult.OK)
  437. // {
  438. // int StartId = int.Parse(changeSTDidFromNum.textBox_NewFirstSTDId.Text);
  439. // Dictionary<int, STDdata> STDDictionaryCopy = new Dictionary<int, STDdata>();
  440. // for (int i = 0; i < Grid_Minerals.RowsCount-1; i++)
  441. // {
  442. // STDdata dataCopy = m_MainForm.STDDictionary[(int)Grid_Minerals[i+1, 0].Tag];
  443. // STDDictionaryCopy.Add(StartId + i, dataCopy);
  444. // }
  445. // m_MainForm.STDDictionary.Clear();
  446. // m_MainForm.STDDictionary = STDDictionaryCopy;
  447. // }
  448. // }
  449. //}
  450. #endregion
  451. m_MainForm.IsModified = true;
  452. }
  453. public void InsertNewRow(int STDId, string RuleName, Color color)
  454. {
  455. Grid_Minerals.Focus(true);
  456. Grid_Minerals.Rows.InsertRange(Grid_Minerals.Selection.ActivePosition.Row, 1);
  457. //Grid_Minerals.Rows.Insert(Grid_Minerals.Rows.Count);
  458. int i = Grid_Minerals.Selection.ActivePosition.Row;
  459. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
  460. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag = STDId;
  461. Grid_Minerals.Rows[Grid_Minerals.Selection.ActivePosition.Row].Height = 25;
  462. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1] = new SourceGrid.Cells.Cell();
  463. m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
  464. Grid_Minerals.Focus(true);
  465. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  466. view.BackColor = color;
  467. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View = view;
  468. Position pos = new Position(Grid_Minerals.Selection.ActivePosition.Row, 0);
  469. Grid_Minerals.Selection.Focus(pos, true);
  470. PreRow = Grid_Minerals.Selection.ActivePosition.Row - 1;
  471. SetOrderButtonsStatus();
  472. }
  473. private void Grid_Minerals_VScrollPositionChanged(object sender, ScrollPositionChangedEventArgs e)
  474. {
  475. //Grid_Minerals.Refresh();
  476. }
  477. void SetOrderButtonsStatus()
  478. {
  479. Grid_Minerals.Focus();
  480. int i = Grid_Minerals.Selection.ActivePosition.Row;
  481. int j = Grid_Minerals.Selection.ActivePosition.Column;
  482. if (i != -1)
  483. {
  484. if (i == 1)
  485. {
  486. button_UpOrder.Enabled = false;
  487. }
  488. else
  489. {
  490. button_UpOrder.Enabled = true;
  491. }
  492. if (i == Grid_Minerals.RowsCount - 1)
  493. {
  494. button_DownOrder.Enabled = false;
  495. }
  496. else
  497. {
  498. button_DownOrder.Enabled = true;
  499. }
  500. }
  501. else
  502. {
  503. button_UpOrder.Enabled = false;
  504. button_DownOrder.Enabled = false;
  505. }
  506. }
  507. }
  508. }