ParticleData.cs 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  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. /// <summary>
  832. /// 去除拼接颗粒组成颗粒
  833. /// </summary>
  834. /// <param name="dataTable_Particle"></param>
  835. /// <param name="dataTable_MergeParticles"></param>
  836. public void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
  837. {
  838. foreach (DataRow row in dataTable_Particle.Rows)
  839. {
  840. foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
  841. {
  842. string subt = MergeParticlesRow["SubParticles"].ToString();
  843. string[] sub = subt.Split(',');
  844. if (row.RowState == DataRowState.Deleted)
  845. {
  846. break;
  847. }
  848. if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
  849. {
  850. row.Delete();
  851. break;
  852. }
  853. if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
  854. {
  855. row.Delete();
  856. break; ;
  857. }
  858. }
  859. }
  860. dataTable_Particle.AcceptChanges();
  861. }
  862. /// <summary>
  863. /// 拼接颗粒图
  864. /// </summary>
  865. /// <param name="sub">拼接字符串</param>
  866. /// <param name="xs">xs = pixw / ScanFieldSize</param>
  867. /// <param name="path">报告文件路径</param>
  868. /// <param name="picHeight">图像高</param>
  869. /// <param name="picWidth">帧图宽</param>
  870. /// <param name="X_AXIS_DIRECTION">电镜x轴正方向</param>
  871. /// <param name="Y_AXIS_DIRECTION">电镜y轴正方向</param>
  872. /// <returns></returns>
  873. 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)
  874. {
  875. string vs = "," + sub.Replace(':', '-') + ",";
  876. DataTable dataTable = GetParticleAllForBig(vs);
  877. if (dataTable.Rows.Count == 0)
  878. {
  879. return null;
  880. }
  881. //内接矩形
  882. double max_Y = Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  883. double max_X = Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  884. double min_Y = max_Y;
  885. double min_X = max_X;
  886. //拼接field矩形
  887. double B_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  888. double R_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  889. double T_Y = B_Y;
  890. double L_X = R_X;
  891. foreach (DataRow item in dataTable.Rows)
  892. {
  893. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  894. if (X_AXIS_DIRECTION == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  895. {
  896. if (lefttopXH > L_X)
  897. {
  898. L_X = lefttopXH;
  899. }
  900. if (lefttopXH < R_X)
  901. {
  902. R_X = lefttopXH;
  903. }
  904. }
  905. else
  906. {
  907. if (lefttopXH < R_X)
  908. {
  909. R_X = lefttopXH;
  910. }
  911. if (lefttopXH > L_X)
  912. {
  913. L_X = lefttopXH;
  914. }
  915. }
  916. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  917. if (Y_AXIS_DIRECTION == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  918. {
  919. if (lrfttopYH < B_Y)
  920. {
  921. B_Y = lrfttopYH;
  922. }
  923. if (lrfttopYH > T_Y)
  924. {
  925. T_Y = lrfttopYH;
  926. }
  927. }
  928. else
  929. {
  930. if (lrfttopYH > B_Y)
  931. {
  932. B_Y= lrfttopYH;
  933. }
  934. if (lrfttopYH < T_Y)
  935. {
  936. T_Y = lrfttopYH;
  937. }
  938. }
  939. }
  940. int WIDTH = Math.Abs(Convert.ToInt32(R_X - L_X)) + picWidth;
  941. int HEIGHT = Math.Abs(Convert.ToInt32(B_Y - T_Y)) + picHeight;
  942. //构造最终的图片白板
  943. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  944. Graphics graph = Graphics.FromImage(tableChartImage);
  945. //初始化这个大图
  946. graph.DrawImage(tableChartImage, 0, 0);
  947. foreach (DataRow item in dataTable.Rows)
  948. {
  949. string filePath = path + "\\FIELD_FILES\\";
  950. string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
  951. //然后将取出的数据,转换成Bitmap对象
  952. Bitmap ls_bt = ReadImageFile(imagePath);
  953. int x = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - L_X));
  954. int y = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - T_Y));
  955. graph.DrawImage(ls_bt, x, y);
  956. //颗粒外接矩形
  957. double lefttopX = x+Convert.ToInt64(item["RectLeft"]);
  958. if (lefttopX < min_X)
  959. {
  960. min_X = lefttopX;
  961. }
  962. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  963. {
  964. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  965. }
  966. double lrfttopY = y+ Convert.ToInt64(item["RectTop"]);
  967. if (lrfttopY + Convert.ToInt64(item["RectHeight"]) > max_Y)
  968. {
  969. max_Y = lrfttopY + Convert.ToInt64(item["RectHeight"]);
  970. }
  971. if ( lrfttopY< min_Y)
  972. {
  973. min_Y = lrfttopY;
  974. }
  975. }
  976. int width = Convert.ToInt32(max_X - min_X);
  977. int height = Convert.ToInt32(max_Y - min_Y);
  978. int X = Convert.ToInt32(min_X);
  979. int Y = Convert.ToInt32(min_Y);
  980. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  981. Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
  982. return bmap;
  983. }
  984. /// <summary>
  985. /// 拼接颗粒黑白图
  986. /// </summary>
  987. /// <param name="sub">拼接字符串</param>
  988. /// <param name="xs">xs = pixw / ScanFieldSize</param>
  989. /// <param name="path">报告文件路径</param>
  990. /// <param name="picHeight">图像高</param>
  991. /// <param name="picWidth">帧图宽</param>
  992. /// <param name="X_AXIS_DIRECTION">电镜x轴正方向</param>
  993. /// <param name="Y_AXIS_DIRECTION">电镜y轴正方向</param>
  994. /// <returns></returns>
  995. 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)
  996. {
  997. string vs = "," + sub.Replace(':', '-') + ",";
  998. DataTable dataTable = GetParticleAllForBig(vs);
  999. if (dataTable.Rows.Count == 0)
  1000. {
  1001. return null;
  1002. }
  1003. //内接矩形
  1004. double max_Y = Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  1005. double max_X = Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  1006. double min_Y = max_Y;
  1007. double min_X = max_X;
  1008. //拼接field矩形
  1009. double B_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  1010. double R_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  1011. double T_Y = B_Y;
  1012. double L_X = R_X;
  1013. foreach (DataRow item in dataTable.Rows)
  1014. {
  1015. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  1016. if (X_AXIS_DIRECTION == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  1017. {
  1018. if (lefttopXH > L_X)
  1019. {
  1020. L_X = lefttopXH;
  1021. }
  1022. if (lefttopXH < R_X)
  1023. {
  1024. R_X = lefttopXH;
  1025. }
  1026. }
  1027. else
  1028. {
  1029. if (lefttopXH < R_X)
  1030. {
  1031. R_X = lefttopXH;
  1032. }
  1033. if (lefttopXH > L_X)
  1034. {
  1035. L_X = lefttopXH;
  1036. }
  1037. }
  1038. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  1039. if (Y_AXIS_DIRECTION == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  1040. {
  1041. if (lrfttopYH < B_Y)
  1042. {
  1043. B_Y = lrfttopYH;
  1044. }
  1045. if (lrfttopYH > T_Y)
  1046. {
  1047. T_Y = lrfttopYH;
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if (lrfttopYH > B_Y)
  1053. {
  1054. B_Y = lrfttopYH;
  1055. }
  1056. if (lrfttopYH < T_Y)
  1057. {
  1058. T_Y = lrfttopYH;
  1059. }
  1060. }
  1061. }
  1062. int WIDTH = Math.Abs(Convert.ToInt32(R_X - L_X)) + picWidth;
  1063. int HEIGHT = Math.Abs(Convert.ToInt32(B_Y - T_Y)) + picHeight;
  1064. //构造最终的图片白板
  1065. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  1066. Graphics graph = Graphics.FromImage(tableChartImage);
  1067. graph.Clear(Color.White);
  1068. //初始化这个大图
  1069. graph.DrawImage(tableChartImage, 0, 0);
  1070. foreach (DataRow item in dataTable.Rows)
  1071. {
  1072. string strs = @"select * from Segment where FieldId="+item["fieldid"].ToString()+" and ParticleId="+item["particleid"].ToString();
  1073. DataTable DTS = dbHelper.ExecuteDataTable(strs, null);
  1074. DataRow[] dd = DTS.Select();
  1075. List<Segment> flist = dbHelper.RowsToList<Segment>(dd);
  1076. int x = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - L_X));
  1077. int y = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - T_Y));
  1078. //颗粒外接矩形
  1079. double lefttopX = x + Convert.ToInt64(item["RectLeft"]);
  1080. if (lefttopX < min_X)
  1081. {
  1082. min_X = lefttopX;
  1083. }
  1084. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  1085. {
  1086. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  1087. }
  1088. double lrfttopY = y + Convert.ToInt64(item["RectTop"]);
  1089. if (lrfttopY + Convert.ToInt64(item["RectHeight"]) > max_Y)
  1090. {
  1091. max_Y = lrfttopY + Convert.ToInt64(item["RectHeight"]);
  1092. }
  1093. if (lrfttopY < min_Y)
  1094. {
  1095. min_Y = lrfttopY;
  1096. }
  1097. foreach (Segment seg in flist)
  1098. {
  1099. int f_length = seg.Length;
  1100. for (int m = 0; m < f_length; m++)
  1101. {
  1102. int lsjs_x = seg.Start + m+ x;
  1103. int lsjs_y = seg.Height+ y;
  1104. tableChartImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
  1105. }
  1106. }
  1107. }
  1108. int width = Convert.ToInt32(max_X - min_X);
  1109. int height = Convert.ToInt32(max_Y - min_Y);
  1110. int X = Convert.ToInt32(min_X);
  1111. int Y = Convert.ToInt32(min_Y);
  1112. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  1113. Bitmap bmap = GetBitmapByParticle(tableChartImage, rectangle);
  1114. return bmap;
  1115. }
  1116. /// <summary>
  1117. /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
  1118. /// </summary>
  1119. /// <param name="path"></param>
  1120. /// <returns></returns>
  1121. public Bitmap ReadImageFile(string path)
  1122. {
  1123. if (!File.Exists(path))
  1124. {
  1125. return null;//文件不存在
  1126. }
  1127. FileStream fs = File.OpenRead(path); //OpenRead
  1128. int filelength = 0;
  1129. filelength = (int)fs.Length; //获得文件长度
  1130. Byte[] image = new Byte[filelength]; //建立一个字节数组
  1131. fs.Read(image, 0, filelength); //按字节流读取
  1132. System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
  1133. fs.Close();
  1134. Bitmap bit = new Bitmap(result);
  1135. return bit;
  1136. }
  1137. /// <summary>
  1138. /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
  1139. /// </summary>
  1140. /// <param name="in_cotsparticleclr"></param>
  1141. /// <returns></returns>
  1142. public Bitmap GetBitmapByParticle(Bitmap ls_bt, Rectangle offset_rect)
  1143. {
  1144. //为了能把整个颗粒显示完整
  1145. offset_rect.X = offset_rect.X - 20;
  1146. offset_rect.Y = offset_rect.Y - 20;
  1147. offset_rect.Width = offset_rect.Width + 40;
  1148. offset_rect.Height = offset_rect.Height + 40;
  1149. //防止计算偏差后,有坐标溢出现象
  1150. if (offset_rect.X < 0)
  1151. offset_rect.X = 0;
  1152. if (offset_rect.Y < 0)
  1153. offset_rect.Y = 0;
  1154. if (offset_rect.X + offset_rect.Width > ls_bt.Width)
  1155. {
  1156. offset_rect.Width = ls_bt.Width - offset_rect.X;
  1157. }
  1158. if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
  1159. {
  1160. offset_rect.Height = ls_bt.Height - offset_rect.Y;
  1161. }
  1162. Bitmap new_ret_bp;
  1163. //防止为0后面计算出错
  1164. if (offset_rect.Width > 0 && offset_rect.Height > 0)
  1165. {
  1166. //最后通过list_showsegment组建成新的图片,进行返回
  1167. new_ret_bp = ls_bt.Clone(offset_rect, ls_bt.PixelFormat);
  1168. }
  1169. else
  1170. {
  1171. new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
  1172. }
  1173. return new_ret_bp;
  1174. }
  1175. public void InsertUpdate(List<int> particleID, List<string> particleData)
  1176. {
  1177. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  1178. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  1179. cmdlist.Add(str);
  1180. try
  1181. {
  1182. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  1183. }
  1184. catch (Exception e)
  1185. {
  1186. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  1187. }
  1188. }
  1189. public KeyValuePair<string, SQLiteParameter[]> GetUpdataAIncACmd(List<int> particleID, List<string> particleData)
  1190. {
  1191. var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
  1192. return str;
  1193. }
  1194. public void ExecuteNonQueryBatch(List<KeyValuePair<string, SQLiteParameter[]>> cmdlist)
  1195. {
  1196. try
  1197. {
  1198. dbHelper.ExecuteNonQueryBatch(ref cmdlist);
  1199. }
  1200. catch (Exception e)
  1201. {
  1202. //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  1203. }
  1204. }
  1205. /// <summary>
  1206. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  1207. /// </summary>
  1208. /// <param name="in_clr_tagid">颗粒id</param>
  1209. /// <param name="in_clr_fieldid"></param>
  1210. /// <param name="Search_xray"></param>
  1211. /// <param name="Analysis_xray"></param>
  1212. public Particle GetXrayByParticleTagIDAndFieldID_ForMergeParticle(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray)
  1213. {
  1214. Search_xray = new uint[2000];
  1215. Analysis_xray = new uint[2000];
  1216. Particle particle = new Particle();
  1217. particle = GetMergedParticleInfo(in_clr_fieldid, in_clr_tagid, out Search_xray, out Analysis_xray);
  1218. return particle;
  1219. }
  1220. public List<ShowElementInfo> GetShowElementInfos_ForMergeParticle(List<Element> list_celementchemistryclr)
  1221. {
  1222. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1223. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1224. {
  1225. ShowElementInfo ls_sei = new ShowElementInfo();
  1226. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1227. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1228. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  1229. double de_sx2 = 0;
  1230. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  1231. {
  1232. de_sx2 = 0;
  1233. }
  1234. else
  1235. {
  1236. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  1237. }
  1238. ls_sei.dLF = de_sx2;
  1239. list_showelementinfo.Add(ls_sei);
  1240. }
  1241. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  1242. return list_showelementinfo;
  1243. }
  1244. #endregion
  1245. #region 清洁度
  1246. public ParticleData()
  1247. {
  1248. }
  1249. /// <summary>
  1250. /// 获得颗粒类别
  1251. /// </summary>
  1252. /// <param name="StandardLibraryAddress">标准库地址</param>
  1253. /// <returns></returns>
  1254. public DataTable ObtainParticleCategory_start(string StandardLibraryAddress)
  1255. {
  1256. DataTable dataTable = new DataTable();
  1257. dataTable.Columns.Add("GroupId");
  1258. dataTable.Columns.Add("GroupName");
  1259. dataTable.Columns.Add("inoId");
  1260. dataTable.Columns.Add("display");
  1261. DataTable get_dt = SelectStandardLibraryGrouping(StandardLibraryAddress);
  1262. if (get_dt.Rows.Count==0)
  1263. {
  1264. DataRow data = dataTable.NewRow();
  1265. data["inoId"] = 0;
  1266. data["GroupId"] = 0;
  1267. data["GroupName"] = "Default";
  1268. data["display"] = "0";
  1269. dataTable.Rows.Add(data);
  1270. return dataTable;
  1271. }
  1272. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  1273. int shul = 0;
  1274. string DefaultGroupId = "";
  1275. foreach (DataRow row in dataRow)
  1276. {
  1277. if (row.ItemArray[1].ToString() != "Default")
  1278. {
  1279. DataRow data = dataTable.NewRow();
  1280. data["inoId"] = shul;
  1281. data["GroupId"] = row.ItemArray[0].ToString();
  1282. data["GroupName"] = row.ItemArray[1].ToString();
  1283. data["display"] = "0";
  1284. dataTable.Rows.Add(data);
  1285. shul++;
  1286. }
  1287. else
  1288. {
  1289. DefaultGroupId = row.ItemArray[0].ToString();
  1290. }
  1291. }
  1292. DataRow data2 = dataTable.NewRow();
  1293. data2["inoId"] = shul;
  1294. data2["GroupId"] = DefaultGroupId;
  1295. data2["GroupName"] = "Default";
  1296. data2["display"] = "0";
  1297. dataTable.Rows.Add(data2);
  1298. return dataTable;
  1299. }
  1300. /// <summary>
  1301. /// 获取规则数据
  1302. /// </summary>
  1303. /// <param name="strings">组类别</param>
  1304. /// <param name="a_SelectedIndex">标准库地址</param>
  1305. /// <returns></returns>
  1306. public List<DataTable> ObtainRuleData_start(DataTable strings, string a_SelectedIndex)
  1307. {
  1308. List<DataTable> List_data = new List<DataTable>();
  1309. DataTable dt_stl = new DataTable();
  1310. SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
  1311. dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
  1312. dt_stl.Columns.Add("display");
  1313. if (dt_stl == null)
  1314. {
  1315. List_data.Add(dt_stl);
  1316. return List_data;
  1317. }
  1318. for (int i = 0; i < strings.Rows.Count; i++)
  1319. {
  1320. DataTable table = dt_stl.Clone();
  1321. table.TableName = strings.Rows[i]["GroupId"].ToString();
  1322. for (int a = 0; a < dt_stl.Rows.Count; a++)
  1323. {
  1324. if (strings.Rows[i]["GroupId"].ToString() == dt_stl.Rows[a]["GroupId"].ToString())
  1325. {
  1326. dt_stl.Rows[a]["display"] = 0;
  1327. table.Rows.Add(dt_stl.Rows[a].ItemArray);
  1328. }
  1329. }
  1330. DataView dvs = table.DefaultView;
  1331. dvs.Sort = "ListNum ASC";
  1332. DataTable TemporaryDataGroup = dvs.ToTable();
  1333. List_data.Add(TemporaryDataGroup);
  1334. }
  1335. return List_data;
  1336. }
  1337. private DataTable SelectStandardLibraryGrouping(string a_SelectedIndex)
  1338. {
  1339. DataTable dt_stl = new DataTable();
  1340. SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
  1341. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  1342. return dt_stl;
  1343. }
  1344. /// <summary>
  1345. /// 获得颗粒类别
  1346. /// </summary>
  1347. /// <returns></returns>
  1348. public List<string> ObtainParticleCategory(OTSReport_Export m_otsreport_export, BasicData basicData)
  1349. {
  1350. List<string> ClassName = new List<string>();
  1351. if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
  1352. {
  1353. DataTable get_dt = ReadClassification(basicData);
  1354. DataTable getClass_dt = get_dt.Clone();
  1355. DataRow[] dataRow = get_dt.Select("", "iorder ASC");
  1356. foreach (DataRow row in dataRow)
  1357. {
  1358. if (row.ItemArray[1].ToString() != "Default")
  1359. {
  1360. getClass_dt.ImportRow(row);
  1361. }
  1362. }
  1363. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1364. {
  1365. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  1366. }
  1367. ClassName.Add("Default");
  1368. }
  1369. else
  1370. {
  1371. DataTable getClass_dt = ReadClassification(basicData);
  1372. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1373. {
  1374. ClassName.Add(getClass_dt.Rows[i][1].ToString());
  1375. }
  1376. bool bl = false;
  1377. for (int i = 0; i < getClass_dt.Rows.Count; i++)
  1378. {
  1379. if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
  1380. && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
  1381. if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
  1382. {
  1383. if (!bl)
  1384. {
  1385. ClassName.Add("Default");
  1386. bl = true;
  1387. }
  1388. }
  1389. else
  1390. {
  1391. bool isDefault = false;
  1392. for (int a = 0; a < ClassName.Count; a++)
  1393. {
  1394. if (getClass_dt.Rows[i]["GroupName"].ToString() == "Default")
  1395. {
  1396. isDefault = true;
  1397. }
  1398. }
  1399. if (isDefault)
  1400. {
  1401. if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
  1402. {
  1403. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1404. }
  1405. }
  1406. else
  1407. {
  1408. ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
  1409. }
  1410. }
  1411. }
  1412. }
  1413. return ClassName;
  1414. }
  1415. public DataTable ReadClassification(BasicData basicData)
  1416. {
  1417. DataTable dt_stl = new DataTable();
  1418. SqLiteHelper sh = new SqLiteHelper("data source='" + basicData.GetFilePath() + "\\" + basicData.GetResfile() + "'");
  1419. dt_stl = sh.ExecuteQuery("select * from STDGroups");
  1420. return dt_stl;
  1421. }
  1422. #endregion
  1423. }
  1424. }