ParticleData.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. using OTSCommon.DBOperate;
  2. using OTSCommon.DBOperate.Model;
  3. using OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SQLite;
  8. using System.Drawing;
  9. using System.Drawing.Imaging;
  10. using System.IO;
  11. using System.Linq;
  12. using static DevExpress.XtraEditors.Mask.Design.MaskSettingsForm.DesignInfo.MaskManagerInfo;
  13. using static OTSDataType.otsdataconst;
  14. using static OTSIncAReportApp.OTSReport_Export;
  15. namespace OTSIncAReportApp.DataOperation.DataAccess
  16. {
  17. public class ParticleData
  18. {
  19. private SqlHelper dbHelper;
  20. public ParticleData(string path)
  21. {
  22. dbHelper = new SqlHelper("data source='" + path + "\\FIELD_FILES\\Inclusion.db'");
  23. }
  24. /// <summary>
  25. /// 获取SegmentList
  26. /// </summary>
  27. /// <param name="model">Feature</param>
  28. /// <returns></returns>
  29. public List<Particle> GetParticleList(Particle model)
  30. {
  31. //存放查询数据的数据表
  32. SQLiteParameter[] Parameter = new SQLiteParameter[1]
  33. {
  34. new SQLiteParameter("@FieldId", model.FieldId)
  35. };
  36. string sql = "select * from IncAData where Fieldid=@FieldId";
  37. DataTable DT = dbHelper.ExecuteDataTable(sql, Parameter);
  38. var result = new List<Particle>();
  39. foreach (DataRow dr in DT.Rows)
  40. {
  41. Particle item = new Particle() { };
  42. result.Add(item);
  43. }
  44. return result;
  45. }
  46. /// <summary>
  47. /// 获取ParticleListBy
  48. /// </summary>
  49. /// <param name="model">Feature</param>
  50. /// <returns></returns>
  51. public List<Particle> GetParticleListByCon(string con, string max, string min, int display)
  52. {
  53. string sqlp = "select a.* from IncAData a ";
  54. string where = " where 1=1 ";
  55. if (display == 1)
  56. {
  57. where = where + " and a.XrayId >-1 ";
  58. }
  59. if (con != "")
  60. {
  61. where = where + " and a." + con + ">" + min + " and a." + con + "<" + max;
  62. }
  63. sqlp = sqlp + where;
  64. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  65. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  66. return listp;
  67. }
  68. /// <summary>
  69. /// 获取ParticleList
  70. /// </summary>
  71. /// <param name="model">Feature</param>
  72. /// <returns></returns>
  73. public DataTable GetParticleListAndEm()
  74. {
  75. string sqlp = @"select *,
  76. (select group_concat(name||'-'||Percentage,';')
  77. from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element
  78. from INcAData where xrayid>-1";
  79. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  80. return DT;
  81. }
  82. /// <summary>
  83. /// 获取ParticleList
  84. /// </summary>
  85. /// <param name="model">Feature</param>
  86. /// <returns></returns>
  87. public DataTable GetMergedParticleInfo()
  88. {
  89. string sqlp = @"select *,
  90. (select group_concat(name||'-'||Percentage,';')
  91. from ElementChemistry where XRayId =MergedParticleInfo.XRayId and fieldid=MergedParticleInfo.fieldid ) as Element
  92. from MergedParticleInfo ";
  93. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  94. return DT;
  95. }
  96. /// <summary>
  97. /// 获取ParticleList
  98. /// </summary>
  99. /// <param name="model">Feature</param>
  100. /// <returns></returns>
  101. public DataTable GetParticleListByIncA(string con)
  102. {
  103. string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,sum(Area) as Area,avg(" + con
  104. + ") as av,max(" + con
  105. + ") as max ";
  106. sqlp = sqlp + "from IncAData where typeid !=-1 and typeid !=4 group by TypeId";
  107. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  108. return DT;
  109. }
  110. /// <summary>
  111. /// 获取ParticleList
  112. /// </summary>
  113. /// <param name="model">Feature</param>
  114. /// <returns></returns>
  115. public DataTable GetParticleListForParticlSize(string con, string fieldAndPartic)
  116. {
  117. string sqlp = @"select TypeId,TypeName,GroupId ,TypeColor,count(1) as con,avg(" + con
  118. + ") as av,max(" + con
  119. + ") as max ,GroupName";
  120. sqlp = sqlp + " from IncAData where typeid !=-1 and typeid !=4";
  121. if (fieldAndPartic != "")
  122. {
  123. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  124. }
  125. sqlp = sqlp + " group by TypeId ";
  126. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  127. if (con == "area")
  128. {
  129. for (int i = 0; i < DT.Rows.Count; i++)
  130. {
  131. DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
  132. }
  133. }
  134. return DT;
  135. }
  136. /// <summary>
  137. /// 获取ParticleList
  138. /// </summary>
  139. /// <param name="model">Feature</param>
  140. /// <returns></returns>
  141. public DataTable GetParticleListForParticlSizeID(string con, string fieldAndPartic)
  142. {
  143. string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,avg(" + con
  144. + ") as av,max(" + con
  145. + ") as max ,GroupName ,GroupId";
  146. sqlp = sqlp + " from IncAData where typeid !=-1 and typeid !=4";
  147. if (fieldAndPartic != "")
  148. {
  149. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  150. }
  151. sqlp = sqlp + " group by TypeId ";
  152. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  153. if (con == "area")
  154. {
  155. for (int i = 0; i < DT.Rows.Count; i++)
  156. {
  157. DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
  158. }
  159. }
  160. return DT;
  161. }
  162. /// <summary>
  163. /// 获取element含量
  164. /// </summary>
  165. /// <returns></returns>
  166. public DataTable GetElementForArea(string fieldAndPartic)
  167. {
  168. string sqlp = @"select e.name,sum(e.percentage*p.area) as earea from ElementChemistry e
  169. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid from IncAData where typeid !=-1 and typeid !=4";
  170. if (fieldAndPartic != "")
  171. {
  172. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
  173. }
  174. sqlp = sqlp + " group by e.name order by sum(e.percentage*p.area) desc";
  175. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  176. return DT;
  177. }
  178. /// <summary>
  179. /// 获取element含量
  180. /// </summary>
  181. /// <returns></returns>
  182. public DataTable GetSmallElementForArea()
  183. {
  184. string sqlp = @"select e.name, sum(e.percentage*i.area) as earea from elementchemistry e inner join incadata i on e.xrayid = i.xrayid and e.fieldid = i.fieldid
  185. group by e.name order by sum(e.percentage*i.area) desc";
  186. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  187. return DT;
  188. }
  189. /// <summary>
  190. /// 获取所有Particle
  191. /// </summary>
  192. /// <returns></returns>
  193. public DataTable GetParticleAll(string fieldAndPartic)
  194. {
  195. string sqlp = @"select * from INcAData where typeid !=-1 and typeid !=4";
  196. if (fieldAndPartic != "")
  197. {
  198. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  199. }
  200. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  201. //for (int i = 0; i < DT.Rows.Count; i++)
  202. //{
  203. // DT.Rows[i]["Area"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  204. //}
  205. return DT;
  206. }
  207. public DataTable GetParticleAllforparticlelist(string fieldAndPartic)
  208. {
  209. string sqlp = @"select * from INcAData";
  210. if (fieldAndPartic != "")
  211. {
  212. sqlp = sqlp + " where '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  213. }
  214. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  215. for (int i = 0; i < DT.Rows.Count; i++)
  216. {
  217. DT.Rows[i]["Area"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  218. }
  219. return DT;
  220. }
  221. /// <summary>
  222. /// 查找所有颗粒的颜色、面积、种类名称信息
  223. /// </summary>
  224. /// <returns></returns>
  225. public DataTable GetParticleTypeInformation()
  226. {
  227. string sqlp = @"select Area,TypeName,TypeColor from IncAData";
  228. DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
  229. return dt;
  230. }
  231. /// <summary>
  232. /// 查找IncaData表中所有种类
  233. /// </summary>
  234. /// <returns></returns>
  235. public DataTable GetParticleClassAll()
  236. {
  237. string sqlp = @"SELECT DISTINCT TypeName FROM IncaData";
  238. DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
  239. return dt;
  240. }
  241. /// <summary>
  242. /// 获取所有Particle
  243. /// </summary>
  244. /// <returns></returns>
  245. public DataTable GetParticleAllHaveXray(string fieldAndPartic)
  246. {
  247. string incaSql = @"select * from IncAData where typeid !=-1 and typeid !=4";
  248. if (fieldAndPartic != "")
  249. {
  250. incaSql = incaSql + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  251. }
  252. DataTable incaDT = dbHelper.ExecuteDataTable(incaSql, null);
  253. incaDT.Columns.Add("Element");
  254. DataTable dt_element = GetElementChemistry();
  255. DataTable elementchemistry = dt_element.Clone();
  256. for (int i = 0; i < dt_element.Rows.Count; i++)
  257. {
  258. if (dt_element.Rows[i]["Name"].ToString() != "Fe")
  259. {
  260. elementchemistry.Rows.Add(dt_element.Rows[i].ItemArray);
  261. }
  262. }
  263. for (int i = 0; i < incaDT.Rows.Count; i++)
  264. {
  265. string str = "XRayId = " + incaDT.Rows[i]["particleId"].ToString() + " and fieldid = " + incaDT.Rows[i]["fieldid"].ToString();
  266. DataRow[] drs = elementchemistry.Select(str);
  267. string ConcatenatedString = "";
  268. for (int j = 0; j < drs.Length; j++)
  269. {
  270. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  271. }
  272. incaDT.Rows[i]["Element"] = ConcatenatedString;
  273. }
  274. return incaDT;
  275. }
  276. /// <summary>
  277. /// 获取所有Particle
  278. /// </summary>
  279. /// <returns></returns>
  280. public DataTable GetParticleHaveXray(string fieldAndPartic)
  281. {
  282. string sqlp = @"select *,
  283. (select group_concat(name||'-'||Percentage,';')
  284. from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element from INcAData where xrayid>-1 ";
  285. if (fieldAndPartic != "")
  286. {
  287. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  288. }
  289. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  290. for (int i = 0; i < DT.Rows.Count; i++)
  291. {
  292. DT.Rows[i]["Area"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  293. }
  294. return DT;
  295. }
  296. /// <summary>
  297. /// 获取所有Particle
  298. /// </summary>
  299. /// <returns></returns>
  300. public List<Particle> GetParticleAllList()
  301. {
  302. string sqlp = @"select * from INcAData";
  303. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  304. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  305. return listp;
  306. }
  307. /// <summary>
  308. /// 获取所有Particle
  309. /// </summary>
  310. /// <returns></returns>
  311. public DataTable GetParticleAllList_DataTable()
  312. {
  313. string sqlp = @"select * from INcAData";
  314. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  315. return DT;
  316. }
  317. /// <summary>
  318. /// 获取所有分类的面积
  319. /// </summary>
  320. /// <param name="fieldAndPartic">选择颗粒</param>
  321. /// <returns></returns>
  322. public DataTable GetAreaByAllIncA(string fieldAndPartic)
  323. {
  324. string sqlp = @"select TypeId,TypeName,GroupId,sum(area) as ar,count(1) as con ,GroupName from INcAData where typeid !=-1 and typeid !=4";
  325. if (fieldAndPartic != "")
  326. {
  327. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  328. }
  329. sqlp = sqlp + " group by TypeId";
  330. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  331. return DT;
  332. }
  333. /// <summary>
  334. /// 获取所有大颗粒没有的小颗粒分类
  335. /// </summary>
  336. /// <param name="fieldAndPartic">选择颗粒</param>
  337. /// <returns></returns>
  338. public DataTable GetSmallParticleInfo()
  339. {
  340. string sqlp = @"select TypeId,TypeName,TypeColor,sum(area) as area,sum(ParticleQuant) as ParticleQuant from SmallParticleInfo where TypeId not in(select TypeId from INcAData) group by TypeId";
  341. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  342. return DT;
  343. }
  344. /// <summary>
  345. /// 获取不同分类的面积
  346. /// </summary>
  347. /// <param name="fieldAndPartic">选择颗粒</param>
  348. /// <returns></returns>
  349. public DataTable GetAreaByIncA(string TypeId, string fieldAndPartic)
  350. {
  351. string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
  352. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid where p.TypeId=" + TypeId + " ";
  353. if (fieldAndPartic != "")
  354. {
  355. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
  356. }
  357. sqlp = sqlp + " group by e.name";
  358. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  359. return DT;
  360. }
  361. public DataTable GetAreaByIncA_All()
  362. {
  363. string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
  364. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid group by e.name ";
  365. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  366. return DT;
  367. }
  368. /// <summary>
  369. /// 获取全部的物质大类
  370. /// </summary>
  371. /// <returns></returns>
  372. public DataTable GetAllClass()
  373. {
  374. string sqlp = @"select GroupName from IncAData group by GroupName order by count(1) desc";
  375. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  376. return DT;
  377. }
  378. /// <summary>
  379. /// 获取所有元素
  380. /// </summary>
  381. /// <param name="model">Feature</param>
  382. /// <returns></returns>
  383. public DataTable GetAllElement()
  384. {
  385. string sqlp = @"select name from ElementChemistry group by name order by count(1) desc";
  386. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  387. return DT;
  388. }
  389. /// <summary>
  390. /// 获取常用夹杂物分类信息
  391. /// </summary>
  392. /// <returns></returns>
  393. public DataTable GetCommonlyUsedClassifyData()
  394. {
  395. string sqlp = @"select
  396. (select count(typeid) from incadata where typeid BETWEEN 10100 and 10199 and typeid BETWEEN 12200 and 12299 and typeid BETWEEN 11300 and 11299 ) as SPINEL ,
  397. (select count(typeid) from incadata where typeid BETWEEN 10000 and 10999 ) as OXIDE ,
  398. (select count(typeid) from incadata where typeid BETWEEN 11200 and 11299 and typeid BETWEEN 11400 and 11499 and typeid BETWEEN 11200 and 11599 ) as SULFIDE_OXIDE ,
  399. (select count(typeid) from incadata where typeid BETWEEN 12000 and 12999 ) as NITRIDE ,
  400. (select count(typeid) from incadata where typeid BETWEEN 11000 and 11999 ) as SULFIDE ";
  401. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  402. return DT;
  403. }
  404. public bool DeleteFromData(string fieldid, string particleid)
  405. {
  406. string sqlp = @"delete from IncAData where FieldId=" + fieldid + " and ParticleId="
  407. + particleid;
  408. if (dbHelper.ExecuteQuery_bool(sqlp))
  409. {
  410. return true;
  411. }
  412. else
  413. {
  414. return false;
  415. }
  416. }
  417. /// <summary>
  418. /// 获取颗粒信息
  419. /// </summary>
  420. /// <param name="model">Feature</param>
  421. /// <returns></returns>
  422. public Particle GetParticleByFidAndPid(string fieldid, string particleid)
  423. {
  424. string sqlp = @"select *,(select xraydata from xraydata where xrayindex=INcAData.xrayid and fieldid="
  425. + fieldid + ") as XRayData,(select group_concat(name || '_' || Percentage, ';')from ElementChemistry where XRayId = INcAData.XRayId and fieldid ="
  426. + fieldid + ") as Element from INcAData where fieldid="
  427. + fieldid + " and particleid= " + particleid;
  428. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  429. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  430. Particle particle = new Particle();
  431. if (listp.Count > 0)
  432. {
  433. particle = listp[0];
  434. List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
  435. string element = DT.Rows[0]["Element"].ToString();
  436. for (int i = 0; i < element.Split(';').Count(); i++)
  437. {
  438. if (element.Split(';')[i] != "")
  439. {
  440. OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = element.Split(';')[i].Split('_')[0], Percentage = Convert.ToDouble(element.Split(';')[i].Split('_')[1]) };
  441. ElementList.Add(ele);
  442. }
  443. }
  444. particle.ElementList = ElementList;
  445. }
  446. return particle;
  447. }
  448. public Particle GetParticleXrayDataByFidAndPid(string fieldid, string xrayid)
  449. {
  450. string sqlp = @"select xraydata from xraydata where xrayindex=" + xrayid + " and fieldid="
  451. + fieldid;
  452. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  453. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  454. if (listp.Count > 0)
  455. {
  456. return listp[0];
  457. }
  458. else
  459. {
  460. return null;
  461. }
  462. }
  463. public enum PARTCLE_TYPE
  464. {
  465. SMALL = 0,//过小颗粒
  466. OVERSIZE = 1,//过大颗粒
  467. AVE_GRAY_NOT_INRANRE = 2,//亮度不在分析范围内的颗粒
  468. SEARCH_X_RAY = 3,
  469. LOW_COUNT = 4,//低计数率颗粒
  470. NO_INTEREST_ELEMENTS = 5,
  471. NO_ANALYSIS_X_RAY = 6,//不含分析元素
  472. NOT_IDENTIFIED_SIC = 7,//非夹杂物颗粒SiC
  473. NOT_IDENTIFIED_FEO = 8,//非夹杂物颗粒FeO
  474. NOT_IDENTIFIED = 9,//未识别颗粒
  475. IDENTIFIED = 10,//分析颗粒,当为可识别类型时,可以被进一步识别为用户类型(1000以上),系统预定义类型(10000以上),所以最终颗粒类型不会为8,但可能为7
  476. USER_DEFINED_MIN = 1000,
  477. SYS_DEFINED_MIN = 10000
  478. }
  479. #region 分页添加读取数据库函数
  480. /// <summary>
  481. /// 获取分页查询所需信息
  482. /// </summary>
  483. /// <param name=""></param>
  484. /// <param name=""></param>
  485. /// <returns></returns>
  486. public DataTable GetInfoForPartucleDevidePage(int currentPage, int pagesize, string OrderFunction, string condition)
  487. {
  488. int p = (currentPage - 1) * pagesize;
  489. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX as 'SEMPosX',FieldPosY as 'SEMPosY',ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles, (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX,FieldPosY,ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,(select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = INcAData.XRayId and fieldid = INcAData.fieldid ) as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " + condition + " order by " + OrderFunction + " limit " + pagesize.ToString() + " offset " + p.ToString();
  490. DataTable DT = new DataTable();
  491. DT = dbHelper.ExecuteQuery(sqliteString);
  492. return DT;
  493. }
  494. public DataTable GetIncaSurfaceData( List<string> lst_str)
  495. {
  496. DataTable particlesAll = GetInfoForPartucleDevidePage2("");
  497. DataTable dt_element = GetElementChemistry();
  498. List<int> list_int = new List<int>();
  499. for (int a = 0; a < lst_str.Count; a++)
  500. {
  501. for (int i = 0; i < dt_element.Rows.Count; i++)
  502. {
  503. if (dt_element.Rows[i]["Name"].ToString() == lst_str[a].ToString())
  504. {
  505. list_int.Add(i);
  506. }
  507. }
  508. }
  509. for (int i = 0; i < list_int.Count; i++)
  510. {
  511. dt_element.Rows[list_int[i]].Delete();
  512. }
  513. dt_element.AcceptChanges();
  514. for (int i = 0; i < particlesAll.Rows.Count; i++)
  515. {
  516. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  517. DataRow[] drs = dt_element.Select(str);
  518. string ConcatenatedString = "";
  519. for (int j = 0; j < drs.Length; j++)
  520. {
  521. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  522. }
  523. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  524. }
  525. return particlesAll;
  526. }
  527. public DataTable AddElementColumn(DataTable particlesAll, c_TemplateClass m_mbszclass)
  528. {
  529. if (!particlesAll.Columns.Contains("Element"))
  530. {
  531. particlesAll.Columns.Add("Element");
  532. }
  533. DataTable dt_element = GetElementChemistry();
  534. for (int i = 0; i < particlesAll.Rows.Count; i++)
  535. {
  536. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  537. DataRow[] drs = dt_element.Select(str);
  538. string ConcatenatedString = "";
  539. for (int j = 0; j < drs.Length; j++)
  540. {
  541. //判断是否在处理元素表中
  542. bool bl = false;
  543. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_qcys.Count; a++)
  544. {
  545. if (drs[j]["name"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_qcys[a].ToString())
  546. {
  547. bl = true;
  548. }
  549. }
  550. if (!bl)
  551. {
  552. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  553. }
  554. }
  555. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  556. }
  557. return particlesAll;
  558. }
  559. /// <summary>
  560. /// 拼接颗粒
  561. /// </summary>
  562. /// <param name="lst_str"></param>
  563. /// <returns></returns>
  564. public DataTable GetSplicingParticlesData()
  565. {
  566. DataTable particlesAll = GetSplicingParticles();
  567. return particlesAll;
  568. }
  569. /// <summary>
  570. /// 保留两位小数
  571. /// </summary>
  572. /// <param name="strData"></param>
  573. /// <returns></returns>
  574. private string ChangeDataToD(string strData)
  575. {
  576. Decimal dData = 0.00M;
  577. if (strData.Contains("E"))
  578. {
  579. dData = Convert.ToDecimal(Decimal.Parse(strData.ToString(), System.Globalization.NumberStyles.Float));
  580. }
  581. else
  582. {
  583. return Convert.ToDouble(strData).ToString("0.00");
  584. }
  585. return Convert.ToDouble(dData).ToString("0.00");
  586. }
  587. public DataTable GetInfoForPartucleDevidePage2(string condition)
  588. {
  589. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
  590. "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles," +
  591. " (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) " +
  592. "as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId," +
  593. "SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,'' " +
  594. "as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " +
  595. condition;
  596. DataTable DT = new DataTable();
  597. DT = dbHelper.ExecuteQuery(sqliteString);
  598. return DT;
  599. }
  600. public DataTable GetSplicingParticles()
  601. {
  602. string sqliteString1 = "select * from MergedParticleInfo";
  603. DataTable DT = new DataTable();
  604. DT = dbHelper.ExecuteQuery(sqliteString1);
  605. return DT;
  606. }
  607. public DataTable GetInfoForPartucleDevidePage_analyticalParticle(string condition)
  608. {
  609. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and typeid !=9 and typeid !=-1 and typeid !=4)" +
  610. condition;
  611. DataTable DT = new DataTable();
  612. DT = dbHelper.ExecuteQuery(sqliteString);
  613. return DT;
  614. }
  615. public DataTable GetInfoForPartucleDevidePage_otherParticle(string condition)
  616. {
  617. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where (typeid =9 or typeid =-1 or typeid =4) " +
  618. condition;
  619. DataTable DT = new DataTable();
  620. DT = dbHelper.ExecuteQuery(sqliteString);
  621. return DT;
  622. }
  623. public DataTable GetInfoForPartucleDevidePage_mergeParticles(string condition)
  624. {
  625. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
  626. "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles,''as Element from MergedParticleInfo where 1=1 " + condition;
  627. DataTable DT1 = new DataTable();
  628. try
  629. {
  630. DT1 = dbHelper.ExecuteQuery(sqliteString);
  631. }
  632. catch
  633. {
  634. }
  635. return DT1;
  636. }
  637. public DataTable GetInfoForPartucleDevidePage_allParticles(string condition)
  638. {
  639. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where 1=1 " +
  640. condition;
  641. DataTable DT = new DataTable();
  642. DT = dbHelper.ExecuteQuery(sqliteString);
  643. return DT;
  644. }
  645. public DataTable GetInfoForPartucleDevidePage_NotIdentifyParticle(string condition)
  646. {
  647. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where typeid =9 " +
  648. condition;
  649. DataTable DT = new DataTable();
  650. DT = dbHelper.ExecuteQuery(sqliteString);
  651. return DT;
  652. }
  653. public DataTable GetInfoForPartucleDevidePage_InvalidParticle(string condition)
  654. {
  655. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where typeid =-1 " +
  656. condition;
  657. DataTable DT = new DataTable();
  658. DT = dbHelper.ExecuteQuery(sqliteString);
  659. return DT;
  660. }
  661. public DataTable GetInfoForPartucleDevidePage_LowCountsParticle(string condition)
  662. {
  663. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where typeid =4 " +
  664. condition;
  665. DataTable DT = new DataTable();
  666. DT = dbHelper.ExecuteQuery(sqliteString);
  667. return DT;
  668. }
  669. public DataTable GetClassificationOfAllParticles(string condition)
  670. {
  671. string sqliteString1 = "select distinct TypeName from INcAData "+ condition;
  672. DataTable DT = new DataTable();
  673. DT = dbHelper.ExecuteQuery(sqliteString1);
  674. return DT;
  675. }
  676. public DataTable GetXRayData()
  677. {
  678. string sqliteString = @"select * from xraydata";
  679. DataTable DT = new DataTable();
  680. DT = dbHelper.ExecuteQuery(sqliteString);
  681. return DT;
  682. }
  683. public DataTable GetElementChemistry()
  684. {
  685. string sqliteString = "select * from ElementChemistry";
  686. DataTable DT = new DataTable();
  687. DT = dbHelper.ExecuteQuery(sqliteString);
  688. return DT;
  689. }
  690. /// <summary>
  691. /// 得到图形形状
  692. /// </summary>
  693. /// <returns></returns>
  694. public DataTable GetSegment()
  695. {
  696. string sqliteString = "select * from Segment";
  697. DataTable DT = new DataTable();
  698. DT = dbHelper.ExecuteQuery(sqliteString);
  699. return DT;
  700. }
  701. public Bitmap GetBitmapForBig(string sub, double xs, string path, int picHeight, int picWidth)
  702. {
  703. string vs = "," + sub.Replace(':', '-') + ",";
  704. DataTable dataTable = GetParticleAll(vs);
  705. if (dataTable.Rows.Count == 0)
  706. {
  707. return null;
  708. }
  709. //内接矩形
  710. double max_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs - Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  711. double max_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs + Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  712. double min_Y = max_Y;
  713. double min_X = max_X;
  714. //拼接field矩形
  715. double MAX_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  716. double MAX_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  717. double MIN_Y = MAX_Y;
  718. double MIN_X = MAX_X;
  719. foreach (DataRow item in dataTable.Rows)
  720. {
  721. //颗粒外接矩形
  722. double lefttopX = Convert.ToInt64(item["FieldPosX"]) * xs + Convert.ToInt64(item["RectLeft"]);
  723. if (lefttopX < min_X)
  724. {
  725. min_X = lefttopX;
  726. }
  727. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  728. {
  729. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  730. }
  731. double lrfttopY = Convert.ToInt64(item["FieldPosY"]) * xs - Convert.ToInt64(item["RectTop"]);
  732. if (max_Y < lrfttopY)
  733. {
  734. max_Y = lrfttopY;
  735. }
  736. if (min_Y > lrfttopY - Convert.ToInt64(item["RectHeight"]))
  737. {
  738. min_Y = lrfttopY - Convert.ToInt64(item["RectHeight"]);
  739. }
  740. //画布
  741. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  742. if (lefttopXH > MAX_X)
  743. {
  744. MAX_X = lefttopXH;
  745. }
  746. if (lefttopXH < MIN_X)
  747. {
  748. MIN_X = lefttopXH;
  749. }
  750. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  751. if (MAX_Y < lrfttopYH)
  752. {
  753. MAX_Y = lrfttopYH;
  754. }
  755. if (MIN_Y > lrfttopYH)
  756. {
  757. MIN_Y = lrfttopYH;
  758. }
  759. }
  760. int WIDTH = Convert.ToInt32(MAX_X - MIN_X) + picWidth;
  761. int HEIGHT = Convert.ToInt32(MAX_Y - MIN_Y) + picHeight;
  762. //构造最终的图片白板
  763. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  764. Graphics graph = Graphics.FromImage(tableChartImage);
  765. //初始化这个大图
  766. graph.DrawImage(tableChartImage, 0, 0);
  767. int width = Convert.ToInt32(max_X - min_X);
  768. int height = Convert.ToInt32(max_Y - min_Y);
  769. int X = Convert.ToInt32(min_X - MIN_X);
  770. int Y = Convert.ToInt32(MAX_Y - max_Y);
  771. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  772. foreach (DataRow item in dataTable.Rows)
  773. {
  774. string filePath = path + "\\FIELD_FILES\\";
  775. string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
  776. //然后将取出的数据,转换成Bitmap对象
  777. Bitmap ls_bt = ReadImageFile(imagePath);
  778. int x = Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - MIN_X);
  779. int y = Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - MIN_Y);
  780. graph.DrawImage(ls_bt, x, y);
  781. }
  782. Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
  783. return bmap;
  784. }
  785. /// <summary>
  786. /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
  787. /// </summary>
  788. /// <param name="path"></param>
  789. /// <returns></returns>
  790. public Bitmap ReadImageFile(string path)
  791. {
  792. if (!File.Exists(path))
  793. {
  794. return null;//文件不存在
  795. }
  796. FileStream fs = File.OpenRead(path); //OpenRead
  797. int filelength = 0;
  798. filelength = (int)fs.Length; //获得文件长度
  799. Byte[] image = new Byte[filelength]; //建立一个字节数组
  800. fs.Read(image, 0, filelength); //按字节流读取
  801. System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
  802. fs.Close();
  803. Bitmap bit = new Bitmap(result);
  804. return bit;
  805. }
  806. /// <summary>
  807. /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
  808. /// </summary>
  809. /// <param name="in_cotsparticleclr"></param>
  810. /// <returns></returns>
  811. public Bitmap GetBitmapByParticle(Bitmap ls_bt, Rectangle offset_rect)
  812. {
  813. //为了能把整个颗粒显示完整
  814. offset_rect.X = offset_rect.X - 20;
  815. offset_rect.Y = offset_rect.Y - 20;
  816. offset_rect.Width = offset_rect.Width + 40;
  817. offset_rect.Height = offset_rect.Height + 40;
  818. //防止计算偏差后,有坐标溢出现象
  819. if (offset_rect.X < 0)
  820. offset_rect.X = 0;
  821. if (offset_rect.Y < 0)
  822. offset_rect.Y = 0;
  823. if (offset_rect.X + offset_rect.Width > ls_bt.Width)
  824. {
  825. offset_rect.Width = ls_bt.Width - offset_rect.X;
  826. }
  827. if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
  828. {
  829. offset_rect.Height = ls_bt.Height - offset_rect.Y;
  830. }
  831. Bitmap new_ret_bp;
  832. //防止为0后面计算出错
  833. if (offset_rect.Width > 0 && offset_rect.Height > 0)
  834. {
  835. //最后通过list_showsegment组建成新的图片,进行返回
  836. new_ret_bp = ls_bt.Clone(offset_rect, ls_bt.PixelFormat);
  837. }
  838. else
  839. {
  840. new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
  841. }
  842. return new_ret_bp;
  843. }
  844. public void InsertUpdate(List<int> particleID, List<string> particleData)
  845. {
  846. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  847. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  848. cmdlist.Add(str);
  849. try
  850. {
  851. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  852. }
  853. catch (Exception e)
  854. {
  855. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  856. }
  857. }
  858. public KeyValuePair<string, SQLiteParameter[]> GetUpdataAIncACmd(List<int> particleID, List<string> particleData)
  859. {
  860. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  861. return str;
  862. }
  863. public void ExecuteNonQueryBatch(List<KeyValuePair<string, SQLiteParameter[]>> cmdlist)
  864. {
  865. try
  866. {
  867. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  868. }
  869. catch (Exception e)
  870. {
  871. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  872. }
  873. }
  874. #endregion
  875. #region 清洁度
  876. public ParticleData()
  877. {
  878. }
  879. /// <summary>
  880. /// 获得颗粒类别
  881. /// </summary>
  882. /// <param name="StandardLibraryAddress">标准库地址</param>
  883. /// <returns></returns>
  884. public DataTable ObtainParticleCategory_start(string StandardLibraryAddress)
  885. {
  886. DataTable dataTable = new DataTable();
  887. dataTable.Columns.Add("GroupId");
  888. dataTable.Columns.Add("GroupName");
  889. dataTable.Columns.Add("inoId");
  890. dataTable.Columns.Add("display");
  891. DataTable get_dt = SelectStandardLibraryGrouping(StandardLibraryAddress);
  892. if (get_dt.Rows.Count==0)
  893. {
  894. DataRow data = dataTable.NewRow();
  895. data["inoId"] = 0;
  896. data["GroupId"] = 0;
  897. data["GroupName"] = "Default";
  898. data["display"] = "0";
  899. dataTable.Rows.Add(data);
  900. return dataTable;
  901. }
  902. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  903. int shul = 0;
  904. string DefaultGroupId = "";
  905. foreach (DataRow row in dataRow)
  906. {
  907. if (row.ItemArray[1].ToString() != "Default")
  908. {
  909. DataRow data = dataTable.NewRow();
  910. data["inoId"] = shul;
  911. data["GroupId"] = row.ItemArray[0].ToString();
  912. data["GroupName"] = row.ItemArray[1].ToString();
  913. data["display"] = "0";
  914. dataTable.Rows.Add(data);
  915. shul++;
  916. }
  917. else
  918. {
  919. DefaultGroupId = row.ItemArray[0].ToString();
  920. }
  921. }
  922. DataRow data2 = dataTable.NewRow();
  923. data2["inoId"] = shul;
  924. data2["GroupId"] = DefaultGroupId;
  925. data2["GroupName"] = "Default";
  926. data2["display"] = "0";
  927. dataTable.Rows.Add(data2);
  928. return dataTable;
  929. }
  930. /// <summary>
  931. /// 获取规则数据
  932. /// </summary>
  933. /// <param name="strings">组类别</param>
  934. /// <param name="a_SelectedIndex">标准库地址</param>
  935. /// <returns></returns>
  936. public List<DataTable> ObtainRuleData_start(DataTable strings, string a_SelectedIndex)
  937. {
  938. List<DataTable> List_data = new List<DataTable>();
  939. DataTable dt_stl = new DataTable();
  940. SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
  941. dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
  942. dt_stl.Columns.Add("display");
  943. if (dt_stl == null)
  944. {
  945. List_data.Add(dt_stl);
  946. return List_data;
  947. }
  948. for (int i = 0; i < strings.Rows.Count; i++)
  949. {
  950. DataTable table = dt_stl.Clone();
  951. table.TableName = strings.Rows[i]["GroupId"].ToString();
  952. for (int a = 0; a < dt_stl.Rows.Count; a++)
  953. {
  954. if (strings.Rows[i]["GroupId"].ToString() == dt_stl.Rows[a]["GroupId"].ToString())
  955. {
  956. dt_stl.Rows[a]["display"] = 0;
  957. table.Rows.Add(dt_stl.Rows[a].ItemArray);
  958. }
  959. }
  960. DataView dvs = table.DefaultView;
  961. dvs.Sort = "ListNum ASC";
  962. DataTable TemporaryDataGroup = dvs.ToTable();
  963. List_data.Add(TemporaryDataGroup);
  964. }
  965. return List_data;
  966. }
  967. private DataTable SelectStandardLibraryGrouping(string a_SelectedIndex)
  968. {
  969. DataTable dt_stl = new DataTable();
  970. SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
  971. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  972. return dt_stl;
  973. }
  974. /// <summary>
  975. /// 获得颗粒类别
  976. /// </summary>
  977. /// <returns></returns>
  978. public List<string> ObtainParticleCategory(OTSReport_Export m_otsreport_export, BasicData basicData)
  979. {
  980. List<string> ClassName = new List<string>();
  981. if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
  982. {
  983. DataTable get_dt = ReadClassification(basicData);
  984. DataTable getClass_dt = get_dt.Clone();
  985. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  986. foreach (DataRow row in dataRow)
  987. {
  988. if (row.ItemArray[1].ToString() != "Default")
  989. {
  990. getClass_dt.ImportRow(row);
  991. }
  992. }
  993. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  994. {
  995. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  996. }
  997. ClassName.Add("Default");
  998. }
  999. else
  1000. {
  1001. DataTable getClass_dt = ReadClassification(basicData);
  1002. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1003. {
  1004. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  1005. }
  1006. bool bl = false;
  1007. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1008. {
  1009. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
  1010. && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
  1011. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  1012. {
  1013. if (!bl)
  1014. {
  1015. ClassName.Add("Default");
  1016. bl = true;
  1017. }
  1018. }
  1019. else
  1020. {
  1021. bool isDefault = false;
  1022. for (int a = 0; a < ClassName.Count; a++)
  1023. {
  1024. if (getClass_dt.Rows[i]["GroupName"].ToString() == "Default")
  1025. {
  1026. isDefault = true;
  1027. }
  1028. }
  1029. if (isDefault)
  1030. {
  1031. if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
  1032. {
  1033. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1034. }
  1035. }
  1036. else
  1037. {
  1038. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1039. }
  1040. }
  1041. }
  1042. }
  1043. return ClassName;
  1044. }
  1045. public DataTable ReadClassification(BasicData basicData)
  1046. {
  1047. DataTable dt_stl = new DataTable();
  1048. SqLiteHelper sh = new SqLiteHelper("data source='" + basicData.GetFilePath() + "\\" + basicData.GetResfile() + "'");
  1049. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  1050. return dt_stl;
  1051. }
  1052. #endregion
  1053. }
  1054. public class UserLibraryData
  1055. {
  1056. private SqlHelper dbHelper;
  1057. public UserLibraryData(string libraryName,string resultpath)
  1058. {
  1059. NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  1060. if (!libraryName.Contains(".db"))
  1061. {
  1062. libraryName += ".db";
  1063. }
  1064. if(libraryName.ToLower()== "nostddb.db")
  1065. {
  1066. dbHelper = null;
  1067. log.Error("Failed to load user-defined library" + "!");
  1068. }
  1069. string fullPath = resultpath + libraryName;
  1070. string fullPath2 = System.IO.Directory.GetCurrentDirectory() + "\\Config\\SysData\\" + libraryName;
  1071. if (System.IO.File.Exists(fullPath))
  1072. {
  1073. dbHelper = new SqlHelper("data source='" + fullPath + "'");
  1074. log.Warn("Loading the user standard library:" + fullPath + "!");
  1075. }
  1076. else if(System.IO.File.Exists(fullPath2))
  1077. {
  1078. dbHelper = new SqlHelper("data source='" + fullPath2 + "'");
  1079. log.Warn("Loading the user standard library:" + fullPath2 + "!");
  1080. }
  1081. else
  1082. {
  1083. dbHelper = null;
  1084. log.Error("Failed to load user-defined library"+ "!");
  1085. }
  1086. }
  1087. public DataTable GetSubAttributeFromDatabase()
  1088. {
  1089. string sqliteString = "select STDId,Hardness,Density,Electrical_conductivity from ClassifySTD";
  1090. DataTable DT = new DataTable();
  1091. DT = dbHelper.ExecuteQuery(sqliteString);
  1092. return DT;
  1093. }
  1094. public SqlHelper GetSqlHelper() { return dbHelper; }
  1095. }
  1096. }