ParticleData.cs 46 KB

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