ParticleData.cs 46 KB

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