ParticleData.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. using OTSCommon.DBOperate.Model;
  2. using OTSIncAReportGraph.Controls;
  3. using OTSPeriodicTable;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SQLite;
  8. using System.Linq;
  9. using static OTSIncAReportApp.OTSReport_Export;
  10. namespace OTSIncAReportApp.DataOperation.DataAccess
  11. {
  12. public class ParticleData
  13. {
  14. private SqlHelper dbHelper;
  15. public ParticleData(string path)
  16. {
  17. dbHelper = new SqlHelper("data source='" + path + "\\FIELD_FILES\\Inclusion.db'");
  18. }
  19. /// <summary>
  20. /// 获取SegmentList
  21. /// </summary>
  22. /// <param name="model">Feature</param>
  23. /// <returns></returns>
  24. public List<Particle> GetParticleList(Particle model)
  25. {
  26. //存放查询数据的数据表
  27. SQLiteParameter[] Parameter = new SQLiteParameter[1]
  28. {
  29. new SQLiteParameter("@FieldId", model.FieldId)
  30. };
  31. string sql = "select * from IncAData where Fieldid=@FieldId";
  32. DataTable DT = dbHelper.ExecuteDataTable(sql, Parameter);
  33. var result = new List<Particle>();
  34. foreach (DataRow dr in DT.Rows)
  35. {
  36. Particle item = new Particle() { };
  37. result.Add(item);
  38. }
  39. return result;
  40. }
  41. /// <summary>
  42. /// 获取ParticleListBy
  43. /// </summary>
  44. /// <param name="model">Feature</param>
  45. /// <returns></returns>
  46. public List<Particle> GetParticleListByCon(string con, string max, string min, int display)
  47. {
  48. string sqlp = "select a.* from IncAData a ";
  49. string where = " where 1=1 ";
  50. if (display == 1)
  51. {
  52. where = where + " and a.XrayId >-1 ";
  53. }
  54. if (con != "")
  55. {
  56. where = where + " and a." + con + ">" + min + " and a." + con + "<" + max;
  57. }
  58. sqlp = sqlp + where;
  59. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  60. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  61. return listp;
  62. }
  63. /// <summary>
  64. /// 获取ParticleList
  65. /// </summary>
  66. /// <param name="model">Feature</param>
  67. /// <returns></returns>
  68. public DataTable GetParticleListAndEm()
  69. {
  70. string sqlp = @"select *,
  71. (select group_concat(name||'-'||Percentage,';')
  72. from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element
  73. from INcAData where xrayid>-1";
  74. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  75. return DT;
  76. }
  77. /// <summary>
  78. /// 获取ParticleList
  79. /// </summary>
  80. /// <param name="model">Feature</param>
  81. /// <returns></returns>
  82. public Particle GetMergedParticleInfo(int fieldid, int particleid, out uint[] Search_xray, out uint[] Analysis_xray)
  83. {
  84. string sqlp = @"select *,
  85. (select group_concat(name||'-'||Percentage,';')
  86. from ElementChemistry where XRayId =IncAData.XRayId and fieldid=IncAData.fieldid ) as Element
  87. from IncAData where FieldId=" + fieldid.ToString() + " and ParticleId="+ particleid.ToString();
  88. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  89. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  90. Particle pte = new Particle();
  91. Analysis_xray =new uint[2000];
  92. Search_xray= new uint[2000];
  93. if (listp.Count > 0)
  94. {
  95. pte = listp[0];
  96. List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
  97. string element = DT.Rows[0]["Element"].ToString();
  98. for (int i = 0; i < element.Split(';').Count(); i++)
  99. {
  100. string elestr = element.Split(';')[i];
  101. if (elestr != "")
  102. {
  103. OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = elestr.Split('-')[0], Percentage = Convert.ToDouble(elestr.Split('-')[1]) };
  104. ElementList.Add(ele);
  105. }
  106. }
  107. pte.ElementList = ElementList;
  108. string SubParticlesstr = DT.Rows[0]["SubParticles"].ToString();
  109. string[] SubParticlesstrG = SubParticlesstr.Split(',');
  110. foreach (string s in SubParticlesstrG)
  111. {
  112. string fieldid1 = s.Split(':')[0];
  113. string pid1 = s.Split(':')[1];
  114. Particle particle1 = GetParticleXrayDataByFidAndPid(fieldid1, pid1);
  115. byte[] bytes = particle1.XRayData;
  116. for (int i = 0; i < 2000; i++)
  117. {
  118. Analysis_xray[i] = Analysis_xray[i]+ BitConverter.ToUInt32(bytes, i * 4);
  119. }
  120. Search_xray = Analysis_xray;
  121. }
  122. }
  123. return pte;
  124. }
  125. /// <summary>
  126. /// 获取ParticleList
  127. /// </summary>
  128. /// <param name="model">Feature</param>
  129. /// <returns></returns>
  130. public DataTable GetParticleStatisticDataListByIncA(string con)
  131. {
  132. string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,sum(Area) as Area,avg(" + con
  133. + ") as av,max(" + con
  134. + ") as max ";
  135. sqlp = sqlp + "from IncAData where typeid !=-1 and typeid !=4 and SubParticles is not 'IsSubParticle' group by TypeId";
  136. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  137. return DT;
  138. }
  139. public DataTable GetParticleListForParticlSize(string con, string fieldAndPartic)
  140. {
  141. string sqlp = @"select TypeId,TypeName,GroupId ,TypeColor,count(1) as con,avg(" + con
  142. + ") as av,max(" + con
  143. + ") as max ,GroupName";
  144. sqlp = sqlp + " from IncAData where typeid !=-1 and typeid !=4 and ParticleId !=-1 and SubParticles is not 'IsSubParticle'";
  145. if (fieldAndPartic != "")
  146. {
  147. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  148. }
  149. sqlp = sqlp + " group by TypeId ";
  150. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  151. if (con == "area")
  152. {
  153. for (int i = 0; i < DT.Rows.Count; i++)
  154. {
  155. DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
  156. }
  157. }
  158. return DT;
  159. }
  160. /// <summary>
  161. /// 获取ParticleList
  162. /// </summary>
  163. /// <param name="model">Feature</param>
  164. /// <returns></returns>
  165. public DataTable GetParticleListForParticlSizeID(string con, string fieldAndPartic)
  166. {
  167. string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,avg(" + con
  168. + ") as av,max(" + con
  169. + ") as max ,GroupName ,GroupId,GroupColor";
  170. sqlp = sqlp + " from IncAData where typeid !=-1 and typeid !=4";
  171. if (fieldAndPartic != "")
  172. {
  173. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  174. }
  175. sqlp = sqlp + " group by TypeId ";
  176. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  177. if (con == "area")
  178. {
  179. for (int i = 0; i < DT.Rows.Count; i++)
  180. {
  181. DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
  182. }
  183. }
  184. return DT;
  185. }
  186. /// <summary>
  187. /// 获取element含量
  188. /// </summary>
  189. /// <returns></returns>
  190. public DataTable GetElementForArea(string fieldAndPartic)
  191. {
  192. string sqlp = @"select e.name,sum(e.percentage*p.area) as earea from ElementChemistry e
  193. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid from IncAData where typeid !=-1 and typeid !=4";
  194. if (fieldAndPartic != "")
  195. {
  196. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
  197. }
  198. sqlp = sqlp + " group by e.name order by sum(e.percentage*p.area) desc";
  199. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  200. return DT;
  201. }
  202. /// <summary>
  203. /// 获取element含量
  204. /// </summary>
  205. /// <returns></returns>
  206. public DataTable GetSmallElementForArea()
  207. {
  208. 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
  209. group by e.name order by sum(e.percentage*i.area) desc";
  210. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  211. return DT;
  212. }
  213. /// <summary>
  214. /// 获取所有Particle
  215. /// </summary>
  216. /// <returns></returns>
  217. public DataTable GetParticleAll(string fieldAndPartic)
  218. {
  219. string sqlp = @"select * from INcAData where typeid !=-1 and typeid !=4 and SubParticles is not 'IsSubParticle'";
  220. if (fieldAndPartic != "")
  221. {
  222. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  223. }
  224. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  225. DT.Columns.Add("ECD",typeof(double));
  226. for (int i = 0; i < DT.Rows.Count; i++)
  227. {
  228. DT.Rows[i]["ECD"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  229. }
  230. DataTable data = DT.Clone();
  231. for (int i = 0; i < DT.Rows.Count; i++)
  232. {
  233. if (Convert.ToInt32(DT.Rows[i]["ParticleId"]) > -1)
  234. {
  235. data.Rows.Add(DT.Rows[i].ItemArray);
  236. }
  237. }
  238. return data;
  239. }
  240. public DataTable GetParticleAllForBig(string fieldAndPartic)
  241. {
  242. string sqlp = @"select * from INcAData where";
  243. if (fieldAndPartic != "")
  244. {
  245. sqlp = sqlp + " '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  246. }
  247. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  248. DT.Columns.Add("ECD", typeof(double));
  249. for (int i = 0; i < DT.Rows.Count; i++)
  250. {
  251. DT.Rows[i]["ECD"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  252. }
  253. DataTable data = DT.Clone();
  254. for (int i = 0; i < DT.Rows.Count; i++)
  255. {
  256. if (Convert.ToInt32(DT.Rows[i]["ParticleId"]) > -1)
  257. {
  258. data.Rows.Add(DT.Rows[i].ItemArray);
  259. }
  260. }
  261. return data;
  262. }
  263. public DataTable GetParticleAllforparticlelist(string fieldAndPartic)
  264. {
  265. string sqlp = @"select * from INcAData where typeid !=-1 and SubParticles is not 'IsSubParticle' ";
  266. if (fieldAndPartic != "")
  267. {
  268. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  269. }
  270. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  271. return DT;
  272. }
  273. public DataTable GetMergedParticle(string fieldAndPartic)
  274. {
  275. string sqlp = @"select * from INcAData where typeid !=-1 and SubParticles is not 'IsSubParticle' and SubParticles is not null ";
  276. if (fieldAndPartic != "")
  277. {
  278. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  279. }
  280. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  281. return DT;
  282. }
  283. /// <summary>
  284. /// 查找所有颗粒的颜色、面积、种类名称信息
  285. /// </summary>
  286. /// <returns></returns>
  287. public DataTable GetParticleTypeInformation()
  288. {
  289. string sqlp = @"select Area,TypeName,TypeColor from IncAData";
  290. DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
  291. return dt;
  292. }
  293. /// <summary>
  294. /// 查找IncaData表中所有种类
  295. /// </summary>
  296. /// <returns></returns>
  297. public DataTable GetParticleClassAll()
  298. {
  299. string sqlp = @"SELECT DISTINCT TypeName FROM IncaData";
  300. DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
  301. return dt;
  302. }
  303. /// <summary>
  304. /// 获取所有Particle
  305. /// </summary>
  306. /// <returns></returns>
  307. public DataTable GetParticleAllHaveXray(string fieldAndPartic)
  308. {
  309. string incaSql = @"select * from IncAData where typeid !=-1 and typeid !=4";
  310. if (fieldAndPartic != "")
  311. {
  312. incaSql = incaSql + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  313. }
  314. DataTable incaDT = dbHelper.ExecuteDataTable(incaSql, null);
  315. incaDT.Columns.Add("Element");
  316. DataTable dt_element = GetElementChemistry();
  317. DataTable elementchemistry = dt_element.Clone();
  318. for (int i = 0; i < dt_element.Rows.Count; i++)
  319. {
  320. if (dt_element.Rows[i]["Name"].ToString() != "Fe")
  321. {
  322. elementchemistry.Rows.Add(dt_element.Rows[i].ItemArray);
  323. }
  324. }
  325. for (int i = 0; i < incaDT.Rows.Count; i++)
  326. {
  327. string str = "XRayId = " + incaDT.Rows[i]["particleId"].ToString() + " and fieldid = " + incaDT.Rows[i]["fieldid"].ToString();
  328. DataRow[] drs = elementchemistry.Select(str);
  329. string ConcatenatedString = "";
  330. for (int j = 0; j < drs.Length; j++)
  331. {
  332. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  333. }
  334. incaDT.Rows[i]["Element"] = ConcatenatedString;
  335. }
  336. return incaDT;
  337. }
  338. /// <summary>
  339. /// 获取所有Particle
  340. /// </summary>
  341. /// <returns></returns>
  342. public DataTable GetParticleHaveXray(string fieldAndPartic)
  343. {
  344. string sqlp = @"select *,
  345. (select group_concat(name||'-'||Percentage,';')
  346. from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element from INcAData where xrayid>-1 ";
  347. if (fieldAndPartic != "")
  348. {
  349. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  350. }
  351. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  352. for (int i = 0; i < DT.Rows.Count; i++)
  353. {
  354. DT.Rows[i]["Area"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  355. }
  356. return DT;
  357. }
  358. /// <summary>
  359. /// 获取所有Particle
  360. /// </summary>
  361. /// <returns></returns>
  362. public List<Particle> GetParticleAllList()
  363. {
  364. string sqlp = @"select * from IncAData";
  365. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  366. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  367. return listp;
  368. }
  369. /// <summary>
  370. /// 获取所有Particle
  371. /// </summary>
  372. /// <returns></returns>
  373. public DataTable GetParticleAllList_DataTable()
  374. {
  375. string sqlp = @"select * from INcAData";
  376. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  377. return DT;
  378. }
  379. /// <summary>
  380. /// 获取所有分类的面积
  381. /// </summary>
  382. /// <param name="fieldAndPartic">选择颗粒</param>
  383. /// <returns></returns>
  384. public DataTable GetAreaByAllIncA(string fieldAndPartic)
  385. {
  386. 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 and SubParticles is not 'IsSubParticle' ";
  387. if (fieldAndPartic != "")
  388. {
  389. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  390. }
  391. sqlp = sqlp + " group by TypeId";
  392. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  393. return DT;
  394. }
  395. /// <summary>
  396. /// 获取所有大颗粒没有的小颗粒分类
  397. /// </summary>
  398. /// <param name="fieldAndPartic">选择颗粒</param>
  399. /// <returns></returns>
  400. public DataTable GetSmallParticleInfo()
  401. {
  402. 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";
  403. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  404. return DT;
  405. }
  406. /// <summary>
  407. /// 获取不同分类的面积
  408. /// </summary>
  409. /// <param name="fieldAndPartic">选择颗粒</param>
  410. /// <returns></returns>
  411. public DataTable GetAreaByIncA(string TypeId, string fieldAndPartic)
  412. {
  413. string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
  414. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid where p.TypeId=" + TypeId + " and SubParticles is not 'IsSubParticle' ";
  415. if (fieldAndPartic != "")
  416. {
  417. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
  418. }
  419. sqlp = sqlp + " group by e.name";
  420. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  421. return DT;
  422. }
  423. public DataTable GetAreaByIncA_All()
  424. {
  425. string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
  426. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid group by e.name where SubParticles is not 'IsSubParticle' ";
  427. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  428. return DT;
  429. }
  430. /// <summary>
  431. /// 获取全部的物质大类
  432. /// </summary>
  433. /// <returns></returns>
  434. public DataTable GetAllClass()
  435. {
  436. string sqlp = @"select GroupName from IncAData group by GroupName order by count(1) desc";
  437. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  438. return DT;
  439. }
  440. /// <summary>
  441. /// 获取所有元素
  442. /// </summary>
  443. /// <param name="model">Feature</param>
  444. /// <returns></returns>
  445. public DataTable GetAllElement()
  446. {
  447. string sqlp = @"select name from ElementChemistry group by name order by count(1) desc";
  448. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  449. return DT;
  450. }
  451. /// <summary>
  452. /// 获取常用夹杂物分类信息
  453. /// </summary>
  454. /// <returns></returns>
  455. public DataTable GetCommonlyUsedClassifyData()
  456. {
  457. string sqlp = @"select
  458. (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 ,
  459. (select count(typeid) from incadata where typeid BETWEEN 10000 and 10999 ) as OXIDE ,
  460. (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 ,
  461. (select count(typeid) from incadata where typeid BETWEEN 12000 and 12999 ) as NITRIDE ,
  462. (select count(typeid) from incadata where typeid BETWEEN 11000 and 11999 ) as SULFIDE ";
  463. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  464. return DT;
  465. }
  466. public bool DeleteFromData(string fieldid, string particleid)
  467. {
  468. string sqlp = @"delete from IncAData where FieldId=" + fieldid + " and ParticleId="
  469. + particleid;
  470. if (dbHelper.ExecuteQuery_bool(sqlp))
  471. {
  472. return true;
  473. }
  474. else
  475. {
  476. return false;
  477. }
  478. }
  479. /// <summary>
  480. /// 获取颗粒信息
  481. /// </summary>
  482. /// <param name="model">Feature</param>
  483. /// <returns></returns>
  484. public Particle GetParticleByFidAndPid(string fieldid, string particleid)
  485. {
  486. string sqlp = @"select *,(select xraydata from xraydata where xrayindex=INcAData.xrayid and fieldid="
  487. + fieldid + ") as XRayData,(select group_concat(name || '_' || Percentage, ';')from ElementChemistry where XRayId = INcAData.XRayId and fieldid ="
  488. + fieldid + ") as Element from INcAData where fieldid="
  489. + fieldid + " and particleid= " + particleid;
  490. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  491. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  492. Particle particle = new Particle();
  493. if (listp.Count > 0)
  494. {
  495. particle = listp[0];
  496. List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
  497. string element = DT.Rows[0]["Element"].ToString();
  498. for (int i = 0; i < element.Split(';').Count(); i++)
  499. {
  500. if (element.Split(';')[i] != "")
  501. {
  502. OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = element.Split(';')[i].Split('_')[0], Percentage = Convert.ToDouble(element.Split(';')[i].Split('_')[1]) };
  503. ElementList.Add(ele);
  504. }
  505. }
  506. particle.ElementList = ElementList;
  507. }
  508. return particle;
  509. }
  510. public Particle GetParticleXrayDataByFidAndPid(string fieldid, string xrayid)
  511. {
  512. string sqlp = @"select xraydata from xraydata where xrayindex=" + xrayid + " and fieldid="
  513. + fieldid;
  514. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  515. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  516. if (listp.Count > 0)
  517. {
  518. return listp[0];
  519. }
  520. else
  521. {
  522. return null;
  523. }
  524. }
  525. public List<Segment> GetSegmentData(int fldId,int partId)
  526. {
  527. string strs = @"select * from Segment where FieldId=" + fldId.ToString() + " and ParticleId=" + partId.ToString();
  528. DataTable DTS = dbHelper.ExecuteDataTable(strs, null);
  529. DataRow[] dd = DTS.Select();
  530. List<Segment> flist = dbHelper.RowsToList<Segment>(dd);
  531. return flist;
  532. }
  533. #region 分页添加读取数据库函数
  534. /// <summary>
  535. /// 获取分页查询所需信息
  536. /// </summary>
  537. /// <param name=""></param>
  538. /// <param name=""></param>
  539. /// <returns></returns>
  540. public DataTable GetInfoForPartucleDevidePage(int currentPage, int pagesize, string OrderFunction, string condition)
  541. {
  542. int p = (currentPage - 1) * pagesize;
  543. 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();
  544. DataTable DT = new DataTable();
  545. DT = dbHelper.ExecuteQuery(sqliteString);
  546. return DT;
  547. }
  548. public DataTable GetIncaSurfaceData( List<string> lst_str)
  549. {
  550. DataTable particlesAll = GetInfoForPartucleDevidePage2("");
  551. DataTable dt_element = GetElementChemistry();
  552. List<int> list_int = new List<int>();
  553. for (int a = 0; a < lst_str.Count; a++)
  554. {
  555. for (int i = 0; i < dt_element.Rows.Count; i++)
  556. {
  557. if (dt_element.Rows[i]["Name"].ToString() == lst_str[a].ToString())
  558. {
  559. list_int.Add(i);
  560. }
  561. }
  562. }
  563. for (int i = 0; i < list_int.Count; i++)
  564. {
  565. dt_element.Rows[list_int[i]].Delete();
  566. }
  567. dt_element.AcceptChanges();
  568. for (int i = 0; i < particlesAll.Rows.Count; i++)
  569. {
  570. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  571. DataRow[] drs = dt_element.Select(str);
  572. string ConcatenatedString = "";
  573. for (int j = 0; j < drs.Length; j++)
  574. {
  575. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  576. }
  577. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  578. }
  579. return particlesAll;
  580. }
  581. public DataTable AddElementColumn(DataTable particlesAll, c_TemplateClass m_mbszclass)
  582. {
  583. if (!particlesAll.Columns.Contains("Element"))
  584. {
  585. particlesAll.Columns.Add("Element");
  586. }
  587. DataTable dt_element = GetElementChemistry();
  588. for (int i = 0; i < particlesAll.Rows.Count; i++)
  589. {
  590. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  591. DataRow[] drs = dt_element.Select(str);
  592. string ConcatenatedString = "";
  593. for (int j = 0; j < drs.Length; j++)
  594. {
  595. //判断是否在处理元素表中
  596. bool bl = false;
  597. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_qcys.Count; a++)
  598. {
  599. if (drs[j]["name"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_qcys[a].ToString())
  600. {
  601. bl = true;
  602. }
  603. }
  604. if (!bl)
  605. {
  606. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  607. }
  608. }
  609. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  610. }
  611. return particlesAll;
  612. }
  613. /// <summary>
  614. /// 拼接颗粒
  615. /// </summary>
  616. /// <param name="lst_str"></param>
  617. /// <returns></returns>
  618. public DataTable GetSplicingParticlesData()
  619. {
  620. DataTable particlesAll = GetSplicingParticles();
  621. return particlesAll;
  622. }
  623. /// <summary>
  624. /// 保留两位小数
  625. /// </summary>
  626. /// <param name="strData"></param>
  627. /// <returns></returns>
  628. private string ChangeDataToD(string strData)
  629. {
  630. Decimal dData = 0.00M;
  631. if (strData.Contains("E"))
  632. {
  633. dData = Convert.ToDecimal(Decimal.Parse(strData.ToString(), System.Globalization.NumberStyles.Float));
  634. }
  635. else
  636. {
  637. return Convert.ToDouble(strData).ToString("0.00");
  638. }
  639. return Convert.ToDouble(dData).ToString("0.00");
  640. }
  641. public DataTable GetInfoForPartucleDevidePage2(string condition)
  642. {
  643. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
  644. "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles," +
  645. " (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) " +
  646. "as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId," +
  647. "SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,'' " +
  648. "as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " +
  649. condition;
  650. DataTable DT = new DataTable();
  651. DT = dbHelper.ExecuteQuery(sqliteString);
  652. return DT;
  653. }
  654. public DataTable GetSplicingParticles()
  655. {
  656. string sqliteString1 = "select * from MergedParticleInfo";
  657. DataTable DT = new DataTable();
  658. DT = dbHelper.ExecuteQuery(sqliteString1);
  659. return DT;
  660. }
  661. public DataTable GetInfoForPartucleDevidePage_analyticalParticle(string condition)
  662. {
  663. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and typeid !=9 and typeid !=-1 and typeid !=4 and SubParticles is not 'IsSubParticle') " +
  664. condition;
  665. DataTable DT = new DataTable();
  666. DT = dbHelper.ExecuteQuery(sqliteString);
  667. return DT;
  668. }
  669. public DataTable GetInfoForPartucleDevidePage_otherParticle(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,SubParticles,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and SubParticles is not 'IsSubParticle' and (typeid =9 or typeid =-1 or typeid =4)) " +
  672. condition;
  673. DataTable DT = new DataTable();
  674. DT = dbHelper.ExecuteQuery(sqliteString);
  675. return DT;
  676. }
  677. /// <summary>
  678. /// 获取拼接颗粒
  679. /// </summary>
  680. /// <param name="condition">帅选条件</param>
  681. /// <returns></returns>
  682. public DataTable GetInfoForPartucleDevidePage_mergeParticles(string condition)
  683. {
  684. 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,SubParticles,TypeName,TypeColor,'' as Element from INcAData where (SubParticles Is not null and SubParticles is not 'IsSubParticle' )" + condition;
  685. DataTable DT1 = new DataTable();
  686. try
  687. {
  688. DT1 = dbHelper.ExecuteQuery(sqliteString);
  689. }
  690. catch
  691. {
  692. }
  693. return DT1;
  694. }
  695. public DataTable GetInfoForPartucleDevidePage_allParticles(string condition)
  696. {
  697. 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,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and SubParticles is not 'IsSubParticle' " +
  698. condition;
  699. DataTable DT = new DataTable();
  700. DT = dbHelper.ExecuteQuery(sqliteString);
  701. return DT;
  702. }
  703. public DataTable GetInfoForPartucleDevidePage_NotIdentifyParticle(string condition)
  704. {
  705. 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,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and typeid =9 and SubParticles is not 'IsSubParticle' " +
  706. condition;
  707. DataTable DT = new DataTable();
  708. DT = dbHelper.ExecuteQuery(sqliteString);
  709. return DT;
  710. }
  711. public DataTable GetInfoForPartucleDevidePage_InvalidParticle(string condition)
  712. {
  713. 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,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and typeid =-1 and SubParticles is not 'IsSubParticle' " +
  714. condition;
  715. DataTable DT = dbHelper.ExecuteQuery(sqliteString);
  716. return DT;
  717. }
  718. public DataTable GetInfoForPartucleDevidePage_LowCountsParticle(string condition)
  719. {
  720. 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,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 typeid =4 and SubParticles is not 'IsSubParticle' " +
  721. condition;
  722. DataTable DT = dbHelper.ExecuteQuery(sqliteString);
  723. return DT;
  724. }
  725. public DataTable GetClassificationOfAllParticles(string condition)
  726. {
  727. string sqliteString1 = "select distinct TypeName from INcAData " + condition;
  728. DataTable DT = dbHelper.ExecuteQuery(sqliteString1);
  729. return DT;
  730. }
  731. public DataTable GetXRayData()
  732. {
  733. string sqliteString = @"select * from xraydata";
  734. DataTable DT = new DataTable();
  735. DT = dbHelper.ExecuteQuery(sqliteString);
  736. return DT;
  737. }
  738. public DataTable GetElementChemistry()
  739. {
  740. string sqliteString = "select * from ElementChemistry";
  741. DataTable DT = new DataTable();
  742. DT = dbHelper.ExecuteQuery(sqliteString);
  743. return DT;
  744. }
  745. /// <summary>
  746. /// 得到图形形状
  747. /// </summary>
  748. /// <returns></returns>
  749. public DataTable GetSegment()
  750. {
  751. string sqliteString = "select * from Segment";
  752. DataTable DT = new DataTable();
  753. DT = dbHelper.ExecuteQuery(sqliteString);
  754. return DT;
  755. }
  756. /// <summary>
  757. /// 全部颗粒不带元素
  758. /// </summary>
  759. /// <param name="condition"></param>
  760. /// <returns></returns>
  761. public DataTable GetAllParticleWithMergeParticlesWithoutEle(string condition)
  762. {
  763. DataTable particlesAll = GetParticleAllforparticlelist(condition);
  764. return particlesAll;
  765. }
  766. /// <summary>
  767. /// 全部颗粒带元素
  768. /// </summary>
  769. /// <param name="condition"></param>
  770. /// <returns></returns>
  771. public DataTable GetAllParticleWithMergeParticles(string condition)
  772. {
  773. DataTable particlesAll=new DataTable();
  774. DataTable particlesAll1 = GetInfoForPartucleDevidePage_allParticles(condition);
  775. DataTable mergeParticles = GetInfoForPartucleDevidePage_mergeParticles(condition);
  776. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  777. {
  778. RemoveMergeParticles(ref particlesAll1, mergeParticles);
  779. }
  780. particlesAll = particlesAll1.Copy();
  781. foreach (DataRow item in mergeParticles.Rows)
  782. {
  783. particlesAll.ImportRow(item);
  784. }
  785. DataTable elementchemistry = GetElementChemistry();
  786. for (int i = 0; i < particlesAll.Rows.Count; i++)
  787. {
  788. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  789. DataRow[] drs = elementchemistry.Select(str);
  790. string ConcatenatedString = "";
  791. for (int j = 0; j < drs.Length; j++)
  792. {
  793. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  794. }
  795. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  796. }
  797. return particlesAll;
  798. }
  799. public void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
  800. {
  801. foreach (DataRow row in dataTable_Particle.Rows)
  802. {
  803. foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
  804. {
  805. string subt = MergeParticlesRow["SubParticles"].ToString();
  806. string[] sub = subt.Split(',');
  807. if (row.RowState == DataRowState.Deleted)
  808. {
  809. break;
  810. }
  811. if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
  812. {
  813. row.Delete();
  814. break;
  815. }
  816. if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
  817. {
  818. row.Delete();
  819. break; ;
  820. }
  821. }
  822. }
  823. dataTable_Particle.AcceptChanges();
  824. }
  825. public void InsertUpdate(List<int> particleID, List<string> particleData)
  826. {
  827. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  828. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  829. cmdlist.Add(str);
  830. try
  831. {
  832. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  833. }
  834. catch (Exception e)
  835. {
  836. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  837. }
  838. }
  839. public KeyValuePair<string, SQLiteParameter[]> GetUpdataAIncACmd(List<int> particleID, List<string> particleData)
  840. {
  841. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  842. return str;
  843. }
  844. public void ExecuteNonQueryBatch(List<KeyValuePair<string, SQLiteParameter[]>> cmdlist)
  845. {
  846. try
  847. {
  848. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  849. }
  850. catch (Exception e)
  851. {
  852. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  853. }
  854. }
  855. /// <summary>
  856. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  857. /// </summary>
  858. /// <param name="in_clr_tagid">颗粒id</param>
  859. /// <param name="in_clr_fieldid"></param>
  860. /// <param name="Search_xray"></param>
  861. /// <param name="Analysis_xray"></param>
  862. public Particle GetXrayByParticleTagIDAndFieldID_ForMergeParticle(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray)
  863. {
  864. Search_xray = new uint[2000];
  865. Analysis_xray = new uint[2000];
  866. Particle particle = new Particle();
  867. particle = GetMergedParticleInfo(in_clr_fieldid, in_clr_tagid, out Search_xray, out Analysis_xray);
  868. return particle;
  869. }
  870. public List<ShowElementInfo> GetShowElementInfos_ForMergeParticle(List<Element> list_celementchemistryclr)
  871. {
  872. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  873. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  874. {
  875. ShowElementInfo ls_sei = new ShowElementInfo();
  876. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  877. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  878. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  879. double de_sx2 = 0;
  880. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  881. {
  882. de_sx2 = 0;
  883. }
  884. else
  885. {
  886. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  887. }
  888. ls_sei.dLF = de_sx2;
  889. list_showelementinfo.Add(ls_sei);
  890. }
  891. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  892. return list_showelementinfo;
  893. }
  894. #endregion
  895. public ParticleData()
  896. {
  897. }
  898. }
  899. }