STDRuleslist.cs 31 KB

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