ParticleData.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  1. using DevExpress.Charts.Native;
  2. using DevExpress.XtraDiagram.Bars;
  3. using DevExpress.XtraEditors.Filtering;
  4. using OTSCommon.DBOperate;
  5. using OTSCommon.DBOperate.Model;
  6. using OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration;
  7. using OTSIncAReportGraph.Controls;
  8. using OTSPeriodicTable;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Data.SQLite;
  13. using System.Drawing;
  14. using System.Drawing.Imaging;
  15. using System.IO;
  16. using System.Linq;
  17. using static OTSDataType.otsdataconst;
  18. using static OTSIncAReportApp.OTSReport_Export;
  19. namespace OTSIncAReportApp.DataOperation.DataAccess
  20. {
  21. public class ParticleData
  22. {
  23. private SqlHelper dbHelper;
  24. public ParticleData(string path)
  25. {
  26. dbHelper = new SqlHelper("data source='" + path + "\\FIELD_FILES\\Inclusion.db'");
  27. }
  28. /// <summary>
  29. /// 获取SegmentList
  30. /// </summary>
  31. /// <param name="model">Feature</param>
  32. /// <returns></returns>
  33. public List<Particle> GetParticleList(Particle model)
  34. {
  35. //存放查询数据的数据表
  36. SQLiteParameter[] Parameter = new SQLiteParameter[1]
  37. {
  38. new SQLiteParameter("@FieldId", model.FieldId)
  39. };
  40. string sql = "select * from IncAData where Fieldid=@FieldId";
  41. DataTable DT = dbHelper.ExecuteDataTable(sql, Parameter);
  42. var result = new List<Particle>();
  43. foreach (DataRow dr in DT.Rows)
  44. {
  45. Particle item = new Particle() { };
  46. result.Add(item);
  47. }
  48. return result;
  49. }
  50. /// <summary>
  51. /// 获取ParticleListBy
  52. /// </summary>
  53. /// <param name="model">Feature</param>
  54. /// <returns></returns>
  55. public List<Particle> GetParticleListByCon(string con, string max, string min, int display)
  56. {
  57. string sqlp = "select a.* from IncAData a ";
  58. string where = " where 1=1 ";
  59. if (display == 1)
  60. {
  61. where = where + " and a.XrayId >-1 ";
  62. }
  63. if (con != "")
  64. {
  65. where = where + " and a." + con + ">" + min + " and a." + con + "<" + max;
  66. }
  67. sqlp = sqlp + where;
  68. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  69. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  70. return listp;
  71. }
  72. /// <summary>
  73. /// 获取ParticleList
  74. /// </summary>
  75. /// <param name="model">Feature</param>
  76. /// <returns></returns>
  77. public DataTable GetParticleListAndEm()
  78. {
  79. string sqlp = @"select *,
  80. (select group_concat(name||'-'||Percentage,';')
  81. from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element
  82. from INcAData where xrayid>-1";
  83. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  84. return DT;
  85. }
  86. /// <summary>
  87. /// 获取ParticleList
  88. /// </summary>
  89. /// <param name="model">Feature</param>
  90. /// <returns></returns>
  91. public Particle GetMergedParticleInfo(int fieldid, int particleid, out uint[] Search_xray, out uint[] Analysis_xray)
  92. {
  93. string sqlp = @"select *,
  94. (select group_concat(name||'-'||Percentage,';')
  95. from ElementChemistry where XRayId =MergedParticleInfo.XRayId and fieldid=MergedParticleInfo.fieldid ) as Element
  96. from MergedParticleInfo where FieldId=" + fieldid.ToString() + " and ParticleId="+ particleid.ToString();
  97. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  98. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  99. Particle pte = new Particle();
  100. Analysis_xray =new uint[2000];
  101. Search_xray= new uint[2000];
  102. if (listp.Count > 0)
  103. {
  104. pte = listp[0];
  105. List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
  106. string element = DT.Rows[0]["Element"].ToString();
  107. for (int i = 0; i < element.Split(';').Count(); i++)
  108. {
  109. string elestr = element.Split(';')[i];
  110. if (elestr != "")
  111. {
  112. OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = elestr.Split('-')[0], Percentage = Convert.ToDouble(elestr.Split('-')[1]) };
  113. ElementList.Add(ele);
  114. }
  115. }
  116. pte.ElementList = ElementList;
  117. string SubParticlesstr = DT.Rows[0]["SubParticles"].ToString();
  118. string[] SubParticlesstrG = SubParticlesstr.Split(',');
  119. foreach (string s in SubParticlesstrG)
  120. {
  121. string fieldid1 = s.Split(':')[0];
  122. string pid1 = s.Split(':')[1];
  123. Particle particle1 = GetParticleXrayDataByFidAndPid(fieldid1, pid1);
  124. byte[] bytes = particle1.XRayData;
  125. for (int i = 0; i < 2000; i++)
  126. {
  127. Analysis_xray[i] = Analysis_xray[i]+ BitConverter.ToUInt32(bytes, i * 4);
  128. }
  129. Search_xray = Analysis_xray;
  130. }
  131. }
  132. return pte;
  133. }
  134. /// <summary>
  135. /// 获取ParticleList
  136. /// </summary>
  137. /// <param name="model">Feature</param>
  138. /// <returns></returns>
  139. public DataTable GetParticleListByIncA(string con)
  140. {
  141. string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,sum(Area) as Area,avg(" + con
  142. + ") as av,max(" + con
  143. + ") as max ";
  144. sqlp = sqlp + "from IncAData where typeid !=-1 and typeid !=4 and fieldid !=-1 group by TypeId";
  145. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  146. return DT;
  147. }
  148. public DataTable GetParticleListForParticlSize(string con, string fieldAndPartic)
  149. {
  150. string sqlp = @"select TypeId,TypeName,GroupId ,TypeColor,count(1) as con,avg(" + con
  151. + ") as av,max(" + con
  152. + ") as max ,GroupName";
  153. sqlp = sqlp + " from IncAData where typeid !=-1 and fieldid!=-1 and typeid !=4 and ParticleId !=-1";
  154. if (fieldAndPartic != "")
  155. {
  156. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  157. }
  158. sqlp = sqlp + " group by TypeId ";
  159. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  160. if (con == "area")
  161. {
  162. for (int i = 0; i < DT.Rows.Count; i++)
  163. {
  164. DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
  165. }
  166. }
  167. return DT;
  168. }
  169. /// <summary>
  170. /// 获取ParticleList
  171. /// </summary>
  172. /// <param name="model">Feature</param>
  173. /// <returns></returns>
  174. public DataTable GetParticleListForParticlSizeID(string con, string fieldAndPartic)
  175. {
  176. string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,avg(" + con
  177. + ") as av,max(" + con
  178. + ") as max ,GroupName ,GroupId,GroupColor";
  179. sqlp = sqlp + " from IncAData where typeid !=-1 and typeid !=4";
  180. if (fieldAndPartic != "")
  181. {
  182. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  183. }
  184. sqlp = sqlp + " group by TypeId ";
  185. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  186. if (con == "area")
  187. {
  188. for (int i = 0; i < DT.Rows.Count; i++)
  189. {
  190. DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
  191. }
  192. }
  193. return DT;
  194. }
  195. /// <summary>
  196. /// 获取element含量
  197. /// </summary>
  198. /// <returns></returns>
  199. public DataTable GetElementForArea(string fieldAndPartic)
  200. {
  201. string sqlp = @"select e.name,sum(e.percentage*p.area) as earea from ElementChemistry e
  202. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid from IncAData where typeid !=-1 and typeid !=4";
  203. if (fieldAndPartic != "")
  204. {
  205. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
  206. }
  207. sqlp = sqlp + " group by e.name order by sum(e.percentage*p.area) desc";
  208. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  209. return DT;
  210. }
  211. /// <summary>
  212. /// 获取element含量
  213. /// </summary>
  214. /// <returns></returns>
  215. public DataTable GetSmallElementForArea()
  216. {
  217. 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
  218. group by e.name order by sum(e.percentage*i.area) desc";
  219. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  220. return DT;
  221. }
  222. /// <summary>
  223. /// 获取所有Particle
  224. /// </summary>
  225. /// <returns></returns>
  226. public DataTable GetParticleAll(string fieldAndPartic)
  227. {
  228. string sqlp = @"select * from INcAData where typeid !=-1 and typeid !=4";
  229. if (fieldAndPartic != "")
  230. {
  231. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  232. }
  233. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  234. DT.Columns.Add("ECD",typeof(double));
  235. for (int i = 0; i < DT.Rows.Count; i++)
  236. {
  237. DT.Rows[i]["ECD"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  238. }
  239. DataTable data = DT.Clone();
  240. for (int i = 0; i < DT.Rows.Count; i++)
  241. {
  242. if (Convert.ToInt32(DT.Rows[i]["ParticleId"]) > -1)
  243. {
  244. data.Rows.Add(DT.Rows[i].ItemArray);
  245. }
  246. }
  247. return data;
  248. }
  249. public DataTable GetParticleAllForBig(string fieldAndPartic)
  250. {
  251. string sqlp = @"select * from INcAData where";
  252. if (fieldAndPartic != "")
  253. {
  254. sqlp = sqlp + " '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  255. }
  256. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  257. DT.Columns.Add("ECD", typeof(double));
  258. for (int i = 0; i < DT.Rows.Count; i++)
  259. {
  260. DT.Rows[i]["ECD"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  261. }
  262. DataTable data = DT.Clone();
  263. for (int i = 0; i < DT.Rows.Count; i++)
  264. {
  265. if (Convert.ToInt32(DT.Rows[i]["ParticleId"]) > -1)
  266. {
  267. data.Rows.Add(DT.Rows[i].ItemArray);
  268. }
  269. }
  270. return data;
  271. }
  272. public DataTable GetParticleAllforparticlelist(string fieldAndPartic)
  273. {
  274. string sqlp = @"select * from INcAData where typeid !=-1";
  275. if (fieldAndPartic != "")
  276. {
  277. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  278. }
  279. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  280. return DT;
  281. }
  282. public DataTable GetMergedParticle(string fieldAndPartic)
  283. {
  284. string sqlp = @"select * from MergedParticleInfo where typeid !=-1";
  285. if (fieldAndPartic != "")
  286. {
  287. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  288. }
  289. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  290. return DT;
  291. }
  292. /// <summary>
  293. /// 查找所有颗粒的颜色、面积、种类名称信息
  294. /// </summary>
  295. /// <returns></returns>
  296. public DataTable GetParticleTypeInformation()
  297. {
  298. string sqlp = @"select Area,TypeName,TypeColor from IncAData";
  299. DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
  300. return dt;
  301. }
  302. /// <summary>
  303. /// 查找IncaData表中所有种类
  304. /// </summary>
  305. /// <returns></returns>
  306. public DataTable GetParticleClassAll()
  307. {
  308. string sqlp = @"SELECT DISTINCT TypeName FROM IncaData";
  309. DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
  310. return dt;
  311. }
  312. /// <summary>
  313. /// 获取所有Particle
  314. /// </summary>
  315. /// <returns></returns>
  316. public DataTable GetParticleAllHaveXray(string fieldAndPartic)
  317. {
  318. string incaSql = @"select * from IncAData where typeid !=-1 and typeid !=4";
  319. if (fieldAndPartic != "")
  320. {
  321. incaSql = incaSql + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  322. }
  323. DataTable incaDT = dbHelper.ExecuteDataTable(incaSql, null);
  324. incaDT.Columns.Add("Element");
  325. DataTable dt_element = GetElementChemistry();
  326. DataTable elementchemistry = dt_element.Clone();
  327. for (int i = 0; i < dt_element.Rows.Count; i++)
  328. {
  329. if (dt_element.Rows[i]["Name"].ToString() != "Fe")
  330. {
  331. elementchemistry.Rows.Add(dt_element.Rows[i].ItemArray);
  332. }
  333. }
  334. for (int i = 0; i < incaDT.Rows.Count; i++)
  335. {
  336. string str = "XRayId = " + incaDT.Rows[i]["particleId"].ToString() + " and fieldid = " + incaDT.Rows[i]["fieldid"].ToString();
  337. DataRow[] drs = elementchemistry.Select(str);
  338. string ConcatenatedString = "";
  339. for (int j = 0; j < drs.Length; j++)
  340. {
  341. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  342. }
  343. incaDT.Rows[i]["Element"] = ConcatenatedString;
  344. }
  345. return incaDT;
  346. }
  347. /// <summary>
  348. /// 获取所有Particle
  349. /// </summary>
  350. /// <returns></returns>
  351. public DataTable GetParticleHaveXray(string fieldAndPartic)
  352. {
  353. string sqlp = @"select *,
  354. (select group_concat(name||'-'||Percentage,';')
  355. from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element from INcAData where xrayid>-1 ";
  356. if (fieldAndPartic != "")
  357. {
  358. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  359. }
  360. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  361. for (int i = 0; i < DT.Rows.Count; i++)
  362. {
  363. DT.Rows[i]["Area"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
  364. }
  365. return DT;
  366. }
  367. /// <summary>
  368. /// 获取所有Particle
  369. /// </summary>
  370. /// <returns></returns>
  371. public List<Particle> GetParticleAllList()
  372. {
  373. string sqlp = @"select * from INcAData";
  374. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  375. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  376. return listp;
  377. }
  378. /// <summary>
  379. /// 获取所有Particle
  380. /// </summary>
  381. /// <returns></returns>
  382. public DataTable GetParticleAllList_DataTable()
  383. {
  384. string sqlp = @"select * from INcAData";
  385. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  386. return DT;
  387. }
  388. /// <summary>
  389. /// 获取所有分类的面积
  390. /// </summary>
  391. /// <param name="fieldAndPartic">选择颗粒</param>
  392. /// <returns></returns>
  393. public DataTable GetAreaByAllIncA(string fieldAndPartic)
  394. {
  395. 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";
  396. if (fieldAndPartic != "")
  397. {
  398. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
  399. }
  400. sqlp = sqlp + " group by TypeId";
  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 GetSmallParticleInfo()
  410. {
  411. 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";
  412. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  413. return DT;
  414. }
  415. /// <summary>
  416. /// 获取不同分类的面积
  417. /// </summary>
  418. /// <param name="fieldAndPartic">选择颗粒</param>
  419. /// <returns></returns>
  420. public DataTable GetAreaByIncA(string TypeId, string fieldAndPartic)
  421. {
  422. string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
  423. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid where p.TypeId=" + TypeId + " ";
  424. if (fieldAndPartic != "")
  425. {
  426. sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
  427. }
  428. sqlp = sqlp + " group by e.name";
  429. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  430. return DT;
  431. }
  432. public DataTable GetAreaByIncA_All()
  433. {
  434. string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
  435. inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid group by e.name ";
  436. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  437. return DT;
  438. }
  439. /// <summary>
  440. /// 获取全部的物质大类
  441. /// </summary>
  442. /// <returns></returns>
  443. public DataTable GetAllClass()
  444. {
  445. string sqlp = @"select GroupName from IncAData group by GroupName order by count(1) desc";
  446. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  447. return DT;
  448. }
  449. /// <summary>
  450. /// 获取所有元素
  451. /// </summary>
  452. /// <param name="model">Feature</param>
  453. /// <returns></returns>
  454. public DataTable GetAllElement()
  455. {
  456. string sqlp = @"select name from ElementChemistry group by name order by count(1) desc";
  457. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  458. return DT;
  459. }
  460. /// <summary>
  461. /// 获取常用夹杂物分类信息
  462. /// </summary>
  463. /// <returns></returns>
  464. public DataTable GetCommonlyUsedClassifyData()
  465. {
  466. string sqlp = @"select
  467. (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 ,
  468. (select count(typeid) from incadata where typeid BETWEEN 10000 and 10999 ) as OXIDE ,
  469. (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 ,
  470. (select count(typeid) from incadata where typeid BETWEEN 12000 and 12999 ) as NITRIDE ,
  471. (select count(typeid) from incadata where typeid BETWEEN 11000 and 11999 ) as SULFIDE ";
  472. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  473. return DT;
  474. }
  475. public bool DeleteFromData(string fieldid, string particleid)
  476. {
  477. string sqlp = @"delete from IncAData where FieldId=" + fieldid + " and ParticleId="
  478. + particleid;
  479. if (dbHelper.ExecuteQuery_bool(sqlp))
  480. {
  481. return true;
  482. }
  483. else
  484. {
  485. return false;
  486. }
  487. }
  488. /// <summary>
  489. /// 获取颗粒信息
  490. /// </summary>
  491. /// <param name="model">Feature</param>
  492. /// <returns></returns>
  493. public Particle GetParticleByFidAndPid(string fieldid, string particleid)
  494. {
  495. string sqlp = @"select *,(select xraydata from xraydata where xrayindex=INcAData.xrayid and fieldid="
  496. + fieldid + ") as XRayData,(select group_concat(name || '_' || Percentage, ';')from ElementChemistry where XRayId = INcAData.XRayId and fieldid ="
  497. + fieldid + ") as Element from INcAData where fieldid="
  498. + fieldid + " and particleid= " + particleid;
  499. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  500. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  501. Particle particle = new Particle();
  502. if (listp.Count > 0)
  503. {
  504. particle = listp[0];
  505. List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
  506. string element = DT.Rows[0]["Element"].ToString();
  507. for (int i = 0; i < element.Split(';').Count(); i++)
  508. {
  509. if (element.Split(';')[i] != "")
  510. {
  511. OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = element.Split(';')[i].Split('_')[0], Percentage = Convert.ToDouble(element.Split(';')[i].Split('_')[1]) };
  512. ElementList.Add(ele);
  513. }
  514. }
  515. particle.ElementList = ElementList;
  516. }
  517. return particle;
  518. }
  519. public Particle GetParticleXrayDataByFidAndPid(string fieldid, string xrayid)
  520. {
  521. string sqlp = @"select xraydata from xraydata where xrayindex=" + xrayid + " and fieldid="
  522. + fieldid;
  523. DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
  524. List<Particle> listp = dbHelper.TableToList<Particle>(DT);
  525. if (listp.Count > 0)
  526. {
  527. return listp[0];
  528. }
  529. else
  530. {
  531. return null;
  532. }
  533. }
  534. public enum PARTCLE_TYPE
  535. {
  536. SMALL = 0,//过小颗粒
  537. OVERSIZE = 1,//过大颗粒
  538. AVE_GRAY_NOT_INRANRE = 2,//亮度不在分析范围内的颗粒
  539. SEARCH_X_RAY = 3,
  540. LOW_COUNT = 4,//低计数率颗粒
  541. NO_INTEREST_ELEMENTS = 5,
  542. NO_ANALYSIS_X_RAY = 6,//不含分析元素
  543. NOT_IDENTIFIED_SIC = 7,//非夹杂物颗粒SiC
  544. NOT_IDENTIFIED_FEO = 8,//非夹杂物颗粒FeO
  545. NOT_IDENTIFIED = 9,//未识别颗粒
  546. IDENTIFIED = 10,//分析颗粒,当为可识别类型时,可以被进一步识别为用户类型(1000以上),系统预定义类型(10000以上),所以最终颗粒类型不会为8,但可能为7
  547. USER_DEFINED_MIN = 1000,
  548. SYS_DEFINED_MIN = 10000
  549. }
  550. #region 分页添加读取数据库函数
  551. /// <summary>
  552. /// 获取分页查询所需信息
  553. /// </summary>
  554. /// <param name=""></param>
  555. /// <param name=""></param>
  556. /// <returns></returns>
  557. public DataTable GetInfoForPartucleDevidePage(int currentPage, int pagesize, string OrderFunction, string condition)
  558. {
  559. int p = (currentPage - 1) * pagesize;
  560. 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();
  561. DataTable DT = new DataTable();
  562. DT = dbHelper.ExecuteQuery(sqliteString);
  563. return DT;
  564. }
  565. public DataTable GetIncaSurfaceData( List<string> lst_str)
  566. {
  567. DataTable particlesAll = GetInfoForPartucleDevidePage2("");
  568. DataTable dt_element = GetElementChemistry();
  569. List<int> list_int = new List<int>();
  570. for (int a = 0; a < lst_str.Count; a++)
  571. {
  572. for (int i = 0; i < dt_element.Rows.Count; i++)
  573. {
  574. if (dt_element.Rows[i]["Name"].ToString() == lst_str[a].ToString())
  575. {
  576. list_int.Add(i);
  577. }
  578. }
  579. }
  580. for (int i = 0; i < list_int.Count; i++)
  581. {
  582. dt_element.Rows[list_int[i]].Delete();
  583. }
  584. dt_element.AcceptChanges();
  585. for (int i = 0; i < particlesAll.Rows.Count; i++)
  586. {
  587. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  588. DataRow[] drs = dt_element.Select(str);
  589. string ConcatenatedString = "";
  590. for (int j = 0; j < drs.Length; j++)
  591. {
  592. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  593. }
  594. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  595. }
  596. return particlesAll;
  597. }
  598. public DataTable AddElementColumn(DataTable particlesAll, c_TemplateClass m_mbszclass)
  599. {
  600. if (!particlesAll.Columns.Contains("Element"))
  601. {
  602. particlesAll.Columns.Add("Element");
  603. }
  604. DataTable dt_element = GetElementChemistry();
  605. for (int i = 0; i < particlesAll.Rows.Count; i++)
  606. {
  607. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  608. DataRow[] drs = dt_element.Select(str);
  609. string ConcatenatedString = "";
  610. for (int j = 0; j < drs.Length; j++)
  611. {
  612. //判断是否在处理元素表中
  613. bool bl = false;
  614. for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_qcys.Count; a++)
  615. {
  616. if (drs[j]["name"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_qcys[a].ToString())
  617. {
  618. bl = true;
  619. }
  620. }
  621. if (!bl)
  622. {
  623. ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
  624. }
  625. }
  626. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  627. }
  628. return particlesAll;
  629. }
  630. /// <summary>
  631. /// 拼接颗粒
  632. /// </summary>
  633. /// <param name="lst_str"></param>
  634. /// <returns></returns>
  635. public DataTable GetSplicingParticlesData()
  636. {
  637. DataTable particlesAll = GetSplicingParticles();
  638. return particlesAll;
  639. }
  640. /// <summary>
  641. /// 保留两位小数
  642. /// </summary>
  643. /// <param name="strData"></param>
  644. /// <returns></returns>
  645. private string ChangeDataToD(string strData)
  646. {
  647. Decimal dData = 0.00M;
  648. if (strData.Contains("E"))
  649. {
  650. dData = Convert.ToDecimal(Decimal.Parse(strData.ToString(), System.Globalization.NumberStyles.Float));
  651. }
  652. else
  653. {
  654. return Convert.ToDouble(strData).ToString("0.00");
  655. }
  656. return Convert.ToDouble(dData).ToString("0.00");
  657. }
  658. public DataTable GetInfoForPartucleDevidePage2(string condition)
  659. {
  660. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
  661. "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles," +
  662. " (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) " +
  663. "as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId," +
  664. "SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,'' " +
  665. "as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " +
  666. condition;
  667. DataTable DT = new DataTable();
  668. DT = dbHelper.ExecuteQuery(sqliteString);
  669. return DT;
  670. }
  671. public DataTable GetSplicingParticles()
  672. {
  673. string sqliteString1 = "select * from MergedParticleInfo";
  674. DataTable DT = new DataTable();
  675. DT = dbHelper.ExecuteQuery(sqliteString1);
  676. return DT;
  677. }
  678. public DataTable GetInfoForPartucleDevidePage_analyticalParticle(string condition)
  679. {
  680. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and typeid !=9 and typeid !=-1 and typeid !=4)" +
  681. condition;
  682. DataTable DT = new DataTable();
  683. DT = dbHelper.ExecuteQuery(sqliteString);
  684. return DT;
  685. }
  686. public DataTable GetInfoForPartucleDevidePage_otherParticle(string condition)
  687. {
  688. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and typeid =9 or typeid =-1 or typeid =4) " +
  689. condition;
  690. DataTable DT = new DataTable();
  691. DT = dbHelper.ExecuteQuery(sqliteString);
  692. return DT;
  693. }
  694. /// <summary>
  695. /// 获取拼接颗粒
  696. /// </summary>
  697. /// <param name="condition">帅选条件</param>
  698. /// <returns></returns>
  699. public DataTable GetInfoForPartucleDevidePage_mergeParticles(string condition)
  700. {
  701. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
  702. "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles,''as Element from MergedParticleInfo where 1=1 " + condition;
  703. DataTable DT1 = new DataTable();
  704. try
  705. {
  706. DT1 = dbHelper.ExecuteQuery(sqliteString);
  707. }
  708. catch
  709. {
  710. }
  711. return DT1;
  712. }
  713. public DataTable GetInfoForPartucleDevidePage_allParticles(string condition)
  714. {
  715. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 " +
  716. condition;
  717. DataTable DT = new DataTable();
  718. DT = dbHelper.ExecuteQuery(sqliteString);
  719. return DT;
  720. }
  721. public DataTable GetInfoForPartucleDevidePage_NotIdentifyParticle(string condition)
  722. {
  723. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and typeid =9 " +
  724. condition;
  725. DataTable DT = new DataTable();
  726. DT = dbHelper.ExecuteQuery(sqliteString);
  727. return DT;
  728. }
  729. public DataTable GetInfoForPartucleDevidePage_InvalidParticle(string condition)
  730. {
  731. string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and typeid =-1 " +
  732. condition;
  733. DataTable DT = new DataTable();
  734. DT = dbHelper.ExecuteQuery(sqliteString);
  735. return DT;
  736. }
  737. public DataTable GetInfoForPartucleDevidePage_LowCountsParticle(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,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 typeid =4 " +
  740. condition;
  741. DataTable DT = new DataTable();
  742. DT = dbHelper.ExecuteQuery(sqliteString);
  743. return DT;
  744. }
  745. public DataTable GetClassificationOfAllParticles(string condition)
  746. {
  747. string sqliteString1 = "select distinct TypeName from INcAData "+ condition;
  748. DataTable DT = new DataTable();
  749. DT = dbHelper.ExecuteQuery(sqliteString1);
  750. return DT;
  751. }
  752. public DataTable GetXRayData()
  753. {
  754. string sqliteString = @"select * from xraydata";
  755. DataTable DT = new DataTable();
  756. DT = dbHelper.ExecuteQuery(sqliteString);
  757. return DT;
  758. }
  759. public DataTable GetElementChemistry()
  760. {
  761. string sqliteString = "select * from ElementChemistry";
  762. DataTable DT = new DataTable();
  763. DT = dbHelper.ExecuteQuery(sqliteString);
  764. return DT;
  765. }
  766. /// <summary>
  767. /// 得到图形形状
  768. /// </summary>
  769. /// <returns></returns>
  770. public DataTable GetSegment()
  771. {
  772. string sqliteString = "select * from Segment";
  773. DataTable DT = new DataTable();
  774. DT = dbHelper.ExecuteQuery(sqliteString);
  775. return DT;
  776. }
  777. /// <summary>
  778. /// 全部颗粒不带元素
  779. /// </summary>
  780. /// <param name="condition"></param>
  781. /// <returns></returns>
  782. public DataTable GetAllParticleWithMergeParticlesWithoutEle(string condition)
  783. {
  784. DataTable particlesAll = new DataTable();
  785. DataTable particlesAll1 = GetParticleAllforparticlelist(condition);
  786. DataTable mergeParticles = GetMergedParticle(condition);
  787. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  788. {
  789. RemoveMergeParticles(ref particlesAll1, mergeParticles);
  790. }
  791. particlesAll = particlesAll1.Copy();
  792. foreach (DataRow item in mergeParticles.Rows)
  793. {
  794. particlesAll.ImportRow(item);
  795. }
  796. return particlesAll;
  797. }
  798. /// <summary>
  799. /// 全部颗粒带元素
  800. /// </summary>
  801. /// <param name="condition"></param>
  802. /// <returns></returns>
  803. public DataTable GetAllParticleWithMergeParticles(string condition)
  804. {
  805. DataTable particlesAll=new DataTable();
  806. DataTable particlesAll1 = GetInfoForPartucleDevidePage_allParticles(condition);
  807. DataTable mergeParticles = GetInfoForPartucleDevidePage_mergeParticles(condition);
  808. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  809. {
  810. RemoveMergeParticles(ref particlesAll1, mergeParticles);
  811. }
  812. particlesAll = particlesAll1.Copy();
  813. foreach (DataRow item in mergeParticles.Rows)
  814. {
  815. particlesAll.ImportRow(item);
  816. }
  817. DataTable elementchemistry = GetElementChemistry();
  818. for (int i = 0; i < particlesAll.Rows.Count; i++)
  819. {
  820. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  821. DataRow[] drs = elementchemistry.Select(str);
  822. string ConcatenatedString = "";
  823. for (int j = 0; j < drs.Length; j++)
  824. {
  825. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  826. }
  827. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  828. }
  829. return particlesAll;
  830. }
  831. public void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
  832. {
  833. foreach (DataRow row in dataTable_Particle.Rows)
  834. {
  835. foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
  836. {
  837. string subt = MergeParticlesRow["SubParticles"].ToString();
  838. string[] sub = subt.Split(',');
  839. if (row.RowState == DataRowState.Deleted)
  840. {
  841. break;
  842. }
  843. if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
  844. {
  845. row.Delete();
  846. break;
  847. }
  848. if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
  849. {
  850. row.Delete();
  851. break; ;
  852. }
  853. }
  854. }
  855. dataTable_Particle.AcceptChanges();
  856. }
  857. /// <summary>
  858. /// 拼接颗粒图
  859. /// </summary>
  860. /// <param name="sub">拼接字符串</param>
  861. /// <param name="xs">xs = pixw / ScanFieldSize</param>
  862. /// <param name="path">报告文件路径</param>
  863. /// <param name="picHeight">图像高</param>
  864. /// <param name="picWidth">帧图宽</param>
  865. /// <param name="X_AXIS_DIRECTION">电镜x轴正方向</param>
  866. /// <param name="Y_AXIS_DIRECTION">电镜y轴正方向</param>
  867. /// <returns></returns>
  868. public Bitmap GetBitmapForBig(string sub, double xs, string path, int picHeight, int picWidth, OTS_X_AXIS_DIRECTION X_AXIS_DIRECTION, OTS_Y_AXIS_DIRECTION Y_AXIS_DIRECTION)
  869. {
  870. string vs = "," + sub.Replace(':', '-') + ",";
  871. DataTable dataTable = GetParticleAllForBig(vs);
  872. if (dataTable.Rows.Count == 0)
  873. {
  874. return null;
  875. }
  876. //内接矩形
  877. double max_Y = Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  878. double max_X = Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  879. double min_Y = max_Y;
  880. double min_X = max_X;
  881. //拼接field矩形
  882. double B_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  883. double R_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  884. double T_Y = B_Y;
  885. double L_X = R_X;
  886. foreach (DataRow item in dataTable.Rows)
  887. {
  888. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  889. if (X_AXIS_DIRECTION == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  890. {
  891. if (lefttopXH > L_X)
  892. {
  893. L_X = lefttopXH;
  894. }
  895. if (lefttopXH < R_X)
  896. {
  897. R_X = lefttopXH;
  898. }
  899. }
  900. else
  901. {
  902. if (lefttopXH < R_X)
  903. {
  904. R_X = lefttopXH;
  905. }
  906. if (lefttopXH > L_X)
  907. {
  908. L_X = lefttopXH;
  909. }
  910. }
  911. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  912. if (Y_AXIS_DIRECTION == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  913. {
  914. if (lrfttopYH < B_Y)
  915. {
  916. B_Y = lrfttopYH;
  917. }
  918. if (lrfttopYH > T_Y)
  919. {
  920. T_Y = lrfttopYH;
  921. }
  922. }
  923. else
  924. {
  925. if (lrfttopYH > B_Y)
  926. {
  927. B_Y= lrfttopYH;
  928. }
  929. if (lrfttopYH < T_Y)
  930. {
  931. T_Y = lrfttopYH;
  932. }
  933. }
  934. }
  935. int WIDTH = Math.Abs(Convert.ToInt32(R_X - L_X)) + picWidth;
  936. int HEIGHT = Math.Abs(Convert.ToInt32(B_Y - T_Y)) + picHeight;
  937. //构造最终的图片白板
  938. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  939. Graphics graph = Graphics.FromImage(tableChartImage);
  940. //初始化这个大图
  941. graph.DrawImage(tableChartImage, 0, 0);
  942. foreach (DataRow item in dataTable.Rows)
  943. {
  944. string filePath = path + "\\FIELD_FILES\\";
  945. string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
  946. //然后将取出的数据,转换成Bitmap对象
  947. Bitmap ls_bt = ReadImageFile(imagePath);
  948. int x = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - L_X));
  949. int y = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - T_Y));
  950. graph.DrawImage(ls_bt, x, y);
  951. //颗粒外接矩形
  952. double lefttopX = x+Convert.ToInt64(item["RectLeft"]);
  953. if (lefttopX < min_X)
  954. {
  955. min_X = lefttopX;
  956. }
  957. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  958. {
  959. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  960. }
  961. double lrfttopY = y+ Convert.ToInt64(item["RectTop"]);
  962. if (lrfttopY + Convert.ToInt64(item["RectHeight"]) > max_Y)
  963. {
  964. max_Y = lrfttopY + Convert.ToInt64(item["RectHeight"]);
  965. }
  966. if ( lrfttopY< min_Y)
  967. {
  968. min_Y = lrfttopY;
  969. }
  970. }
  971. int width = Convert.ToInt32(max_X - min_X);
  972. int height = Convert.ToInt32(max_Y - min_Y);
  973. int X = Convert.ToInt32(min_X);
  974. int Y = Convert.ToInt32(min_Y);
  975. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  976. Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
  977. return bmap;
  978. }
  979. /// <summary>
  980. /// 拼接颗粒黑白图
  981. /// </summary>
  982. /// <param name="sub">拼接字符串</param>
  983. /// <param name="xs">xs = pixw / ScanFieldSize</param>
  984. /// <param name="path">报告文件路径</param>
  985. /// <param name="picHeight">图像高</param>
  986. /// <param name="picWidth">帧图宽</param>
  987. /// <param name="X_AXIS_DIRECTION">电镜x轴正方向</param>
  988. /// <param name="Y_AXIS_DIRECTION">电镜y轴正方向</param>
  989. /// <returns></returns>
  990. public Bitmap GetBitmapForBigBlackAndWhiteImage(string sub, double xs, string path, int picHeight, int picWidth, OTS_X_AXIS_DIRECTION X_AXIS_DIRECTION, OTS_Y_AXIS_DIRECTION Y_AXIS_DIRECTION)
  991. {
  992. string vs = "," + sub.Replace(':', '-') + ",";
  993. DataTable dataTable = GetParticleAllForBig(vs);
  994. if (dataTable.Rows.Count == 0)
  995. {
  996. return null;
  997. }
  998. //内接矩形
  999. double max_Y = Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  1000. double max_X = Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  1001. double min_Y = max_Y;
  1002. double min_X = max_X;
  1003. //拼接field矩形
  1004. double B_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  1005. double R_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  1006. double T_Y = B_Y;
  1007. double L_X = R_X;
  1008. foreach (DataRow item in dataTable.Rows)
  1009. {
  1010. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  1011. if (X_AXIS_DIRECTION == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  1012. {
  1013. if (lefttopXH > L_X)
  1014. {
  1015. L_X = lefttopXH;
  1016. }
  1017. if (lefttopXH < R_X)
  1018. {
  1019. R_X = lefttopXH;
  1020. }
  1021. }
  1022. else
  1023. {
  1024. if (lefttopXH < R_X)
  1025. {
  1026. R_X = lefttopXH;
  1027. }
  1028. if (lefttopXH > L_X)
  1029. {
  1030. L_X = lefttopXH;
  1031. }
  1032. }
  1033. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  1034. if (Y_AXIS_DIRECTION == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  1035. {
  1036. if (lrfttopYH < B_Y)
  1037. {
  1038. B_Y = lrfttopYH;
  1039. }
  1040. if (lrfttopYH > T_Y)
  1041. {
  1042. T_Y = lrfttopYH;
  1043. }
  1044. }
  1045. else
  1046. {
  1047. if (lrfttopYH > B_Y)
  1048. {
  1049. B_Y = lrfttopYH;
  1050. }
  1051. if (lrfttopYH < T_Y)
  1052. {
  1053. T_Y = lrfttopYH;
  1054. }
  1055. }
  1056. }
  1057. int WIDTH = Math.Abs(Convert.ToInt32(R_X - L_X)) + picWidth;
  1058. int HEIGHT = Math.Abs(Convert.ToInt32(B_Y - T_Y)) + picHeight;
  1059. //构造最终的图片白板
  1060. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  1061. Graphics graph = Graphics.FromImage(tableChartImage);
  1062. graph.Clear(Color.White);
  1063. //初始化这个大图
  1064. graph.DrawImage(tableChartImage, 0, 0);
  1065. foreach (DataRow item in dataTable.Rows)
  1066. {
  1067. string strs = @"select * from Segment where FieldId="+item["fieldid"].ToString()+" and ParticleId="+item["particleid"].ToString();
  1068. DataTable DTS = dbHelper.ExecuteDataTable(strs, null);
  1069. DataRow[] dd = DTS.Select();
  1070. List<Segment> flist = dbHelper.RowsToList<Segment>(dd);
  1071. int x = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - L_X));
  1072. int y = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - T_Y));
  1073. //颗粒外接矩形
  1074. double lefttopX = x + Convert.ToInt64(item["RectLeft"]);
  1075. if (lefttopX < min_X)
  1076. {
  1077. min_X = lefttopX;
  1078. }
  1079. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  1080. {
  1081. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  1082. }
  1083. double lrfttopY = y + Convert.ToInt64(item["RectTop"]);
  1084. if (lrfttopY + Convert.ToInt64(item["RectHeight"]) > max_Y)
  1085. {
  1086. max_Y = lrfttopY + Convert.ToInt64(item["RectHeight"]);
  1087. }
  1088. if (lrfttopY < min_Y)
  1089. {
  1090. min_Y = lrfttopY;
  1091. }
  1092. foreach (Segment seg in flist)
  1093. {
  1094. int f_length = seg.Length;
  1095. for (int m = 0; m < f_length; m++)
  1096. {
  1097. int lsjs_x = seg.Start + m+ x;
  1098. int lsjs_y = seg.Height+ y;
  1099. tableChartImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
  1100. }
  1101. }
  1102. }
  1103. int width = Convert.ToInt32(max_X - min_X);
  1104. int height = Convert.ToInt32(max_Y - min_Y);
  1105. int X = Convert.ToInt32(min_X);
  1106. int Y = Convert.ToInt32(min_Y);
  1107. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  1108. Bitmap bmap = GetBitmapByParticle(tableChartImage, rectangle);
  1109. return bmap;
  1110. }
  1111. /// <summary>
  1112. /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
  1113. /// </summary>
  1114. /// <param name="path"></param>
  1115. /// <returns></returns>
  1116. public Bitmap ReadImageFile(string path)
  1117. {
  1118. if (!File.Exists(path))
  1119. {
  1120. return null;//文件不存在
  1121. }
  1122. FileStream fs = File.OpenRead(path); //OpenRead
  1123. int filelength = 0;
  1124. filelength = (int)fs.Length; //获得文件长度
  1125. Byte[] image = new Byte[filelength]; //建立一个字节数组
  1126. fs.Read(image, 0, filelength); //按字节流读取
  1127. System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
  1128. fs.Close();
  1129. Bitmap bit = new Bitmap(result);
  1130. return bit;
  1131. }
  1132. /// <summary>
  1133. /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
  1134. /// </summary>
  1135. /// <param name="in_cotsparticleclr"></param>
  1136. /// <returns></returns>
  1137. public Bitmap GetBitmapByParticle(Bitmap ls_bt, Rectangle offset_rect)
  1138. {
  1139. //为了能把整个颗粒显示完整
  1140. offset_rect.X = offset_rect.X - 20;
  1141. offset_rect.Y = offset_rect.Y - 20;
  1142. offset_rect.Width = offset_rect.Width + 40;
  1143. offset_rect.Height = offset_rect.Height + 40;
  1144. //防止计算偏差后,有坐标溢出现象
  1145. if (offset_rect.X < 0)
  1146. offset_rect.X = 0;
  1147. if (offset_rect.Y < 0)
  1148. offset_rect.Y = 0;
  1149. if (offset_rect.X + offset_rect.Width > ls_bt.Width)
  1150. {
  1151. offset_rect.Width = ls_bt.Width - offset_rect.X;
  1152. }
  1153. if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
  1154. {
  1155. offset_rect.Height = ls_bt.Height - offset_rect.Y;
  1156. }
  1157. Bitmap new_ret_bp;
  1158. //防止为0后面计算出错
  1159. if (offset_rect.Width > 0 && offset_rect.Height > 0)
  1160. {
  1161. //最后通过list_showsegment组建成新的图片,进行返回
  1162. new_ret_bp = ls_bt.Clone(offset_rect, ls_bt.PixelFormat);
  1163. }
  1164. else
  1165. {
  1166. new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
  1167. }
  1168. return new_ret_bp;
  1169. }
  1170. public void InsertUpdate(List<int> particleID, List<string> particleData)
  1171. {
  1172. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  1173. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  1174. cmdlist.Add(str);
  1175. try
  1176. {
  1177. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  1178. }
  1179. catch (Exception e)
  1180. {
  1181. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  1182. }
  1183. }
  1184. public KeyValuePair<string, SQLiteParameter[]> GetUpdataAIncACmd(List<int> particleID, List<string> particleData)
  1185. {
  1186. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  1187. return str;
  1188. }
  1189. public void ExecuteNonQueryBatch(List<KeyValuePair<string, SQLiteParameter[]>> cmdlist)
  1190. {
  1191. try
  1192. {
  1193. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  1194. }
  1195. catch (Exception e)
  1196. {
  1197. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  1198. }
  1199. }
  1200. /// <summary>
  1201. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  1202. /// </summary>
  1203. /// <param name="in_clr_tagid">颗粒id</param>
  1204. /// <param name="in_clr_fieldid"></param>
  1205. /// <param name="Search_xray"></param>
  1206. /// <param name="Analysis_xray"></param>
  1207. public Particle GetXrayByParticleTagIDAndFieldID_ForMergeParticle(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray)
  1208. {
  1209. Search_xray = new uint[2000];
  1210. Analysis_xray = new uint[2000];
  1211. Particle particle = new Particle();
  1212. particle = GetMergedParticleInfo(in_clr_fieldid, in_clr_tagid, out Search_xray, out Analysis_xray);
  1213. return particle;
  1214. }
  1215. public List<ShowElementInfo> GetShowElementInfos_ForMergeParticle(List<Element> list_celementchemistryclr)
  1216. {
  1217. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1218. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1219. {
  1220. ShowElementInfo ls_sei = new ShowElementInfo();
  1221. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1222. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1223. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  1224. double de_sx2 = 0;
  1225. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  1226. {
  1227. de_sx2 = 0;
  1228. }
  1229. else
  1230. {
  1231. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  1232. }
  1233. ls_sei.dLF = de_sx2;
  1234. list_showelementinfo.Add(ls_sei);
  1235. }
  1236. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  1237. return list_showelementinfo;
  1238. }
  1239. #endregion
  1240. #region 清洁度
  1241. public ParticleData()
  1242. {
  1243. }
  1244. /// <summary>
  1245. /// 获得颗粒类别
  1246. /// </summary>
  1247. /// <param name="StandardLibraryAddress">标准库地址</param>
  1248. /// <returns></returns>
  1249. public DataTable ObtainParticleCategory_start(string StandardLibraryAddress)
  1250. {
  1251. DataTable dataTable = new DataTable();
  1252. dataTable.Columns.Add("GroupId");
  1253. dataTable.Columns.Add("GroupName");
  1254. dataTable.Columns.Add("inoId");
  1255. dataTable.Columns.Add("display");
  1256. DataTable get_dt = SelectStandardLibraryGrouping(StandardLibraryAddress);
  1257. if (get_dt.Rows.Count==0)
  1258. {
  1259. DataRow data = dataTable.NewRow();
  1260. data["inoId"] = 0;
  1261. data["GroupId"] = 0;
  1262. data["GroupName"] = "Default";
  1263. data["display"] = "0";
  1264. dataTable.Rows.Add(data);
  1265. return dataTable;
  1266. }
  1267. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  1268. int shul = 0;
  1269. string DefaultGroupId = "";
  1270. foreach (DataRow row in dataRow)
  1271. {
  1272. if (row.ItemArray[1].ToString() != "Default")
  1273. {
  1274. DataRow data = dataTable.NewRow();
  1275. data["inoId"] = shul;
  1276. data["GroupId"] = row.ItemArray[0].ToString();
  1277. data["GroupName"] = row.ItemArray[1].ToString();
  1278. data["display"] = "0";
  1279. dataTable.Rows.Add(data);
  1280. shul++;
  1281. }
  1282. else
  1283. {
  1284. DefaultGroupId = row.ItemArray[0].ToString();
  1285. }
  1286. }
  1287. DataRow data2 = dataTable.NewRow();
  1288. data2["inoId"] = shul;
  1289. data2["GroupId"] = DefaultGroupId;
  1290. data2["GroupName"] = "Default";
  1291. data2["display"] = "0";
  1292. dataTable.Rows.Add(data2);
  1293. return dataTable;
  1294. }
  1295. /// <summary>
  1296. /// 获取规则数据
  1297. /// </summary>
  1298. /// <param name="strings">组类别</param>
  1299. /// <param name="a_SelectedIndex">标准库地址</param>
  1300. /// <returns></returns>
  1301. public List<DataTable> ObtainRuleData_start(DataTable strings, string a_SelectedIndex)
  1302. {
  1303. List<DataTable> List_data = new List<DataTable>();
  1304. DataTable dt_stl = new DataTable();
  1305. SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
  1306. dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
  1307. dt_stl.Columns.Add("display");
  1308. if (dt_stl == null)
  1309. {
  1310. List_data.Add(dt_stl);
  1311. return List_data;
  1312. }
  1313. for (int i = 0; i < strings.Rows.Count; i++)
  1314. {
  1315. DataTable table = dt_stl.Clone();
  1316. table.TableName = strings.Rows[i]["GroupId"].ToString();
  1317. for (int a = 0; a < dt_stl.Rows.Count; a++)
  1318. {
  1319. if (strings.Rows[i]["GroupId"].ToString() == dt_stl.Rows[a]["GroupId"].ToString())
  1320. {
  1321. dt_stl.Rows[a]["display"] = 0;
  1322. table.Rows.Add(dt_stl.Rows[a].ItemArray);
  1323. }
  1324. }
  1325. DataView dvs = table.DefaultView;
  1326. dvs.Sort = "ListNum ASC";
  1327. DataTable TemporaryDataGroup = dvs.ToTable();
  1328. List_data.Add(TemporaryDataGroup);
  1329. }
  1330. return List_data;
  1331. }
  1332. private DataTable SelectStandardLibraryGrouping(string a_SelectedIndex)
  1333. {
  1334. DataTable dt_stl = new DataTable();
  1335. SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
  1336. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  1337. return dt_stl;
  1338. }
  1339. /// <summary>
  1340. /// 获得颗粒类别
  1341. /// </summary>
  1342. /// <returns></returns>
  1343. public List<string> ObtainParticleCategory(OTSReport_Export m_otsreport_export, BasicData basicData)
  1344. {
  1345. List<string> ClassName = new List<string>();
  1346. if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
  1347. {
  1348. DataTable get_dt = ReadClassification(basicData);
  1349. DataTable getClass_dt = get_dt.Clone();
  1350. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  1351. foreach (DataRow row in dataRow)
  1352. {
  1353. if (row.ItemArray[1].ToString() != "Default")
  1354. {
  1355. getClass_dt.ImportRow(row);
  1356. }
  1357. }
  1358. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1359. {
  1360. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  1361. }
  1362. ClassName.Add("Default");
  1363. }
  1364. else
  1365. {
  1366. DataTable getClass_dt = ReadClassification(basicData);
  1367. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1368. {
  1369. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  1370. }
  1371. bool bl = false;
  1372. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1373. {
  1374. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
  1375. && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
  1376. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  1377. {
  1378. if (!bl)
  1379. {
  1380. ClassName.Add("Default");
  1381. bl = true;
  1382. }
  1383. }
  1384. else
  1385. {
  1386. bool isDefault = false;
  1387. for (int a = 0; a < ClassName.Count; a++)
  1388. {
  1389. if (getClass_dt.Rows[i]["GroupName"].ToString() == "Default")
  1390. {
  1391. isDefault = true;
  1392. }
  1393. }
  1394. if (isDefault)
  1395. {
  1396. if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
  1397. {
  1398. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1399. }
  1400. }
  1401. else
  1402. {
  1403. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1404. }
  1405. }
  1406. }
  1407. }
  1408. return ClassName;
  1409. }
  1410. public DataTable ReadClassification(BasicData basicData)
  1411. {
  1412. DataTable dt_stl = new DataTable();
  1413. SqLiteHelper sh = new SqLiteHelper("data source='" + basicData.GetFilePath() + "\\" + basicData.GetResfile() + "'");
  1414. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  1415. return dt_stl;
  1416. }
  1417. #endregion
  1418. }
  1419. }