ParticleData.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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
  674. {
  675. return Convert.ToDouble(strData).ToString("0.00");
  676. }
  677. return Convert.ToDouble(dData).ToString("0.00");
  678. }
  679. public DataTable GetInfoForPartucleDevidePage2(string condition)
  680. {
  681. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
  682. "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles," +
  683. " (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) " +
  684. "as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId," +
  685. "SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,'' " +
  686. "as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " +
  687. condition;
  688. DataTable DT = new DataTable();
  689. DT = dbHelper.ExecuteQuery(sqliteString);
  690. return DT;
  691. }
  692. public DataTable GetSplicingParticles()
  693. {
  694. string sqliteString1 = "select * from MergedParticleInfo";
  695. DataTable DT = new DataTable();
  696. DT = dbHelper.ExecuteQuery(sqliteString1);
  697. return DT;
  698. }
  699. public DataTable GetInfoForPartucleDevidePage_analyticalParticle(string condition)
  700. {
  701. 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') " +
  702. condition;
  703. DataTable DT = new DataTable();
  704. DT = dbHelper.ExecuteQuery(sqliteString);
  705. return DT;
  706. }
  707. public DataTable GetInfoForPartucleDevidePage_otherParticle(string condition)
  708. {
  709. 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)) " +
  710. condition;
  711. DataTable DT = new DataTable();
  712. DT = dbHelper.ExecuteQuery(sqliteString);
  713. return DT;
  714. }
  715. /// <summary>
  716. /// 获取拼接颗粒
  717. /// </summary>
  718. /// <param name="condition">帅选条件</param>
  719. /// <returns></returns>
  720. public DataTable GetInfoForPartucleDevidePage_mergeParticles(string condition)
  721. {
  722. 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;
  723. DataTable DT1 = new DataTable();
  724. try
  725. {
  726. DT1 = dbHelper.ExecuteQuery(sqliteString);
  727. }
  728. catch
  729. {
  730. }
  731. return DT1;
  732. }
  733. public DataTable GetInfoForPartucleDevidePage_allParticles(string condition)
  734. {
  735. 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' " +
  736. condition;
  737. DataTable DT = new DataTable();
  738. DT = dbHelper.ExecuteQuery(sqliteString);
  739. return DT;
  740. }
  741. public DataTable GetInfoForPartucleDevidePage_NotIdentifyParticle(string condition)
  742. {
  743. 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' " +
  744. condition;
  745. DataTable DT = new DataTable();
  746. DT = dbHelper.ExecuteQuery(sqliteString);
  747. return DT;
  748. }
  749. public DataTable GetInfoForPartucleDevidePage_InvalidParticle(string condition)
  750. {
  751. 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' " +
  752. condition;
  753. DataTable DT = dbHelper.ExecuteQuery(sqliteString);
  754. return DT;
  755. }
  756. public DataTable GetInfoForPartucleDevidePage_LowCountsParticle(string condition)
  757. {
  758. 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' " +
  759. condition;
  760. DataTable DT = dbHelper.ExecuteQuery(sqliteString);
  761. return DT;
  762. }
  763. public DataTable GetClassificationOfAllParticles(string condition)
  764. {
  765. string sqliteString1 = "select distinct TypeName from INcAData " + condition;
  766. DataTable DT = dbHelper.ExecuteQuery(sqliteString1);
  767. return DT;
  768. }
  769. public DataTable GetXRayData()
  770. {
  771. string sqliteString = @"select * from xraydata";
  772. DataTable DT = new DataTable();
  773. DT = dbHelper.ExecuteQuery(sqliteString);
  774. return DT;
  775. }
  776. public DataTable GetElementChemistry()
  777. {
  778. string sqliteString = "select * from ElementChemistry";
  779. DataTable DT = new DataTable();
  780. DT = dbHelper.ExecuteQuery(sqliteString);
  781. return DT;
  782. }
  783. /// <summary>
  784. /// 得到图形形状
  785. /// </summary>
  786. /// <returns></returns>
  787. public DataTable GetSegment()
  788. {
  789. string sqliteString = "select * from Segment";
  790. DataTable DT = new DataTable();
  791. DT = dbHelper.ExecuteQuery(sqliteString);
  792. return DT;
  793. }
  794. /// <summary>
  795. /// 全部颗粒不带元素
  796. /// </summary>
  797. /// <param name="condition"></param>
  798. /// <returns></returns>
  799. public DataTable GetAllParticleWithMergeParticlesWithoutEle(string condition)
  800. {
  801. DataTable particlesAll = GetParticleAllforparticlelist(condition);
  802. return particlesAll;
  803. }
  804. /// <summary>
  805. /// 全部颗粒带元素
  806. /// </summary>
  807. /// <param name="condition"></param>
  808. /// <returns></returns>
  809. public DataTable GetAllParticleWithMergeParticles(string condition)
  810. {
  811. DataTable particlesAll=new DataTable();
  812. DataTable particlesAll1 = GetInfoForPartucleDevidePage_allParticles(condition);
  813. DataTable mergeParticles = GetInfoForPartucleDevidePage_mergeParticles(condition);
  814. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  815. {
  816. RemoveMergeParticles(ref particlesAll1, mergeParticles);
  817. }
  818. particlesAll = particlesAll1.Copy();
  819. foreach (DataRow item in mergeParticles.Rows)
  820. {
  821. particlesAll.ImportRow(item);
  822. }
  823. DataTable elementchemistry = GetElementChemistry();
  824. for (int i = 0; i < particlesAll.Rows.Count; i++)
  825. {
  826. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  827. DataRow[] drs = elementchemistry.Select(str);
  828. string ConcatenatedString = "";
  829. for (int j = 0; j < drs.Length; j++)
  830. {
  831. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  832. }
  833. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  834. }
  835. return particlesAll;
  836. }
  837. public void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
  838. {
  839. foreach (DataRow row in dataTable_Particle.Rows)
  840. {
  841. foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
  842. {
  843. string subParticleString = MergeParticlesRow["SubParticles"].ToString();
  844. string[] sub = subParticleString.Split(',');
  845. if (row.RowState == DataRowState.Deleted)
  846. {
  847. break;
  848. }
  849. if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
  850. {
  851. row.Delete();
  852. break;
  853. }
  854. if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
  855. {
  856. row.Delete();
  857. break; ;
  858. }
  859. }
  860. }
  861. dataTable_Particle.AcceptChanges();
  862. }
  863. public void InsertUpdate(List<int> particleID, List<string> particleData)
  864. {
  865. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  866. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  867. cmdlist.Add(str);
  868. try
  869. {
  870. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  871. }
  872. catch (Exception e)
  873. {
  874. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  875. }
  876. }
  877. public KeyValuePair<string, SQLiteParameter[]> GetUpdataAIncACmd(List<int> particleID, List<string> particleData)
  878. {
  879. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  880. return str;
  881. }
  882. public void ExecuteNonQueryBatch(List<KeyValuePair<string, SQLiteParameter[]>> cmdlist)
  883. {
  884. try
  885. {
  886. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  887. }
  888. catch (Exception e)
  889. {
  890. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  891. }
  892. }
  893. /// <summary>
  894. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  895. /// </summary>
  896. /// <param name="in_clr_tagid">颗粒id</param>
  897. /// <param name="in_clr_fieldid"></param>
  898. /// <param name="Analysis_xray"></param>
  899. public Particle GetXrayByParticleTagIDAndFieldID_ForMergeParticle(int in_clr_tagid, int in_clr_fieldid, out uint[] Analysis_xray)
  900. {
  901. Analysis_xray = new uint[2000];
  902. Particle particle = new Particle();
  903. particle = GetMergedParticleInfo(in_clr_fieldid, in_clr_tagid, out Analysis_xray);
  904. return particle;
  905. }
  906. public Particle GetXrayByParticleIDAndFieldID(string subParticleString, int in_clr_tagid, int in_clr_fieldid, out uint[] Analysis_xray)
  907. {
  908. if (subParticleString != "" && subParticleString != null)
  909. {
  910. return GetXrayByParticleTagIDAndFieldID_ForMergeParticle(in_clr_tagid, in_clr_fieldid, out Analysis_xray);
  911. }
  912. else
  913. {
  914. return GetXrayByParticleTagIDAndFieldID_ForUncombinedParticle(in_clr_tagid, in_clr_fieldid, out Analysis_xray);
  915. }
  916. }
  917. public Particle GetXrayByParticleTagIDAndFieldID_ForUncombinedParticle(int in_clr_tagid, int in_clr_fieldid, out uint[] Analysis_xray)
  918. {
  919. string sqlp = @"select *,
  920. (select group_concat(name||'-'||Percentage,';')
  921. from ElementChemistry where XRayId =IncAData.XRayId and fieldid=IncAData.fieldid ) as Element
  922. from IncAData where FieldId=" + in_clr_fieldid.ToString() + " and ParticleId=" + in_clr_tagid.ToString();
  923. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  924. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  925. Particle pte = new Particle();
  926. Analysis_xray = new uint[2000];
  927. if (listp.Count > 0)
  928. {
  929. pte = listp[0];
  930. List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
  931. string element = DT.Rows[0]["Element"].ToString();
  932. for (int i = 0; i < element.Split(';').Count(); i++)
  933. {
  934. string elestr = element.Split(';')[i];
  935. if (elestr != "")
  936. {
  937. OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = elestr.Split('-')[0], Percentage = Convert.ToDouble(elestr.Split('-')[1]) };
  938. ElementList.Add(ele);
  939. }
  940. }
  941. pte.ElementList = ElementList;
  942. Analysis_xray = new uint[2000];
  943. var particle = GetParticleXrayDataByFidAndPid(Convert.ToString(in_clr_fieldid), Convert.ToString(in_clr_tagid));
  944. pte.XRayData = particle.XRayData;
  945. if (particle != null)
  946. {
  947. if (particle.XrayId > -1)
  948. {
  949. for (int i = 0; i < 2000; i++)
  950. {
  951. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  952. }
  953. }
  954. }
  955. }
  956. return pte;
  957. }
  958. public List<ShowElementInfo> GetShowElementInfos(List<Element> list_celementchemistryclr)
  959. {
  960. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  961. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  962. {
  963. ShowElementInfo ls_sei = new ShowElementInfo();
  964. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  965. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  966. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  967. double de_sx2 = 0;
  968. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  969. {
  970. de_sx2 = 0;
  971. }
  972. else
  973. {
  974. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  975. }
  976. ls_sei.dLF = de_sx2;
  977. list_showelementinfo.Add(ls_sei);
  978. }
  979. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  980. return list_showelementinfo;
  981. }
  982. #endregion
  983. public ParticleData()
  984. {
  985. }
  986. }
  987. }