ReferenceLibrary.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. using OTS.WinFormsUI.Docking;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSPartA_STDEditor
  12. {
  13. public partial class ReferenceLibrary : DockContent
  14. {
  15. public SubMidWindow m_SubMidWindow = null;
  16. protected SourceGrid.Cells.Views.Cell m_CellGroupType = null;
  17. public Dictionary<int, STDdata> ReferenceDictionary = new Dictionary<int, STDdata>();
  18. List<STDEditor.STDXray> ReferenceXrayList = null;
  19. byte[] ReferencexrayByteData = null;
  20. System.Collections.Hashtable table_ReferenceLibrary;
  21. Dictionary<int, string> ReferenceGroup = new Dictionary<int, string>();
  22. public ReferenceLibrary(SubMidWindow SubMidWindow)
  23. {
  24. InitializeComponent();
  25. m_SubMidWindow = SubMidWindow;
  26. }
  27. private void InitGrid()
  28. {
  29. int iColumnWidth = 20; // 第一列的宽度
  30. int width = this.Width;
  31. PropGrid.Redim(1, 12);
  32. PropGrid.Columns.SetWidth(0, iColumnWidth);
  33. PropGrid.Columns.AutoSizeColumn(2); // 固定进度条
  34. PropGrid.Columns.SetWidth(2, 1 * (width - iColumnWidth) / 30);
  35. PropGrid.Columns.SetWidth(3, 25 * (width - iColumnWidth) / 30);
  36. PropGrid.Columns.SetWidth(4, 3 * (width - iColumnWidth) / 30);
  37. PropGrid.Columns.SetWidth(5, 1 * (width - iColumnWidth) / 30);
  38. PropGrid.Columns.SetWidth(6, 1 * (width - iColumnWidth) / 30);
  39. PropGrid.Columns.SetWidth(7, 2 * (width - iColumnWidth) / 30);
  40. PropGrid.Columns.SetWidth(8, 1 * (width - iColumnWidth) / 30);
  41. PropGrid.Columns.SetWidth(9, 3 * (width - iColumnWidth) / 30);
  42. PropGrid.Columns.SetWidth(10, 10 * (width - iColumnWidth) / 30);
  43. PropGrid.Columns.SetWidth(11, 1 * (width - iColumnWidth) / 30);
  44. PropGrid.AutoStretchColumnsToFitWidth = true;
  45. // 创建列标题
  46. if (null == PropGrid[0, 1])
  47. {
  48. List<String> listColName = new List<string>();
  49. if (m_SubMidWindow.m_MainForm.lan.GetNameTable("Form_ConstantsEditor2")["language"].ToString() == "ZH")
  50. {
  51. listColName.Add("规则名称");
  52. listColName.Add("颜色");
  53. listColName.Add("表达式");
  54. listColName.Add("必须存在元素");
  55. listColName.Add("硬度");
  56. listColName.Add("密度");
  57. listColName.Add("导电性");
  58. listColName.Add("BSE");
  59. listColName.Add("化学式");
  60. listColName.Add("元素");
  61. listColName.Add("分组名称");
  62. }
  63. else
  64. {
  65. listColName.Add("Rule Name");
  66. listColName.Add("Color");
  67. listColName.Add("Expression");
  68. listColName.Add("Elements must exist");
  69. listColName.Add("Hardness");
  70. listColName.Add("Density");
  71. listColName.Add("Conductivity");
  72. listColName.Add("BSE");
  73. listColName.Add("Formula");
  74. listColName.Add("Element");
  75. listColName.Add("GroupName");
  76. }
  77. for (int i = 0; i < listColName.Count; i++)
  78. {
  79. if (null == PropGrid[0, 1 + i])
  80. {
  81. PropGrid[0, 1 + i] = new SourceGrid.Cells.Cell(listColName[i]);
  82. }
  83. else
  84. {
  85. PropGrid[0, 1 + i].Value = listColName[i];
  86. }
  87. }
  88. PropGrid.FixedRows = 1; // 第一行是列标题不可以滚动
  89. PropGrid.Selection.EnableMultiSelection = false;
  90. PropGrid.Refresh();
  91. }
  92. }
  93. private void ComparativeLibrary_Load(object sender, EventArgs e)
  94. {
  95. m_SubMidWindow.m_MainForm.lan = new Language(this);
  96. table_ReferenceLibrary = m_SubMidWindow.m_MainForm.lan.GetNameTable("ReferenceLibrary");
  97. InitGrid();
  98. }
  99. bool LoadClassifyToDictionary(string DBAddress, ref Dictionary<int, STDdata> STDDictionary)
  100. {
  101. try
  102. {
  103. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  104. m_dbConnection.Open();
  105. //加载STD信息
  106. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD", m_dbConnection);
  107. DataSet ds = new DataSet();
  108. m_dataAdapter.Fill(ds);
  109. DataTable dt = ds.Tables[0];
  110. ReferenceGroup.Clear();
  111. STDDictionary.Clear();
  112. if (dt != null)
  113. {
  114. if (dt.Rows.Count > 0)
  115. {
  116. foreach (DataRow item in dt.Rows)
  117. {
  118. STDdata new_STDdata = new STDdata();
  119. new_STDdata.Hardness = item["Hardness"].ToString();
  120. new_STDdata.Density = item["Density"].ToString();
  121. new_STDdata.Electrical_conductivity = item["Electrical_conductivity"].ToString();
  122. new_STDdata.BSE = item["BSE"].ToString();
  123. new_STDdata.Formula = item["Formula"].ToString();
  124. new_STDdata.Element = item["Formula"].ToString();
  125. new_STDdata.StrName = item["StrName"].ToString();
  126. new_STDdata.Expression = item["Expression"].ToString();
  127. new_STDdata.Color = item["Color"].ToString();
  128. new_STDdata.KeyElementList = item["KeyElementList"].ToString();
  129. new_STDdata.SubElementList = item["SubElementList"].ToString();
  130. new_STDdata.GroupId = item["GroupId"].ToString();
  131. STDDictionary.Add(int.Parse(item["STDId"].ToString()), new_STDdata);
  132. }
  133. }
  134. }
  135. //加载Xray信息
  136. System.Data.SQLite.SQLiteDataAdapter m_dataAdapterXray = new System.Data.SQLite.SQLiteDataAdapter("select Id,SPEC from STDMinerals", m_dbConnection);
  137. DataSet dsXray = new DataSet();
  138. m_dataAdapterXray.Fill(dsXray);
  139. DataTable dtXray = dsXray.Tables[0];
  140. ReferenceXrayList=new List<STDEditor.STDXray>();
  141. if (dtXray != null)
  142. {
  143. if (dtXray.Rows.Count > 0)
  144. {
  145. foreach (DataRow item in dtXray.Rows)
  146. {
  147. STDEditor.STDXray sXray = new STDEditor.STDXray();
  148. sXray.StdID = item["Id"].ToString();
  149. sXray.XrayData = (byte[])item["SPEC"];
  150. ReferenceXrayList.Add(sXray);
  151. }
  152. }
  153. }
  154. System.Data.SQLite.SQLiteDataAdapter m_dataAdapterGroup = new System.Data.SQLite.SQLiteDataAdapter("select Id,name from STDGroups", m_dbConnection);
  155. DataSet dsGroup = new DataSet();
  156. m_dataAdapterGroup.Fill(dsGroup);
  157. DataTable dtGroup = dsGroup.Tables[0];
  158. if (dtGroup != null)
  159. {
  160. if (dtGroup.Rows.Count > 0)
  161. {
  162. foreach (DataRow item in dtGroup.Rows)
  163. {
  164. ReferenceGroup.Add(int.Parse(item["Id"].ToString()), item["name"].ToString());
  165. }
  166. }
  167. }
  168. return true;
  169. }
  170. catch (Exception ee)
  171. {
  172. MessageBox.Show("Reference library format error, please open the correct reference library!", "Tip");
  173. return false;
  174. }
  175. }
  176. void AddDataToRefereceLiberary(Dictionary<int, STDdata> RefDictionary)
  177. {
  178. PropGrid.Redim(RefDictionary.Count+1, 12);
  179. int i = 1;
  180. foreach (KeyValuePair<int, STDdata> kv in RefDictionary)
  181. {
  182. if (null == PropGrid[i, 0])
  183. {
  184. PropGrid[i, 0] = new SourceGrid.Cells.CheckBox(null, false);
  185. SourceGrid.Cells.Controllers.CheckBox clickEvent = new SourceGrid.Cells.Controllers.CheckBox();
  186. clickEvent.CheckedChanged += new EventHandler(clickEvent_Click);
  187. PropGrid[i, 0].AddController(clickEvent);
  188. }
  189. else
  190. {
  191. PropGrid[i, 0].Value = false;
  192. }
  193. PropGrid.Rows[i].Height = 25;
  194. PropGrid.Rows[i].Tag = kv.Key;
  195. PropGrid[i, 1] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
  196. PropGrid[i, 1].Tag = kv.Key;
  197. PropGrid[i, 2] = new SourceGrid.Cells.Cell("", typeof(string));
  198. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  199. view.BackColor = STDRuleslist.colorHx16toRGB(kv.Value.Color);
  200. PropGrid[i, 2].View = view;
  201. PropGrid[i, 3] = new SourceGrid.Cells.Cell(kv.Value.Expression, typeof(string));
  202. PropGrid[i, 4] = new SourceGrid.Cells.Cell(kv.Value.KeyElementList, typeof(string));
  203. PropGrid[i, 5] = new SourceGrid.Cells.Cell(kv.Value.Hardness, typeof(string));
  204. PropGrid[i, 6] = new SourceGrid.Cells.Cell(kv.Value.Density, typeof(string));
  205. PropGrid[i, 7] = new SourceGrid.Cells.Cell(kv.Value.Electrical_conductivity, typeof(string));
  206. PropGrid[i, 8] = new SourceGrid.Cells.Cell(kv.Value.BSE, typeof(string));
  207. PropGrid[i, 9] = new SourceGrid.Cells.Cell(kv.Value.Formula, typeof(string));
  208. PropGrid[i, 10] = new SourceGrid.Cells.Cell(kv.Value.Element, typeof(string));
  209. PropGrid[i, 11] = new SourceGrid.Cells.Cell(ReferenceGroup[int.Parse(kv.Value.GroupId)], typeof(string));
  210. i++;
  211. }
  212. PropGrid.AutoSizeCells();
  213. int iColumnWidth = 45; // 第一列的宽度
  214. int width = this.Width;
  215. PropGrid.Columns.SetWidth(0, iColumnWidth);
  216. PropGrid.Columns.SetWidth(2, 1 * (width - iColumnWidth) / 20);
  217. //PropGrid.Columns.SetWidth(3, 25 * (width - iColumnWidth) / 30);
  218. //PropGrid.Columns.SetWidth(4, 3 * (width - iColumnWidth) / 30);
  219. //PropGrid.Columns.SetWidth(5, 1 * (width - iColumnWidth) / 30);
  220. //PropGrid.Columns.SetWidth(6, 1 * (width - iColumnWidth) / 30);
  221. //PropGrid.Columns.SetWidth(7, 2 * (width - iColumnWidth) / 30);
  222. //PropGrid.Columns.SetWidth(8, 1 * (width - iColumnWidth) / 30);
  223. //PropGrid.Columns.SetWidth(9, 3 * (width - iColumnWidth) / 30);
  224. //PropGrid.Columns.SetWidth(10, 10 * (width - iColumnWidth) / 30);
  225. for (int ro = 0; ro < PropGrid.RowsCount; ro++)
  226. {
  227. PropGrid.Rows.SetHeight(ro,25);
  228. }
  229. for (int col = 1; col < PropGrid.ColumnsCount; col++)
  230. {
  231. for (int ro = 0; ro < PropGrid.RowsCount; ro++)
  232. {
  233. PropGrid[ro,col].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
  234. }
  235. }
  236. PropGrid.Refresh();
  237. //为修改bug 第一次点击sourcegrid滚动界面时,取数不准问题(载入数据时将第一次点击落在1,0单元格)
  238. if (PropGrid[1,0] != null)
  239. {
  240. SourceGrid.Position pos = new SourceGrid.Position(1, 0);
  241. PropGrid.Selection.Focus(pos, true);
  242. }
  243. }
  244. public void MakeCheckboxUnchecked()
  245. {
  246. for (int i = 1; i < PropGrid.RowsCount; i++)
  247. {
  248. if ((bool)PropGrid[i, 0].Value == true)
  249. {
  250. PropGrid[i, 0].Value = false;
  251. }
  252. }
  253. }
  254. private void clickEvent_Click(object sender, EventArgs e)
  255. {
  256. int t = PropGrid.Selection.ActivePosition.Column;
  257. if (t == 0)//选择事件
  258. {
  259. if ((bool)PropGrid[PropGrid.Selection.ActivePosition.Row, 0].Value == true)
  260. {
  261. PropGrid[PropGrid.Selection.ActivePosition.Row, 0].Value = false;
  262. m_SubMidWindow.m_STDEditor.ShowXrayAtlas();
  263. }
  264. else
  265. {
  266. int r = PropGrid.Selection.ActivePosition.Row;
  267. SelReferenceXray((int)PropGrid.Rows[r].Tag,ReferenceDictionary[(int)PropGrid.Rows[r].Tag]);
  268. ShowReferenceContent(PropGrid.Rows[r].Tag.ToString());
  269. MakeCheckboxUnchecked();
  270. PropGrid[PropGrid.Selection.ActivePosition.Row, 0].Value = true;
  271. }
  272. PropGrid.Refresh();
  273. }
  274. }
  275. private void ShowReferenceContent(string stdID)
  276. {
  277. if (ReferenceXrayList != null)
  278. {
  279. for (int i = 0; i < ReferenceXrayList.Count; i++)
  280. {
  281. if (ReferenceXrayList[i].StdID == stdID)
  282. {
  283. //获取修改行的信息
  284. ReferencexrayByteData = (byte[])ReferenceXrayList[i].XrayData;
  285. }
  286. }
  287. }
  288. }
  289. /// <summary>
  290. /// 根据选择节点显示对应的Xray信息
  291. /// </summary>
  292. public void SelReferenceXray(int Key, STDdata sT)
  293. {
  294. if (sT == null)
  295. {
  296. return;
  297. }
  298. if (ReferenceXrayList != null)
  299. {
  300. //if (m_STDXrayList.Count > 0)
  301. //{
  302. bool isExists = false;
  303. foreach (STDEditor.STDXray item in ReferenceXrayList)
  304. {
  305. //修改XrayData信息
  306. if (item.StdID == Key.ToString())
  307. {
  308. string selColor = m_SubMidWindow.m_STDEditor.ParseRGB(STDEditor.colorHx16toRGB(sT.Color)).ToString();
  309. int colorValue = Convert.ToInt32(selColor);
  310. //显示Xray信息
  311. if (item.XrayData != null)
  312. {
  313. isExists = true;
  314. m_SubMidWindow.m_STDEditor.ShowXrayAtlas(colorValue, item.XrayData);
  315. }
  316. break;
  317. }
  318. }
  319. if (!isExists)
  320. {
  321. m_SubMidWindow.m_STDEditor.ShowXrayAtlas();
  322. }
  323. //}
  324. }
  325. }
  326. private void TSLoad_Click(object sender, EventArgs e)
  327. {
  328. OpenFileDialog fileSel = new OpenFileDialog();
  329. fileSel.Filter = "(*.db)|*.db";
  330. if (DialogResult.OK == fileSel.ShowDialog())
  331. {
  332. ReferenceDictionary.Clear();
  333. if (LoadClassifyToDictionary(fileSel.FileName, ref ReferenceDictionary))
  334. {
  335. AddDataToRefereceLiberary(ReferenceDictionary);
  336. this.Text += " " + fileSel.FileName;
  337. PropGrid.Refresh();
  338. }
  339. }
  340. }
  341. private void TSClose_Click(object sender, EventArgs e)
  342. {
  343. if (PropGrid.RowsCount > 1)
  344. {
  345. PropGrid.Rows.RemoveRange(1, PropGrid.RowsCount - 1);
  346. m_SubMidWindow.m_STDEditor.ShowXrayAtlas();
  347. ReferenceDictionary.Clear();
  348. this.Text = this.Text.Split(' ')[0];
  349. PropGrid.Refresh();
  350. }
  351. else
  352. {
  353. ReferenceDictionary.Clear();
  354. this.Text = this.Text.Split(' ')[0];
  355. PropGrid.Refresh();
  356. }
  357. }
  358. private void PropGrid_MouseClick(object sender, MouseEventArgs e)
  359. {
  360. SourceGrid.Grid oSender = (SourceGrid.Grid)sender;
  361. oSender.Focus();
  362. // 表示右击的是无效区域, 则退出(第0行是标题)
  363. if (oSender.MouseCellPosition.Row < 1 || oSender.MouseCellPosition.Column < 0)
  364. {
  365. return;
  366. }
  367. // 右击的区域获取焦点
  368. PropGrid.Selection.Focus(new SourceGrid.Position(oSender.MouseCellPosition.Row, oSender.MouseCellPosition.Column), true);
  369. try
  370. {
  371. if (MouseButtons.Right == e.Button && e.Clicks == 1)
  372. {
  373. // 此处编写在什么情况下弹出右击菜单
  374. contextMenuStrip.Show(PointToScreen(e.Location));
  375. // 判断左侧区域是否已经选中了某个stdmineral
  376. bool bEnable = false;
  377. bEnable = (-1 == m_SubMidWindow.m_MainForm.m_STDRuleslist.PreRow) ? false : true;
  378. this.insertToolStripMenuItem.Enabled = bEnable;
  379. }
  380. }
  381. catch (Exception/* ex*/)
  382. {
  383. }
  384. }
  385. private void insertToolStripMenuItem_Click(object sender, EventArgs e)
  386. {
  387. m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Focus(true);
  388. int i = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row;
  389. int j = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column;
  390. /// 保证鼠标点击的GRID行和列是有效的
  391. if (i >= 0 && j >= 0)
  392. {
  393. //规则名称不为空
  394. if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
  395. {
  396. if (m_SubMidWindow.m_MainForm.CheckAttributes())
  397. {
  398. if (m_SubMidWindow.m_MainForm.Checktextbox_STDEditor())
  399. {
  400. m_SubMidWindow.m_MainForm.SaveDataOfSelRule(i, j);
  401. PropGrid.Focus(true);
  402. int selrow = PropGrid.Selection.ActivePosition.Row;
  403. int STDnum = (int)PropGrid[selrow, 1].Tag;
  404. int STDId = 1;
  405. foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm.STDDictionary)
  406. {
  407. if (STDId < kv.Key)
  408. {
  409. STDId = kv.Key;
  410. }
  411. }
  412. STDdata sT = new STDdata();
  413. sT.BSE = ReferenceDictionary[STDnum].BSE;
  414. sT.StrName = ReferenceDictionary[STDnum].StrName;
  415. sT.Color = ReferenceDictionary[STDnum].Color;
  416. sT.Density = ReferenceDictionary[STDnum].Density;
  417. sT.Expression = ReferenceDictionary[STDnum].Expression;
  418. sT.Formula = ReferenceDictionary[STDnum].Formula;
  419. sT.Hardness = ReferenceDictionary[STDnum].Hardness;
  420. sT.UsingImgPropertyList = ReferenceDictionary[STDnum].UsingImgPropertyList;
  421. sT.UsingOtherPropertyList = ReferenceDictionary[STDnum].UsingOtherPropertyList;
  422. sT.KeyElementList = ReferenceDictionary[STDnum].KeyElementList;
  423. sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
  424. sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
  425. sT.Element = ReferenceDictionary[STDnum].Element;
  426. sT.GroupId = ReferenceDictionary[STDnum].GroupId;
  427. m_SubMidWindow.m_MainForm.STDDictionary.Add(STDId + 1, sT);
  428. m_SubMidWindow.m_MainForm.m_STDRuleslist.InsertNewRow(STDId + 1, sT.StrName, STDRuleslist.colorHx16toRGB(sT.Color));
  429. m_SubMidWindow.m_MainForm.m_STDRuleslist.Refresh();
  430. m_SubMidWindow.m_MainForm.m_STDRuleslist.PreRow = i;
  431. for (int k = 0; k < ReferenceXrayList.Count; k++)
  432. {
  433. if (int.Parse(ReferenceXrayList[k].StdID) == STDnum)
  434. {
  435. STDEditor.STDXray tDXray=new STDEditor.STDXray();
  436. tDXray.StdID = (STDId+1).ToString();
  437. tDXray.XrayData = ReferenceXrayList[k].XrayData;
  438. tDXray.InfoState = (int)STDEditor.STDXrayInfoState.Add;
  439. m_SubMidWindow.m_STDEditor.m_STDXrayList.Add(tDXray);
  440. }
  441. }
  442. }
  443. }
  444. }
  445. }
  446. else
  447. {
  448. AddIntoMainLab();
  449. }
  450. }
  451. #region 因为复制容易引起用户误操作,故取消
  452. private void copyDataToolStripMenuItem_Click(object sender, EventArgs e)
  453. {
  454. //int selrow = PropGrid.Selection.ActivePosition.Row;
  455. //int STDnum = (int)PropGrid[selrow, 1].Tag;
  456. //int STDid = (int)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[m_SubMidWindow.m_MainForm.m_STDRuleslist.PreRow, 0].Tag;
  457. //m_SubMidWindow.m_MainForm.STDDictionary[STDid] = ReferenceDictionary[STDnum];
  458. //m_SubMidWindow.m_MainForm.m_STDRuleslist.ChangeStrName(m_SubMidWindow.m_MainForm.m_STDRuleslist.PreRow, ReferenceDictionary[STDnum].StrName);
  459. //m_SubMidWindow.m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDid);
  460. //m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Refresh();
  461. }
  462. #endregion
  463. private void addIntoMainLabToolStripMenuItem_Click(object sender, EventArgs e)
  464. {
  465. m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Focus(true);
  466. int i = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row;
  467. int j = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column;
  468. /// 保证鼠标点击的GRID行和列是有效的
  469. if (i > 0 && j >= 0)
  470. {
  471. //规则名称不为空
  472. if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, j].Value.ToString().Replace(" ", "").Trim() != "")
  473. {
  474. if (m_SubMidWindow.m_MainForm.CheckAttributes())
  475. {
  476. if (m_SubMidWindow.m_MainForm.Checktextbox_STDEditor())
  477. {
  478. m_SubMidWindow.m_MainForm.SaveDataOfSelRule(i, j);
  479. AddIntoMainLab();
  480. }
  481. }
  482. }
  483. }
  484. else if(i==-1&&j==-1)
  485. {
  486. AddIntoMainLab();
  487. }
  488. }
  489. void AddIntoMainLab()
  490. {
  491. PropGrid.Focus(true);
  492. int selrow = PropGrid.Selection.ActivePosition.Row;
  493. int STDnum = (int)PropGrid[selrow, 1].Tag;
  494. int STDId = 1;
  495. foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm.STDDictionary)
  496. {
  497. if (STDId < kv.Key)
  498. {
  499. STDId = kv.Key;
  500. }
  501. }
  502. STDdata sT = new STDdata();
  503. sT.BSE = ReferenceDictionary[STDnum].BSE;
  504. sT.StrName = ReferenceDictionary[STDnum].StrName;
  505. sT.Color = ReferenceDictionary[STDnum].Color;
  506. sT.Density = ReferenceDictionary[STDnum].Density;
  507. sT.Expression = ReferenceDictionary[STDnum].Expression;
  508. sT.Formula = ReferenceDictionary[STDnum].Formula;
  509. sT.Hardness = ReferenceDictionary[STDnum].Hardness;
  510. sT.UsingImgPropertyList = ReferenceDictionary[STDnum].UsingImgPropertyList;
  511. sT.UsingOtherPropertyList = ReferenceDictionary[STDnum].UsingOtherPropertyList;
  512. sT.KeyElementList = ReferenceDictionary[STDnum].KeyElementList;
  513. sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
  514. sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
  515. sT.Element = ReferenceDictionary[STDnum].Element;
  516. if (m_SubMidWindow.m_MainForm.GroupIdDictionaryFromId.ContainsKey(int.Parse(ReferenceDictionary[STDnum].GroupId)))
  517. { sT.GroupId = ReferenceDictionary[STDnum].GroupId; }
  518. else
  519. {
  520. MessageBox.Show("As this classification group is not defined, it has been adjusted to the default grouping!");
  521. }
  522. m_SubMidWindow.m_MainForm.STDDictionary.Add(STDId + 1, sT);
  523. m_SubMidWindow.m_MainForm.m_STDRuleslist.AddNewRow(STDId + 1, sT.StrName, STDRuleslist.colorHx16toRGB(sT.Color));
  524. m_SubMidWindow.m_MainForm.m_STDRuleslist.Refresh();
  525. m_SubMidWindow.m_MainForm.m_STDRuleslist.PreRow = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.RowsCount - 1;
  526. for (int k = 0; k < ReferenceXrayList.Count; k++)
  527. {
  528. if (int.Parse(ReferenceXrayList[k].StdID) == STDnum)
  529. {
  530. STDEditor.STDXray tDXray = new STDEditor.STDXray();
  531. tDXray.StdID = (STDId + 1).ToString();
  532. tDXray.XrayData = ReferenceXrayList[k].XrayData;
  533. tDXray.InfoState = (int)STDEditor.STDXrayInfoState.Add;
  534. m_SubMidWindow.m_STDEditor.m_STDXrayList.Add(tDXray);
  535. }
  536. }
  537. }
  538. }
  539. }