ReferenceLibrary.cs 26 KB

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