STDRuleslist.cs 25 KB

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