ParticleData.cs 61 KB

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