Form_ConstantsEditor2.cs 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  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. try
  584. {
  585. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  586. m_dbConnection.Open();
  587. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  588. cmm.CommandText = "delete from ClassifySTD";
  589. //cmm.CommandText = "delete from ClassifySTD_Backup";
  590. try
  591. {
  592. cmm.ExecuteNonQuery();
  593. }
  594. catch (Exception ex)
  595. {
  596. MessageBox.Show(ex.ToString());
  597. return false;
  598. }
  599. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD", m_dbConnection);
  600. //System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD_Backup", m_dbConnection);
  601. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  602. DataSet ds = new DataSet();
  603. m_dataAdapter.Fill(ds, "ClassifySTD");
  604. DataTable dt = ds.Tables["ClassifySTD"];
  605. //m_dataAdapter.Fill(ds, "ClassifySTD_Backup");
  606. //DataTable dt = ds.Tables["ClassifySTD_Backup"];
  607. dt.Clear();
  608. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  609. {
  610. string UsingElementList = "";
  611. string UsingImgPropertyList = "";
  612. string UsingOtherPropertyList = "";
  613. List<string> UsingElementL = new List<string>();
  614. List<string> UsingImgPropertyL = new List<string>();
  615. List<string> UsingOtherPropertyL = new List<string>();
  616. string str_RemoveBlank = kv.Value.Expression;
  617. //forth_elem干扰or分隔符,故先行去掉
  618. if (str_RemoveBlank.Contains("forth_elem"))
  619. {
  620. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  621. UsingOtherPropertyList = "forth_elem,";
  622. }
  623. str_RemoveBlank = str_RemoveBlank.Replace(" ", "");
  624. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  625. List<string> str_Removeandor = new List<string>();
  626. for (int i = 0; i < str_Removeand.Length; i++)
  627. {
  628. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  629. }
  630. List<string> list_all = new List<string>();
  631. for (int i = 0; i < str_Removeandor.Count; i++)
  632. {
  633. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  634. }
  635. for (int i = 0; i < list_all.Count; i++)
  636. {
  637. //周期元素?
  638. if (m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  639. {
  640. if (!UsingElementL.Contains(list_all[i]))
  641. {
  642. UsingElementL.Add(list_all[i]);
  643. }
  644. }
  645. //first_elem?
  646. if (m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  647. {
  648. if (!UsingOtherPropertyL.Contains(list_all[i]))
  649. {
  650. UsingOtherPropertyL.Add(list_all[i]);
  651. }
  652. }
  653. //Element1?
  654. if (m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  655. {
  656. if (!UsingOtherPropertyL.Contains(list_all[i]))
  657. {
  658. UsingOtherPropertyL.Add(list_all[i]);
  659. }
  660. }
  661. //其它元素?
  662. if (m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  663. {
  664. if (!UsingImgPropertyL.Contains(list_all[i]))
  665. {
  666. UsingImgPropertyL.Add(list_all[i]);
  667. }
  668. }
  669. }
  670. if (UsingElementL.Count > 0)
  671. {
  672. for (int i = 0; i < UsingElementL.Count - 1; i++)
  673. {
  674. UsingElementList += UsingElementL[i] + ",";
  675. }
  676. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  677. }
  678. if (UsingImgPropertyL.Count > 0)
  679. {
  680. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  681. {
  682. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  683. }
  684. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  685. }
  686. if (UsingOtherPropertyL.Count > 0)
  687. {
  688. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  689. {
  690. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  691. }
  692. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  693. }
  694. DataRow newRow = dt.NewRow();
  695. newRow["STDId"] = kv.Key;
  696. newRow["StrName"] = kv.Value.StrName;
  697. newRow["Color"] = kv.Value.Color;
  698. newRow["KeyElementList"] = kv.Value.KeyElementList;
  699. newRow["SubElementList"] = kv.Value.SubElementList;
  700. newRow["UsingImgPropertyList"] = UsingImgPropertyList;
  701. newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
  702. newRow["Expression"] = kv.Value.Expression;
  703. newRow["Hardness"] = kv.Value.Hardness;
  704. newRow["Density"] = kv.Value.Density;
  705. newRow["Electrical_conductivity"] = kv.Value.Electrical_conductivity;
  706. newRow["BSE"] = int.Parse(kv.Value.BSE);
  707. newRow["Formula"] = kv.Value.Formula;
  708. newRow["Element"] = kv.Value.Element;
  709. newRow["GroupId"] = int.Parse(kv.Value.GroupId);
  710. newRow["ListNum"] = kv.Value.ListNum;
  711. dt.Rows.Add(newRow);
  712. }
  713. m_dataAdapter.Update(ds,"ClassifySTD");
  714. m_dbConnection.Close();
  715. }
  716. catch (Exception ex)
  717. {
  718. MessageBox.Show(ex.ToString());
  719. return false;
  720. }
  721. return true;
  722. }
  723. public int AddSTDDictionaryItem()
  724. {
  725. STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
  726. new_STDdata.Hardness = "1";
  727. new_STDdata.Density = "1";
  728. new_STDdata.Electrical_conductivity = "1";
  729. new_STDdata.BSE = "1";
  730. new_STDdata.Formula = "1";
  731. new_STDdata.Element = "1";
  732. new_STDdata.StrName = "NewRuleName";
  733. //new_STDdata.Expression = "NewRules";
  734. new_STDdata.Expression = "";
  735. new_STDdata.KeyElementList = "";
  736. new_STDdata.SubElementList = "";
  737. new_STDdata.Color = colorRGBtoHx16(Color.Gray.R, Color.Gray.G, Color.Gray.B);
  738. int STDId = 40000;
  739. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  740. {
  741. if (STDId < kv.Key)
  742. {
  743. STDId = kv.Key;
  744. }
  745. }
  746. STDDictionary.Add(STDId + 1, new_STDdata);
  747. return STDId + 1;
  748. }
  749. public void RemoveSTDDictionaryItem(int STDId)
  750. {
  751. STDDictionary.Remove(STDId);
  752. }
  753. public void ChangeStrName(int RowNum, string NewStrName)
  754. {
  755. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag].StrName = NewStrName;
  756. m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
  757. }
  758. public void ChangeSTDRulesLISTBackColor()
  759. {
  760. int stdid=m_STDRuleslist.ChangeSTDRulesLISTBackColor();
  761. if (stdid != -1)
  762. {
  763. m_SubMidWindow.m_STDEditor.SelSTDXray(stdid, STDDictionary[stdid]);
  764. }
  765. }
  766. public void ChangeSTDRuleName(String RuleName)
  767. {
  768. m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value = RuleName;
  769. }
  770. public void SetNull()
  771. {
  772. m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  773. for (int i = 1; i<m_Attributes.Grid_Attributes.RowsCount-1; i++)
  774. {
  775. m_Attributes.Grid_Attributes[i, 1].Value = "";
  776. }
  777. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  778. view.BackColor = Color.White;
  779. m_Attributes.Grid_Attributes[2, 1].View= view;
  780. m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows.Clear();
  781. m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Clear();
  782. m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows.Clear();
  783. m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Clear();
  784. }
  785. private void ribbon_ESDMaxRules_Click(object sender, EventArgs e)
  786. {
  787. Form_MaxEDSRules form_MaxEDSRules = new Form_MaxEDSRules(STDDBAddress);
  788. form_MaxEDSRules.Show();
  789. }
  790. private void ribbon_ZeroRules_Click(object sender, EventArgs e)
  791. {
  792. Form_ZeroElementRules form_ZeroElementRules = new Form_ZeroElementRules(STDDBAddress);
  793. form_ZeroElementRules.Show();
  794. }
  795. private void ribbon_UserConstants_Click(object sender, EventArgs e)
  796. {
  797. Form_UserConstants form_UserConstants = new Form_UserConstants(STDDBAddress);
  798. DialogResult dialogResult=form_UserConstants.ShowDialog();
  799. if (dialogResult == DialogResult.Yes)
  800. {
  801. try
  802. {
  803. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  804. m_dbConnection.Open();
  805. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select value from Constants", m_dbConnection);
  806. DataSet ds = new DataSet();
  807. m_dataAdapter.Fill(ds);
  808. DataTable dt = ds.Tables[0];
  809. string ConstantsStr = dt.Rows[0][0].ToString();
  810. ConstantsStr = ConstantsStr.Replace(" ", "");
  811. string[] ConstantsStr2 = ConstantsStr.Split(',');
  812. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  813. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  814. m_dbConnection.Close();
  815. }
  816. catch (Exception ee)
  817. {
  818. MessageBox.Show(ee.ToString());
  819. }
  820. }
  821. }
  822. public void AddSTDGroupsToAttribute()
  823. {
  824. try
  825. {
  826. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  827. m_dbConnection.Open();
  828. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select name,id from STDGroups order by iorder", m_dbConnection);
  829. DataSet ds = new DataSet();
  830. m_dataAdapter.Fill(ds);
  831. DataTable dt = ds.Tables[0];
  832. if (dt != null)
  833. {
  834. if (dt.Rows.Count >= 0)
  835. {
  836. GroupIdDictionaryFromId.Clear();
  837. GroupIdDictionaryFromName.Clear();
  838. if (dt.Select("id='0'").Length==0)
  839. {
  840. GroupIdDictionaryFromId.Add(0, "Default");
  841. GroupIdDictionaryFromName.Add("Default", 0);
  842. }
  843. List<string> ss = new List<string>();
  844. foreach (DataRow item in dt.Rows)
  845. {
  846. ss.Add(item["name"].ToString());
  847. GroupIdDictionaryFromName.Add(item["name"].ToString(), int.Parse(item["id"].ToString()));
  848. GroupIdDictionaryFromId.Add(int.Parse(item["id"].ToString()),item["name"].ToString());
  849. }
  850. SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
  851. GroupIdCBBox.StandardValues = ss;
  852. GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick| SourceGrid.EditableMode.Focus;
  853. m_Attributes.Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("Default", GroupIdCBBox);
  854. }
  855. }
  856. //string ConstantsStr = dt.Rows[0][0].ToString();
  857. m_dbConnection.Close();
  858. }
  859. catch (Exception ee)
  860. {
  861. MessageBox.Show(ee.ToString());
  862. }
  863. }
  864. void SetNonexistentGroupsToDefault()
  865. {
  866. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  867. {
  868. if(!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
  869. {
  870. kv.Value.GroupId = "0";
  871. }
  872. }
  873. m_Attributes.Grid_Attributes.Refresh();
  874. }
  875. private void ribbon_GroupNameMaintenance_Click(object sender, EventArgs e)
  876. {
  877. 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();
  878. Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress,this);
  879. DialogResult dialogResult = form_GroupId.ShowDialog();
  880. if (dialogResult == DialogResult.Yes)
  881. {
  882. AddSTDGroupsToAttribute();
  883. //SetNonexistentGroupsToDefault();
  884. }
  885. }
  886. private void ribbon_Exit_Click(object sender, EventArgs e)
  887. {
  888. this.Close();
  889. }
  890. #region XML文档部分代码
  891. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  892. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  893. //private void Form_ConstantsEditor2_Load(object sender, EventArgs e)
  894. //{
  895. // //XmlDocument doc = new XmlDocument();
  896. // //doc.Load(Address);
  897. // //doc.Load(Address_backup);
  898. // //LoadXmlToDictionary(doc, ref STDDictionary);
  899. //}
  900. //private void rbRecover_Click(object sender, EventArgs e)
  901. //{
  902. // try
  903. // {
  904. // //System.IO.File.Copy(Address_backup, Address, true);
  905. // //XmlDocument doc = new XmlDocument();
  906. // //doc.Load(Address);
  907. // //LoadXmlToDictionary(doc, ref STDDictionary);
  908. // }
  909. //}
  910. //void LoadXmlToDictionary(XmlDocument xml, ref Dictionary<int, STDdata> STDDictionary)
  911. //{
  912. // XmlNode root = xml.SelectSingleNode("XMLData");
  913. // XmlNodeList root2 = root.SelectNodes("Collection");
  914. // for (int j = 0; j < root2.Count; j++)
  915. // {
  916. // if (root2[j].Attributes["RegName"].Value.ToString() == "STDList")
  917. // {
  918. // XmlNodeList childlist = root2[j].ChildNodes;
  919. // for (int i = 0; i < childlist.Count; i++)
  920. // {
  921. // //BSE、化学式、元素
  922. // string strBseValue = string.Empty;
  923. // string strFormula = string.Empty;
  924. // string strElement = string.Empty;
  925. // if (childlist[i].Attributes["BSE"] != null)
  926. // {
  927. // strBseValue = childlist[i].Attributes["BSE"].Value;
  928. // }
  929. // if (childlist[i].Attributes["Formula"] != null)
  930. // {
  931. // strFormula = childlist[i].Attributes["Formula"].Value;
  932. // }
  933. // if (childlist[i].Attributes["Element"] != null)
  934. // {
  935. // strElement = childlist[i].Attributes["Element"].Value;
  936. // }
  937. // STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
  938. // new_STDdata.Hardness = childlist[i].Attributes["Hardness"].Value;
  939. // new_STDdata.Density = childlist[i].Attributes["Density"].Value;
  940. // new_STDdata.Electrical_conductivity = childlist[i].Attributes["Electrical_conductivity"].Value;
  941. // new_STDdata.BSE = strBseValue;
  942. // new_STDdata.Formula = strFormula;
  943. // new_STDdata.Element = strElement;
  944. // new_STDdata.StrName = childlist[i].Attributes["StrName"].Value;
  945. // new_STDdata.Expression = childlist[i].Attributes["Expression"].Value;
  946. // new_STDdata.STDId = childlist[i].Attributes["STDId"].Value;
  947. // new_STDdata.Color = childlist[i].Attributes["Color"].Value;
  948. // new_STDdata.KeyElementList = childlist[i].Attributes["KeyElementList"].Value;
  949. // new_STDdata.SubElementList = childlist[i].Attributes["SubElementList"].Value;
  950. // STDDictionary.Add(int.Parse(childlist[i].Attributes["STDId"].Value), new_STDdata);
  951. // }
  952. // }
  953. // }
  954. // XmlNode root3 = root.SelectSingleNode("Member");
  955. // string ConstantsStr = root3.Attributes["value"].Value;
  956. // ConstantsStr = ConstantsStr.Replace(" ", "");
  957. // string[] ConstantsStr2 = ConstantsStr.Split(',');
  958. // m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  959. // m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  960. //}
  961. ////保存xmltree内容到xml文件
  962. //void SaveXmlTreeDataToXml(string Address)
  963. //{
  964. // #region text
  965. // //XElement xele = XElement.Load(Address);
  966. // //var item = (from ele1 in xele.Elements("Collection")
  967. // // where ele1.Attribute("RegName").Value.Equals("STDList")
  968. // // select ele1).FirstOrDefault();
  969. // //if (item != null)
  970. // //{
  971. // // item.Remove();
  972. // //}
  973. // //xele.Save(Address);
  974. // #endregion
  975. // XDocument xdoc = XDocument.Load(Address);
  976. // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  977. // var item = (from ele1 in elements.Elements("Collection")
  978. // where ele1.Attribute("RegName").Value.Equals("STDList")
  979. // select ele1).FirstOrDefault();
  980. // if (item != null)
  981. // {
  982. // item.Remove();
  983. // }
  984. // XElement STD = new XElement("Collection");
  985. // STD.SetAttributeValue("RegName", "STDList");
  986. // elements.ElementAt(0).Add(STD);
  987. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  988. // {
  989. // string UsingElementList = "";
  990. // string UsingImgPropertyList = "";
  991. // string UsingOtherPropertyList = "";
  992. // List<string> UsingElementL = new List<string>();
  993. // List<string> UsingImgPropertyL = new List<string>();
  994. // List<string> UsingOtherPropertyL = new List<string>();
  995. // string str_RemoveBlank = kv.Value.Expression;
  996. // //forth_elem干扰or分隔符,故先行去掉
  997. // if (str_RemoveBlank.Contains("forth_elem"))
  998. // {
  999. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1000. // UsingOtherPropertyList = "forth_elem,";
  1001. // }
  1002. // str_RemoveBlank = str_RemoveBlank.Replace(" ", "");
  1003. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1004. // List<string> str_Removeandor = new List<string>();
  1005. // for (int i = 0; i < str_Removeand.Length; i++)
  1006. // {
  1007. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1008. // }
  1009. // List<string> list_all = new List<string>();
  1010. // for (int i = 0; i < str_Removeandor.Count; i++)
  1011. // {
  1012. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1013. // }
  1014. // for (int i = 0; i < list_all.Count; i++)
  1015. // {
  1016. // //周期元素?
  1017. // if (m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1018. // {
  1019. // if (!UsingElementL.Contains(list_all[i]))
  1020. // {
  1021. // UsingElementL.Add(list_all[i]);
  1022. // }
  1023. // }
  1024. // //first_elem?
  1025. // if (m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  1026. // {
  1027. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1028. // {
  1029. // UsingOtherPropertyL.Add(list_all[i]);
  1030. // }
  1031. // }
  1032. // //Element1?
  1033. // if (m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  1034. // {
  1035. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1036. // {
  1037. // UsingOtherPropertyL.Add(list_all[i]);
  1038. // }
  1039. // }
  1040. // //其它元素?
  1041. // if (m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1042. // {
  1043. // if (!UsingImgPropertyL.Contains(list_all[i]))
  1044. // {
  1045. // UsingImgPropertyL.Add(list_all[i]);
  1046. // }
  1047. // }
  1048. // }
  1049. // if (UsingElementL.Count > 0)
  1050. // {
  1051. // for (int i = 0; i < UsingElementL.Count - 1; i++)
  1052. // {
  1053. // UsingElementList += UsingElementL[i] + ",";
  1054. // }
  1055. // UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1056. // }
  1057. // if (UsingImgPropertyL.Count > 0)
  1058. // {
  1059. // for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1060. // {
  1061. // UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1062. // }
  1063. // UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1064. // }
  1065. // if (UsingOtherPropertyL.Count > 0)
  1066. // {
  1067. // for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1068. // {
  1069. // UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1070. // }
  1071. // UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1072. // }
  1073. // XElement EleName = new XElement("Member");
  1074. // EleName.SetAttributeValue("STDId", kv.Key);
  1075. // EleName.SetAttributeValue("StrName", kv.Value.StrName);
  1076. // EleName.SetAttributeValue("Color", kv.Value.Color);
  1077. // //EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1078. // EleName.SetAttributeValue("KeyElementList", kv.Value.KeyElementList);
  1079. // EleName.SetAttributeValue("SubElementList", kv.Value.SubElementList);
  1080. // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1081. // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1082. // EleName.SetAttributeValue("Expression", kv.Value.Expression);
  1083. // EleName.SetAttributeValue("Hardness", kv.Value.Hardness);
  1084. // EleName.SetAttributeValue("Density", kv.Value.Density);
  1085. // EleName.SetAttributeValue("Electrical_conductivity", kv.Value.Electrical_conductivity);
  1086. // EleName.SetAttributeValue("BSE", kv.Value.BSE);
  1087. // EleName.SetAttributeValue("Formula", kv.Value.Formula);
  1088. // EleName.SetAttributeValue("Element", kv.Value.Element);
  1089. // STD.Add(EleName);
  1090. // }
  1091. // xdoc.Save(Address);
  1092. //}
  1093. #endregion
  1094. private void rbClose_Click(object sender, EventArgs e)
  1095. {
  1096. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1097. {
  1098. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "") && CheckAttributes() && Checktextbox_STDEditor())
  1099. {
  1100. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  1101. }
  1102. else
  1103. {
  1104. return;
  1105. }
  1106. }
  1107. else
  1108. {
  1109. STDDictionaryInitial.Clear();
  1110. } if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
  1111. {
  1112. DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1113. if (dr == DialogResult.Yes)
  1114. {
  1115. FormForWaiting forWaiting = new FormForWaiting();
  1116. forWaiting.Show();
  1117. bool result = SaveDictionaryToClassify(STDDBAddress);
  1118. if (result)
  1119. {
  1120. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  1121. forWaiting.Close();
  1122. }
  1123. else
  1124. {
  1125. forWaiting.Close();
  1126. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  1127. }
  1128. }
  1129. }
  1130. m_Attributes.Close();
  1131. m_STDRuleslist.Close();
  1132. m_SubMidWindow.m_STDEditor.Close();
  1133. m_SubMidWindow.m_ComparativeLibrary.Close();
  1134. m_SubMidWindow.Close();
  1135. ButtonStatusClose();
  1136. if (this.Text.Split(' ').Count() != 0)
  1137. {
  1138. this.Text = this.Text.Split(' ')[0];
  1139. }
  1140. }
  1141. private void rbOpen_Click(object sender, EventArgs e)
  1142. {
  1143. OpenFileDialog openFileDialog = new OpenFileDialog();
  1144. openFileDialog.Filter = "(*.db)|*.db";
  1145. openFileDialog.RestoreDirectory = true;
  1146. openFileDialog.FilterIndex = 1;
  1147. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1148. {
  1149. try
  1150. {
  1151. STDDBAddress = openFileDialog.FileName;
  1152. InitForms(STDDBAddress);
  1153. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  1154. IsModified = false;
  1155. }
  1156. catch (Exception ex)
  1157. {
  1158. MessageBox.Show(table["message6"].ToString(), table["message32"].ToString());
  1159. }
  1160. }
  1161. }
  1162. void ButtonStatusOpen()
  1163. {
  1164. rbOpen.Enabled = false;
  1165. rbClose.Enabled = true;
  1166. //rbRecover.Enabled = true;
  1167. rbBackup.Enabled = true;
  1168. rbSave.Enabled = true;
  1169. ribbon_ZeroRules.Enabled = true;
  1170. ribbon_ESDMaxRules.Enabled = true;
  1171. ribbon_UserConstants.Enabled = true;
  1172. ribbon_GroupNameMaintenance.Enabled = true;
  1173. ribbon_BulkImport.Enabled = true;
  1174. }
  1175. void ButtonStatusClose()
  1176. {
  1177. rbOpen.Enabled = true;
  1178. rbClose.Enabled = false;
  1179. //rbRecover.Enabled = false;
  1180. rbBackup.Enabled = false;
  1181. rbSave.Enabled = false;
  1182. ribbon_ZeroRules.Enabled = false;
  1183. ribbon_ESDMaxRules.Enabled = false;
  1184. ribbon_UserConstants.Enabled = false;
  1185. ribbon_GroupNameMaintenance.Enabled = false;
  1186. ribbon_BulkImport.Enabled = false;
  1187. }
  1188. void InitForms(string DBAddress)
  1189. {
  1190. STDDictionary.Clear();
  1191. bool ret = LoadClassifyToDictionary(DBAddress, ref STDDictionary);
  1192. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  1193. if (!ret)
  1194. {
  1195. return;
  1196. }
  1197. ButtonStatusOpen();
  1198. m_STDRuleslist = new STDRuleslist(this);
  1199. m_Attributes = new Attributes(this);
  1200. m_SubMidWindow = new SubMidWindow(this);
  1201. m_DockWindow = new OTSDockWindow(this);
  1202. m_DockWindow.CreateMainWindow();
  1203. if (m_SubMidWindow.m_STDEditor.m_sc != null)
  1204. {
  1205. m_SubMidWindow.m_STDEditor.m_sc.CloseDB();
  1206. }
  1207. m_SubMidWindow.m_STDEditor.m_sc = new SqlLiteClass(DBAddress);
  1208. LoadConstants(DBAddress);
  1209. m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  1210. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1211. {
  1212. Position pos = new Position(1, 0);
  1213. m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  1214. m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
  1215. ChangeSTDEditorAndGrid_Attributes(int.Parse(m_STDRuleslist.Grid_Minerals[1, 0].Tag.ToString()));
  1216. m_STDRuleslist.button_UpOrder.Enabled = false;
  1217. }
  1218. }
  1219. private void ribbon_BulkImport_Click(object sender, EventArgs e)
  1220. {
  1221. OpenFileDialog openFileDialog = new OpenFileDialog();
  1222. openFileDialog.Filter = "(*.db)|*.db";
  1223. openFileDialog.RestoreDirectory = true;
  1224. openFileDialog.FilterIndex = 1;
  1225. openFileDialog.Title = table["message33"].ToString();
  1226. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1227. {
  1228. try
  1229. {
  1230. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");
  1231. m_dbConnection.Open();
  1232. if(STDDictionary.Count==0)
  1233. {
  1234. MessageBox.Show(table["message27"].ToString(), table["message32"].ToString());
  1235. return;
  1236. }
  1237. string STDId = m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row,m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column].Tag.ToString();
  1238. bool ret = false;//搜索结果
  1239. for(int i=0;i< STDDictionary.Count;i++)
  1240. {
  1241. STDEditor.Result result = m_SubMidWindow.m_STDEditor.ImportFromResult(STDDictionary.Keys.ElementAt(i).ToString(), m_dbConnection);
  1242. if (result == STDEditor.Result.Success)
  1243. {
  1244. ret = true;
  1245. }
  1246. else if(result == STDEditor.Result.Fail)
  1247. {
  1248. return;
  1249. }
  1250. }
  1251. if (!ret)
  1252. {
  1253. MessageBox.Show(table["message34"].ToString(), table["message32"].ToString());
  1254. }
  1255. int color = Convert.ToInt32(m_SubMidWindow.m_STDEditor.ParseRGB(STDRuleslist.colorHx16toRGB(STDDictionary[int.Parse(STDId)].Color)).ToString());
  1256. for (int j = 0; j < m_SubMidWindow.m_STDEditor.m_STDXrayList.Count; j++)
  1257. {
  1258. if (m_SubMidWindow.m_STDEditor.m_STDXrayList[j].StdID == STDId)
  1259. {
  1260. m_SubMidWindow.m_STDEditor.ShowXrayAtlas(color, m_SubMidWindow.m_STDEditor.m_STDXrayList[j].XrayData);
  1261. break;
  1262. }
  1263. }
  1264. m_dbConnection.Close();
  1265. }
  1266. catch(Exception ex)
  1267. {
  1268. MessageBox.Show(ex.ToString());
  1269. }
  1270. }
  1271. }
  1272. bool EqualsBetweenDictionary(Dictionary<int, STDdata> STDDictionaryInitial, Dictionary<int, STDdata> STDDictionary)
  1273. {
  1274. if(STDDictionaryInitial.Count!= STDDictionary.Count)
  1275. {
  1276. return false;
  1277. }
  1278. foreach(var key in STDDictionaryInitial.Keys)
  1279. {
  1280. if (STDDictionary.Keys.Contains(key))
  1281. {
  1282. if(!STDDictionaryInitial[key].Equals(STDDictionary[key]))
  1283. {
  1284. return false;
  1285. }
  1286. }
  1287. else
  1288. {
  1289. return false;
  1290. }
  1291. }
  1292. return true;
  1293. }
  1294. private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
  1295. {
  1296. if (m_STDRuleslist.Text != "")
  1297. {
  1298. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1299. {
  1300. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "") && CheckAttributes() && Checktextbox_STDEditor())
  1301. {
  1302. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  1303. }
  1304. else
  1305. {
  1306. e.Cancel = true;
  1307. return;
  1308. }
  1309. }
  1310. else
  1311. {
  1312. STDDictionaryInitial.Clear();
  1313. }
  1314. if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary)|| IsModified)
  1315. {
  1316. DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1317. if (dr == DialogResult.Yes)
  1318. {
  1319. FormForWaiting forWaiting = new FormForWaiting();
  1320. forWaiting.Show();
  1321. bool result = SaveDictionaryToClassify(STDDBAddress);
  1322. if (result)
  1323. {
  1324. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  1325. forWaiting.Close();
  1326. }
  1327. else
  1328. {
  1329. forWaiting.Close();
  1330. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  1331. }
  1332. }
  1333. else
  1334. {
  1335. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  1336. {
  1337. if (!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
  1338. {
  1339. MessageBox.Show("There is non-existent grouping informations in the classification, please adjust!");
  1340. e.Cancel = true;
  1341. return;
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. private void ribbon_ConvertOreDatabaseToOtsDatabase_Click(object sender, EventArgs e)
  1349. {
  1350. DataTable OreDatabasedt = new DataTable();
  1351. OpenFileDialog openFileDialog = new OpenFileDialog();
  1352. openFileDialog.Title= table["message37"].ToString();
  1353. openFileDialog.Filter = "(*.db)|*.db";
  1354. openFileDialog.RestoreDirectory = true;
  1355. openFileDialog.FilterIndex = 1;
  1356. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1357. {
  1358. try
  1359. {
  1360. string OreDatabaseAddress = openFileDialog.FileName;
  1361. System.Data.SQLite.SQLiteConnection m_OreDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + OreDatabaseAddress + "'");
  1362. m_OreDatabaseConnection.Open();
  1363. System.Data.SQLite.SQLiteDataAdapter m_OreDatabasedataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals", m_OreDatabaseConnection);
  1364. DataSet OreDatabaseds = new DataSet();
  1365. m_OreDatabasedataAdapter.Fill(OreDatabaseds);
  1366. OreDatabasedt = OreDatabaseds.Tables[0];
  1367. int listnum = 1;
  1368. SaveFileDialog saveFile = new SaveFileDialog();
  1369. saveFile.Title = table["message23"].ToString();
  1370. saveFile.Filter = table["message36"].ToString();
  1371. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  1372. saveFile.RestoreDirectory = true; //还原上次目录
  1373. if (saveFile.ShowDialog() == DialogResult.OK)
  1374. {
  1375. System.Data.SQLite.SQLiteConnection.CreateFile(saveFile.FileName);
  1376. System.Data.SQLite.SQLiteConnection m_OtsDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + saveFile.FileName + "'");
  1377. m_OtsDatabaseConnection.Open();
  1378. System.Data.SQLite.SQLiteCommand OtsDatabaseCommand = m_OtsDatabaseConnection.CreateCommand();
  1379. 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)";
  1380. OtsDatabaseCommand.ExecuteNonQuery();
  1381. OtsDatabaseCommand.CommandText = "CREATE TABLE Constants (value TEXT)";
  1382. OtsDatabaseCommand.ExecuteNonQuery();
  1383. OtsDatabaseCommand.CommandText = "CREATE TABLE MaxEDSRules (MaxEDSTime INT,UsingElementList TEXT, UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT)";
  1384. OtsDatabaseCommand.ExecuteNonQuery();
  1385. OtsDatabaseCommand.CommandText = "CREATE TABLE STDGroups (id INTEGER,name TEXT, color INTEGER,iorder INTEGER)";
  1386. OtsDatabaseCommand.ExecuteNonQuery();
  1387. OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,SPEC BLOB)";
  1388. OtsDatabaseCommand.ExecuteNonQuery();
  1389. OtsDatabaseCommand.CommandText = "CREATE TABLE ZeroElementRules (ZeroElement TEXT,UsingElementList TEXT, UsingImgPropertyList TEXT,Expression TEXT)";
  1390. OtsDatabaseCommand.ExecuteNonQuery();
  1391. System.Data.Common.DbTransaction trans = m_OtsDatabaseConnection.BeginTransaction();
  1392. foreach (DataRow item in OreDatabasedt.Rows)
  1393. {
  1394. 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,' ',' ',' ',' ',' ',' ',' ',' ')";
  1395. OtsDatabaseCommand.ExecuteNonQuery();
  1396. listnum++;
  1397. OtsDatabaseCommand.CommandText = "insert into STDMinerals (id,SPEC) values (@id,@SPEC)";
  1398. OtsDatabaseCommand.Parameters.Add("id", DbType.Int32).Value = item["id"];
  1399. OtsDatabaseCommand.Parameters.Add("SPEC", DbType.Binary).Value = item["SPEC"];
  1400. OtsDatabaseCommand.ExecuteNonQuery();
  1401. }
  1402. trans.Commit();
  1403. }
  1404. else
  1405. {
  1406. return;
  1407. }
  1408. }
  1409. catch(Exception ex)
  1410. {
  1411. MessageBox.Show(ex.ToString());
  1412. }
  1413. }
  1414. else
  1415. {
  1416. return;
  1417. }
  1418. }
  1419. }
  1420. }