ParticleData.cs 46 KB

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