Form_ConstantsEditor2.cs 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. using SourceGrid;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.Xml;
  13. using System.Xml.Linq;
  14. namespace OTSPartA_STDEditor
  15. {
  16. public partial class Form_ConstantsEditor2 : Form
  17. {
  18. OTSDockWindow m_DockWindow = null;
  19. public STDRuleslist m_STDRuleslist = null;
  20. public Attributes m_Attributes = null;
  21. public SubMidWindow m_SubMidWindow = null;
  22. public Dictionary<int, STDdata> STDDictionary = new Dictionary<int, STDdata>();
  23. private Dictionary<int, STDdata> STDDictionaryInitial=new Dictionary<int, STDdata>();
  24. public Dictionary<int,string> GroupIdDictionaryFromId = new Dictionary<int,string>();
  25. public Dictionary<string, int> GroupIdDictionaryFromName = new Dictionary<string, int>();
  26. string STDDBAddress_backupDirectory = Application.StartupPath + "\\Config\\SysData\\LibBackup\\";
  27. public string STDDBAddress = "";
  28. //国际化
  29. public Language lan;
  30. Hashtable table;
  31. //是否做出过更改
  32. public bool IsModified { set; get; }
  33. public Form_ConstantsEditor2()
  34. {
  35. InitializeComponent();
  36. m_STDRuleslist = new STDRuleslist(this);
  37. m_Attributes = new Attributes(this);
  38. m_SubMidWindow = new SubMidWindow(this);
  39. m_DockWindow = new OTSDockWindow(this);
  40. }
  41. private void Form_ConstantsEditor2_Load(object sender, EventArgs e)
  42. {
  43. lan = new Language(this);
  44. table = lan.GetNameTable("Form_ConstantsEditor2");
  45. if (STDDBAddress != "")
  46. {
  47. InitForms(STDDBAddress);
  48. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  49. IsModified = false;
  50. }
  51. }
  52. void LoadConstants(string STDDBAddress)
  53. {
  54. try
  55. {
  56. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  57. m_dbConnection.Open();
  58. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from Constants", m_dbConnection);
  59. DataSet ds = new DataSet();
  60. m_dataAdapter.Fill(ds);
  61. DataTable dt = ds.Tables[0];
  62. if (dt.Rows.Count > 0)
  63. {
  64. string ConstantsStr = dt.Rows[0][0].ToString();
  65. ConstantsStr = ConstantsStr.Replace(" ", "");
  66. string[] ConstantsStr2 = ConstantsStr.Split(',');
  67. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  68. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  69. }
  70. m_dbConnection.Close();
  71. }
  72. catch (Exception ee)
  73. {
  74. MessageBox.Show(ee.ToString());
  75. }
  76. }
  77. bool LoadClassifyToDictionary(string DBAddress, ref Dictionary<int, STDdata> STDDictionary)
  78. {
  79. try
  80. {
  81. //STDDictionaryInitial.Clear();
  82. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  83. m_dbConnection.Open();
  84. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD order by ListNum", m_dbConnection);
  85. DataSet ds = new DataSet();
  86. m_dataAdapter.Fill(ds);
  87. DataTable dt = ds.Tables[0];
  88. if (dt != null)
  89. {
  90. if (dt.Rows.Count > 0)
  91. {
  92. foreach (DataRow item in dt.Rows)
  93. {
  94. STDdata new_STDdata = new STDdata();
  95. new_STDdata.Hardness = item["Hardness"].ToString();
  96. new_STDdata.Density = item["Density"].ToString();
  97. new_STDdata.Electrical_conductivity = item["Electrical_conductivity"].ToString();
  98. new_STDdata.BSE = item["BSE"].ToString();
  99. new_STDdata.Formula = item["Formula"].ToString();
  100. new_STDdata.Element = item["Element"].ToString();
  101. new_STDdata.StrName = item["StrName"].ToString();
  102. new_STDdata.Expression = item["Expression"].ToString();
  103. new_STDdata.Color = item["Color"].ToString();
  104. new_STDdata.KeyElementList = item["KeyElementList"].ToString();
  105. new_STDdata.SubElementList = item["SubElementList"].ToString();
  106. new_STDdata.GroupId = item["GroupId"].ToString();
  107. new_STDdata.ListNum= item["ListNum"].ToString();
  108. new_STDdata.GroupId = item["GroupId"].ToString();
  109. STDDictionary.Add(int.Parse(item["STDId"].ToString()), new_STDdata);
  110. }
  111. }
  112. }
  113. return true;
  114. }
  115. catch /*(Exception ee)*/
  116. {
  117. MessageBox.Show(table["message6"].ToString(), table["message32"].ToString());
  118. return false;
  119. }
  120. }
  121. public void ChangeSTDEditorAndGrid_Attributes(int STDId)
  122. {
  123. m_SubMidWindow.ChangeText_textbox_STDEditor(STDId);
  124. m_SubMidWindow.SelSTDXray(STDId, STDDictionary[STDId]);
  125. m_Attributes.SetDatatoGrid_Attributes(STDId);
  126. }
  127. private void rbBackup_Click(object sender, EventArgs e)
  128. {
  129. if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row >= 0)
  130. {
  131. //if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  132. //{
  133. if (CheckAttributes())
  134. {
  135. if (Checktextbox_STDEditor())
  136. {
  137. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column);
  138. try
  139. {
  140. SaveFileDialog saveFile = new SaveFileDialog();
  141. saveFile.Title = table["message23"].ToString();
  142. saveFile.Filter = table["message36"].ToString();
  143. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  144. saveFile.RestoreDirectory = true; //还原上次目录
  145. if (saveFile.ShowDialog() == DialogResult.OK)
  146. {
  147. System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
  148. bool result = SaveDictionaryToClassify(saveFile.FileName);
  149. if (result)
  150. {
  151. MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  152. }
  153. }
  154. else
  155. {
  156. return;
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. MessageBox.Show(ex.Message);
  162. }
  163. }
  164. //}
  165. }
  166. else
  167. {
  168. MessageBox.Show(table["message3"].ToString(), table["message32"].ToString());
  169. }
  170. }
  171. else
  172. {
  173. try
  174. {
  175. SaveFileDialog saveFile = new SaveFileDialog();
  176. saveFile.Title = table["message23"].ToString();
  177. saveFile.Filter = table["message36"].ToString();
  178. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  179. saveFile.RestoreDirectory = true; //还原上次目录
  180. if (saveFile.ShowDialog() == DialogResult.OK)
  181. {
  182. System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
  183. bool result = SaveDictionaryToClassify(saveFile.FileName);
  184. if (result)
  185. {
  186. MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  187. }
  188. }
  189. else
  190. {
  191. return;
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. MessageBox.Show(ex.Message);
  197. }
  198. }
  199. }
  200. public bool ClearDb(string DBAddress, string DBTableName)
  201. {
  202. try
  203. {
  204. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  205. m_dbConnection.Open();
  206. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  207. cmm.CommandText = "delete from " + DBTableName;
  208. cmm.ExecuteNonQuery();
  209. m_dbConnection.Close();
  210. return true;
  211. }
  212. catch (Exception ex)
  213. {
  214. MessageBox.Show(ex.ToString());
  215. return false;
  216. }
  217. }
  218. private void rbRecover_Click(object sender, EventArgs e)
  219. {
  220. }
  221. object Clone(Dictionary<int, STDdata> STDDictionary)
  222. {
  223. Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
  224. foreach (var key in STDDictionary.Keys)
  225. {
  226. STDdata tDdata = new STDdata();
  227. tDdata = tDdata.Clone(STDDictionary[key]) as STDdata;
  228. STDDictionaryInitial.Add(key, tDdata);
  229. }
  230. return STDDictionaryInitial;
  231. }
  232. private void rbSave_Click(object sender, EventArgs e)
  233. {
  234. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  235. {
  236. if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
  237. {
  238. if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  239. {
  240. if (CheckAttributes())
  241. {
  242. if (Checktextbox_STDEditor())
  243. {
  244. FormForWaiting forWaiting = new FormForWaiting();
  245. forWaiting.Show();
  246. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  247. // SaveXmlTreeDataToXml(Address);
  248. bool result = SaveDictionaryToClassify(STDDBAddress);
  249. if (result)
  250. {
  251. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  252. STDDictionaryInitial.Clear();
  253. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  254. forWaiting.Close();
  255. IsModified = false;
  256. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString());
  257. }
  258. else
  259. {
  260. forWaiting.Close();
  261. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  262. }
  263. }
  264. }
  265. }
  266. }
  267. else
  268. {
  269. Position pos = new Position(1, 0);
  270. m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  271. if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  272. {
  273. if (CheckAttributes())
  274. {
  275. if (Checktextbox_STDEditor())
  276. {
  277. FormForWaiting forWaiting = new FormForWaiting();
  278. forWaiting.Show();
  279. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  280. //SaveXmlTreeDataToXml(Address);
  281. bool result = SaveDictionaryToClassify(STDDBAddress);
  282. if (result)
  283. {
  284. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  285. STDDictionaryInitial.Clear();
  286. STDDictionaryInitial = new Dictionary<int, STDdata>(STDDictionary);
  287. forWaiting.Close();
  288. IsModified = false;
  289. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString());
  290. }
  291. else
  292. {
  293. forWaiting.Close();
  294. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  295. }
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. /// <summary>
  303. /// [颜色:RGB转成16进制]
  304. /// </summary>
  305. /// <param name="R">红 int</param>
  306. /// <param name="G">绿 int</param>
  307. /// <param name="B">蓝 int</param>
  308. /// <returns></returns>
  309. public static string colorRGBtoHx16(int R, int G, int B)
  310. {
  311. return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  312. }
  313. //表达式规则检查
  314. public bool Checktextbox_STDEditor()
  315. {
  316. string str_RemoveBlank = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString().Replace(" ", "");
  317. if (str_RemoveBlank != "")
  318. {
  319. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  320. //分割符号检验
  321. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  322. for (int i = 0; i < Symbol.Length; i++)
  323. {
  324. for (int j = 0; j < Symbol.Length; j++)
  325. {
  326. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  327. {
  328. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  329. {
  330. MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  331. return false;
  332. }
  333. }
  334. }
  335. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  336. {
  337. MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  338. return false;
  339. }
  340. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  341. {
  342. MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  343. return false;
  344. }
  345. }
  346. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  347. {
  348. //左右括号匹配检验
  349. int BracketsNum = 0;
  350. for (int i = 0; i < str_RemoveBlank.Length; i++)
  351. {
  352. if (str_RemoveBlank[i] == '(') BracketsNum++;
  353. if (str_RemoveBlank[i] == ')') BracketsNum--;
  354. }
  355. if (BracketsNum != 0)
  356. {
  357. MessageBox.Show(table["message19"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  358. return false;
  359. }
  360. //首字符检测
  361. if ((str_RemoveBlank[0] == '+') || (str_RemoveBlank[0] == '-') || (str_RemoveBlank[0] == '*') || (str_RemoveBlank[0] == '/') || (str_RemoveBlank[0] == '>') || (str_RemoveBlank[0] == '<') || (str_RemoveBlank[0] == '=') || (str_RemoveBlank[0] == ')') || (str_RemoveBlank[str_RemoveBlank.Length - 1] == '('))
  362. {
  363. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  364. return false;
  365. }
  366. if (str_RemoveBlank.Length >= 3)
  367. {
  368. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  369. {
  370. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  371. return false;
  372. }
  373. }
  374. }
  375. //forth_elem干扰or分隔符,故先行去掉
  376. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  377. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  378. List<string> str_Removeandor = new List<string>();
  379. for (int i = 0; i < str_Removeand.Length; i++)
  380. {
  381. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  382. }
  383. List<string> list_all = new List<string>();
  384. for (int i = 0; i < str_Removeandor.Count; i++)
  385. {
  386. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  387. }
  388. //常量
  389. List<string> Constantslist = new List<string>();
  390. for (int j = 0; j < m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Count; j++)
  391. {
  392. Constantslist.Add(m_SubMidWindow.m_STDEditor.comboBox_Constants.Items[j].ToString().Split('=')[0]);
  393. }
  394. for (int i = 0; i < list_all.Count; i++)
  395. {
  396. //周期元素?
  397. if (this.m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  398. {
  399. continue;
  400. }
  401. //first_elem?
  402. if (this.m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  403. {
  404. continue;
  405. }
  406. //Element1?
  407. if (this.m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  408. {
  409. continue;
  410. }
  411. //其它元素?
  412. if (this.m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  413. {
  414. continue;
  415. }
  416. //常量?
  417. if (Constantslist.Contains(list_all[i]))
  418. {
  419. continue;
  420. }
  421. //数字?
  422. double DNum = 0;
  423. if (double.TryParse(list_all[i], out DNum))
  424. {
  425. continue;
  426. }
  427. //>=? <=?等其它情况
  428. if (list_all[i] == "")
  429. {
  430. continue;
  431. }
  432. //true false?
  433. if ((list_all[i] == "true") || (list_all[i] == "false"))
  434. {
  435. continue;
  436. }
  437. MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  438. return false;
  439. }
  440. //检测是否有<>= true,false
  441. if (!m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString().Contains("<") && !m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString().Contains(">") && !m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString().Contains("=") && m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString() != "true" && m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString() != "false")
  442. {
  443. MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  444. return false;
  445. }
  446. }
  447. else
  448. {
  449. var XrayInfo = m_SubMidWindow.m_STDEditor.m_STDXrayList.Find(STDXray => STDXray.StdID == m_STDRuleslist.Grid_Minerals[m_STDRuleslist.PreRow, 0].Tag.ToString());
  450. if (XrayInfo==null||XrayInfo.XrayData==null)
  451. {
  452. MessageBox.Show(table["message38"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  453. return false;
  454. }
  455. }
  456. return true;
  457. }
  458. //属性检测
  459. public bool CheckAttributes()
  460. {
  461. //if (double.Parse(m_Attributes.Grid_Attributes[4, 1].Value.ToString()) <= 0)
  462. //{
  463. // Position pos = new Position(4, 1);
  464. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  465. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  466. // return false;
  467. //}
  468. //if (double.Parse(m_Attributes.Grid_Attributes[5, 1].Value.ToString()) <= 0)
  469. //{
  470. // Position pos = new Position(5, 1);
  471. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  472. // MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  473. // return false;
  474. //}
  475. //if (double.Parse(m_Attributes.Grid_Attributes[6, 1].Value.ToString()) <= 0)
  476. //{
  477. // Position pos = new Position(6, 1);
  478. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  479. // MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  480. // return false;
  481. //}
  482. //if (int.Parse(m_Attributes.Grid_Attributes[7, 1].Value.ToString()) <= 0)
  483. //{
  484. // Position pos = new Position(7, 1);
  485. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  486. // MessageBox.Show(table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  487. // return false;
  488. //}
  489. if (m_Attributes.Grid_Attributes[10, 1].Value != null)
  490. {
  491. if (!GroupIdDictionaryFromName.ContainsKey(m_Attributes.Grid_Attributes[10, 1].Value.ToString()))
  492. {
  493. Position pos = new Position(10, 1);
  494. m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  495. MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  496. return false;
  497. }
  498. }
  499. #region 化学式和元素暂无限制
  500. //if (m_Attributes.Grid_Attributes[7, 1].Value.ToString())
  501. //{
  502. // Position pos = new Position(7, 1);
  503. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  504. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  505. // return false;
  506. //}
  507. //if (m_Attributes.Grid_Attributes[8, 1].Value.ToString())
  508. //{
  509. // Position pos = new Position(8, 1);
  510. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  511. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  512. // return false;
  513. //}
  514. #endregion
  515. return true;
  516. }
  517. public void SaveDataOfSelRule(int PreRow, int PreColumn)
  518. {
  519. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].StrName = m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Value.ToString();
  520. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Color = colorRGBtoHx16(m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
  521. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Hardness = m_Attributes.Grid_Attributes[4, 1].Value.ToString();
  522. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Density = m_Attributes.Grid_Attributes[5, 1].Value.ToString();
  523. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Electrical_conductivity = m_Attributes.Grid_Attributes[6, 1].Value.ToString();
  524. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].BSE = m_Attributes.Grid_Attributes[7, 1].Value.ToString();
  525. if (m_Attributes.Grid_Attributes[8, 1].Value!= null)
  526. {
  527. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Formula = m_Attributes.Grid_Attributes[8, 1].Value.ToString();
  528. }
  529. else
  530. {
  531. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Formula = "";
  532. }
  533. if (m_Attributes.Grid_Attributes[9, 1].Value != null)
  534. {
  535. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Element = m_Attributes.Grid_Attributes[9, 1].Value.ToString();
  536. }
  537. else
  538. {
  539. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Element = "";
  540. }
  541. if (m_Attributes.Grid_Attributes[10, 1].Value != null)
  542. {
  543. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].GroupId = GroupIdDictionaryFromName[m_Attributes.Grid_Attributes[10, 1].Value.ToString()].ToString();
  544. }
  545. else
  546. {
  547. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].GroupId = "0";
  548. }
  549. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Expression = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString();
  550. string sKeyElements = "";
  551. for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Count; i++)
  552. {
  553. sKeyElements += m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  554. }
  555. if (sKeyElements.Length > 0)
  556. {
  557. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  558. }
  559. string sSubElements = "";
  560. for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Count; i++)
  561. {
  562. sSubElements += m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  563. }
  564. if (sSubElements.Length > 0)
  565. {
  566. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  567. }
  568. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].KeyElementList = sKeyElements;
  569. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].SubElementList = sSubElements;
  570. }
  571. /// <summary>
  572. /// 保存ClassifySTD库和MineralElements库
  573. /// </summary>
  574. /// <param name="DBAddress"></param>
  575. /// <returns></returns>
  576. bool SaveDictionaryToClassify(string DBAddress)
  577. {
  578. //保存列表顺序
  579. for(int i=1;i<m_STDRuleslist.Grid_Minerals.RowsCount;i++)
  580. {
  581. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[i,0].Tag].ListNum = i.ToString();
  582. }
  583. #region 数据库存贮方式一
  584. //System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  585. //System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  586. //cmm.CommandText = "delete from ClassifySTD";
  587. //try
  588. //{
  589. // m_dbConnection.Open();
  590. // cmm.ExecuteNonQuery();
  591. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  592. // {
  593. // string insertstr = "Insert into ClassifySTD(STDId,StrName,Color,KeyElementList,SubElementList,UsingImgPropertyList,UsingOtherPropertyList,Expression,Hardness,Density,Electrical_conductivity,BSE,Formula,Element)";
  594. // string aa="values(" + kv.Value.STDId + ",'" + kv.Value.StrName + "','" + kv.Value.Color + "','" + kv.Value.KeyElementList + "','" + kv.Value.SubElementList + "','" + kv.Value.UsingImgPropertyList + "','" + kv.Value.UsingOtherPropertyList + "','" + kv.Value.Expression + "'," + kv.Value.Hardness + "," + kv.Value.Density + "," + kv.Value.Electrical_conductivity + "," + kv.Value.BSE + ",'" + kv.Value.Formula + "','" + kv.Value.Element + "')";
  595. // cmm.CommandText = insertstr+aa;
  596. // cmm.ExecuteNonQuery();
  597. // }
  598. //}
  599. //catch (Exception ex)
  600. //{
  601. // MessageBox.Show(ex.ToString());
  602. //}
  603. //m_dbConnection.Close();
  604. #endregion
  605. try
  606. {
  607. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  608. m_dbConnection.Open();
  609. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  610. cmm.CommandText = "delete from ClassifySTD";
  611. //cmm.CommandText = "delete from ClassifySTD_Backup";
  612. try
  613. {
  614. cmm.ExecuteNonQuery();
  615. }
  616. catch (Exception ex)
  617. {
  618. MessageBox.Show(ex.ToString());
  619. return false;
  620. }
  621. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD", m_dbConnection);
  622. //System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD_Backup", m_dbConnection);
  623. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  624. DataSet ds = new DataSet();
  625. m_dataAdapter.Fill(ds, "ClassifySTD");
  626. DataTable dt = ds.Tables["ClassifySTD"];
  627. //m_dataAdapter.Fill(ds, "ClassifySTD_Backup");
  628. //DataTable dt = ds.Tables["ClassifySTD_Backup"];
  629. dt.Clear();
  630. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  631. {
  632. string UsingElementList = "";
  633. string UsingImgPropertyList = "";
  634. string UsingOtherPropertyList = "";
  635. List<string> UsingElementL = new List<string>();
  636. List<string> UsingImgPropertyL = new List<string>();
  637. List<string> UsingOtherPropertyL = new List<string>();
  638. string str_RemoveBlank = kv.Value.Expression;
  639. //forth_elem干扰or分隔符,故先行去掉
  640. if (str_RemoveBlank.Contains("forth_elem"))
  641. {
  642. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  643. UsingOtherPropertyList = "forth_elem,";
  644. }
  645. str_RemoveBlank = str_RemoveBlank.Replace(" ", "");
  646. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  647. List<string> str_Removeandor = new List<string>();
  648. for (int i = 0; i < str_Removeand.Length; i++)
  649. {
  650. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  651. }
  652. List<string> list_all = new List<string>();
  653. for (int i = 0; i < str_Removeandor.Count; i++)
  654. {
  655. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  656. }
  657. for (int i = 0; i < list_all.Count; i++)
  658. {
  659. //周期元素?
  660. if (m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  661. {
  662. if (!UsingElementL.Contains(list_all[i]))
  663. {
  664. UsingElementL.Add(list_all[i]);
  665. }
  666. }
  667. //first_elem?
  668. if (m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  669. {
  670. if (!UsingOtherPropertyL.Contains(list_all[i]))
  671. {
  672. UsingOtherPropertyL.Add(list_all[i]);
  673. }
  674. }
  675. //Element1?
  676. if (m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  677. {
  678. if (!UsingOtherPropertyL.Contains(list_all[i]))
  679. {
  680. UsingOtherPropertyL.Add(list_all[i]);
  681. }
  682. }
  683. //其它元素?
  684. if (m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  685. {
  686. if (!UsingImgPropertyL.Contains(list_all[i]))
  687. {
  688. UsingImgPropertyL.Add(list_all[i]);
  689. }
  690. }
  691. }
  692. if (UsingElementL.Count > 0)
  693. {
  694. for (int i = 0; i < UsingElementL.Count - 1; i++)
  695. {
  696. UsingElementList += UsingElementL[i] + ",";
  697. }
  698. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  699. }
  700. if (UsingImgPropertyL.Count > 0)
  701. {
  702. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  703. {
  704. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  705. }
  706. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  707. }
  708. if (UsingOtherPropertyL.Count > 0)
  709. {
  710. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  711. {
  712. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  713. }
  714. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  715. }
  716. DataRow newRow = dt.NewRow();
  717. newRow["STDId"] = kv.Key;
  718. newRow["StrName"] = kv.Value.StrName;
  719. newRow["Color"] = kv.Value.Color;
  720. newRow["KeyElementList"] = kv.Value.KeyElementList;
  721. newRow["SubElementList"] = kv.Value.SubElementList;
  722. newRow["UsingImgPropertyList"] = UsingImgPropertyList;
  723. newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
  724. newRow["Expression"] = kv.Value.Expression;
  725. newRow["Hardness"] = kv.Value.Hardness;
  726. newRow["Density"] = kv.Value.Density;
  727. newRow["Electrical_conductivity"] = kv.Value.Electrical_conductivity;
  728. newRow["BSE"] = int.Parse(kv.Value.BSE);
  729. newRow["Formula"] = kv.Value.Formula;
  730. newRow["Element"] = kv.Value.Element;
  731. newRow["GroupId"] = int.Parse(kv.Value.GroupId);
  732. newRow["ListNum"] = kv.Value.ListNum;
  733. dt.Rows.Add(newRow);
  734. }
  735. m_dataAdapter.Update(ds,"ClassifySTD");
  736. m_dbConnection.Close();
  737. }
  738. catch (Exception ex)
  739. {
  740. MessageBox.Show(ex.ToString());
  741. return false;
  742. }
  743. return true;
  744. }
  745. public int AddSTDDictionaryItem()
  746. {
  747. STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
  748. new_STDdata.Hardness = "1";
  749. new_STDdata.Density = "1";
  750. new_STDdata.Electrical_conductivity = "1";
  751. new_STDdata.BSE = "1";
  752. new_STDdata.Formula = "1";
  753. new_STDdata.Element = "1";
  754. new_STDdata.StrName = "NewRuleName";
  755. //new_STDdata.Expression = "NewRules";
  756. new_STDdata.Expression = "";
  757. new_STDdata.KeyElementList = "";
  758. new_STDdata.SubElementList = "";
  759. new_STDdata.Color = colorRGBtoHx16(Color.Gray.R, Color.Gray.G, Color.Gray.B);
  760. int STDId = 40000;
  761. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  762. {
  763. if (STDId < kv.Key)
  764. {
  765. STDId = kv.Key;
  766. }
  767. }
  768. STDDictionary.Add(STDId + 1, new_STDdata);
  769. return STDId + 1;
  770. }
  771. public void RemoveSTDDictionaryItem(int STDId)
  772. {
  773. STDDictionary.Remove(STDId);
  774. }
  775. public void ChangeStrName(int RowNum, string NewStrName)
  776. {
  777. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag].StrName = NewStrName;
  778. m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
  779. }
  780. public void ChangeSTDRulesLISTBackColor()
  781. {
  782. int stdid=m_STDRuleslist.ChangeSTDRulesLISTBackColor();
  783. if (stdid != -1)
  784. {
  785. m_SubMidWindow.m_STDEditor.SelSTDXray(stdid, STDDictionary[stdid]);
  786. }
  787. }
  788. public void ChangeSTDRuleName(String RuleName)
  789. {
  790. m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value = RuleName;
  791. }
  792. public void SetNull()
  793. {
  794. m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  795. for (int i = 1; i<m_Attributes.Grid_Attributes.RowsCount-1; i++)
  796. {
  797. m_Attributes.Grid_Attributes[i, 1].Value = "";
  798. }
  799. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  800. view.BackColor = Color.White;
  801. m_Attributes.Grid_Attributes[2, 1].View= view;
  802. m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows.Clear();
  803. m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Clear();
  804. m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows.Clear();
  805. m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Clear();
  806. }
  807. private void ribbon_ESDMaxRules_Click(object sender, EventArgs e)
  808. {
  809. Form_MaxEDSRules form_MaxEDSRules = new Form_MaxEDSRules(STDDBAddress);
  810. form_MaxEDSRules.Show();
  811. }
  812. private void ribbon_ZeroRules_Click(object sender, EventArgs e)
  813. {
  814. Form_ZeroElementRules form_ZeroElementRules = new Form_ZeroElementRules(STDDBAddress);
  815. form_ZeroElementRules.Show();
  816. }
  817. private void ribbon_UserConstants_Click(object sender, EventArgs e)
  818. {
  819. Form_UserConstants form_UserConstants = new Form_UserConstants(STDDBAddress);
  820. DialogResult dialogResult=form_UserConstants.ShowDialog();
  821. if (dialogResult == DialogResult.Yes)
  822. {
  823. try
  824. {
  825. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  826. m_dbConnection.Open();
  827. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select value from Constants", m_dbConnection);
  828. DataSet ds = new DataSet();
  829. m_dataAdapter.Fill(ds);
  830. DataTable dt = ds.Tables[0];
  831. string ConstantsStr = dt.Rows[0][0].ToString();
  832. ConstantsStr = ConstantsStr.Replace(" ", "");
  833. string[] ConstantsStr2 = ConstantsStr.Split(',');
  834. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  835. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  836. m_dbConnection.Close();
  837. }
  838. catch (Exception ee)
  839. {
  840. MessageBox.Show(ee.ToString());
  841. }
  842. }
  843. }
  844. public void AddSTDGroupsToAttribute()
  845. {
  846. try
  847. {
  848. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  849. m_dbConnection.Open();
  850. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select name,id from STDGroups order by iorder", m_dbConnection);
  851. DataSet ds = new DataSet();
  852. m_dataAdapter.Fill(ds);
  853. DataTable dt = ds.Tables[0];
  854. if (dt != null)
  855. {
  856. if (dt.Rows.Count >= 0)
  857. {
  858. GroupIdDictionaryFromId.Clear();
  859. GroupIdDictionaryFromName.Clear();
  860. if (dt.Select("id='0'").Length==0)
  861. {
  862. GroupIdDictionaryFromId.Add(0, "Default");
  863. GroupIdDictionaryFromName.Add("Default", 0);
  864. }
  865. List<string> ss = new List<string>();
  866. foreach (DataRow item in dt.Rows)
  867. {
  868. ss.Add(item["name"].ToString());
  869. GroupIdDictionaryFromName.Add(item["name"].ToString(), int.Parse(item["id"].ToString()));
  870. GroupIdDictionaryFromId.Add(int.Parse(item["id"].ToString()),item["name"].ToString());
  871. }
  872. SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
  873. GroupIdCBBox.StandardValues = ss;
  874. GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick| SourceGrid.EditableMode.Focus;
  875. m_Attributes.Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("Default", GroupIdCBBox);
  876. }
  877. }
  878. //string ConstantsStr = dt.Rows[0][0].ToString();
  879. m_dbConnection.Close();
  880. }
  881. catch (Exception ee)
  882. {
  883. MessageBox.Show(ee.ToString());
  884. }
  885. }
  886. void SetNonexistentGroupsToDefault()
  887. {
  888. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  889. {
  890. if(!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
  891. {
  892. kv.Value.GroupId = "0";
  893. }
  894. }
  895. m_Attributes.Grid_Attributes.Refresh();
  896. }
  897. private void ribbon_GroupNameMaintenance_Click(object sender, EventArgs e)
  898. {
  899. 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();
  900. Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress,this);
  901. DialogResult dialogResult = form_GroupId.ShowDialog();
  902. if (dialogResult == DialogResult.Yes)
  903. {
  904. AddSTDGroupsToAttribute();
  905. //SetNonexistentGroupsToDefault();
  906. }
  907. }
  908. private void ribbon_Exit_Click(object sender, EventArgs e)
  909. {
  910. this.Close();
  911. }
  912. #region XML文档部分代码
  913. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  914. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  915. //private void Form_ConstantsEditor2_Load(object sender, EventArgs e)
  916. //{
  917. // //XmlDocument doc = new XmlDocument();
  918. // //doc.Load(Address);
  919. // //doc.Load(Address_backup);
  920. // //LoadXmlToDictionary(doc, ref STDDictionary);
  921. //}
  922. //private void rbRecover_Click(object sender, EventArgs e)
  923. //{
  924. // try
  925. // {
  926. // //System.IO.File.Copy(Address_backup, Address, true);
  927. // //XmlDocument doc = new XmlDocument();
  928. // //doc.Load(Address);
  929. // //LoadXmlToDictionary(doc, ref STDDictionary);
  930. // }
  931. //}
  932. //void LoadXmlToDictionary(XmlDocument xml, ref Dictionary<int, STDdata> STDDictionary)
  933. //{
  934. // XmlNode root = xml.SelectSingleNode("XMLData");
  935. // XmlNodeList root2 = root.SelectNodes("Collection");
  936. // for (int j = 0; j < root2.Count; j++)
  937. // {
  938. // if (root2[j].Attributes["RegName"].Value.ToString() == "STDList")
  939. // {
  940. // XmlNodeList childlist = root2[j].ChildNodes;
  941. // for (int i = 0; i < childlist.Count; i++)
  942. // {
  943. // //BSE、化学式、元素
  944. // string strBseValue = string.Empty;
  945. // string strFormula = string.Empty;
  946. // string strElement = string.Empty;
  947. // if (childlist[i].Attributes["BSE"] != null)
  948. // {
  949. // strBseValue = childlist[i].Attributes["BSE"].Value;
  950. // }
  951. // if (childlist[i].Attributes["Formula"] != null)
  952. // {
  953. // strFormula = childlist[i].Attributes["Formula"].Value;
  954. // }
  955. // if (childlist[i].Attributes["Element"] != null)
  956. // {
  957. // strElement = childlist[i].Attributes["Element"].Value;
  958. // }
  959. // STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
  960. // new_STDdata.Hardness = childlist[i].Attributes["Hardness"].Value;
  961. // new_STDdata.Density = childlist[i].Attributes["Density"].Value;
  962. // new_STDdata.Electrical_conductivity = childlist[i].Attributes["Electrical_conductivity"].Value;
  963. // new_STDdata.BSE = strBseValue;
  964. // new_STDdata.Formula = strFormula;
  965. // new_STDdata.Element = strElement;
  966. // new_STDdata.StrName = childlist[i].Attributes["StrName"].Value;
  967. // new_STDdata.Expression = childlist[i].Attributes["Expression"].Value;
  968. // new_STDdata.STDId = childlist[i].Attributes["STDId"].Value;
  969. // new_STDdata.Color = childlist[i].Attributes["Color"].Value;
  970. // new_STDdata.KeyElementList = childlist[i].Attributes["KeyElementList"].Value;
  971. // new_STDdata.SubElementList = childlist[i].Attributes["SubElementList"].Value;
  972. // STDDictionary.Add(int.Parse(childlist[i].Attributes["STDId"].Value), new_STDdata);
  973. // }
  974. // }
  975. // }
  976. // XmlNode root3 = root.SelectSingleNode("Member");
  977. // string ConstantsStr = root3.Attributes["value"].Value;
  978. // ConstantsStr = ConstantsStr.Replace(" ", "");
  979. // string[] ConstantsStr2 = ConstantsStr.Split(',');
  980. // m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  981. // m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  982. //}
  983. ////保存xmltree内容到xml文件
  984. //void SaveXmlTreeDataToXml(string Address)
  985. //{
  986. // #region text
  987. // //XElement xele = XElement.Load(Address);
  988. // //var item = (from ele1 in xele.Elements("Collection")
  989. // // where ele1.Attribute("RegName").Value.Equals("STDList")
  990. // // select ele1).FirstOrDefault();
  991. // //if (item != null)
  992. // //{
  993. // // item.Remove();
  994. // //}
  995. // //xele.Save(Address);
  996. // #endregion
  997. // XDocument xdoc = XDocument.Load(Address);
  998. // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  999. // var item = (from ele1 in elements.Elements("Collection")
  1000. // where ele1.Attribute("RegName").Value.Equals("STDList")
  1001. // select ele1).FirstOrDefault();
  1002. // if (item != null)
  1003. // {
  1004. // item.Remove();
  1005. // }
  1006. // XElement STD = new XElement("Collection");
  1007. // STD.SetAttributeValue("RegName", "STDList");
  1008. // elements.ElementAt(0).Add(STD);
  1009. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  1010. // {
  1011. // string UsingElementList = "";
  1012. // string UsingImgPropertyList = "";
  1013. // string UsingOtherPropertyList = "";
  1014. // List<string> UsingElementL = new List<string>();
  1015. // List<string> UsingImgPropertyL = new List<string>();
  1016. // List<string> UsingOtherPropertyL = new List<string>();
  1017. // string str_RemoveBlank = kv.Value.Expression;
  1018. // //forth_elem干扰or分隔符,故先行去掉
  1019. // if (str_RemoveBlank.Contains("forth_elem"))
  1020. // {
  1021. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1022. // UsingOtherPropertyList = "forth_elem,";
  1023. // }
  1024. // str_RemoveBlank = str_RemoveBlank.Replace(" ", "");
  1025. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1026. // List<string> str_Removeandor = new List<string>();
  1027. // for (int i = 0; i < str_Removeand.Length; i++)
  1028. // {
  1029. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1030. // }
  1031. // List<string> list_all = new List<string>();
  1032. // for (int i = 0; i < str_Removeandor.Count; i++)
  1033. // {
  1034. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1035. // }
  1036. // for (int i = 0; i < list_all.Count; i++)
  1037. // {
  1038. // //周期元素?
  1039. // if (m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1040. // {
  1041. // if (!UsingElementL.Contains(list_all[i]))
  1042. // {
  1043. // UsingElementL.Add(list_all[i]);
  1044. // }
  1045. // }
  1046. // //first_elem?
  1047. // if (m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  1048. // {
  1049. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1050. // {
  1051. // UsingOtherPropertyL.Add(list_all[i]);
  1052. // }
  1053. // }
  1054. // //Element1?
  1055. // if (m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  1056. // {
  1057. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1058. // {
  1059. // UsingOtherPropertyL.Add(list_all[i]);
  1060. // }
  1061. // }
  1062. // //其它元素?
  1063. // if (m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1064. // {
  1065. // if (!UsingImgPropertyL.Contains(list_all[i]))
  1066. // {
  1067. // UsingImgPropertyL.Add(list_all[i]);
  1068. // }
  1069. // }
  1070. // }
  1071. // if (UsingElementL.Count > 0)
  1072. // {
  1073. // for (int i = 0; i < UsingElementL.Count - 1; i++)
  1074. // {
  1075. // UsingElementList += UsingElementL[i] + ",";
  1076. // }
  1077. // UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1078. // }
  1079. // if (UsingImgPropertyL.Count > 0)
  1080. // {
  1081. // for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1082. // {
  1083. // UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1084. // }
  1085. // UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1086. // }
  1087. // if (UsingOtherPropertyL.Count > 0)
  1088. // {
  1089. // for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1090. // {
  1091. // UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1092. // }
  1093. // UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1094. // }
  1095. // XElement EleName = new XElement("Member");
  1096. // EleName.SetAttributeValue("STDId", kv.Key);
  1097. // EleName.SetAttributeValue("StrName", kv.Value.StrName);
  1098. // EleName.SetAttributeValue("Color", kv.Value.Color);
  1099. // //EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1100. // EleName.SetAttributeValue("KeyElementList", kv.Value.KeyElementList);
  1101. // EleName.SetAttributeValue("SubElementList", kv.Value.SubElementList);
  1102. // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1103. // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1104. // EleName.SetAttributeValue("Expression", kv.Value.Expression);
  1105. // EleName.SetAttributeValue("Hardness", kv.Value.Hardness);
  1106. // EleName.SetAttributeValue("Density", kv.Value.Density);
  1107. // EleName.SetAttributeValue("Electrical_conductivity", kv.Value.Electrical_conductivity);
  1108. // EleName.SetAttributeValue("BSE", kv.Value.BSE);
  1109. // EleName.SetAttributeValue("Formula", kv.Value.Formula);
  1110. // EleName.SetAttributeValue("Element", kv.Value.Element);
  1111. // STD.Add(EleName);
  1112. // }
  1113. // xdoc.Save(Address);
  1114. //}
  1115. #endregion
  1116. private void rbClose_Click(object sender, EventArgs e)
  1117. {
  1118. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1119. {
  1120. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "") && CheckAttributes() && Checktextbox_STDEditor())
  1121. {
  1122. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  1123. }
  1124. else
  1125. {
  1126. return;
  1127. }
  1128. }
  1129. else
  1130. {
  1131. STDDictionaryInitial.Clear();
  1132. } if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
  1133. {
  1134. DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1135. if (dr == DialogResult.Yes)
  1136. {
  1137. FormForWaiting forWaiting = new FormForWaiting();
  1138. forWaiting.Show();
  1139. bool result = SaveDictionaryToClassify(STDDBAddress);
  1140. if (result)
  1141. {
  1142. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  1143. forWaiting.Close();
  1144. }
  1145. else
  1146. {
  1147. forWaiting.Close();
  1148. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  1149. }
  1150. }
  1151. }
  1152. m_Attributes.Close();
  1153. m_STDRuleslist.Close();
  1154. m_SubMidWindow.m_STDEditor.Close();
  1155. m_SubMidWindow.m_ComparativeLibrary.Close();
  1156. m_SubMidWindow.Close();
  1157. ButtonStatusClose();
  1158. if (this.Text.Split(' ').Count() != 0)
  1159. {
  1160. this.Text = this.Text.Split(' ')[0];
  1161. }
  1162. }
  1163. private void rbOpen_Click(object sender, EventArgs e)
  1164. {
  1165. OpenFileDialog openFileDialog = new OpenFileDialog();
  1166. openFileDialog.Filter = "(*.db)|*.db";
  1167. openFileDialog.RestoreDirectory = true;
  1168. openFileDialog.FilterIndex = 1;
  1169. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1170. {
  1171. try
  1172. {
  1173. STDDBAddress = openFileDialog.FileName;
  1174. InitForms(STDDBAddress);
  1175. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  1176. IsModified = false;
  1177. }
  1178. catch (Exception ex)
  1179. {
  1180. MessageBox.Show(table["message6"].ToString(), table["message32"].ToString());
  1181. }
  1182. }
  1183. }
  1184. void ButtonStatusOpen()
  1185. {
  1186. rbOpen.Enabled = false;
  1187. rbClose.Enabled = true;
  1188. //rbRecover.Enabled = true;
  1189. rbBackup.Enabled = true;
  1190. rbSave.Enabled = true;
  1191. ribbon_ZeroRules.Enabled = true;
  1192. ribbon_ESDMaxRules.Enabled = true;
  1193. ribbon_UserConstants.Enabled = true;
  1194. ribbon_GroupNameMaintenance.Enabled = true;
  1195. ribbon_BulkImport.Enabled = true;
  1196. }
  1197. void ButtonStatusClose()
  1198. {
  1199. rbOpen.Enabled = true;
  1200. rbClose.Enabled = false;
  1201. //rbRecover.Enabled = false;
  1202. rbBackup.Enabled = false;
  1203. rbSave.Enabled = false;
  1204. ribbon_ZeroRules.Enabled = false;
  1205. ribbon_ESDMaxRules.Enabled = false;
  1206. ribbon_UserConstants.Enabled = false;
  1207. ribbon_GroupNameMaintenance.Enabled = false;
  1208. ribbon_BulkImport.Enabled = false;
  1209. }
  1210. void InitForms(string DBAddress)
  1211. {
  1212. STDDictionary.Clear();
  1213. bool ret = LoadClassifyToDictionary(DBAddress, ref STDDictionary);
  1214. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  1215. if (!ret)
  1216. {
  1217. return;
  1218. }
  1219. ButtonStatusOpen();
  1220. m_STDRuleslist = new STDRuleslist(this);
  1221. m_Attributes = new Attributes(this);
  1222. m_SubMidWindow = new SubMidWindow(this);
  1223. m_DockWindow = new OTSDockWindow(this);
  1224. m_DockWindow.CreateMainWindow();
  1225. if (m_SubMidWindow.m_STDEditor.m_sc != null)
  1226. {
  1227. m_SubMidWindow.m_STDEditor.m_sc.CloseDB();
  1228. }
  1229. m_SubMidWindow.m_STDEditor.m_sc = new SqlLiteClass(DBAddress);
  1230. LoadConstants(DBAddress);
  1231. m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  1232. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1233. {
  1234. Position pos = new Position(1, 0);
  1235. m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  1236. m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
  1237. ChangeSTDEditorAndGrid_Attributes(int.Parse(m_STDRuleslist.Grid_Minerals[1, 0].Tag.ToString()));
  1238. m_STDRuleslist.button_UpOrder.Enabled = false;
  1239. }
  1240. }
  1241. private void ribbon_BulkImport_Click(object sender, EventArgs e)
  1242. {
  1243. OpenFileDialog openFileDialog = new OpenFileDialog();
  1244. openFileDialog.Filter = "(*.db)|*.db";
  1245. openFileDialog.RestoreDirectory = true;
  1246. openFileDialog.FilterIndex = 1;
  1247. openFileDialog.Title = table["message33"].ToString();
  1248. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1249. {
  1250. try
  1251. {
  1252. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");
  1253. m_dbConnection.Open();
  1254. if(STDDictionary.Count==0)
  1255. {
  1256. MessageBox.Show(table["message27"].ToString(), table["message32"].ToString());
  1257. return;
  1258. }
  1259. string STDId = m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row,m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column].Tag.ToString();
  1260. bool ret = false;//搜索结果
  1261. for(int i=0;i< STDDictionary.Count;i++)
  1262. {
  1263. STDEditor.Result result = m_SubMidWindow.m_STDEditor.ImportFromResult(STDDictionary.Keys.ElementAt(i).ToString(), m_dbConnection);
  1264. if (result == STDEditor.Result.Success)
  1265. {
  1266. ret = true;
  1267. }
  1268. else if(result == STDEditor.Result.Fail)
  1269. {
  1270. return;
  1271. }
  1272. }
  1273. if (!ret)
  1274. {
  1275. MessageBox.Show(table["message34"].ToString(), table["message32"].ToString());
  1276. }
  1277. int color = Convert.ToInt32(m_SubMidWindow.m_STDEditor.ParseRGB(STDRuleslist.colorHx16toRGB(STDDictionary[int.Parse(STDId)].Color)).ToString());
  1278. for (int j = 0; j < m_SubMidWindow.m_STDEditor.m_STDXrayList.Count; j++)
  1279. {
  1280. if (m_SubMidWindow.m_STDEditor.m_STDXrayList[j].StdID == STDId)
  1281. {
  1282. m_SubMidWindow.m_STDEditor.ShowXrayAtlas(color, m_SubMidWindow.m_STDEditor.m_STDXrayList[j].XrayData);
  1283. break;
  1284. }
  1285. }
  1286. m_dbConnection.Close();
  1287. }
  1288. catch(Exception ex)
  1289. {
  1290. MessageBox.Show(ex.ToString());
  1291. }
  1292. }
  1293. }
  1294. bool EqualsBetweenDictionary(Dictionary<int, STDdata> STDDictionaryInitial, Dictionary<int, STDdata> STDDictionary)
  1295. {
  1296. if(STDDictionaryInitial.Count!= STDDictionary.Count)
  1297. {
  1298. return false;
  1299. }
  1300. foreach(var key in STDDictionaryInitial.Keys)
  1301. {
  1302. if (STDDictionary.Keys.Contains(key))
  1303. {
  1304. if(!STDDictionaryInitial[key].Equals(STDDictionary[key]))
  1305. {
  1306. return false;
  1307. }
  1308. }
  1309. else
  1310. {
  1311. return false;
  1312. }
  1313. }
  1314. return true;
  1315. }
  1316. private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
  1317. {
  1318. if (m_STDRuleslist.Text != "")
  1319. {
  1320. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1321. {
  1322. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "") && CheckAttributes() && Checktextbox_STDEditor())
  1323. {
  1324. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  1325. }
  1326. else
  1327. {
  1328. e.Cancel = true;
  1329. return;
  1330. }
  1331. }
  1332. else
  1333. {
  1334. STDDictionaryInitial.Clear();
  1335. }
  1336. if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary)|| IsModified)
  1337. {
  1338. DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1339. if (dr == DialogResult.Yes)
  1340. {
  1341. FormForWaiting forWaiting = new FormForWaiting();
  1342. forWaiting.Show();
  1343. bool result = SaveDictionaryToClassify(STDDBAddress);
  1344. if (result)
  1345. {
  1346. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  1347. forWaiting.Close();
  1348. }
  1349. else
  1350. {
  1351. forWaiting.Close();
  1352. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  1353. }
  1354. }
  1355. else
  1356. {
  1357. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  1358. {
  1359. if (!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
  1360. {
  1361. MessageBox.Show("There is non-existent grouping informations in the classification, please adjust!");
  1362. e.Cancel = true;
  1363. return;
  1364. }
  1365. }
  1366. }
  1367. }
  1368. }
  1369. }
  1370. private void ribbon_ConvertOreDatabaseToOtsDatabase_Click(object sender, EventArgs e)
  1371. {
  1372. DataTable OreDatabasedt = new DataTable();
  1373. OpenFileDialog openFileDialog = new OpenFileDialog();
  1374. openFileDialog.Title= table["message37"].ToString();
  1375. openFileDialog.Filter = "(*.db)|*.db";
  1376. openFileDialog.RestoreDirectory = true;
  1377. openFileDialog.FilterIndex = 1;
  1378. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1379. {
  1380. try
  1381. {
  1382. string OreDatabaseAddress = openFileDialog.FileName;
  1383. System.Data.SQLite.SQLiteConnection m_OreDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + OreDatabaseAddress + "'");
  1384. m_OreDatabaseConnection.Open();
  1385. System.Data.SQLite.SQLiteDataAdapter m_OreDatabasedataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals", m_OreDatabaseConnection);
  1386. DataSet OreDatabaseds = new DataSet();
  1387. m_OreDatabasedataAdapter.Fill(OreDatabaseds);
  1388. OreDatabasedt = OreDatabaseds.Tables[0];
  1389. int listnum = 1;
  1390. SaveFileDialog saveFile = new SaveFileDialog();
  1391. saveFile.Title = table["message23"].ToString();
  1392. saveFile.Filter = table["message36"].ToString();
  1393. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  1394. saveFile.RestoreDirectory = true; //还原上次目录
  1395. if (saveFile.ShowDialog() == DialogResult.OK)
  1396. {
  1397. System.Data.SQLite.SQLiteConnection.CreateFile(saveFile.FileName);
  1398. System.Data.SQLite.SQLiteConnection m_OtsDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + saveFile.FileName + "'");
  1399. m_OtsDatabaseConnection.Open();
  1400. System.Data.SQLite.SQLiteCommand OtsDatabaseCommand = m_OtsDatabaseConnection.CreateCommand();
  1401. OtsDatabaseCommand.CommandText = "CREATE TABLE ClassifySTD (STDId INTEGER,StrName TEXT, Color TEXT,KeyElementList TEXT,SubElementList TEXT,UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT,Hardness TEXT,Density TEXT,Electrical_conductivity TEXT,BSE INTEGER,Formula TEXT,Element TEXT,ListNum INT,GroupId INT)";
  1402. OtsDatabaseCommand.ExecuteNonQuery();
  1403. OtsDatabaseCommand.CommandText = "CREATE TABLE Constants (value TEXT)";
  1404. OtsDatabaseCommand.ExecuteNonQuery();
  1405. OtsDatabaseCommand.CommandText = "CREATE TABLE MaxEDSRules (MaxEDSTime INT,UsingElementList TEXT, UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT)";
  1406. OtsDatabaseCommand.ExecuteNonQuery();
  1407. OtsDatabaseCommand.CommandText = "CREATE TABLE STDGroups (id INTEGER,name TEXT, color INTEGER,iorder INTEGER)";
  1408. OtsDatabaseCommand.ExecuteNonQuery();
  1409. OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,SPEC BLOB)";
  1410. OtsDatabaseCommand.ExecuteNonQuery();
  1411. OtsDatabaseCommand.CommandText = "CREATE TABLE ZeroElementRules (ZeroElement TEXT,UsingElementList TEXT, UsingImgPropertyList TEXT,Expression TEXT)";
  1412. OtsDatabaseCommand.ExecuteNonQuery();
  1413. System.Data.Common.DbTransaction trans = m_OtsDatabaseConnection.BeginTransaction();
  1414. foreach (DataRow item in OreDatabasedt.Rows)
  1415. {
  1416. OtsDatabaseCommand.CommandText = "insert into ClassifySTD (Density,BSE,Formula,StrName,Color,STDId,ListNum,GroupId,KeyElementList,SubElementList,UsingImgPropertyList,UsingOtherPropertyList,Expression,Hardness,Electrical_conductivity,Element) values ( '" + item["density"].ToString() + "','" + item["BSEValue"].ToString() + "','" + item["formula"].ToString() + "','" + item["name"].ToString() + "','" + item["color"].ToString() + "'," + item["id"].ToString() + "," + listnum.ToString() + @",0,' ',' ',' ',' ',' ',' ',' ',' ')";
  1417. OtsDatabaseCommand.ExecuteNonQuery();
  1418. listnum++;
  1419. OtsDatabaseCommand.CommandText = "insert into STDMinerals (id,SPEC) values (@id,@SPEC)";
  1420. OtsDatabaseCommand.Parameters.Add("id", DbType.Int32).Value = item["id"];
  1421. OtsDatabaseCommand.Parameters.Add("SPEC", DbType.Binary).Value = item["SPEC"];
  1422. OtsDatabaseCommand.ExecuteNonQuery();
  1423. }
  1424. trans.Commit();
  1425. }
  1426. else
  1427. {
  1428. return;
  1429. }
  1430. }
  1431. catch(Exception ex)
  1432. {
  1433. MessageBox.Show(ex.ToString());
  1434. }
  1435. }
  1436. else
  1437. {
  1438. return;
  1439. }
  1440. }
  1441. }
  1442. }