STDRuleslist.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. using OTS.WinFormsUI.Docking;
  2. using SourceGrid;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.Runtime.InteropServices;
  8. using System.Windows.Forms;
  9. namespace OTSPartA_STDEditor
  10. {
  11. public partial class STDRuleslist : DockContent
  12. {
  13. public STDdata Predata = null;//之前选中的位置
  14. public Form_Main m_MainForm = null;
  15. ValueChangedEvent m_ValueChangedEvent = null;//单元格内容改变事件
  16. Dictionary<int,STDGroups> GroupViewDic=null;
  17. public STDRuleslist(Form_Main mainForm)
  18. {
  19. InitializeComponent();
  20. m_MainForm = mainForm;
  21. m_ValueChangedEvent = new ValueChangedEvent(this);
  22. }
  23. System.Collections.Hashtable table_STDRuleslist;
  24. private void STDRuleslist_Load(object sender, EventArgs e)
  25. {
  26. m_MainForm.lan = new Language(this);
  27. table_STDRuleslist = m_MainForm.lan.GetNameTable("Attributes");
  28. InitRuleView();
  29. button_UpOrder.Enabled = false;
  30. button_DownOrder.Enabled = false;
  31. }
  32. /// <summary>
  33. /// [颜色:16进制转成RGB]
  34. /// </summary>
  35. /// <param name="strColor">设置16进制颜色 [返回RGB]</param>
  36. /// <returns></returns>
  37. public static System.Drawing.Color colorHx16toRGB(string strHxColor)
  38. {
  39. try
  40. {
  41. if (strHxColor.Length == 0)
  42. {//如果为空
  43. return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色
  44. }
  45. else
  46. {//转换颜色
  47. 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));
  48. }
  49. }
  50. catch
  51. {//设为白色
  52. return System.Drawing.Color.FromArgb(255, 255, 204);
  53. }
  54. }
  55. private void MineralsGrid_Click(object sender, EventArgs e)
  56. {
  57. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  58. ls_gd.Focus();
  59. int i = ls_gd.Selection.ActivePosition.Row;
  60. int j = ls_gd.Selection.ActivePosition.Column;
  61. if (i >= 0 && j >= 0)
  62. {
  63. if (Predata != null)
  64. {
  65. m_MainForm.SaveDataOfSelRule(Predata.STDId);
  66. }
  67. m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i, 0].Tag).STDId);
  68. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  69. Predata = (STDdata)Grid_Minerals[i, 0].Tag;
  70. }
  71. SetOrderButtonsStatus();
  72. }
  73. private void ToolStripMenuItem_New_Click(object sender, EventArgs e)
  74. {
  75. int i = Grid_Minerals.Selection.ActivePosition.Row;
  76. int j = Grid_Minerals.Selection.ActivePosition.Column;
  77. if (i >= 0 && j >= 0)
  78. {
  79. int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
  80. m_MainForm.SaveDataOfSelRule(id);
  81. Predata = (STDdata)Grid_Minerals[i, 0].Tag;
  82. int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
  83. AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
  84. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  85. }
  86. else
  87. {
  88. int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
  89. AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
  90. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  91. }
  92. }
  93. public void AddNewRow(int STDId, string RuleName, Color color)
  94. {
  95. Grid_Minerals.Rows.Insert(Grid_Minerals.Rows.Count);
  96. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
  97. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag = m_MainForm._sTDEditor.STDDictionary[STDId];
  98. Grid_Minerals.Rows[Grid_Minerals.Rows.Count - 1].Height = 25;
  99. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1] = new SourceGrid.Cells.Cell();
  100. m_MainForm._sTDEditor.STDDictionary[STDId].StrName = RuleName;
  101. m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
  102. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  103. view.BackColor = color;
  104. Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1].View = view;
  105. Position pos = new Position(Grid_Minerals.Rows.Count - 1, 0);
  106. Grid_Minerals.Selection.Focus(pos, true);
  107. Predata = (STDdata)Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag;
  108. SetOrderButtonsStatus();
  109. }
  110. void Grid_MineralsDelRow()
  111. {
  112. int x = Grid_Minerals.Selection.ActivePosition.Row;
  113. if (x > 0)
  114. {
  115. m_MainForm.RemoveSTDDictionaryItem(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
  116. Grid_Minerals.Rows.Remove(x);
  117. if (Grid_Minerals.RowsCount > 1)
  118. {
  119. if (x != Grid_Minerals.RowsCount)
  120. {
  121. Position pos = new Position(x, 0);
  122. Grid_Minerals.Selection.Focus(pos, true);
  123. Grid_Minerals[x, 0].Grid.Select();
  124. m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
  125. Predata = (STDdata)Grid_Minerals[x, 0].Tag;
  126. }
  127. else
  128. {
  129. Position pos = new Position(x - 1, 0);
  130. Grid_Minerals.Selection.Focus(pos, true);
  131. Grid_Minerals[x - 1, 0].Grid.Select();
  132. m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x-1, 0].Tag).STDId);
  133. Predata = (STDdata)Grid_Minerals[x-1, 0].Tag;
  134. }
  135. }
  136. else
  137. {
  138. m_MainForm.SetNull();
  139. Predata = null;
  140. }
  141. }
  142. else
  143. {
  144. MessageBox.Show("There is no rule to delete!", "Tip");
  145. }
  146. }
  147. private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
  148. {
  149. Grid_MineralsDelRow();
  150. }
  151. public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
  152. {
  153. protected STDRuleslist m_parentWnd = null;
  154. public ValueChangedEvent(STDRuleslist parentWnd)
  155. {
  156. m_parentWnd = parentWnd;
  157. }
  158. public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)
  159. {
  160. base.OnValueChanged(sender, e);
  161. if (sender.Value != null&& sender.Value.ToString().Replace(" ", "").Trim() != "")
  162. {
  163. m_parentWnd.ChangeStrName(sender.Position.Row, sender.Value.ToString());
  164. }
  165. else
  166. {
  167. m_parentWnd.ChangeStrName(sender.Position.Row, "NewRuleName");
  168. m_parentWnd.Grid_Minerals[sender.Position.Row,0].Value = "NewRuleName";
  169. }
  170. }
  171. }
  172. public void ChangeStrName(int RowNum, string NewStrName)
  173. {
  174. m_MainForm.ChangeStrName(RowNum, NewStrName);
  175. }
  176. private void Grid_Minerals_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  177. {
  178. SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
  179. ls_gd.Focus();
  180. int i = ls_gd.Selection.ActivePosition.Row;
  181. int j = ls_gd.Selection.ActivePosition.Column;
  182. if(i==-1)
  183. {
  184. return;
  185. }
  186. if (e.KeyCode == Keys.Up)
  187. {
  188. if (i >= 2 && j >= 0)
  189. {
  190. //规则名称不为空
  191. if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
  192. {
  193. int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
  194. m_MainForm.SaveDataOfSelRule(id);
  195. m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i - 1, 0].Tag).STDId);
  196. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  197. Predata = (STDdata)Grid_Minerals[i - 1, 0].Tag;
  198. if (i == 2)
  199. {
  200. button_UpOrder.Enabled = false;
  201. }
  202. if (i == ls_gd.RowsCount - 1)
  203. {
  204. button_DownOrder.Enabled = true;
  205. }
  206. }
  207. else
  208. {
  209. Position pos = new Position(i + 1, 0);
  210. Grid_Minerals.Selection.Focus(pos, true);
  211. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  212. }
  213. }
  214. }
  215. if (e.KeyCode == Keys.Down)
  216. {
  217. if (i < ls_gd.RowsCount - 1 && j >= 0)
  218. {
  219. if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
  220. {
  221. int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
  222. m_MainForm.SaveDataOfSelRule(id);
  223. m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i + 1, 0].Tag).STDId);
  224. Predata = (STDdata)Grid_Minerals[i+1, 0].Tag;
  225. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  226. if (i == 1)
  227. {
  228. button_UpOrder.Enabled = true;
  229. }
  230. if (i == ls_gd.RowsCount - 2)
  231. {
  232. button_DownOrder.Enabled = false;
  233. }
  234. }
  235. else
  236. {
  237. Position pos = new Position(i - 1, 0);
  238. Grid_Minerals.Selection.Focus(pos, true);
  239. m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  240. }
  241. }
  242. }
  243. if (e.KeyCode == Keys.Delete)
  244. {
  245. Grid_MineralsDelRow();
  246. }
  247. }
  248. public int ChangeSTDRulesLISTBackColor()
  249. {
  250. if (tabControl1.SelectedIndex == 1)
  251. {
  252. if (Grid_Minerals.RowsCount > 1)
  253. {
  254. Position pos = new Position(1, 0);
  255. Grid_Minerals[1, 0].Grid.Select();
  256. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View.BackColor = m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor;
  257. m_MainForm._sTDEditor.STDDictionary[((STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag).STDId].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);
  258. Grid_Minerals.Refresh();
  259. return ((STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag).STDId;
  260. }
  261. else
  262. {
  263. return -1;
  264. }
  265. }
  266. else
  267. {
  268. if(treeView_G.SelectedNode.Level==0)
  269. {
  270. return -1;
  271. }
  272. STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
  273. int id= ddata.STDId;
  274. m_MainForm._sTDEditor.STDDictionary[id].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);
  275. InitGroupView();
  276. foreach(TreeNode treeNode in treeView_G.Nodes)
  277. {
  278. if(((STDGroups)treeNode.Tag).id== ddata.GroupId)
  279. {
  280. foreach (TreeNode node in treeNode.Nodes)
  281. {
  282. if (((STDdata)node.Tag).STDId == id)
  283. {
  284. treeView_G.SelectedNode = node;
  285. Predata = (STDdata)node.Tag;
  286. }
  287. }
  288. }
  289. }
  290. return id;
  291. }
  292. }
  293. private void button_UpOrder_Click(object sender, EventArgs e)
  294. {
  295. }
  296. private void button_DownOrder_Click(object sender, EventArgs e)
  297. {
  298. }
  299. public void InsertNewRow(int STDId, string RuleName, Color color)
  300. {
  301. Grid_Minerals.Focus(true);
  302. Grid_Minerals.Rows.InsertRange(Grid_Minerals.Selection.ActivePosition.Row, 1);
  303. int i = Grid_Minerals.Selection.ActivePosition.Row;
  304. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
  305. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag = m_MainForm._sTDEditor.STDDictionary[STDId];
  306. Grid_Minerals.Rows[Grid_Minerals.Selection.ActivePosition.Row].Height = 25;
  307. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1] = new SourceGrid.Cells.Cell();
  308. m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
  309. Grid_Minerals.Focus(true);
  310. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  311. view.BackColor = color;
  312. Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View = view;
  313. Position pos = new Position(Grid_Minerals.Selection.ActivePosition.Row, 0);
  314. Grid_Minerals.Selection.Focus(pos, true);
  315. Predata = (STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row - 1, 0].Tag ;
  316. SetOrderButtonsStatus();
  317. }
  318. void SetOrderButtonsStatus()
  319. {
  320. Grid_Minerals.Focus();
  321. int i = Grid_Minerals.Selection.ActivePosition.Row;
  322. int j = Grid_Minerals.Selection.ActivePosition.Column;
  323. if (i != -1)
  324. {
  325. if (i == 1)
  326. {
  327. button_UpOrder.Enabled = false;
  328. }
  329. else
  330. {
  331. button_UpOrder.Enabled = true;
  332. }
  333. if (i == Grid_Minerals.RowsCount - 1)
  334. {
  335. button_DownOrder.Enabled = false;
  336. }
  337. else
  338. {
  339. button_DownOrder.Enabled = true;
  340. }
  341. }
  342. else
  343. {
  344. button_UpOrder.Enabled = false;button_DownOrder.Enabled = false;
  345. }
  346. }
  347. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  348. {
  349. if (Predata != null)
  350. {
  351. m_MainForm.SaveDataOfSelRule(Predata.STDId);
  352. }
  353. if (tabControl1.SelectedIndex == 0)
  354. {
  355. Predata = null;
  356. InitGroupEditorView();
  357. }
  358. else if (tabControl1.SelectedIndex == 1)
  359. {
  360. ConvertToRuleViewDic();
  361. InitRuleView();
  362. //int i = Grid_Minerals.Selection.ActivePosition.Row;
  363. //int j = Grid_Minerals.Selection.ActivePosition.Column;
  364. //if (i >= 0 && j >= 0)
  365. //{
  366. // int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
  367. // if (m_MainForm._sTDEditor.STDDictionary.ContainsKey(id))
  368. // {
  369. // m_MainForm.ChangeSTDEditorAndGrid_Attributes(id);
  370. // Predata = (STDdata)Grid_Minerals[i, 0].Tag;
  371. // }
  372. if (m_MainForm._sTDEditor.STDDictionary.Count == 0)
  373. {
  374. m_MainForm.SetNull();
  375. Predata = null;
  376. }
  377. else
  378. {
  379. Position pos = new Position(1, 0);
  380. Grid_Minerals[1, 0].Grid.Select();
  381. Grid_Minerals.Selection.Focus(pos, true);
  382. Grid_Minerals.Refresh();
  383. m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[1, 0].Tag).STDId);
  384. Predata = (STDdata)Grid_Minerals[1, 0].Tag;
  385. }
  386. //}
  387. }
  388. }
  389. void InitGroupEditorView()
  390. {
  391. GroupViewDic = ConvertToGroupViewDic();
  392. InitGroupView();
  393. }
  394. Dictionary<int, STDGroups> ConvertToGroupViewDic()
  395. {
  396. Dictionary<int, STDGroups> keyValuePairs = new Dictionary<int, STDGroups>();
  397. keyValuePairs = m_MainForm._sTDEditor.GroupDictionary;
  398. foreach (STDGroups group in keyValuePairs.Values)
  399. {
  400. group.ContainSTD.Clear();
  401. }
  402. foreach (STDdata Ddata in m_MainForm._sTDEditor.STDDictionary.Values)
  403. {
  404. keyValuePairs[Ddata.GroupId].ContainSTD.Add(Ddata);
  405. }
  406. return keyValuePairs;
  407. }
  408. public void ConvertToRuleViewDic()
  409. {
  410. m_MainForm._sTDEditor.GroupIdDictionaryFromId.Clear();
  411. m_MainForm._sTDEditor.GroupIdDictionaryFromName.Clear();
  412. m_MainForm._sTDEditor.STDDictionary.Clear();
  413. foreach (STDGroups group in GroupViewDic.Values)
  414. {
  415. foreach (STDdata Ddata in group.ContainSTD)
  416. {
  417. m_MainForm._sTDEditor.STDDictionary.Add(Ddata.STDId, Ddata);
  418. }
  419. m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(group.name.ToString(), int.Parse(group.id.ToString()));
  420. m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(int.Parse(group.id.ToString()), group.name.ToString());
  421. }
  422. if (treeView_G.SelectedNode == null){return;}
  423. if (treeView_G.SelectedNode.Level == 1)
  424. {
  425. m_MainForm.SaveDataOfSelRule(((STDdata)treeView_G.SelectedNode.Tag).STDId);
  426. }
  427. }
  428. private void ToolStripMenuItem_NewGroup_Click(object sender, EventArgs e)
  429. {
  430. STDGroups group = new STDGroups();
  431. int id = 0;
  432. foreach(STDGroups grp in GroupViewDic.Values)
  433. {
  434. if(grp.id>id)
  435. {
  436. id= grp.id;
  437. }
  438. }
  439. id++;
  440. group.id = id;
  441. group.name = "Group" + id.ToString();
  442. group.color = Attributes.colorRGBtoHx16(Color.WhiteSmoke.R, Color.WhiteSmoke.G, Color.WhiteSmoke.B);
  443. GroupViewDic.Add(group.id, group);
  444. m_MainForm.m_Attributes.AddSTDGroupsToAttribute();
  445. this.Refresh();
  446. TreeNode treeNode = new TreeNode();
  447. treeNode.Tag = group;
  448. treeNode.Text = group.name;
  449. m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(id, group.name);
  450. m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(group.name, group.id);
  451. treeView_G.Nodes.Add(treeNode);
  452. treeView_G.SelectedNode = treeNode;
  453. m_MainForm.SetNull();
  454. Predata = null;
  455. }
  456. private void ToolStripMenuItem_DelGroup_Click(object sender, EventArgs e)
  457. {
  458. if(treeView_G.SelectedNode==null)
  459. {
  460. MessageBox.Show("Please select a group!", "Tip");
  461. return;
  462. }
  463. if (treeView_G.SelectedNode.Level == 0)
  464. {
  465. int id = ((STDGroups)treeView_G.SelectedNode.Tag).id;
  466. if(((STDGroups)treeView_G.SelectedNode.Tag).id==0)
  467. {
  468. MessageBox.Show("Can not delete the group which named default!", "Tip");
  469. return;
  470. }
  471. DialogResult result = MessageBox.Show("删除组会一并删除组内规则,是否继续?", "Tip", MessageBoxButtons.YesNo);
  472. if (result == DialogResult.Yes)
  473. {
  474. m_MainForm._sTDEditor.GroupIdDictionaryFromId.Remove(id);
  475. m_MainForm._sTDEditor.GroupIdDictionaryFromName.Remove(GroupViewDic[id].name);
  476. GroupViewDic.Remove(id);
  477. treeView_G.Nodes.Remove(treeView_G.SelectedNode);
  478. this.Refresh();
  479. }
  480. }
  481. else
  482. {
  483. MessageBox.Show("Please select a group!", "Tip");
  484. return;
  485. }
  486. }
  487. private void ToolStripMenuItem_EdGroupColor_Click(object sender, EventArgs e)
  488. {
  489. if(treeView_G.SelectedNode==null)
  490. {
  491. MessageBox.Show("Please select a group!", "Tip");
  492. return;
  493. }
  494. if (treeView_G.SelectedNode.Level == 0)
  495. {
  496. ColorDialog cd = new ColorDialog();
  497. cd.FullOpen = true;//自定义颜色界面打开
  498. DialogResult result = cd.ShowDialog();
  499. if (result == DialogResult.OK)
  500. {
  501. GroupViewDic[((STDGroups)treeView_G.SelectedNode.Tag).id].color = Attributes.colorRGBtoHx16(cd.Color.R, cd.Color.G, cd.Color.B);
  502. InitGroupView();
  503. }
  504. }
  505. else
  506. {
  507. MessageBox.Show("Please select a group!", "Tip");
  508. }
  509. }
  510. void InitGroupView()
  511. {
  512. treeView_G.ImageList=new ImageList();
  513. treeView_G.Nodes.Clear();
  514. treeView_G.ImageList.ColorDepth = ColorDepth.Depth32Bit;
  515. foreach (STDGroups group in GroupViewDic.Values)
  516. {
  517. TreeNode treeNode = new TreeNode();
  518. treeNode.Tag = group;
  519. treeNode.Text = group.name;
  520. Color color = Attributes.colorHx16toRGB(group.color);
  521. Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format32bppArgb);
  522. Graphics graphics = Graphics.FromImage(bitmap);
  523. SolidBrush b1 = new SolidBrush(color);
  524. graphics.FillEllipse(b1, new Rectangle(0, 0, 100, 100));
  525. treeView_G.ImageList.Images.Add(group.id.ToString(),bitmap);
  526. treeNode.ImageKey = group.id.ToString();
  527. treeNode.SelectedImageKey = group.id.ToString();
  528. treeView_G.Nodes.Add(treeNode);
  529. foreach (STDdata ddata in group.ContainSTD)
  530. {
  531. TreeNode childtreeNode = new TreeNode();
  532. childtreeNode.Tag = ddata;
  533. childtreeNode.Text = ddata.StrName;
  534. Color color2 = Attributes.colorHx16toRGB(ddata.Color);
  535. SolidBrush b2 = new SolidBrush(color2);
  536. graphics.FillEllipse(b2, new Rectangle(0, 0, 100, 100));
  537. treeView_G.ImageList.Images.Add("0x"+ ddata.STDId, bitmap);
  538. //bitmap.Save(@"C:\Users\yunyunyun\Desktop\9-9-1\a\"+ ddata.STDId + @".bmp");
  539. childtreeNode.ImageKey = "0x" + ddata.STDId;
  540. childtreeNode.SelectedImageKey = "0x" + ddata.STDId;
  541. treeNode.Nodes.Add(childtreeNode);
  542. }
  543. }
  544. treeView_G.Font = new Font("微软雅黑", 12);
  545. treeView_G.ShowLines = false;
  546. this.Refresh();
  547. }
  548. void InitRuleView()
  549. {
  550. Grid_Minerals.Rows.Clear();
  551. Grid_Minerals.Columns.Clear();
  552. Grid_Minerals.Redim(m_MainForm._sTDEditor.STDDictionary.Count + 1, 2);
  553. SourceGrid.Cells.ColumnHeader head1 = null;
  554. if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "EN")
  555. {
  556. head1 = new SourceGrid.Cells.ColumnHeader("Rule Name");
  557. }
  558. else
  559. {
  560. head1 = new SourceGrid.Cells.ColumnHeader("规则名称");
  561. }
  562. Grid_Minerals[0, 0] = head1;
  563. SourceGrid.Cells.ColumnHeader head2 = null;
  564. if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "EN")
  565. {
  566. head2 = new SourceGrid.Cells.ColumnHeader("Color");
  567. }
  568. else
  569. {
  570. head2 = new SourceGrid.Cells.ColumnHeader("颜色");
  571. }
  572. Grid_Minerals[0, 1] = head2;
  573. SourceGrid.Cells.Views.ColumnHeader boldHeader = new SourceGrid.Cells.Views.ColumnHeader();
  574. boldHeader.Font = new Font("Microsoft YaHei UI", 11, FontStyle.Bold);
  575. boldHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
  576. Grid_Minerals[0, 0].View = boldHeader;
  577. Grid_Minerals[0, 1].View = boldHeader;
  578. Grid_Minerals.Rows.SetHeight(0, 25);
  579. head1.AutomaticSortEnabled = false;
  580. head2.AutomaticSortEnabled = false;
  581. Grid_Minerals.Selection.EnableMultiSelection = false;
  582. Grid_Minerals.AutoStretchColumnsToFitWidth = true;
  583. Grid_Minerals.Columns[0].Width = this.Width / 2 - 15;
  584. Grid_Minerals.Columns[1].Width = this.Width / 2 - 39;
  585. int i = 1;
  586. foreach (KeyValuePair<int, STDdata> kv in m_MainForm._sTDEditor.STDDictionary)
  587. {
  588. Grid_Minerals[i, 0] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
  589. Grid_Minerals.Rows[i].Height = 25;
  590. Grid_Minerals[i, 0].Tag = kv.Value;
  591. Grid_Minerals[i, 1] = new SourceGrid.Cells.Cell();
  592. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  593. view.BackColor = colorHx16toRGB(kv.Value.Color);
  594. Grid_Minerals[i, 1].View = view;
  595. i++;
  596. }
  597. Grid_Minerals.Controller.AddController(m_ValueChangedEvent);
  598. Grid_Minerals.FixedRows = 1;
  599. Grid_Minerals.Selection.FocusStyle = FocusStyle.None;
  600. }
  601. private void treeView_G_ItemDrag(object sender, ItemDragEventArgs e)
  602. {
  603. if (e.Button == MouseButtons.Left)
  604. {
  605. //只处理左键拖拽操作;
  606. m_targetNode = null;
  607. TreeNode _node = (TreeNode)e.Item;
  608. //只允许拖拽子级节点;
  609. if (_node.Level > 0)
  610. {
  611. //开始拖拽;
  612. DoDragDrop(e.Item, DragDropEffects.Move | DragDropEffects.Copy);
  613. }
  614. }
  615. }
  616. TreeNode m_targetNode; //用于记录当前拖拽到的目标节点;
  617. private void treeView_G_DragDrop(object sender, DragEventArgs e)
  618. {
  619. if (m_targetNode != null)
  620. {
  621. TreeNode _node = (TreeNode)e.Data.GetData(typeof(TreeNode));
  622. if (!m_targetNode.Equals(_node))
  623. {
  624. if (m_targetNode.Level == _node.Level)
  625. {
  626. //1. 不同的父节点;
  627. //2. 被拖拽的节点不在目标节点的上面(相邻);
  628. if (!_node.Parent.Equals(m_targetNode.Parent) || m_targetNode.Index - 1 != _node.Index)
  629. {
  630. _node.Remove();
  631. m_targetNode.Parent.Nodes.Insert(m_targetNode.Index, _node);
  632. m_targetNode.Parent.ExpandAll();
  633. }
  634. }
  635. else
  636. {
  637. GroupViewDic[((STDGroups)_node.Parent.Tag).id].ContainSTD.Remove((STDdata)_node.Tag);
  638. _node.Remove();
  639. ((STDdata)_node.Tag).GroupId = ((STDGroups)m_targetNode.Tag).id;
  640. m_targetNode.Nodes.Add(_node);
  641. GroupViewDic[((STDGroups)m_targetNode.Tag).id].ContainSTD.Add((STDdata)_node.Tag);
  642. treeView_G.SelectedNode = _node; // 选中节点
  643. m_targetNode.Expand(); // 展开父节点
  644. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)_node.Tag).STDId.ToString()));
  645. Predata = (STDdata)_node.Tag;
  646. }
  647. }
  648. m_targetNode = null;
  649. _node = null;
  650. }
  651. }
  652. [DllImport("user32.dll")]
  653. private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam,int lParam);
  654. private void treeView_G_DragOver(object sender, DragEventArgs e)
  655. {
  656. const Single scrollRegion = 20;
  657. Point pt = treeView_G.PointToClient(Cursor.Position);
  658. if ((pt.Y + scrollRegion) > treeView_G.Height)
  659. {
  660. SendMessage(treeView_G.Handle, (int)277, (int)1, 0);
  661. }
  662. else if (pt.Y < (treeView_G.Top + scrollRegion))
  663. {
  664. SendMessage(treeView_G.Handle, (int)277, (int)0, 0);
  665. }
  666. TreeNode _node2 = treeView_G.GetNodeAt(treeView_G.PointToClient(new Point(e.X, e.Y)));
  667. m_targetNode = null;
  668. if (_node2 != null)
  669. {
  670. m_targetNode = _node2;
  671. e.Effect = DragDropEffects.Move;
  672. }
  673. else
  674. {
  675. e.Effect = DragDropEffects.None;
  676. }
  677. }
  678. private void treeView_G_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  679. {
  680. if(Predata!=null)
  681. {
  682. m_MainForm.SaveDataOfSelRule(Predata.STDId);
  683. }
  684. if(e.Node.Level==0)
  685. {
  686. m_MainForm.SetNull();
  687. Predata = null;
  688. }
  689. else
  690. {
  691. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)e.Node.Tag).STDId.ToString()));
  692. Predata = (STDdata)e.Node.Tag;
  693. }
  694. }
  695. public void AdjustTreenodeByGroup(int Groupid)
  696. {
  697. if (m_MainForm.m_STDRuleslist.tabControl1.SelectedIndex == 1)
  698. {
  699. return;
  700. }
  701. if (treeView_G.SelectedNode.Level == 0)
  702. {
  703. return;
  704. }
  705. STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
  706. TreeNode nodenew = null;
  707. foreach (TreeNode node in treeView_G.Nodes)
  708. {
  709. if (((STDGroups)node.Tag).id == Groupid)
  710. {
  711. nodenew = node;break;
  712. }
  713. }
  714. foreach (TreeNode node in treeView_G.Nodes)
  715. {
  716. foreach (TreeNode node1 in node.Nodes)
  717. {
  718. if (((STDdata)node1.Tag).STDId == ddata.STDId)
  719. {
  720. GroupViewDic[((STDGroups)node.Tag).id].ContainSTD.Remove(ddata);
  721. node1.Remove();
  722. ((STDdata)node1.Tag).GroupId = ddata.GroupId;
  723. nodenew.Nodes.Add(node1);
  724. GroupViewDic[Groupid].ContainSTD.Add(ddata);
  725. treeView_G.SelectedNode = node1;
  726. nodenew.Expand();
  727. m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)node1.Tag).STDId.ToString()));
  728. Predata = ddata;
  729. break;
  730. }
  731. }
  732. }
  733. }
  734. }
  735. }