ParticleData.cs 47 KB

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