ParticleData.cs 48 KB

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