Form_ConstantsEditor2.cs 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  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 = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db";
  27. //string STDDBAddress_backup = Application.StartupPath + "\\Config\\SysData\\LibBackup\\" + "OTSCleanlinesSTD_backup.db";
  28. string STDDBAddress_backupDirectory = Application.StartupPath + "\\Config\\SysData\\LibBackup\\";
  29. public string STDDBAddress = "";
  30. //public string STDDBAddress_backup = "";
  31. //国际化
  32. public Language lan;
  33. Hashtable table;
  34. //是否做出过更改
  35. public bool IsModified { set; get; }
  36. public Form_ConstantsEditor2()
  37. {
  38. InitializeComponent();
  39. m_STDRuleslist = new STDRuleslist(this);
  40. m_Attributes = new Attributes(this);
  41. m_SubMidWindow = new SubMidWindow(this);
  42. m_DockWindow = new OTSDockWindow(this);
  43. }
  44. private void Form_ConstantsEditor2_Load(object sender, EventArgs e)
  45. {
  46. lan = new Language(this);
  47. table = lan.GetNameTable("Form_ConstantsEditor2");
  48. if (STDDBAddress != "")
  49. {
  50. InitForms(STDDBAddress);
  51. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  52. IsModified = false;
  53. }
  54. }
  55. void LoadConstants(string STDDBAddress)
  56. {
  57. try
  58. {
  59. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  60. m_dbConnection.Open();
  61. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from Constants", m_dbConnection);
  62. DataSet ds = new DataSet();
  63. m_dataAdapter.Fill(ds);
  64. DataTable dt = ds.Tables[0];
  65. string ConstantsStr = dt.Rows[0][0].ToString();
  66. ConstantsStr = ConstantsStr.Replace(" ", "");
  67. string[] ConstantsStr2 = ConstantsStr.Split(',');
  68. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  69. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  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. //STDDictionaryInitial = new Dictionary<int, STDdata>(STDDictionary);
  111. }
  112. }
  113. }
  114. return true;
  115. }
  116. catch (Exception ee)
  117. {
  118. MessageBox.Show(table["message6"].ToString(), table["message32"].ToString());
  119. return false;
  120. }
  121. }
  122. public void ChangeSTDEditorAndGrid_Attributes(int STDId)
  123. {
  124. m_SubMidWindow.ChangeText_textbox_STDEditor(STDId);
  125. m_SubMidWindow.SelSTDXray(STDId, STDDictionary[STDId]);
  126. m_Attributes.SetDatatoGrid_Attributes(STDId);
  127. }
  128. private void rbBackup_Click(object sender, EventArgs e)
  129. {
  130. if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row >= 0)
  131. {
  132. //if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  133. //{
  134. if (CheckAttributes())
  135. {
  136. if (Checktextbox_STDEditor())
  137. {
  138. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column);
  139. try
  140. {
  141. SaveFileDialog saveFile = new SaveFileDialog();
  142. saveFile.Title = table["message23"].ToString();
  143. saveFile.Filter = table["message36"].ToString();
  144. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  145. saveFile.RestoreDirectory = true; //还原上次目录
  146. if (saveFile.ShowDialog() == DialogResult.OK)
  147. {
  148. System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
  149. bool result = SaveDictionaryToClassify(saveFile.FileName);
  150. if (result)
  151. {
  152. MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  153. }
  154. }
  155. else
  156. {
  157. return;
  158. }
  159. }
  160. catch (Exception ex)
  161. {
  162. MessageBox.Show(ex.Message);
  163. }
  164. }
  165. //}
  166. }
  167. else
  168. {
  169. MessageBox.Show(table["message3"].ToString(), table["message32"].ToString());
  170. }
  171. }
  172. else
  173. {
  174. try
  175. {
  176. SaveFileDialog saveFile = new SaveFileDialog();
  177. saveFile.Title = table["message23"].ToString();
  178. saveFile.Filter = table["message36"].ToString();
  179. saveFile.OverwritePrompt = true; //是否覆盖当前文件
  180. saveFile.RestoreDirectory = true; //还原上次目录
  181. if (saveFile.ShowDialog() == DialogResult.OK)
  182. {
  183. System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
  184. bool result = SaveDictionaryToClassify(saveFile.FileName);
  185. if (result)
  186. {
  187. MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  188. }
  189. }
  190. else
  191. {
  192. return;
  193. }
  194. }
  195. catch (Exception ex)
  196. {
  197. MessageBox.Show(ex.Message);
  198. }
  199. }
  200. }
  201. public bool ClearDb(string DBAddress, string DBTableName)
  202. {
  203. try
  204. {
  205. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  206. m_dbConnection.Open();
  207. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  208. cmm.CommandText = "delete from " + DBTableName;
  209. cmm.ExecuteNonQuery();
  210. m_dbConnection.Close();
  211. return true;
  212. }
  213. catch (Exception ex)
  214. {
  215. MessageBox.Show(ex.ToString());
  216. return false;
  217. }
  218. }
  219. private void rbRecover_Click(object sender, EventArgs e)
  220. {
  221. }
  222. object Clone(Dictionary<int, STDdata> STDDictionary)
  223. {
  224. Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
  225. foreach (var key in STDDictionary.Keys)
  226. {
  227. STDdata tDdata = new STDdata();
  228. tDdata = tDdata.Clone(STDDictionary[key]) as STDdata;
  229. STDDictionaryInitial.Add(key, tDdata);
  230. }
  231. return STDDictionaryInitial;
  232. }
  233. private void rbSave_Click(object sender, EventArgs e)
  234. {
  235. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  236. {
  237. if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
  238. {
  239. if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  240. {
  241. if (CheckAttributes())
  242. {
  243. if (Checktextbox_STDEditor())
  244. {
  245. FormForWaiting forWaiting = new FormForWaiting();
  246. forWaiting.Show();
  247. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  248. // SaveXmlTreeDataToXml(Address);
  249. bool result = SaveDictionaryToClassify(STDDBAddress);
  250. if (result)
  251. {
  252. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  253. STDDictionaryInitial.Clear();
  254. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  255. forWaiting.Close();
  256. IsModified = false;
  257. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString());
  258. }
  259. else
  260. {
  261. forWaiting.Close();
  262. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  263. }
  264. }
  265. }
  266. }
  267. }
  268. else
  269. {
  270. Position pos = new Position(1, 0);
  271. m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  272. if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  273. {
  274. if (CheckAttributes())
  275. {
  276. if (Checktextbox_STDEditor())
  277. {
  278. FormForWaiting forWaiting = new FormForWaiting();
  279. forWaiting.Show();
  280. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  281. //SaveXmlTreeDataToXml(Address);
  282. bool result = SaveDictionaryToClassify(STDDBAddress);
  283. if (result)
  284. {
  285. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  286. STDDictionaryInitial.Clear();
  287. STDDictionaryInitial = new Dictionary<int, STDdata>(STDDictionary);
  288. forWaiting.Close();
  289. IsModified = false;
  290. MessageBox.Show(table["message1"].ToString(), table["message32"].ToString());
  291. }
  292. else
  293. {
  294. forWaiting.Close();
  295. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. }
  303. /// <summary>
  304. /// [颜色:RGB转成16进制]
  305. /// </summary>
  306. /// <param name="R">红 int</param>
  307. /// <param name="G">绿 int</param>
  308. /// <param name="B">蓝 int</param>
  309. /// <returns></returns>
  310. public static string colorRGBtoHx16(int R, int G, int B)
  311. {
  312. return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
  313. }
  314. //表达式规则检查
  315. public bool Checktextbox_STDEditor()
  316. {
  317. string str_RemoveBlank = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString().Replace(" ", "");
  318. str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
  319. //分割符号检验
  320. string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
  321. for (int i = 0; i < Symbol.Length; i++)
  322. {
  323. for (int j = 0; j < Symbol.Length; j++)
  324. {
  325. if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
  326. {
  327. if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
  328. {
  329. MessageBox.Show(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  330. return false;
  331. }
  332. }
  333. }
  334. if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
  335. {
  336. MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  337. return false;
  338. }
  339. if (str_RemoveBlank.Contains("(" + Symbol[i]))
  340. {
  341. MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  342. return false;
  343. }
  344. }
  345. if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
  346. {
  347. //左右括号匹配检验
  348. int BracketsNum = 0;
  349. for (int i = 0; i < str_RemoveBlank.Length; i++)
  350. {
  351. if (str_RemoveBlank[i] == '(') BracketsNum++;
  352. if (str_RemoveBlank[i] == ')') BracketsNum--;
  353. }
  354. if (BracketsNum != 0)
  355. {
  356. MessageBox.Show(table["message19"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  357. return false;
  358. }
  359. //首字符检测
  360. 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] == '('))
  361. {
  362. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  363. return false;
  364. }
  365. if (str_RemoveBlank.Length >= 3)
  366. {
  367. if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
  368. {
  369. MessageBox.Show(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  370. return false;
  371. }
  372. }
  373. }
  374. //forth_elem干扰or分隔符,故先行去掉
  375. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  376. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  377. List<string> str_Removeandor = new List<string>();
  378. for (int i = 0; i < str_Removeand.Length; i++)
  379. {
  380. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  381. }
  382. List<string> list_all = new List<string>();
  383. for (int i = 0; i < str_Removeandor.Count; i++)
  384. {
  385. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  386. }
  387. //常量
  388. List<string> Constantslist = new List<string>();
  389. for (int j = 0; j < m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Count; j++)
  390. {
  391. Constantslist.Add(m_SubMidWindow.m_STDEditor.comboBox_Constants.Items[j].ToString().Split('=')[0]);
  392. }
  393. for (int i = 0; i < list_all.Count; i++)
  394. {
  395. //周期元素?
  396. if (this.m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  397. {
  398. continue;
  399. }
  400. //first_elem?
  401. if (this.m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  402. {
  403. continue;
  404. }
  405. //Element1?
  406. if (this.m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  407. {
  408. continue;
  409. }
  410. //其它元素?
  411. if (this.m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  412. {
  413. continue;
  414. }
  415. //常量?
  416. if (Constantslist.Contains(list_all[i]))
  417. {
  418. continue;
  419. }
  420. //数字?
  421. double DNum = 0;
  422. if (double.TryParse(list_all[i], out DNum))
  423. {
  424. continue;
  425. }
  426. //>=? <=?等其它情况
  427. if (list_all[i] == "")
  428. {
  429. continue;
  430. }
  431. //true false?
  432. if ((list_all[i] == "true") || (list_all[i] == "false"))
  433. {
  434. continue;
  435. }
  436. MessageBox.Show(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  437. return false;
  438. }
  439. //检测是否有<>= true,false
  440. 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")
  441. {
  442. MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  443. return false;
  444. }
  445. return true;
  446. }
  447. //属性检测
  448. public bool CheckAttributes()
  449. {
  450. //if (double.Parse(m_Attributes.Grid_Attributes[4, 1].Value.ToString()) <= 0)
  451. //{
  452. // Position pos = new Position(4, 1);
  453. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  454. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  455. // return false;
  456. //}
  457. //if (double.Parse(m_Attributes.Grid_Attributes[5, 1].Value.ToString()) <= 0)
  458. //{
  459. // Position pos = new Position(5, 1);
  460. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  461. // MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  462. // return false;
  463. //}
  464. //if (double.Parse(m_Attributes.Grid_Attributes[6, 1].Value.ToString()) <= 0)
  465. //{
  466. // Position pos = new Position(6, 1);
  467. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  468. // MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  469. // return false;
  470. //}
  471. if (int.Parse(m_Attributes.Grid_Attributes[7, 1].Value.ToString()) <= 0)
  472. {
  473. Position pos = new Position(7, 1);
  474. m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  475. MessageBox.Show(table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  476. return false;
  477. }
  478. if (m_Attributes.Grid_Attributes[10, 1].Value != null)
  479. {
  480. if (!GroupIdDictionaryFromName.ContainsKey(m_Attributes.Grid_Attributes[10, 1].Value.ToString()))
  481. {
  482. Position pos = new Position(10, 1);
  483. m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  484. MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  485. return false;
  486. }
  487. }
  488. #region 化学式和元素暂无限制
  489. //if (m_Attributes.Grid_Attributes[7, 1].Value.ToString())
  490. //{
  491. // Position pos = new Position(7, 1);
  492. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  493. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  494. // return false;
  495. //}
  496. //if (m_Attributes.Grid_Attributes[8, 1].Value.ToString())
  497. //{
  498. // Position pos = new Position(8, 1);
  499. // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
  500. // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
  501. // return false;
  502. //}
  503. #endregion
  504. return true;
  505. }
  506. public void SaveDataOfSelRule(int PreRow, int PreColumn)
  507. {
  508. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].StrName = m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Value.ToString();
  509. 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);
  510. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Hardness = m_Attributes.Grid_Attributes[4, 1].Value.ToString();
  511. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Density = m_Attributes.Grid_Attributes[5, 1].Value.ToString();
  512. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Electrical_conductivity = m_Attributes.Grid_Attributes[6, 1].Value.ToString();
  513. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].BSE = m_Attributes.Grid_Attributes[7, 1].Value.ToString();
  514. if (m_Attributes.Grid_Attributes[8, 1].Value!= null)
  515. {
  516. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Formula = m_Attributes.Grid_Attributes[8, 1].Value.ToString();
  517. }
  518. else
  519. {
  520. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Formula = "";
  521. }
  522. if (m_Attributes.Grid_Attributes[9, 1].Value != null)
  523. {
  524. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Element = m_Attributes.Grid_Attributes[9, 1].Value.ToString();
  525. }
  526. else
  527. {
  528. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Element = "";
  529. }
  530. if (m_Attributes.Grid_Attributes[10, 1].Value != null)
  531. {
  532. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].GroupId = GroupIdDictionaryFromName[m_Attributes.Grid_Attributes[10, 1].Value.ToString()].ToString();
  533. }
  534. else
  535. {
  536. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].GroupId = "0";
  537. }
  538. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].Expression = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString();
  539. string sKeyElements = "";
  540. for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Count; i++)
  541. {
  542. sKeyElements += m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
  543. }
  544. if (sKeyElements.Length > 0)
  545. {
  546. sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
  547. }
  548. string sSubElements = "";
  549. for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Count; i++)
  550. {
  551. sSubElements += m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
  552. }
  553. if (sSubElements.Length > 0)
  554. {
  555. sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
  556. }
  557. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].KeyElementList = sKeyElements;
  558. STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, PreColumn].Tag.ToString())].SubElementList = sSubElements;
  559. }
  560. /// <summary>
  561. /// 保存ClassifySTD库和MineralElements库
  562. /// </summary>
  563. /// <param name="DBAddress"></param>
  564. /// <returns></returns>
  565. bool SaveDictionaryToClassify(string DBAddress)
  566. {
  567. //保存列表顺序
  568. for(int i=1;i<m_STDRuleslist.Grid_Minerals.RowsCount;i++)
  569. {
  570. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[i,0].Tag].ListNum = i.ToString();
  571. }
  572. #region 数据库存贮方式一
  573. //System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  574. //System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  575. //cmm.CommandText = "delete from ClassifySTD";
  576. //try
  577. //{
  578. // m_dbConnection.Open();
  579. // cmm.ExecuteNonQuery();
  580. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  581. // {
  582. // string insertstr = "Insert into ClassifySTD(STDId,StrName,Color,KeyElementList,SubElementList,UsingImgPropertyList,UsingOtherPropertyList,Expression,Hardness,Density,Electrical_conductivity,BSE,Formula,Element)";
  583. // 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 + "')";
  584. // cmm.CommandText = insertstr+aa;
  585. // cmm.ExecuteNonQuery();
  586. // }
  587. //}
  588. //catch (Exception ex)
  589. //{
  590. // MessageBox.Show(ex.ToString());
  591. //}
  592. //m_dbConnection.Close();
  593. #endregion
  594. try
  595. {
  596. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
  597. m_dbConnection.Open();
  598. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  599. cmm.CommandText = "delete from ClassifySTD";
  600. //cmm.CommandText = "delete from ClassifySTD_Backup";
  601. try
  602. {
  603. cmm.ExecuteNonQuery();
  604. }
  605. catch (Exception ex)
  606. {
  607. MessageBox.Show(ex.ToString());
  608. return false;
  609. }
  610. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD", m_dbConnection);
  611. //System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD_Backup", m_dbConnection);
  612. System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
  613. DataSet ds = new DataSet();
  614. m_dataAdapter.Fill(ds, "ClassifySTD");
  615. DataTable dt = ds.Tables["ClassifySTD"];
  616. //m_dataAdapter.Fill(ds, "ClassifySTD_Backup");
  617. //DataTable dt = ds.Tables["ClassifySTD_Backup"];
  618. dt.Clear();
  619. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  620. {
  621. string UsingElementList = "";
  622. string UsingImgPropertyList = "";
  623. string UsingOtherPropertyList = "";
  624. List<string> UsingElementL = new List<string>();
  625. List<string> UsingImgPropertyL = new List<string>();
  626. List<string> UsingOtherPropertyL = new List<string>();
  627. string str_RemoveBlank = kv.Value.Expression;
  628. //forth_elem干扰or分隔符,故先行去掉
  629. if (str_RemoveBlank.Contains("forth_elem"))
  630. {
  631. str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  632. UsingOtherPropertyList = "forth_elem,";
  633. }
  634. str_RemoveBlank = str_RemoveBlank.Replace(" ", "");
  635. string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  636. List<string> str_Removeandor = new List<string>();
  637. for (int i = 0; i < str_Removeand.Length; i++)
  638. {
  639. str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  640. }
  641. List<string> list_all = new List<string>();
  642. for (int i = 0; i < str_Removeandor.Count; i++)
  643. {
  644. list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  645. }
  646. for (int i = 0; i < list_all.Count; i++)
  647. {
  648. //周期元素?
  649. if (m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  650. {
  651. if (!UsingElementL.Contains(list_all[i]))
  652. {
  653. UsingElementL.Add(list_all[i]);
  654. }
  655. }
  656. //first_elem?
  657. if (m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  658. {
  659. if (!UsingOtherPropertyL.Contains(list_all[i]))
  660. {
  661. UsingOtherPropertyL.Add(list_all[i]);
  662. }
  663. }
  664. //Element1?
  665. if (m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  666. {
  667. if (!UsingOtherPropertyL.Contains(list_all[i]))
  668. {
  669. UsingOtherPropertyL.Add(list_all[i]);
  670. }
  671. }
  672. //其它元素?
  673. if (m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  674. {
  675. if (!UsingImgPropertyL.Contains(list_all[i]))
  676. {
  677. UsingImgPropertyL.Add(list_all[i]);
  678. }
  679. }
  680. }
  681. if (UsingElementL.Count > 0)
  682. {
  683. for (int i = 0; i < UsingElementL.Count - 1; i++)
  684. {
  685. UsingElementList += UsingElementL[i] + ",";
  686. }
  687. UsingElementList += UsingElementL[UsingElementL.Count - 1];
  688. }
  689. if (UsingImgPropertyL.Count > 0)
  690. {
  691. for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  692. {
  693. UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  694. }
  695. UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  696. }
  697. if (UsingOtherPropertyL.Count > 0)
  698. {
  699. for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  700. {
  701. UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  702. }
  703. UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  704. }
  705. DataRow newRow = dt.NewRow();
  706. newRow["STDId"] = kv.Key;
  707. newRow["StrName"] = kv.Value.StrName;
  708. newRow["Color"] = kv.Value.Color;
  709. newRow["KeyElementList"] = kv.Value.KeyElementList;
  710. newRow["SubElementList"] = kv.Value.SubElementList;
  711. newRow["UsingImgPropertyList"] = UsingImgPropertyList;
  712. newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
  713. newRow["Expression"] = kv.Value.Expression;
  714. newRow["Hardness"] = kv.Value.Hardness;
  715. newRow["Density"] = kv.Value.Density;
  716. newRow["Electrical_conductivity"] = kv.Value.Electrical_conductivity;
  717. newRow["BSE"] = int.Parse(kv.Value.BSE);
  718. newRow["Formula"] = kv.Value.Formula;
  719. newRow["Element"] = kv.Value.Element;
  720. newRow["GroupId"] = int.Parse(kv.Value.GroupId);
  721. newRow["ListNum"] = kv.Value.ListNum;
  722. dt.Rows.Add(newRow);
  723. }
  724. m_dataAdapter.Update(ds,"ClassifySTD");
  725. //m_dataAdapter.Update(ds, "ClassifySTD_Backup");
  726. //Dictionary<int, string> MineralElements = new Dictionary<int, string>();
  727. //foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  728. //{
  729. // string[] ConstantsStr = kv.Value.Element.Split(',');
  730. // //string[] ConstantsStrnew=new
  731. // //for (int i = 0; i < ConstantsStr.Length; i++)
  732. // //{
  733. // //}
  734. // for (int i = 0; i < ConstantsStr.Length; i++)
  735. // {
  736. // string[] ConstantsStr2 = ConstantsStr[i].Split(':');
  737. // double elementPercentage=0;
  738. // if (ConstantsStr2.Length == 2)
  739. // {
  740. // if (double.TryParse(ConstantsStr2[1], out elementPercentage) && m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(ConstantsStr2[0]))
  741. // {
  742. // int elementID = GetelementID(ConstantsStr2[0]);
  743. // string insertstr = "Insert into MineralElements(mineralID,elementID,elementName,elementPercentage)";
  744. // string aa="values(" + kv.Key + ",'" + elementID + "','" + ConstantsStr2[0] + "','" + elementPercentage + "')";
  745. // cmm.CommandText = insertstr+aa;
  746. // cmm.ExecuteNonQuery();
  747. // }
  748. // }
  749. // }
  750. //}
  751. m_dbConnection.Close();
  752. }
  753. catch (Exception ex)
  754. {
  755. MessageBox.Show(ex.ToString());
  756. return false;
  757. }
  758. return true;
  759. }
  760. //int GetelementID(string elementName)
  761. //{
  762. // int elementID = 0;
  763. // switch (elementName)
  764. // {
  765. // case "H":
  766. // elementID = 1;
  767. // break;
  768. // case "He":
  769. // elementID = 2;
  770. // break;
  771. // case "Li":
  772. // elementID = 3;
  773. // break;
  774. // case "Be":
  775. // elementID = 4;
  776. // break;
  777. // case "B":
  778. // elementID = 5;
  779. // break;
  780. // case "C":
  781. // elementID = 6;
  782. // break;
  783. // case "N":
  784. // elementID = 7;
  785. // break;
  786. // case "O":
  787. // elementID = 8;
  788. // break;
  789. // case "F":
  790. // elementID = 9;
  791. // break;
  792. // case "Ne":
  793. // elementID = 10;
  794. // break;
  795. // case "Na":
  796. // elementID = 11;
  797. // break;
  798. // case "Mg":
  799. // elementID = 12;
  800. // break;
  801. // case "Al":
  802. // elementID = 13;
  803. // break;
  804. // case "Si":
  805. // elementID = 14;
  806. // break;
  807. // case "P":
  808. // elementID = 15;
  809. // break;
  810. // case "S":
  811. // elementID = 16;
  812. // break;
  813. // case "Cl":
  814. // elementID = 17;
  815. // break;
  816. // case "Ar":
  817. // elementID = 18;
  818. // break;
  819. // case "K":
  820. // elementID = 19;
  821. // break;
  822. // case "Ca":
  823. // elementID = 20;
  824. // break;
  825. // case "Sc":
  826. // elementID = 21;
  827. // break;
  828. // case "Ti":
  829. // elementID = 22;
  830. // break;
  831. // case "V":
  832. // elementID = 23;
  833. // break;
  834. // case "Cr":
  835. // elementID = 24;
  836. // break;
  837. // case "Mn":
  838. // elementID = 25;
  839. // break;
  840. // case "Fe":
  841. // elementID = 26;
  842. // break;
  843. // case "Co":
  844. // elementID = 27;
  845. // break;
  846. // case "Ni":
  847. // elementID = 28;
  848. // break;
  849. // case "Cu":
  850. // elementID = 29;
  851. // break;
  852. // case "Zn":
  853. // elementID = 30;
  854. // break;
  855. // case "Ga":
  856. // elementID = 31;
  857. // break;
  858. // case "Ge":
  859. // elementID = 32;
  860. // break;
  861. // case "As":
  862. // elementID = 33;
  863. // break;
  864. // case "Se":
  865. // elementID = 34;
  866. // break;
  867. // case "Br":
  868. // elementID = 35;
  869. // break;
  870. // case "Kr":
  871. // elementID = 36;
  872. // break;
  873. // case "Rb":
  874. // elementID = 37;
  875. // break;
  876. // case "Sr":
  877. // elementID = 38;
  878. // break;
  879. // case "Y":
  880. // elementID = 39;
  881. // break;
  882. // case "Zr":
  883. // elementID = 40;
  884. // break;
  885. // case "Nb":
  886. // elementID = 41;
  887. // break;
  888. // case "Mo":
  889. // elementID = 42;
  890. // break;
  891. // case "Tc":
  892. // elementID = 43;
  893. // break;
  894. // case "Ru":
  895. // elementID = 44;
  896. // break;
  897. // case "Rh":
  898. // elementID = 45;
  899. // break;
  900. // case "Pd":
  901. // elementID = 46;
  902. // break;
  903. // case "Ag":
  904. // elementID = 47;
  905. // break;
  906. // case "Cd":
  907. // elementID = 48;
  908. // break;
  909. // case "In":
  910. // elementID = 49;
  911. // break;
  912. // case "Sn":
  913. // elementID = 50;
  914. // break;
  915. // case "Sb":
  916. // elementID = 51;
  917. // break;
  918. // case "Te":
  919. // elementID = 52;
  920. // break;
  921. // case "I":
  922. // elementID = 53;
  923. // break;
  924. // case "Xe":
  925. // elementID = 54;
  926. // break;
  927. // case "Cs":
  928. // elementID = 55;
  929. // break;
  930. // case "Ba":
  931. // elementID = 56;
  932. // break;
  933. // case "La":
  934. // elementID = 57;
  935. // break;
  936. // case "Ce":
  937. // elementID = 58;
  938. // break;
  939. // case "Pr":
  940. // elementID = 59;
  941. // break;
  942. // case "Nd":
  943. // elementID = 60;
  944. // break;
  945. // case "Pm":
  946. // elementID = 61;
  947. // break;
  948. // case "Sm":
  949. // elementID = 62;
  950. // break;
  951. // case "Eu":
  952. // elementID = 63;
  953. // break;
  954. // case "Gd":
  955. // elementID = 64;
  956. // break;
  957. // case "Tb":
  958. // elementID = 65;
  959. // break;
  960. // case "Dy":
  961. // elementID = 66;
  962. // break;
  963. // case "Ho":
  964. // elementID = 67;
  965. // break;
  966. // case "Er":
  967. // elementID = 68;
  968. // break;
  969. // case "Tm":
  970. // elementID = 69;
  971. // break;
  972. // case "Yb":
  973. // elementID = 70;
  974. // break;
  975. // case "Lu":
  976. // elementID = 71;
  977. // break;
  978. // case "Hf":
  979. // elementID = 72;
  980. // break;
  981. // case "Ta":
  982. // elementID = 73;
  983. // break;
  984. // case "W":
  985. // elementID = 74;
  986. // break;
  987. // case "Re":
  988. // elementID = 75;
  989. // break;
  990. // case "Os":
  991. // elementID = 76;
  992. // break;
  993. // case "Ir":
  994. // elementID = 77;
  995. // break;
  996. // case "Pt":
  997. // elementID = 78;
  998. // break;
  999. // case "Au":
  1000. // elementID = 79;
  1001. // break;
  1002. // case "Hq":
  1003. // elementID = 80;
  1004. // break;
  1005. // case "TI":
  1006. // elementID = 81;
  1007. // break;
  1008. // case "Pb":
  1009. // elementID = 82;
  1010. // break;
  1011. // case "Bi":
  1012. // elementID = 83;
  1013. // break;
  1014. // case "Po":
  1015. // elementID = 84;
  1016. // break;
  1017. // case "At":
  1018. // elementID = 85;
  1019. // break;
  1020. // case "Rn":
  1021. // elementID = 86;
  1022. // break;
  1023. // case "Fr":
  1024. // elementID = 87;
  1025. // break;
  1026. // case "Ra":
  1027. // elementID = 88;
  1028. // break;
  1029. // case "Ac":
  1030. // elementID = 89;
  1031. // break;
  1032. // case "Th":
  1033. // elementID = 90;
  1034. // break;
  1035. // case "Pa":
  1036. // elementID = 91;
  1037. // break;
  1038. // case "U":
  1039. // elementID = 92;
  1040. // break;
  1041. // case "Np":
  1042. // elementID = 93;
  1043. // break;
  1044. // case "Pu":
  1045. // elementID = 94;
  1046. // break;
  1047. // case "Am":
  1048. // elementID = 95;
  1049. // break;
  1050. // case "Cm":
  1051. // elementID = 96;
  1052. // break;
  1053. // case "Bk":
  1054. // elementID = 97;
  1055. // break;
  1056. // case "Cf":
  1057. // elementID = 98;
  1058. // break;
  1059. // case "Es":
  1060. // elementID = 99;
  1061. // break;
  1062. // case "Fm":
  1063. // elementID = 100;
  1064. // break;
  1065. // case "Mc":
  1066. // elementID = 101;
  1067. // break;
  1068. // case "No":
  1069. // elementID = 102;
  1070. // break;
  1071. // case "Lr":
  1072. // elementID = 103;
  1073. // break;
  1074. // case "Rf":
  1075. // elementID = 104;
  1076. // break;
  1077. // case "Db":
  1078. // elementID = 105;
  1079. // break;
  1080. // case "Sg":
  1081. // elementID = 106;
  1082. // break;
  1083. // case "Bh":
  1084. // elementID = 107;
  1085. // break;
  1086. // case "Hs":
  1087. // elementID = 108;
  1088. // break;
  1089. // case "Mt":
  1090. // elementID = 109;
  1091. // break;
  1092. // case "Ds":
  1093. // elementID = 110;
  1094. // break;
  1095. // case "Rg":
  1096. // elementID = 111;
  1097. // break;
  1098. // case "Unb":
  1099. // elementID = 112;
  1100. // break;
  1101. // }
  1102. // return elementID;
  1103. //}
  1104. public int AddSTDDictionaryItem()
  1105. {
  1106. STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
  1107. new_STDdata.Hardness = "1";
  1108. new_STDdata.Density = "1";
  1109. new_STDdata.Electrical_conductivity = "1";
  1110. new_STDdata.BSE = "1";
  1111. new_STDdata.Formula = "1";
  1112. new_STDdata.Element = "1";
  1113. new_STDdata.StrName = "NewRuleName";
  1114. //new_STDdata.Expression = "NewRules";
  1115. new_STDdata.Expression = "";
  1116. new_STDdata.KeyElementList = "";
  1117. new_STDdata.SubElementList = "";
  1118. new_STDdata.Color = colorRGBtoHx16(Color.Gray.R, Color.Gray.G, Color.Gray.B);
  1119. int STDId = 40000;
  1120. foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  1121. {
  1122. if (STDId < kv.Key)
  1123. {
  1124. STDId = kv.Key;
  1125. }
  1126. }
  1127. STDDictionary.Add(STDId + 1, new_STDdata);
  1128. return STDId + 1;
  1129. }
  1130. public void RemoveSTDDictionaryItem(int STDId)
  1131. {
  1132. STDDictionary.Remove(STDId);
  1133. }
  1134. public void ChangeStrName(int RowNum, string NewStrName)
  1135. {
  1136. STDDictionary[(int)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag].StrName = NewStrName;
  1137. m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
  1138. }
  1139. public void ChangeSTDRulesLISTBackColor()
  1140. {
  1141. int stdid=m_STDRuleslist.ChangeSTDRulesLISTBackColor();
  1142. if (stdid != -1)
  1143. {
  1144. m_SubMidWindow.m_STDEditor.SelSTDXray(stdid, STDDictionary[stdid]);
  1145. }
  1146. }
  1147. public void ChangeSTDRuleName(String RuleName)
  1148. {
  1149. m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value = RuleName;
  1150. }
  1151. public void SetNull()
  1152. {
  1153. m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  1154. for (int i = 1; i<m_Attributes.Grid_Attributes.RowsCount-1; i++)
  1155. {
  1156. m_Attributes.Grid_Attributes[i, 1].Value = "";
  1157. }
  1158. SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
  1159. view.BackColor = Color.White;
  1160. m_Attributes.Grid_Attributes[2, 1].View= view;
  1161. m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows.Clear();
  1162. m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Clear();
  1163. m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows.Clear();
  1164. m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Clear();
  1165. }
  1166. private void ribbon_ESDMaxRules_Click(object sender, EventArgs e)
  1167. {
  1168. Form_MaxEDSRules form_MaxEDSRules = new Form_MaxEDSRules(STDDBAddress);
  1169. form_MaxEDSRules.Show();
  1170. }
  1171. private void ribbon_ZeroRules_Click(object sender, EventArgs e)
  1172. {
  1173. Form_ZeroElementRules form_ZeroElementRules = new Form_ZeroElementRules(STDDBAddress);
  1174. form_ZeroElementRules.Show();
  1175. }
  1176. private void ribbon_UserConstants_Click(object sender, EventArgs e)
  1177. {
  1178. Form_UserConstants form_UserConstants = new Form_UserConstants(STDDBAddress);
  1179. DialogResult dialogResult=form_UserConstants.ShowDialog();
  1180. if (dialogResult == DialogResult.Yes)
  1181. {
  1182. try
  1183. {
  1184. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  1185. m_dbConnection.Open();
  1186. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select value from Constants", m_dbConnection);
  1187. DataSet ds = new DataSet();
  1188. m_dataAdapter.Fill(ds);
  1189. DataTable dt = ds.Tables[0];
  1190. string ConstantsStr = dt.Rows[0][0].ToString();
  1191. ConstantsStr = ConstantsStr.Replace(" ", "");
  1192. string[] ConstantsStr2 = ConstantsStr.Split(',');
  1193. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  1194. m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  1195. m_dbConnection.Close();
  1196. }
  1197. catch (Exception ee)
  1198. {
  1199. MessageBox.Show(ee.ToString());
  1200. }
  1201. }
  1202. }
  1203. public void AddMineralGroupsToAttribute()
  1204. {
  1205. try
  1206. {
  1207. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  1208. m_dbConnection.Open();
  1209. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select name,id from MineralGroups order by iorder", m_dbConnection);
  1210. DataSet ds = new DataSet();
  1211. m_dataAdapter.Fill(ds);
  1212. DataTable dt = ds.Tables[0];
  1213. if (dt != null)
  1214. {
  1215. if (dt.Rows.Count >= 0)
  1216. {
  1217. GroupIdDictionaryFromId.Clear();
  1218. GroupIdDictionaryFromName.Clear();
  1219. GroupIdDictionaryFromId.Add(0, "");
  1220. GroupIdDictionaryFromName.Add("", 0);
  1221. List<string> ss = new List<string>();
  1222. foreach (DataRow item in dt.Rows)
  1223. {
  1224. ss.Add(item["name"].ToString());
  1225. GroupIdDictionaryFromName.Add(item["name"].ToString(), int.Parse(item["id"].ToString()));
  1226. GroupIdDictionaryFromId.Add(int.Parse(item["id"].ToString()),item["name"].ToString());
  1227. }
  1228. SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
  1229. GroupIdCBBox.StandardValues = ss;
  1230. GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick| SourceGrid.EditableMode.Focus;
  1231. m_Attributes.Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("", GroupIdCBBox);
  1232. }
  1233. }
  1234. //string ConstantsStr = dt.Rows[0][0].ToString();
  1235. m_dbConnection.Close();
  1236. }
  1237. catch (Exception ee)
  1238. {
  1239. MessageBox.Show(ee.ToString());
  1240. }
  1241. }
  1242. private void ribbon_GroupNameMaintenance_Click(object sender, EventArgs e)
  1243. {
  1244. Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress);
  1245. DialogResult dialogResult = form_GroupId.ShowDialog();
  1246. if (dialogResult == DialogResult.Yes)
  1247. {
  1248. AddMineralGroupsToAttribute();
  1249. }
  1250. }
  1251. private void ribbon_Exit_Click(object sender, EventArgs e)
  1252. {
  1253. this.Close();
  1254. }
  1255. #region XML文档部分代码
  1256. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  1257. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  1258. //private void Form_ConstantsEditor2_Load(object sender, EventArgs e)
  1259. //{
  1260. // //XmlDocument doc = new XmlDocument();
  1261. // //doc.Load(Address);
  1262. // //doc.Load(Address_backup);
  1263. // //LoadXmlToDictionary(doc, ref STDDictionary);
  1264. //}
  1265. //private void rbRecover_Click(object sender, EventArgs e)
  1266. //{
  1267. // try
  1268. // {
  1269. // //System.IO.File.Copy(Address_backup, Address, true);
  1270. // //XmlDocument doc = new XmlDocument();
  1271. // //doc.Load(Address);
  1272. // //LoadXmlToDictionary(doc, ref STDDictionary);
  1273. // }
  1274. //}
  1275. //void LoadXmlToDictionary(XmlDocument xml, ref Dictionary<int, STDdata> STDDictionary)
  1276. //{
  1277. // XmlNode root = xml.SelectSingleNode("XMLData");
  1278. // XmlNodeList root2 = root.SelectNodes("Collection");
  1279. // for (int j = 0; j < root2.Count; j++)
  1280. // {
  1281. // if (root2[j].Attributes["RegName"].Value.ToString() == "STDList")
  1282. // {
  1283. // XmlNodeList childlist = root2[j].ChildNodes;
  1284. // for (int i = 0; i < childlist.Count; i++)
  1285. // {
  1286. // //BSE、化学式、元素
  1287. // string strBseValue = string.Empty;
  1288. // string strFormula = string.Empty;
  1289. // string strElement = string.Empty;
  1290. // if (childlist[i].Attributes["BSE"] != null)
  1291. // {
  1292. // strBseValue = childlist[i].Attributes["BSE"].Value;
  1293. // }
  1294. // if (childlist[i].Attributes["Formula"] != null)
  1295. // {
  1296. // strFormula = childlist[i].Attributes["Formula"].Value;
  1297. // }
  1298. // if (childlist[i].Attributes["Element"] != null)
  1299. // {
  1300. // strElement = childlist[i].Attributes["Element"].Value;
  1301. // }
  1302. // STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
  1303. // new_STDdata.Hardness = childlist[i].Attributes["Hardness"].Value;
  1304. // new_STDdata.Density = childlist[i].Attributes["Density"].Value;
  1305. // new_STDdata.Electrical_conductivity = childlist[i].Attributes["Electrical_conductivity"].Value;
  1306. // new_STDdata.BSE = strBseValue;
  1307. // new_STDdata.Formula = strFormula;
  1308. // new_STDdata.Element = strElement;
  1309. // new_STDdata.StrName = childlist[i].Attributes["StrName"].Value;
  1310. // new_STDdata.Expression = childlist[i].Attributes["Expression"].Value;
  1311. // new_STDdata.STDId = childlist[i].Attributes["STDId"].Value;
  1312. // new_STDdata.Color = childlist[i].Attributes["Color"].Value;
  1313. // new_STDdata.KeyElementList = childlist[i].Attributes["KeyElementList"].Value;
  1314. // new_STDdata.SubElementList = childlist[i].Attributes["SubElementList"].Value;
  1315. // STDDictionary.Add(int.Parse(childlist[i].Attributes["STDId"].Value), new_STDdata);
  1316. // }
  1317. // }
  1318. // }
  1319. // XmlNode root3 = root.SelectSingleNode("Member");
  1320. // string ConstantsStr = root3.Attributes["value"].Value;
  1321. // ConstantsStr = ConstantsStr.Replace(" ", "");
  1322. // string[] ConstantsStr2 = ConstantsStr.Split(',');
  1323. // m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
  1324. // m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
  1325. //}
  1326. ////保存xmltree内容到xml文件
  1327. //void SaveXmlTreeDataToXml(string Address)
  1328. //{
  1329. // #region text
  1330. // //XElement xele = XElement.Load(Address);
  1331. // //var item = (from ele1 in xele.Elements("Collection")
  1332. // // where ele1.Attribute("RegName").Value.Equals("STDList")
  1333. // // select ele1).FirstOrDefault();
  1334. // //if (item != null)
  1335. // //{
  1336. // // item.Remove();
  1337. // //}
  1338. // //xele.Save(Address);
  1339. // #endregion
  1340. // XDocument xdoc = XDocument.Load(Address);
  1341. // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
  1342. // var item = (from ele1 in elements.Elements("Collection")
  1343. // where ele1.Attribute("RegName").Value.Equals("STDList")
  1344. // select ele1).FirstOrDefault();
  1345. // if (item != null)
  1346. // {
  1347. // item.Remove();
  1348. // }
  1349. // XElement STD = new XElement("Collection");
  1350. // STD.SetAttributeValue("RegName", "STDList");
  1351. // elements.ElementAt(0).Add(STD);
  1352. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  1353. // {
  1354. // string UsingElementList = "";
  1355. // string UsingImgPropertyList = "";
  1356. // string UsingOtherPropertyList = "";
  1357. // List<string> UsingElementL = new List<string>();
  1358. // List<string> UsingImgPropertyL = new List<string>();
  1359. // List<string> UsingOtherPropertyL = new List<string>();
  1360. // string str_RemoveBlank = kv.Value.Expression;
  1361. // //forth_elem干扰or分隔符,故先行去掉
  1362. // if (str_RemoveBlank.Contains("forth_elem"))
  1363. // {
  1364. // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
  1365. // UsingOtherPropertyList = "forth_elem,";
  1366. // }
  1367. // str_RemoveBlank = str_RemoveBlank.Replace(" ", "");
  1368. // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);
  1369. // List<string> str_Removeandor = new List<string>();
  1370. // for (int i = 0; i < str_Removeand.Length; i++)
  1371. // {
  1372. // str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));
  1373. // }
  1374. // List<string> list_all = new List<string>();
  1375. // for (int i = 0; i < str_Removeandor.Count; i++)
  1376. // {
  1377. // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
  1378. // }
  1379. // for (int i = 0; i < list_all.Count; i++)
  1380. // {
  1381. // //周期元素?
  1382. // if (m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
  1383. // {
  1384. // if (!UsingElementL.Contains(list_all[i]))
  1385. // {
  1386. // UsingElementL.Add(list_all[i]);
  1387. // }
  1388. // }
  1389. // //first_elem?
  1390. // if (m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
  1391. // {
  1392. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1393. // {
  1394. // UsingOtherPropertyL.Add(list_all[i]);
  1395. // }
  1396. // }
  1397. // //Element1?
  1398. // if (m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
  1399. // {
  1400. // if (!UsingOtherPropertyL.Contains(list_all[i]))
  1401. // {
  1402. // UsingOtherPropertyL.Add(list_all[i]);
  1403. // }
  1404. // }
  1405. // //其它元素?
  1406. // if (m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
  1407. // {
  1408. // if (!UsingImgPropertyL.Contains(list_all[i]))
  1409. // {
  1410. // UsingImgPropertyL.Add(list_all[i]);
  1411. // }
  1412. // }
  1413. // }
  1414. // if (UsingElementL.Count > 0)
  1415. // {
  1416. // for (int i = 0; i < UsingElementL.Count - 1; i++)
  1417. // {
  1418. // UsingElementList += UsingElementL[i] + ",";
  1419. // }
  1420. // UsingElementList += UsingElementL[UsingElementL.Count - 1];
  1421. // }
  1422. // if (UsingImgPropertyL.Count > 0)
  1423. // {
  1424. // for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)
  1425. // {
  1426. // UsingImgPropertyList += UsingImgPropertyL[i] + ",";
  1427. // }
  1428. // UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];
  1429. // }
  1430. // if (UsingOtherPropertyL.Count > 0)
  1431. // {
  1432. // for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)
  1433. // {
  1434. // UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";
  1435. // }
  1436. // UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];
  1437. // }
  1438. // XElement EleName = new XElement("Member");
  1439. // EleName.SetAttributeValue("STDId", kv.Key);
  1440. // EleName.SetAttributeValue("StrName", kv.Value.StrName);
  1441. // EleName.SetAttributeValue("Color", kv.Value.Color);
  1442. // //EleName.SetAttributeValue("UsingElementList", UsingElementList);
  1443. // EleName.SetAttributeValue("KeyElementList", kv.Value.KeyElementList);
  1444. // EleName.SetAttributeValue("SubElementList", kv.Value.SubElementList);
  1445. // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
  1446. // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
  1447. // EleName.SetAttributeValue("Expression", kv.Value.Expression);
  1448. // EleName.SetAttributeValue("Hardness", kv.Value.Hardness);
  1449. // EleName.SetAttributeValue("Density", kv.Value.Density);
  1450. // EleName.SetAttributeValue("Electrical_conductivity", kv.Value.Electrical_conductivity);
  1451. // EleName.SetAttributeValue("BSE", kv.Value.BSE);
  1452. // EleName.SetAttributeValue("Formula", kv.Value.Formula);
  1453. // EleName.SetAttributeValue("Element", kv.Value.Element);
  1454. // STD.Add(EleName);
  1455. // }
  1456. // xdoc.Save(Address);
  1457. //}
  1458. #endregion
  1459. private void rbClose_Click(object sender, EventArgs e)
  1460. {
  1461. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1462. {
  1463. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "") && CheckAttributes() && Checktextbox_STDEditor())
  1464. {
  1465. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  1466. }
  1467. else
  1468. {
  1469. return;
  1470. }
  1471. }
  1472. else
  1473. {
  1474. STDDictionaryInitial.Clear();
  1475. }
  1476. if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
  1477. {
  1478. DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1479. if (dr == DialogResult.Yes)
  1480. {
  1481. FormForWaiting forWaiting = new FormForWaiting();
  1482. forWaiting.Show();
  1483. bool result = SaveDictionaryToClassify(STDDBAddress);
  1484. if (result)
  1485. {
  1486. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  1487. forWaiting.Close();
  1488. }
  1489. else
  1490. {
  1491. forWaiting.Close();
  1492. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  1493. }
  1494. }
  1495. }
  1496. m_Attributes.Close();
  1497. m_STDRuleslist.Close();
  1498. m_SubMidWindow.m_STDEditor.Close();
  1499. m_SubMidWindow.m_ComparativeLibrary.Close();
  1500. m_SubMidWindow.Close();
  1501. ButtonStatusClose();
  1502. if (this.Text.Split(' ').Count() != 0)
  1503. {
  1504. this.Text = this.Text.Split(' ')[0];
  1505. }
  1506. }
  1507. private void rbOpen_Click(object sender, EventArgs e)
  1508. {
  1509. OpenFileDialog openFileDialog = new OpenFileDialog();
  1510. openFileDialog.Filter = "(*.db)|*.db";
  1511. openFileDialog.RestoreDirectory = true;
  1512. openFileDialog.FilterIndex = 1;
  1513. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1514. {
  1515. try
  1516. {
  1517. STDDBAddress = openFileDialog.FileName;
  1518. InitForms(STDDBAddress);
  1519. this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
  1520. IsModified = false;
  1521. }
  1522. catch(Exception ex)
  1523. {
  1524. MessageBox.Show(table["message6"].ToString(), table["message32"].ToString());
  1525. }
  1526. }
  1527. }
  1528. void ButtonStatusOpen()
  1529. {
  1530. rbOpen.Enabled = false;
  1531. rbClose.Enabled = true;
  1532. //rbRecover.Enabled = true;
  1533. rbBackup.Enabled = true;
  1534. rbSave.Enabled = true;
  1535. ribbon_ZeroRules.Enabled = true;
  1536. ribbon_ESDMaxRules.Enabled = true;
  1537. ribbon_UserConstants.Enabled = true;
  1538. ribbon_GroupNameMaintenance.Enabled = true;
  1539. ribbon_BulkImport.Enabled = true;
  1540. }
  1541. void ButtonStatusClose()
  1542. {
  1543. rbOpen.Enabled = true;
  1544. rbClose.Enabled = false;
  1545. //rbRecover.Enabled = false;
  1546. rbBackup.Enabled = false;
  1547. rbSave.Enabled = false;
  1548. ribbon_ZeroRules.Enabled = false;
  1549. ribbon_ESDMaxRules.Enabled = false;
  1550. ribbon_UserConstants.Enabled = false;
  1551. ribbon_GroupNameMaintenance.Enabled = false;
  1552. ribbon_BulkImport.Enabled = false;
  1553. }
  1554. void InitForms(string DBAddress)
  1555. {
  1556. STDDictionary.Clear();
  1557. bool ret = LoadClassifyToDictionary(DBAddress, ref STDDictionary);
  1558. STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
  1559. if (!ret)
  1560. {
  1561. return;
  1562. }
  1563. ButtonStatusOpen();
  1564. m_STDRuleslist = new STDRuleslist(this);
  1565. m_Attributes = new Attributes(this);
  1566. m_SubMidWindow = new SubMidWindow(this);
  1567. m_DockWindow = new OTSDockWindow(this);
  1568. m_DockWindow.CreateMainWindow();
  1569. if (m_SubMidWindow.m_STDEditor.m_sc != null)
  1570. {
  1571. m_SubMidWindow.m_STDEditor.m_sc.CloseDB();
  1572. }
  1573. m_SubMidWindow.m_STDEditor.m_sc = new SqlLiteClass(DBAddress);
  1574. LoadConstants(DBAddress);
  1575. m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
  1576. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1577. {
  1578. Position pos = new Position(1, 0);
  1579. m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  1580. m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
  1581. ChangeSTDEditorAndGrid_Attributes(int.Parse(m_STDRuleslist.Grid_Minerals[1, 0].Tag.ToString()));
  1582. m_STDRuleslist.button_UpOrder.Enabled = false;
  1583. }
  1584. }
  1585. private void ribbon_BulkImport_Click(object sender, EventArgs e)
  1586. {
  1587. OpenFileDialog openFileDialog = new OpenFileDialog();
  1588. openFileDialog.Filter = "(*.db)|*.db";
  1589. openFileDialog.RestoreDirectory = true;
  1590. openFileDialog.FilterIndex = 1;
  1591. openFileDialog.Title = table["message33"].ToString();
  1592. if (openFileDialog.ShowDialog() == DialogResult.OK)
  1593. {
  1594. try
  1595. {
  1596. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");
  1597. m_dbConnection.Open();
  1598. if(STDDictionary.Count==0)
  1599. {
  1600. MessageBox.Show(table["message27"].ToString(), table["message32"].ToString());
  1601. return;
  1602. }
  1603. string STDId = m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row,m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column].Tag.ToString();
  1604. bool ret = false;//搜索结果
  1605. for(int i=0;i< STDDictionary.Count;i++)
  1606. {
  1607. STDEditor.Result result = m_SubMidWindow.m_STDEditor.ImportFromResult(STDDictionary.Keys.ElementAt(i).ToString(), m_dbConnection);
  1608. if (result == STDEditor.Result.Success)
  1609. {
  1610. ret = true;
  1611. }
  1612. else if(result == STDEditor.Result.Fail)
  1613. {
  1614. return;
  1615. }
  1616. }
  1617. if (!ret)
  1618. {
  1619. MessageBox.Show(table["message34"].ToString(), table["message32"].ToString());
  1620. }
  1621. int color = Convert.ToInt32(m_SubMidWindow.m_STDEditor.ParseRGB(STDRuleslist.colorHx16toRGB(STDDictionary[int.Parse(STDId)].Color)).ToString());
  1622. for (int j = 0; j < m_SubMidWindow.m_STDEditor.m_STDXrayList.Count; j++)
  1623. {
  1624. if (m_SubMidWindow.m_STDEditor.m_STDXrayList[j].StdID == STDId)
  1625. {
  1626. m_SubMidWindow.m_STDEditor.ShowXrayAtlas(color, m_SubMidWindow.m_STDEditor.m_STDXrayList[j].XrayData);
  1627. break;
  1628. }
  1629. }
  1630. m_dbConnection.Close();
  1631. }
  1632. catch(Exception ex)
  1633. {
  1634. MessageBox.Show(ex.ToString());
  1635. }
  1636. }
  1637. }
  1638. //public bool EqualToDictionary(Dictionary<int, STDdata> STDDictionary, Dictionary<int, STDdata> STDDictionaryInitial)
  1639. //{
  1640. // if(STDDictionary.Count!= STDDictionaryInitial.Count)
  1641. // {
  1642. // return false;
  1643. // }
  1644. // foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
  1645. // {
  1646. // if (!STDDictionaryInitial.ContainsKey(kv.Key))
  1647. // {
  1648. // return false;
  1649. // }
  1650. // else
  1651. // {
  1652. // if (kv.Value.StrName != STDDictionaryInitial[kv.Key].StrName || kv.Value.Color != STDDictionaryInitial[kv.Key].Color || kv.Value.KeyElementList != STDDictionaryInitial[kv.Key].KeyElementList || kv.Value.SubElementList != STDDictionaryInitial[kv.Key].SubElementList || kv.Value.UsingImgPropertyList != STDDictionaryInitial[kv.Key].UsingImgPropertyList || kv.Value.UsingOtherPropertyList != STDDictionaryInitial[kv.Key].UsingOtherPropertyList || kv.Value.Expression != STDDictionaryInitial[kv.Key].Expression || kv.Value.Hardness != STDDictionaryInitial[kv.Key].Hardness || kv.Value.Density != STDDictionaryInitial[kv.Key].Density || kv.Value.Electrical_conductivity != STDDictionaryInitial[kv.Key].Electrical_conductivity || kv.Value.BSE != STDDictionaryInitial[kv.Key].BSE || kv.Value.Formula != STDDictionaryInitial[kv.Key].Formula || kv.Value.Element != STDDictionaryInitial[kv.Key].Element || kv.Value.GroupId != STDDictionaryInitial[kv.Key].GroupId || kv.Value.ListNum != STDDictionaryInitial[kv.Key].ListNum)
  1653. // {
  1654. // return false;
  1655. // }
  1656. // }
  1657. // }
  1658. // return true;
  1659. //}
  1660. bool EqualsBetweenDictionary(Dictionary<int, STDdata> STDDictionaryInitial, Dictionary<int, STDdata> STDDictionary)
  1661. {
  1662. if(STDDictionaryInitial.Count!= STDDictionary.Count)
  1663. {
  1664. return false;
  1665. }
  1666. foreach(var key in STDDictionaryInitial.Keys)
  1667. {
  1668. if (STDDictionary.Keys.Contains(key))
  1669. {
  1670. if(!STDDictionaryInitial[key].Equals(STDDictionary[key]))
  1671. {
  1672. return false;
  1673. }
  1674. }
  1675. else
  1676. {
  1677. return false;
  1678. }
  1679. }
  1680. return true;
  1681. }
  1682. private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
  1683. {
  1684. if (m_STDRuleslist.Text != "")
  1685. {
  1686. if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1687. {
  1688. if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "") && CheckAttributes() && Checktextbox_STDEditor())
  1689. {
  1690. SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
  1691. }
  1692. else
  1693. {
  1694. e.Cancel = true;
  1695. return;
  1696. }
  1697. }
  1698. else
  1699. {
  1700. STDDictionaryInitial.Clear();
  1701. }
  1702. if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary)|| IsModified)
  1703. {
  1704. DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1705. if (dr == DialogResult.Yes)
  1706. {
  1707. FormForWaiting forWaiting = new FormForWaiting();
  1708. forWaiting.Show();
  1709. bool result = SaveDictionaryToClassify(STDDBAddress);
  1710. if (result)
  1711. {
  1712. m_SubMidWindow.m_STDEditor.SaveSTDXray();
  1713. forWaiting.Close();
  1714. }
  1715. else
  1716. {
  1717. forWaiting.Close();
  1718. MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
  1719. }
  1720. }
  1721. }
  1722. }
  1723. #region 老方法,标识判断,总是重复性保存
  1724. //if (IsModified)
  1725. //{
  1726. // DialogResult dr = MessageBox.Show("是否保存当前修改", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  1727. // if (dr == DialogResult.Yes)
  1728. // {
  1729. // if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
  1730. // {
  1731. // if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
  1732. // {
  1733. // if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  1734. // {
  1735. // if (CheckAttributes())
  1736. // {
  1737. // if (Checktextbox_STDEditor())
  1738. // {
  1739. // }
  1740. // else
  1741. // {
  1742. // e.Cancel = true;
  1743. // return;
  1744. // }
  1745. // }
  1746. // else
  1747. // {
  1748. // e.Cancel = true;
  1749. // return;
  1750. // }
  1751. // }
  1752. // else
  1753. // {
  1754. // e.Cancel = true;
  1755. // return;
  1756. // }
  1757. // }
  1758. // else
  1759. // {
  1760. // Position pos = new Position(1, 0);
  1761. // m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
  1762. // if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
  1763. // {
  1764. // if (CheckAttributes())
  1765. // {
  1766. // if (Checktextbox_STDEditor())
  1767. // {
  1768. // }
  1769. // else
  1770. // {
  1771. // e.Cancel = true;
  1772. // return;
  1773. // }
  1774. // }
  1775. // else
  1776. // {
  1777. // e.Cancel = true;
  1778. // return;
  1779. // }
  1780. // }
  1781. // else
  1782. // {
  1783. // e.Cancel = true;
  1784. // return;
  1785. // }
  1786. // }
  1787. // }
  1788. // rbSave_Click(this, e);
  1789. // }
  1790. //}
  1791. #endregion
  1792. }
  1793. }
  1794. }