Form_Main.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. using OTS.WinFormsUI.Docking;
  2. using SourceGrid;
  3. using SpectrumSTDEditor.BaseClass;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Windows.Forms;
  11. namespace SpectrumSTDEditor
  12. {
  13. public partial class Form_Main : Form
  14. {
  15. public STDRuleslist m_STDRuleslist = null;
  16. public Attributes m_Attributes = null;
  17. public SubMidWindow m_SubMidWindow = null;
  18. //public STDEditor m_STDEditor = null;
  19. /// <summary>
  20. /// 实际存储的字典
  21. /// </summary>
  22. public Dictionary<int, STDdata> STDDictionary = new Dictionary<int, STDdata>();
  23. /// <summary>
  24. /// 原始数据字典用于在关闭时比较是否弹出保存提示
  25. /// </summary>
  26. private Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
  27. public Dictionary<int, string> GroupIdDictionaryFromId = new Dictionary<int, string>();
  28. public Dictionary<string, int> GroupIdDictionaryFromName = new Dictionary<string, int>();
  29. public string STDDBAddress = "";
  30. /// <summary>
  31. /// 0:正在打开的标准库路径;1:所增加标准的颗粒所在结果库位置;2:所增加标准的颗粒FieldId;3:所增加标准的颗粒ParticleId;4:所增加标准的颗粒XRayId
  32. /// </summary>
  33. List<string> ImportArgs = new List<string>();
  34. //国际化
  35. public Language lan;
  36. Hashtable table;
  37. //是否做出过更改
  38. public bool IsModified { set; get; }
  39. public bool Isoldversion { set; get; }
  40. //public static readonly string[] ColorGroup = { "#FFB6C1", "#FFC0CB", "#DC143C", "#FFF0F5", "#DB7093", "#FF69B4", "#FF1493", "#C71585", "#DA70D6", "#D8BFD8", "#DDA0DD", "#EE82EE", "#FF00FF", "#8B008B", "#800080", "#BA55D3", "#9400D3", "#9932CC", "#4B0082", "#8A2BE2", "#9370DB","#7B68EE", "#6A5ACD", "#483D8B", "#E6E6FA", "#F8F8FF", "#0000FF", "#0000CD", "#191970", "#00008B", "#000080", "#4169E1" , "#6495ED", "#B0C4DE", "#778899", "#708090", "#1E90FF", "#F0F8FF", "#00FFFF" };
  41. public Form_Main()
  42. {
  43. InitializeComponent();
  44. m_STDRuleslist = new STDRuleslist(this);
  45. m_Attributes = new Attributes(this);
  46. //m_STDEditor = new STDEditor(this, m_MainForm.STDDBAddress);
  47. m_SubMidWindow = new SubMidWindow(this);
  48. }
  49. public Form_Main(string[] ImportStandardLibraryArgs)
  50. {
  51. InitializeComponent();
  52. m_STDRuleslist = new STDRuleslist(this);
  53. m_Attributes = new Attributes(this);
  54. m_SubMidWindow = new SubMidWindow(this);
  55. foreach (var it in ImportStandardLibraryArgs)
  56. {
  57. ImportArgs.Add(it);
  58. }
  59. }
  60. private void Form_Main_Load(object sender, EventArgs e)
  61. {
  62. lan = new Language(this);
  63. table = lan.GetNameTable("Form_Main");
  64. if (STDDBAddress != "")
  65. {
  66. InitForms(STDDBAddress);
  67. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  68. IsModified = false;
  69. //if (ImportArgs.Count > 1)
  70. //{
  71. // ImportStandardLibraryTypeSelection m_importStandardLibraryTypeSelection = new ImportStandardLibraryTypeSelection();
  72. // var result = m_importStandardLibraryTypeSelection.ShowDialog();
  73. // if (m_importStandardLibraryTypeSelection.SelectEvent == "expression")
  74. // {
  75. // int STDId = AddSTDDictionaryItem();
  76. // m_STDRuleslist.AddNewRow(STDId, "NewClassify", Attributes.string10ToColor(STDDictionary[STDId].Color));
  77. // }
  78. //}
  79. }
  80. }
  81. bool LoadClassifyToDictionary(string DBAddress, ref Dictionary<int, STDdata> STDDictionary)
  82. {
  83. try
  84. {
  85. //STDDictionaryInitial.Clear();
  86. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  87. m_dbConnection.Open();
  88. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals order by orderid", m_dbConnection);
  89. DataSet ds = new DataSet();
  90. m_dataAdapter.Fill(ds);
  91. DataTable dt = ds.Tables[0];
  92. if (dt != null)
  93. {
  94. rbSave.Enabled = true;
  95. Isoldversion = false;
  96. if (dt.Rows.Count > 0)
  97. {
  98. foreach (DataRow item in dt.Rows)
  99. {
  100. STDdata new_STDdata = new STDdata();
  101. new_STDdata.Hardness = item["rigiditymod"].ToString();
  102. new_STDdata.Density = item["density"].ToString();
  103. //new_STDdata.Electrical_conductivity = item["Electrical_conductivity"].ToString();
  104. new_STDdata.BSE = item["BSEValue"].ToString();
  105. new_STDdata.Formula = item["formula"].ToString();
  106. new_STDdata.Element = item["element"].ToString();
  107. new_STDdata.StrName = item["name"].ToString();
  108. new_STDdata.ChineseName = item["chinesename"].ToString();
  109. //new_STDdata.Expression = item["Expression"].ToString();
  110. new_STDdata.Color = item["Color"].ToString();
  111. //new_STDdata.KeyElementList = item["KeyElementList"].ToString();
  112. //new_STDdata.SubElementList = item["SubElementList"].ToString();
  113. //new_STDdata.GroupId = item["GroupId"].ToString();
  114. new_STDdata.OrderId = item["orderid"].ToString();
  115. new_STDdata.XrayData = (byte[])item["SPEC"];
  116. //new_STDdata.GroupId = item["GroupId"].ToString();
  117. //if (dt.Columns.Contains("IfElementAnalysis"))
  118. //{
  119. // if (Convert.ToBoolean(item["IfElementAnalysis"]))
  120. // {
  121. // new_STDdata.IfElementAnalysis = true;
  122. // }
  123. // else
  124. // {
  125. // new_STDdata.IfElementAnalysis = false;
  126. // }
  127. //}
  128. STDDictionary.Add(int.Parse(item["id"].ToString()), new_STDdata);
  129. }
  130. }
  131. }
  132. return true;
  133. }
  134. catch /*(Exception ee)*/
  135. {
  136. MessageBox.Show("The selected standard library is formatted incorrectly, please open the correct standard library!", "Tip");
  137. return false;
  138. }
  139. }
  140. public void ChangeSTDEditorAndGrid_Attributes(int STDId)
  141. {
  142. m_SubMidWindow.SelSTDXray(STDId, STDDictionary[STDId]);
  143. m_Attributes.SetDatatoGrid_Attributes(STDId);
  144. }
  145. private void rbBackup_Click(object sender, EventArgs e)
  146. {
  147. if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row >= 0)
  148. {
  149. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column);
  150. }
  151. try
  152. {
  153. SaveFileDialog saveFile = new SaveFileDialog();
  154. saveFile.Title = "Please select the path which to save the file";
  155. saveFile.Filter = "Database File(*.db)|*.db";
  156. saveFile.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  157. saveFile.OverwritePrompt = false; //是否覆盖当前文件
  158. if (saveFile.ShowDialog() == DialogResult.OK)
  159. {
  160. if (STDDBAddress == saveFile.FileName)
  161. {
  162. MessageBox.Show("不能另存为同名文件!", "Tip");
  163. return;
  164. }
  165. FormForWaiting forWaiting = new FormForWaiting();
  166. forWaiting.Show();
  167. System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
  168. bool result = SaveAsDictionaryToClassify(saveFile.FileName);
  169. if (result)
  170. {
  171. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  172. STDDictionaryInitial.Clear();
  173. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  174. STDDBAddress = saveFile.FileName;
  175. this.Text = this.Text.Split(' ')[0] + " " + saveFile.FileName;
  176. IsModified = false;
  177. forWaiting.Close();
  178. MessageBox.Show("Save successful!", "Tip");
  179. }
  180. else
  181. {
  182. forWaiting.Close();
  183. MessageBox.Show("Save failed!", "Tip");
  184. }
  185. }
  186. else
  187. {
  188. return;
  189. }
  190. }
  191. catch (Exception ex)
  192. {
  193. MessageBox.Show(ex.Message);
  194. }
  195. }
  196. public bool ClearDb(string DBAddress, string DBTableName)
  197. {
  198. try
  199. {
  200. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  201. m_dbConnection.Open();
  202. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  203. cmm.CommandText = "delete from " + DBTableName;
  204. cmm.ExecuteNonQuery();
  205. m_dbConnection.Close();
  206. return true;
  207. }
  208. catch (Exception ex)
  209. {
  210. MessageBox.Show(ex.ToString());
  211. return false;
  212. }
  213. }
  214. object Clone(Dictionary<int, STDdata> STDDictionary)
  215. {
  216. Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
  217. foreach (var key in STDDictionary.Keys)
  218. {
  219. STDdata tDdata = new STDdata();
  220. tDdata = tDdata.Clone(STDDictionary[key]) as STDdata;
  221. STDDictionaryInitial.Add(key, tDdata);
  222. }
  223. return STDDictionaryInitial;
  224. }
  225. private void rbSave_Click(object sender, EventArgs e)
  226. {
  227. if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
  228. {
  229. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  230. }
  231. //if (RuleformatcheckAndSave())
  232. //{
  233. FormForWaiting forWaiting = new FormForWaiting();
  234. forWaiting.Show();
  235. bool result = SaveDictionaryToClassify(STDDBAddress);
  236. if (result)
  237. {
  238. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  239. STDDictionaryInitial.Clear();
  240. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  241. forWaiting.Close();
  242. IsModified = false;
  243. MessageBox.Show("Save successful!", "Tip");
  244. }
  245. else
  246. {
  247. forWaiting.Close();
  248. MessageBox.Show("Save failed!", "Tip");
  249. }
  250. //}
  251. //else
  252. //{
  253. // return;
  254. //}
  255. }
  256. bool RuleformatcheckAndSave()
  257. {
  258. foreach (var ite in STDDictionary)
  259. {
  260. Position pos = new Position(Convert.ToInt32(ite.Value.OrderId), 0);
  261. m_STDRuleslist.Grid_Minerals[Convert.ToInt32(ite.Value.OrderId), 0].Grid.Select();
  262. m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
  263. m_STDRuleslist.Grid_Minerals.Refresh();
  264. ChangeSTDEditorAndGrid_Attributes(ite.Key);
  265. m_STDRuleslist.PreRow = Convert.ToInt32(ite.Value.OrderId);
  266. return false;
  267. }
  268. return true;
  269. }
  270. ///// <summary>
  271. ///// [颜色:RGB转成16进制]
  272. ///// </summary>
  273. ///// <param name="R">红 int</param>
  274. ///// <param name="G">绿 int</param>
  275. ///// <param name="B">蓝 int</param>
  276. ///// <returns></returns>
  277. //public static string colorRGBtoHx16(int R, int G, int B)
  278. //{
  279. // return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  280. //}
  281. /// <summary>
  282. /// 属性检测
  283. /// </summary>
  284. /// <param name="ddata"></param>
  285. /// <returns></returns>
  286. public bool CheckAttributes(STDdata ddata)
  287. {
  288. if (string.IsNullOrEmpty(ddata.StrName))
  289. {
  290. MessageBox.Show("Rule name can not be null !", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  291. }
  292. //if (string.IsNullOrEmpty(ddata.g)
  293. //{
  294. // if (!GroupIdDictionaryFromName.ContainsKey(m_Attributes.Grid_Attributes[11, 1].Value.ToString()))
  295. // {
  296. // Position pos = new Position(11, 1);
  297. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  298. // MessageBox.Show("This group name is not included, please fill in again!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  299. // return false;
  300. // }
  301. //}
  302. #region 化学式和元素暂无限制
  303. //if (m_Attributes.Grid_Attributes[7, 1].Value.ToString())
  304. //{
  305. // Position pos = new Position(7, 1);
  306. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  307. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  308. // return false;
  309. //}
  310. //if (m_Attributes.Grid_Attributes[8, 1].Value.ToString())
  311. //{
  312. // Position pos = new Position(8, 1);
  313. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  314. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  315. // return false;
  316. //}
  317. #endregion
  318. return true;
  319. }
  320. public void SaveDataOfSelRule(int PreRow, int PreColumn)
  321. {
  322. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].StrName = Convert.ToString(m_Attributes.Grid_Attributes[2, 1].Value);
  323. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].ChineseName = Convert.ToString(m_Attributes.Grid_Attributes[3, 1].Value);
  324. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Color = shareFunction.ColorTostring10(m_Attributes.Grid_Attributes[4, 1].View.BackColor);
  325. //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].IfElementAnalysis = Convert.ToBoolean(m_Attributes.Grid_Attributes[4, 1].Value);
  326. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Hardness = Convert.ToString(m_Attributes.Grid_Attributes[5, 1].Value);
  327. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Density = Convert.ToString(m_Attributes.Grid_Attributes[6, 1].Value);
  328. //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Electrical_conductivity = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
  329. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].BSE = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
  330. if (m_Attributes.Grid_Attributes[8, 1].Value != null)
  331. {
  332. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Formula = Convert.ToString(m_Attributes.Grid_Attributes[8, 1].Value);
  333. }
  334. else
  335. {
  336. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Formula = "";
  337. }
  338. if (m_Attributes.Grid_Attributes[9, 1].Value != null)
  339. {
  340. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Element = Convert.ToString(m_Attributes.Grid_Attributes[9, 1].Value);
  341. }
  342. else
  343. {
  344. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Element = "";
  345. }
  346. //if (m_Attributes.Grid_Attributes[11, 1].Value != null)
  347. //{
  348. // STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].GroupId = GroupIdDictionaryFromName[Convert.ToString(m_Attributes.Grid_Attributes[11, 1].Value)].ToString();
  349. //}
  350. //else
  351. //{
  352. // STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].GroupId = "0";
  353. //}
  354. //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Expression = "";
  355. //string sKeyElements = "";
  356. //string sSubElements = "";
  357. //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].KeyElementList = sKeyElements;
  358. //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].SubElementList = sSubElements;
  359. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].OrderId = PreRow.ToString();
  360. }
  361. /// <summary>
  362. /// 保存ClassifySTD库和MineralElements库
  363. /// </summary>
  364. /// <param name="DBAddress"></param>
  365. /// <returns></returns>
  366. bool SaveDictionaryToClassify(string DBAddress)
  367. {
  368. //保存列表顺序
  369. for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++)
  370. {
  371. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[i, 0].Tag].OrderId = i.ToString();
  372. }
  373. try
  374. {
  375. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  376. m_dbConnection.Open();
  377. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  378. cmm.CommandText = "delete from STDMinerals";
  379. try
  380. {
  381. cmm.ExecuteNonQuery();
  382. }
  383. catch (Exception ex)
  384. {
  385. MessageBox.Show(ex.ToString());
  386. return false;
  387. }
  388. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals", m_dbConnection);
  389. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  390. DataSet ds = new DataSet();
  391. m_dataAdapter.Fill(ds, "STDMinerals");
  392. DataTable dt = ds.Tables["STDMinerals"];
  393. dt.Clear();
  394. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  395. {
  396. DataRow newRow = dt.NewRow();
  397. newRow["id"] = kv.Key;
  398. newRow["name"] = kv.Value.StrName;
  399. newRow["chinesename"] = kv.Value.ChineseName;
  400. newRow["color"] = kv.Value.Color;
  401. newRow["rigiditymod"] = kv.Value.Hardness;
  402. newRow["density"] = kv.Value.Density;
  403. newRow["BSEValue"] = int.Parse(kv.Value.BSE);
  404. newRow["formula"] = kv.Value.Formula;
  405. newRow["element"] = kv.Value.Element;
  406. newRow["orderid"] = kv.Value.OrderId;
  407. newRow["SPEC"] = kv.Value.XrayData;
  408. dt.Rows.Add(newRow);
  409. }
  410. m_dataAdapter.Update(ds, "STDMinerals");
  411. m_dbConnection.Close();
  412. }
  413. catch (Exception ex)
  414. {
  415. MessageBox.Show(ex.ToString());
  416. return false;
  417. }
  418. return true;
  419. }
  420. bool SaveAsDictionaryToClassify(string DBAddress)
  421. {
  422. try
  423. {
  424. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  425. m_dbConnection.Open();
  426. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  427. cmm.CommandText = "drop table STDMinerals";
  428. cmm.ExecuteNonQuery();
  429. cmm.CommandText = "CREATE TABLE STDMinerals (id INTEGER,name TEXT,chinesename TEXT,formula TEXT,density FLOAT,BSEValue INTEGER,rigiditymod FLOAT,color INTEGER,SPEC BLOB,element TEXT,orderid INTEGER)";
  430. cmm.ExecuteNonQuery();
  431. System.Data.Common.DbTransaction trans = m_dbConnection.BeginTransaction();
  432. trans.Commit();
  433. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals", m_dbConnection);
  434. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  435. DataSet ds = new DataSet();
  436. m_dataAdapter.Fill(ds, "STDMinerals");
  437. DataTable dt = ds.Tables["STDMinerals"];
  438. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  439. {
  440. DataRow newRow = dt.NewRow();
  441. newRow["id"] = kv.Key;
  442. newRow["name"] = kv.Value.StrName;
  443. newRow["chinesename"] = kv.Value.ChineseName;
  444. newRow["color"] = kv.Value.Color;
  445. newRow["rigiditymod"] = kv.Value.Hardness;
  446. newRow["density"] = kv.Value.Density;
  447. newRow["BSEValue"] = int.Parse(kv.Value.BSE);
  448. newRow["formula"] = kv.Value.Formula;
  449. newRow["element"] = kv.Value.Element;
  450. newRow["orderid"] = kv.Value.OrderId;
  451. newRow["SPEC"] = kv.Value.XrayData;
  452. dt.Rows.Add(newRow);
  453. }
  454. m_dataAdapter.Update(ds, "STDMinerals");
  455. m_dbConnection.Close();
  456. }
  457. catch (Exception ex)
  458. {
  459. MessageBox.Show(ex.ToString());
  460. return false;
  461. }
  462. return true;
  463. }
  464. public int AddSTDDictionaryItem()
  465. {
  466. STDdata new_STDdata = new STDdata();
  467. new_STDdata.Hardness = "1";
  468. new_STDdata.Density = "1";
  469. new_STDdata.BSE = "1";
  470. new_STDdata.Formula = "1";
  471. new_STDdata.Element = "1";
  472. new_STDdata.StrName = "NewRuleName";
  473. new_STDdata.ChineseName = "新建标准";
  474. Random random = new Random();
  475. new_STDdata.Color = shareFunction.ObtainRandomColor();
  476. int STDId = 40000;
  477. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  478. {
  479. if (STDId < kv.Key)
  480. {
  481. STDId = kv.Key;
  482. }
  483. }
  484. STDDictionary.Add(STDId + 1, new_STDdata);
  485. return STDId + 1;
  486. }
  487. public void RemoveSTDDictionaryItem(int STDId)
  488. {
  489. STDDictionary.Remove(STDId);
  490. }
  491. public void ChangeStrName(int RowNum, string NewStrName)
  492. {
  493. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag].StrName = NewStrName;
  494. m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
  495. }
  496. public void ChangeSTDRulesLISTBackColor()
  497. {
  498. int stdid = m_STDRuleslist.ChangeSTDRulesLISTBackColor();
  499. m_SubMidWindow.SelSTDXray(stdid, STDDictionary[stdid]);
  500. }
  501. public void ChangeSTDRuleName(String RuleName)
  502. {
  503. m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value = RuleName;
  504. }
  505. public void SetNull()
  506. {
  507. //m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  508. for (int i = 1; i < m_Attributes.Grid_Attributes.RowsCount - 1; i++)
  509. {
  510. if (m_Attributes.Grid_Attributes[i, 1].Value != null)
  511. {
  512. if (m_Attributes.Grid_Attributes[i, 1].View is SourceGrid.Cells.Views.CheckBox)
  513. {
  514. m_Attributes.Grid_Attributes[i, 1].Value = true;
  515. }
  516. else
  517. {
  518. m_Attributes.Grid_Attributes[i, 1].Value = "";
  519. }
  520. }
  521. }
  522. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  523. view.BackColor = Color.White;
  524. m_Attributes.Grid_Attributes[2, 1].View = view;
  525. }
  526. //void SetNonexistentGroupsToDefault()
  527. //{
  528. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  529. // {
  530. // if (!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
  531. // {
  532. // kv.Value.GroupId = "0";
  533. // }
  534. // }
  535. // m_Attributes.Grid_Attributes.Refresh();
  536. //}
  537. //private void ribbon_GroupNameMaintenance_Click(object sender, EventArgs e)
  538. //{
  539. // //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Tag.ToString())].GroupId = GroupIdDictionaryFromName[m_Attributes.Grid_Attributes[10, 1].Value.ToString()].ToString();
  540. // int selGroupId = GroupIdDictionaryFromName[m_Attributes.Grid_Attributes[11, 1].Value.ToString()];
  541. // Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress, this);
  542. // DialogResult dialogResult = form_GroupId.ShowDialog();
  543. // if (dialogResult == DialogResult.Yes)
  544. // {
  545. // AddSTDGroupsToAttribute();
  546. // //SetNonexistentGroupsToDefault();
  547. // m_Attributes.Grid_Attributes[11, 1].Value = GroupIdDictionaryFromId[selGroupId];
  548. // }
  549. //}
  550. private void ribbon_Exit_Click(object sender, EventArgs e)
  551. {
  552. this.Close();
  553. }
  554. private void rbClose_Click(object sender, EventArgs e)
  555. {
  556. if (!Isoldversion)
  557. {
  558. if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
  559. {
  560. DialogResult dr = MessageBox.Show("Whether to save the current modification?", "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  561. if (dr == DialogResult.Yes)
  562. {
  563. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  564. {
  565. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != ""))
  566. {
  567. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  568. }
  569. else
  570. {
  571. return;
  572. }
  573. }
  574. else
  575. {
  576. STDDictionaryInitial.Clear();
  577. }
  578. FormForWaiting forWaiting = new FormForWaiting();
  579. forWaiting.Show();
  580. bool result = SaveDictionaryToClassify(STDDBAddress);
  581. if (result)
  582. {
  583. forWaiting.Close();
  584. }
  585. else
  586. {
  587. forWaiting.Close();
  588. MessageBox.Show("Save failed!", "Tip");
  589. }
  590. }
  591. }
  592. }
  593. m_Attributes.Close();
  594. m_STDRuleslist.Close();
  595. m_SubMidWindow.m_STDEditor.Close();
  596. m_SubMidWindow.m_ComparativeLibrary.Close();
  597. m_SubMidWindow.Close();
  598. ButtonStatusClose();
  599. if (this.Text.Split(' ').Count() != 0)
  600. {
  601. this.Text = this.Text.Split(' ')[0];
  602. }
  603. }
  604. private void rbOpen_Click(object sender, EventArgs e)
  605. {
  606. OpenFileDialog openFileDialog = new OpenFileDialog();
  607. openFileDialog.Filter = "(*.db)|*.db";
  608. openFileDialog.RestoreDirectory = true;
  609. openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
  610. openFileDialog.FilterIndex = 1;
  611. if (openFileDialog.ShowDialog() == DialogResult.OK)
  612. {
  613. try
  614. {
  615. this.Cursor = Cursors.WaitCursor;
  616. STDDBAddress = openFileDialog.FileName;
  617. InitForms(STDDBAddress);
  618. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  619. IsModified = false;
  620. this.Cursor = Cursors.Default;
  621. //CheckAccuracyofZeroRules();
  622. }
  623. catch(Exception ex)
  624. {
  625. MessageBox.Show(ex.ToString(), "Tip");
  626. this.Cursor = Cursors.Default;
  627. }
  628. }
  629. }
  630. void ButtonStatusOpen()
  631. {
  632. rbOpen.Enabled = false;
  633. rbClose.Enabled = true;
  634. //rbRecover.Enabled = true;
  635. rbBackup.Enabled = true;
  636. rbSave.Enabled = true;
  637. rbNew.Enabled = false;
  638. }
  639. void ButtonStatusClose()
  640. {
  641. rbOpen.Enabled = true;
  642. rbClose.Enabled = false;
  643. //rbRecover.Enabled = false;
  644. rbBackup.Enabled = false;
  645. rbSave.Enabled = false;
  646. rbNew.Enabled = true;
  647. }
  648. void InitForms(string DBAddress)
  649. {
  650. STDDictionary.Clear();
  651. ButtonStatusOpen();
  652. bool ret = LoadClassifyToDictionary(DBAddress, ref STDDictionary);
  653. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  654. if (!ret)
  655. {
  656. return;
  657. }
  658. m_STDRuleslist = new STDRuleslist(this);
  659. m_Attributes = new Attributes(this);
  660. m_SubMidWindow = new SubMidWindow(this);
  661. m_STDRuleslist.Show(dockPanel1, DockState.DockLeft);
  662. m_Attributes.Show(dockPanel1, DockState.DockRight);
  663. m_SubMidWindow.Show(dockPanel1, DockState.Document);
  664. dockPanel1.DockLeftPortion = 360;
  665. dockPanel1.DockRightPortion = 381;
  666. if (m_SubMidWindow.m_STDEditor.m_sc != null)
  667. {
  668. m_SubMidWindow.m_STDEditor.m_sc.CloseDB();
  669. }
  670. m_SubMidWindow.m_STDEditor.m_sc = new SqlLiteClass(DBAddress);
  671. //AddSTDGroupsToAttribute();
  672. //m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  673. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  674. {
  675. m_STDRuleslist.button_UpOrder.Enabled = false;
  676. if (m_STDRuleslist.Grid_Minerals.RowsCount == 2) //就一条时向下按钮置灰
  677. {
  678. m_STDRuleslist.button_DownOrder.Enabled = false;
  679. }
  680. ChangeSTDEditorAndGrid_Attributes(int.Parse(m_STDRuleslist.Grid_Minerals[1, 0].Tag.ToString()));
  681. Position pos = new Position(1, 0);
  682. m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  683. m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
  684. }
  685. }
  686. bool EqualsBetweenDictionary(Dictionary<int, STDdata> STDDictionaryInitial, Dictionary<int, STDdata> STDDictionary)
  687. {
  688. if (STDDictionaryInitial.Count != STDDictionary.Count)
  689. {
  690. return false;
  691. }
  692. foreach (var key in STDDictionaryInitial.Keys)
  693. {
  694. if (STDDictionary.Keys.Contains(key))
  695. {
  696. if (!STDDictionaryInitial[key].Equals(STDDictionary[key]))
  697. {
  698. return false;
  699. }
  700. }
  701. else
  702. {
  703. return false;
  704. }
  705. }
  706. return true;
  707. }
  708. private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
  709. {
  710. if (Isoldversion)
  711. {
  712. return;
  713. }
  714. if (m_STDRuleslist.Text != "")
  715. {
  716. if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
  717. {
  718. DialogResult dr = MessageBox.Show("Whether to save the current modification", "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  719. if (dr == DialogResult.Yes)
  720. {
  721. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  722. {
  723. if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  724. {
  725. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  726. }
  727. else
  728. {
  729. e.Cancel = true;
  730. return;
  731. }
  732. }
  733. else
  734. {
  735. STDDictionaryInitial.Clear();
  736. }
  737. FormForWaiting forWaiting = new FormForWaiting();
  738. forWaiting.Show();
  739. bool result = SaveDictionaryToClassify(STDDBAddress);
  740. if (result)
  741. {
  742. forWaiting.Close();
  743. }
  744. else
  745. {
  746. forWaiting.Close();
  747. MessageBox.Show("Save failed!", "Tip");
  748. }
  749. }
  750. else
  751. {
  752. //foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  753. //{
  754. // if (!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
  755. // {
  756. // MessageBox.Show("There is non-existent grouping informations in the classification, please adjust!");
  757. // e.Cancel = true;
  758. // return;
  759. // }
  760. //}
  761. }
  762. }
  763. }
  764. }
  765. private void rbNew_Click(object sender, EventArgs e)
  766. {
  767. SaveFileDialog saveFile = new SaveFileDialog();
  768. saveFile.Title = table["message23"].ToString();
  769. saveFile.Filter = table["message36"].ToString();
  770. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  771. saveFile.RestoreDirectory = true; //还原上次目录
  772. if (saveFile.ShowDialog() == DialogResult.OK)
  773. {
  774. try
  775. {
  776. System.Data.SQLite.SQLiteConnection.CreateFile(saveFile.FileName);
  777. System.Data.SQLite.SQLiteConnection m_OtsDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + saveFile.FileName + "'");
  778. m_OtsDatabaseConnection.Open();
  779. System.Data.SQLite.SQLiteCommand OtsDatabaseCommand = m_OtsDatabaseConnection.CreateCommand();
  780. OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,name TEXT,chinesename TEXT,formula TEXT,density FLOAT,BSEValue INTEGER,rigiditymod FLOAT,color INTEGER,SPEC BLOB,element TEXT,orderid INTEGER)";
  781. OtsDatabaseCommand.ExecuteNonQuery();
  782. System.Data.Common.DbTransaction trans = m_OtsDatabaseConnection.BeginTransaction();
  783. trans.Commit();
  784. }
  785. catch (Exception ex)
  786. {
  787. MessageBox.Show(ex.ToString());
  788. return;
  789. }
  790. STDDBAddress = saveFile.FileName;
  791. InitForms(STDDBAddress);
  792. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  793. IsModified = false;
  794. }
  795. else
  796. {
  797. return;
  798. }
  799. }
  800. //void CheckAccuracyofZeroRules()
  801. //{
  802. // System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  803. // m_dbConnection.Open();
  804. // System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ZeroElementRules", m_dbConnection);
  805. // DataSet ds = new DataSet();
  806. // m_dataAdapter.Fill(ds);
  807. // DataTable dt = ds.Tables[0];
  808. // DataTable dt2 = dt.Copy();
  809. // if (dt != null)
  810. // {
  811. // if (dt.Columns[dt.Columns.Count - 1].ColumnName != "Expression")
  812. // {
  813. // System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  814. // cmm.CommandText = "CREATE TABLE sqlitestudio_temp_table AS SELECT * FROM ZeroElementRules";
  815. // cmm.ExecuteNonQuery();
  816. // cmm.CommandText = "DROP TABLE ZeroElementRules";
  817. // cmm.ExecuteNonQuery();
  818. // cmm.CommandText = "CREATE TABLE ZeroElementRules (ZeroElement TEXT,UsingElementList TEXT,UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT)";
  819. // cmm.ExecuteNonQuery();
  820. // cmm.CommandText = @"INSERT INTO ZeroElementRules (
  821. // ZeroElement,
  822. // UsingElementList,
  823. // UsingImgPropertyList,
  824. // UsingOtherPropertyList,
  825. // Expression
  826. // )
  827. // SELECT ZeroElement,
  828. // UsingElementList,
  829. // UsingImgPropertyList,
  830. // UsingOtherPropertyList,
  831. // Expression
  832. // FROM sqlitestudio_temp_table; ";
  833. // cmm.ExecuteNonQuery();
  834. // cmm.CommandText = "DROP TABLE sqlitestudio_temp_table";
  835. // cmm.ExecuteNonQuery();
  836. // m_dbConnection.Close();
  837. // MessageBox.Show("检测到该数据库零元素规则格式错误,已进行修正!");
  838. // }
  839. // }
  840. //}
  841. private void ribbonOrbMenuItem_Convert_Click(object sender, EventArgs e)
  842. {
  843. DataTable OreDatabasedt = new DataTable();
  844. OpenFileDialog openFileDialog = new OpenFileDialog();
  845. openFileDialog.Title = "Please select the database you want to convert";
  846. openFileDialog.Filter = "(*.db)|*.db";
  847. openFileDialog.RestoreDirectory = true;
  848. openFileDialog.FilterIndex = 1;
  849. if (openFileDialog.ShowDialog() == DialogResult.OK)
  850. {
  851. try
  852. {
  853. string OreDatabaseAddress = openFileDialog.FileName;
  854. System.Data.SQLite.SQLiteConnection m_OreDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + OreDatabaseAddress + "'");
  855. m_OreDatabaseConnection.Open();
  856. System.Data.SQLite.SQLiteDataAdapter m_OreDatabasedataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals", m_OreDatabaseConnection);
  857. DataSet OreDatabaseds = new DataSet();
  858. m_OreDatabasedataAdapter.Fill(OreDatabaseds);
  859. OreDatabasedt = OreDatabaseds.Tables[0];
  860. int listnum = 1;
  861. SaveFileDialog saveFile = new SaveFileDialog();
  862. saveFile.Title = table["message23"].ToString();
  863. saveFile.Filter = table["message36"].ToString();
  864. saveFile.OverwritePrompt = true;
  865. saveFile.RestoreDirectory = true;
  866. if (saveFile.ShowDialog() == DialogResult.OK)
  867. {
  868. System.Data.SQLite.SQLiteConnection.CreateFile(saveFile.FileName);
  869. System.Data.SQLite.SQLiteConnection m_OtsDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + saveFile.FileName + "'");
  870. m_OtsDatabaseConnection.Open();
  871. System.Data.SQLite.SQLiteCommand OtsDatabaseCommand = m_OtsDatabaseConnection.CreateCommand();
  872. OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,name TEXT,chinesename TEXT,formula TEXT,density FLOAT,BSEValue INTEGER,rigiditymod FLOAT,color INTEGER,SPEC BLOB,element TEXT,orderid INTEGER)";
  873. OtsDatabaseCommand.ExecuteNonQuery();
  874. System.Data.Common.DbTransaction trans = m_OtsDatabaseConnection.BeginTransaction();
  875. foreach (DataRow item in OreDatabasedt.Rows)
  876. {
  877. OtsDatabaseCommand.CommandText = "insert into STDMinerals (id,name,chinesename,formula,density,BSEValue,rigiditymod,color,SPEC,element,orderid) values (@id, @name, @chinesename, @formula, @density, @BSEValue, @rigiditymod, @color,@SPEC,@element, @orderid)";
  878. OtsDatabaseCommand.Parameters.Add("id", DbType.Int32).Value = item["id"];
  879. OtsDatabaseCommand.Parameters.Add("name", DbType.String).Value = item["name"];
  880. OtsDatabaseCommand.Parameters.Add("chinesename", DbType.String).Value = " ";
  881. OtsDatabaseCommand.Parameters.Add("formula", DbType.String).Value = item["formula"].ToString();
  882. OtsDatabaseCommand.Parameters.Add("density", DbType.String).Value = item["density"];
  883. OtsDatabaseCommand.Parameters.Add("BSEValue", DbType.String).Value = item["BSEValue"];
  884. OtsDatabaseCommand.Parameters.Add("rigiditymod", DbType.String).Value = item["rigiditymod"];
  885. OtsDatabaseCommand.Parameters.Add("color", DbType.String).Value = item["color"];
  886. OtsDatabaseCommand.Parameters.Add("SPEC", DbType.Binary).Value = item["SPEC"];
  887. OtsDatabaseCommand.Parameters.Add("element", DbType.String).Value = " ";
  888. OtsDatabaseCommand.Parameters.Add("orderid", DbType.String).Value = listnum.ToString();
  889. OtsDatabaseCommand.ExecuteNonQuery();
  890. }
  891. trans.Commit();
  892. MessageBox.Show("successful");
  893. }
  894. else
  895. {
  896. return;
  897. }
  898. }
  899. catch (Exception ex)
  900. {
  901. MessageBox.Show(ex.ToString());
  902. }
  903. }
  904. else
  905. {
  906. return;
  907. }
  908. }
  909. private void Form_Main_Paint(object sender, PaintEventArgs e)
  910. {
  911. comboBoxfilter.Location = new Point(ribbonPanel5.GetContentBounds().X+1, ribbonPanel5.GetContentBounds().Y + 1);
  912. btnfilter.Location = new Point(ribbonPanel5.GetContentBounds().X + 36, ribbonPanel5.GetContentBounds().Y + 25);
  913. }
  914. private void comboBoxfilter_Enter(object sender, EventArgs e)
  915. {
  916. comboBoxfilter.Items.Clear();
  917. List<string> PeriodicTable =new List<string>();
  918. foreach (var item in STDDictionary)
  919. {
  920. PeriodicTable.Add(item.Value.ChineseName);
  921. PeriodicTable.Add(item.Value.StrName);
  922. }
  923. AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
  924. sc.AddRange(PeriodicTable.ToArray());
  925. this.comboBoxfilter.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
  926. this.comboBoxfilter.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
  927. this.comboBoxfilter.AutoCompleteCustomSource = sc;
  928. }
  929. private void comboBoxfilter_SelectedIndexChanged(object sender, EventArgs e)
  930. {
  931. if (comboBoxfilter.Text.Length > 0)
  932. {
  933. // 将 SelectionStart 设置为文本的长度,即光标位置移到文本末尾
  934. comboBoxfilter.SelectionStart = comboBoxfilter.Text.Length;
  935. // 如果你想让光标仅仅定位而没有任何文本被选中,保持 SelectionLength 为 0
  936. comboBoxfilter.SelectionLength = 0;
  937. }
  938. }
  939. private void btnfilter_Click(object sender, EventArgs e)
  940. {
  941. for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++)
  942. {
  943. int id = (int)m_STDRuleslist.Grid_Minerals[i, 0].Tag;
  944. if (STDDictionary[id].StrName == comboBoxfilter.Text || STDDictionary[id].ChineseName == comboBoxfilter.Text)
  945. {
  946. Position pos = new Position(i, 0);
  947. m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
  948. SaveDataOfSelRule(m_STDRuleslist.PreRow, 0);
  949. ChangeSTDEditorAndGrid_Attributes(id);
  950. m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
  951. m_STDRuleslist.PreRow = i;
  952. }
  953. m_STDRuleslist.SetOrderButtonsStatus();
  954. }
  955. }
  956. }
  957. }