ParticlesGridDevidePage.cs 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672
  1. using NPOI.SS.UserModel;
  2. using NPOI.SS.UserModel.Charts;
  3. using NPOI.SS.Util;
  4. using NPOI.XSSF.UserModel;
  5. using OTSCLRINTERFACE;
  6. using OTSCommon.DBOperate;
  7. using OTSCommon.DBOperate.Model;
  8. using OTSIncAReportApp;
  9. using OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage;
  10. using OTSIncAReportApp.DataOperation.DataAccess;
  11. using OTSIncAReportApp.OTSRstMgrFunction;
  12. using OTSIncAReportApp.SysMgrTools;
  13. using OTSIncAReportGraph.Class;
  14. using OTSIncAReportGraph.Controls;
  15. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  16. using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
  17. using OTSIncAReportMailInterface;
  18. using OTSPeriodicTable;
  19. using System;
  20. using System.Collections;
  21. using System.Collections.Generic;
  22. using System.Data;
  23. using System.Data.SQLite;
  24. using System.Drawing;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Reflection;
  28. using System.Threading;
  29. using System.Windows.Forms;
  30. using static OTSDataType.otsdataconst;
  31. namespace OTSIncAReportGrids
  32. {
  33. public partial class ParticlesGridDevidePage : UserControl
  34. {
  35. ParticlesGridDevidePageShowConfig m_particlesGridDevidePageShowConfig = null;
  36. //设置模拟数据表
  37. public DataTable m_dt = new DataTable();
  38. //底层操作类
  39. OTSReportGridsFun m_OTSIncAReportGridsFun = null;
  40. //进度条窗体
  41. public Frm_UserProgress m_frm_userprogress;
  42. //移动SEM到指定位置发生线程
  43. private Thread m_mythread;
  44. //记录线程是否已经运行完成的状态
  45. private bool m_mythread_state = false;
  46. //导出图像文件的路径
  47. private string m_imagefilepath = "";
  48. //显示元素列表
  49. public List<string> m_list_elementscolname = null;
  50. //单个数据源所拥有的列数,这里保存下来,供导出模块使用
  51. public int m_oneresult_columncount = 0;
  52. OTSImageDisHelp m_ReportFun = null;
  53. public OTSImageDisHelp ReportFun { get => m_ReportFun; set => m_ReportFun = value; }
  54. /// <summary>
  55. /// 选择颗粒缓存表
  56. /// </summary>
  57. List<Particle> Particleslist_selecttodisplay = new List<Particle>();
  58. //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
  59. public List<int> m_list_oneresult_columncount;
  60. //国际化
  61. Language lan;
  62. public Hashtable table;
  63. //测量结果
  64. public ResultFile result = null;
  65. frmReportConditionChoose m_condition;
  66. FieldData fieldData;
  67. DataTable particlesAll;
  68. DataTable particles;
  69. public ParticleData Particledata;
  70. UserLibraryData userLibrary;
  71. DataTable userLibraryData;
  72. NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  73. enum SelItem
  74. {
  75. analyticalParticle = 0,
  76. otherParticles = 1,
  77. MergeParticles = 2,
  78. allParticles = 3
  79. }
  80. //ListOfSimilarParticles Form_listOfSimilarParticles;
  81. #region 分页器相关
  82. #region 分页字段和属性
  83. string condition = "";
  84. public string FileName = null;
  85. private int pageIndex = 1;
  86. /// <summary>
  87. /// 当前页面
  88. /// </summary>
  89. public virtual int PageIndex
  90. {
  91. get { return pageIndex; }
  92. set { pageIndex = value; }
  93. }
  94. private int pageSize = 20;
  95. /// <summary>
  96. /// 每页记录数
  97. /// </summary>
  98. public virtual int PageSize
  99. {
  100. get { return pageSize; }
  101. set { pageSize = value; }
  102. }
  103. private int recordCount = 0;
  104. /// <summary>
  105. /// 总记录数
  106. /// </summary>
  107. public virtual int RecordCount
  108. {
  109. get { return recordCount; }
  110. set { recordCount = value; }
  111. }
  112. private int pageCount = 0;
  113. /// <summary>
  114. /// 总页数
  115. /// </summary>
  116. public int PageCount
  117. {
  118. get
  119. {
  120. pageCount = GetPageCount();
  121. return pageCount;
  122. }
  123. }
  124. /// <summary>
  125. /// 计算总页数
  126. /// </summary>
  127. /// <returns></returns>
  128. private int GetPageCount()
  129. {
  130. if (PageSize == 0)
  131. {
  132. return 0;
  133. }
  134. int pageCount = RecordCount / PageSize;
  135. if (RecordCount % PageSize == 0)
  136. {
  137. pageCount = RecordCount / PageSize;
  138. }
  139. else
  140. {
  141. pageCount = RecordCount / PageSize + 1;
  142. }
  143. return pageCount;
  144. }
  145. #endregion
  146. frmReportApp m_ReportApp;
  147. #endregion
  148. public ParticlesGridDevidePage(frmReportApp ReportApp)
  149. {
  150. m_ReportApp = ReportApp;
  151. m_condition = ReportApp.m_conditionChoose;
  152. string sou = m_condition.m_CurrentConditions[OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  153. if (sou.Contains("+"))
  154. {
  155. MessageBox.Show("This function does not support multiple samples!");
  156. result = m_ReportApp.m_rstDataMgr.ResultFilesList[0];
  157. }
  158. else
  159. {
  160. result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE)];
  161. }
  162. ReportFun = new OTSImageDisHelp(result);
  163. //设置窗体的双缓冲,以保证大数据时拖动不卡
  164. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  165. this.UpdateStyles();
  166. InitializeComponent();
  167. //利用反射设置DataGridView的双缓冲
  168. Type dgvType = this.dgV_ParticlesDevidePage.GetType();
  169. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  170. pi.SetValue(this.dgV_ParticlesDevidePage, true, null);
  171. this.control_XRayTable1 = new Control_XRayTable(null);
  172. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
  173. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
  174. this.control_XRayTable1.GBInfoStr = "";
  175. this.control_XRayTable1.GoodChineseName = "";
  176. this.control_XRayTable1.MaterialName = "";
  177. this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
  178. this.control_XRayTable1.Name = "control_XRayTable1";
  179. this.control_XRayTable1.ShowAnalysisXray = true;
  180. this.control_XRayTable1.ShowSearchXray = false;
  181. this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
  182. this.control_XRayTable1.STDName = "";
  183. this.control_XRayTable1.Visible = false;
  184. this.control_XRayTable1.label_close.Visible = true;
  185. this.Controls.Add(this.control_XRayTable1);
  186. }
  187. bool Init()
  188. {
  189. if (result == null)
  190. {
  191. return false;
  192. }
  193. try
  194. {
  195. lan = new Language(this);
  196. table = lan.GetNameTable(this.Name);
  197. m_mythread_state = false;
  198. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  199. fieldData = new FieldData(result.FilePath);
  200. Particledata = new ParticleData(result.FilePath);
  201. var systype = m_ReportApp.m_RptConfigFile.Systype;
  202. if (systype == OTS_SysType_ID.TCCleannessA || systype == OTS_SysType_ID.BatteryCleannessA)
  203. {
  204. string str_libraryName = result.GetSTDName();
  205. userLibrary = new UserLibraryData(str_libraryName, result.FilePath + "\\");
  206. if (userLibrary.GetSqlHelper() != null)
  207. {
  208. userLibraryData = userLibrary.GetSubAttributeFromDatabase();
  209. }
  210. else
  211. {
  212. userLibraryData = null;
  213. }
  214. }
  215. //初始化底层操作类
  216. m_OTSIncAReportGridsFun = new OTSReportGridsFun();
  217. return true;
  218. }
  219. catch (Exception ex)
  220. {
  221. log.Error(ex.ToString());
  222. return false;
  223. }
  224. }
  225. private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
  226. {
  227. if (!Init())
  228. {
  229. return;
  230. }
  231. ProgressStart();//进度条关闭通过cbB_PageSize.SelectedIndex事件
  232. if (!UpdateTable())
  233. {
  234. return;
  235. }
  236. cbB_PageSize.Items.Add("20");
  237. cbB_PageSize.Items.Add("100");
  238. cbB_PageSize.Items.Add("500");
  239. cbB_PageSize.Items.Add("1000");
  240. cbB_PageSize.Items.Add("5000");
  241. cbB_PageSize.Items.Add("All");
  242. cbB_PageSize.SelectedIndex = 0;
  243. DataTable table = GetClassificationOfAllParticles();
  244. if (table != null)
  245. {
  246. if (table.Rows.Count > 0)
  247. {
  248. foreach (DataRow row in table.Rows)
  249. {
  250. tbx_Type.Text += row["TypeName"].ToString() + '$';
  251. }
  252. }
  253. if (tbx_Type.Text != "")
  254. {
  255. tbx_Type.Text = tbx_Type.Text.Remove(tbx_Type.Text.Length - 1);
  256. }
  257. }
  258. dgV_ParticlesDevidePage.Focus();
  259. }
  260. #region 自定义方法
  261. bool UpdateTable()
  262. {
  263. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  264. particlesAll = new DataTable();
  265. if (sel == (int)SelItem.analyticalParticle)
  266. {
  267. particlesAll = Particledata.GetInfoForPartucleDevidePage_analyticalParticle(condition);
  268. DataTable mergeParticles = Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
  269. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  270. {
  271. RemoveMergeParticles(ref particlesAll, mergeParticles);
  272. }
  273. }
  274. if (sel == (int)SelItem.otherParticles)
  275. {
  276. particlesAll = Particledata.GetInfoForPartucleDevidePage_otherParticle(condition);
  277. DataTable mergeParticles = Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
  278. if (mergeParticles != null && mergeParticles.Rows.Count > 0)
  279. {
  280. RemoveMergeParticles(ref particlesAll, mergeParticles);
  281. }
  282. }
  283. if (sel == (int)SelItem.MergeParticles)
  284. {
  285. particlesAll = Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
  286. }
  287. if (sel == (int)SelItem.allParticles)
  288. {
  289. particlesAll = Particledata.GetInfoForPartucleDevidePage_allParticles(condition);
  290. }
  291. particlesAll.Columns.Add("Hardness");
  292. particlesAll.Columns.Add("Density");
  293. particlesAll.Columns.Add("Electrical_conductivity");
  294. if (userLibraryData != null)
  295. {
  296. for (int i = 0; i < particlesAll.Rows.Count; i++)
  297. {
  298. DataRow[] dr = userLibraryData.Select("STDId=" + particlesAll.Rows[i]["TypeId"].ToString());
  299. if (dr.Length > 0)
  300. {
  301. particlesAll.Rows[i]["Hardness"] = dr[0]["Hardness"].ToString();
  302. particlesAll.Rows[i]["Density"] = dr[0]["Density"].ToString();
  303. particlesAll.Rows[i]["Electrical_conductivity"] = dr[0]["Electrical_conductivity"].ToString();
  304. }
  305. else
  306. {
  307. particlesAll.Rows[i]["Hardness"] = "";
  308. particlesAll.Rows[i]["Density"] = "";
  309. particlesAll.Rows[i]["Electrical_conductivity"] = "";
  310. }
  311. }
  312. }
  313. else
  314. {
  315. for (int i = 0; i < particlesAll.Rows.Count; i++)
  316. {
  317. particlesAll.Rows[i]["Hardness"] = "";
  318. particlesAll.Rows[i]["Density"] = "";
  319. particlesAll.Rows[i]["Electrical_conductivity"] = "";
  320. }
  321. }
  322. btn_Sel.Enabled = true;
  323. if (particlesAll == null)
  324. {
  325. log.Error("There is an exception in the data of the database!");
  326. #region 加载进度条进度部份结束
  327. this.Cursor = Cursors.Default;
  328. m_frm_userprogress.Close();
  329. #endregion
  330. return false;
  331. }
  332. DataTable elementchemistry = Particledata.GetElementChemistry();
  333. for (int i = 0; i < particlesAll.Rows.Count; i++)
  334. {
  335. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  336. DataRow[] drs = elementchemistry.Select(str);
  337. string ConcatenatedString = "";
  338. for (int j = 0; j < drs.Length; j++)
  339. {
  340. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  341. }
  342. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  343. }
  344. if (sel != (int)SelItem.MergeParticles)
  345. {
  346. DataTable XRayData = Particledata.GetXRayData();
  347. particlesAll.Columns.Add("XRayDataCount");
  348. for (int i = 0; i < particlesAll.Rows.Count; i++)
  349. {
  350. if (int.Parse(particlesAll.Rows[i]["particleId"].ToString()) > -1)
  351. {
  352. particlesAll.Rows[i]["XRayDataCount"] = 0;
  353. string str = " XrayIndex= " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  354. DataRow[] drs = XRayData.Select(str);
  355. uint xraycount = 0;
  356. if (drs != null)
  357. {
  358. if (drs.Length > 0)
  359. {
  360. uint[] Analysis_xray = new uint[2000];
  361. for (int j = 0; j < 2000; j++)
  362. {
  363. Analysis_xray[j] = BitConverter.ToUInt32((byte[])drs[0][2], j * 4);
  364. }
  365. for (int j = 0; j < 2000; j++)
  366. {
  367. xraycount += Analysis_xray[j];
  368. }
  369. particlesAll.Rows[i]["XRayDataCount"] = xraycount;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. return true;
  376. }
  377. private void BindDataGridView()
  378. {
  379. dgV_ParticlesDevidePage.Visible = false;
  380. if (m_frm_userprogress.IsDisposed)
  381. {
  382. ProgressStart();
  383. }
  384. dgV_ParticlesDevidePage.Rows.Clear();
  385. dgV_ParticlesDevidePage.Columns.Clear();
  386. var startFun = m_ReportApp.m_RptConfigFile.Systype;
  387. string str_DefaultComputedColName = "", str_ElementsColName = "";
  388. DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData");
  389. DataTable dt = ds.Tables["Member"];
  390. foreach (DataRow element in dt.Rows)
  391. {
  392. string RegName = element["RegName"].ToString();
  393. if (RegName == "DefaultComputedColName")
  394. {
  395. str_DefaultComputedColName = element["strValue"].ToString();
  396. }
  397. if (RegName == "ElementsColName")
  398. {
  399. str_ElementsColName = element["strValue"].ToString();
  400. }
  401. }
  402. string[] strs = str_DefaultComputedColName.Split(',');
  403. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  404. keyValues.Add("rowid", table["str4"].ToString());
  405. keyValues.Add("TypeName", table["str6"].ToString());
  406. keyValues.Add("ParticleImage", table["str5"].ToString());
  407. keyValues.Add("FieldId", "FieldId");
  408. keyValues.Add("ParticleId", "ParticleId");
  409. keyValues.Add("SEMPosX", "SEMPosX");
  410. keyValues.Add("SEMPosY", "SEMPosY");
  411. for (int i = 0; i < strs.Count(); i++)
  412. {
  413. if (strs[i] == "ParticleCoordinate")
  414. {
  415. keyValues.Add("AbPosX", "PosX");
  416. keyValues.Add("AbPosY", "PosY");
  417. }
  418. if (strs[i] == "Area")
  419. {
  420. keyValues.Add("Area", table["str21"].ToString());
  421. }
  422. if (strs[i] == "EquivalentCircleDiameter")
  423. {
  424. keyValues.Add("Equivalent", table["str22"].ToString());
  425. }
  426. if (strs[i] == "MaxDiameter")
  427. {
  428. keyValues.Add("DMAX", table["str23"].ToString());
  429. }
  430. if (strs[i] == "MinDiameter")
  431. {
  432. keyValues.Add("DMIN", table["str24"].ToString());
  433. }
  434. if (strs[i] == "DiameterRatio")
  435. {
  436. keyValues.Add("DiameterRatio", table["str25"].ToString());
  437. }
  438. if (strs[i] == "FerretDiameter")
  439. {
  440. keyValues.Add("DFERET", table["str26"].ToString());
  441. }
  442. if (strs[i] == "PERP")
  443. {
  444. keyValues.Add("DPERP", table["str27"].ToString());
  445. }
  446. if (strs[i] == "PERI")
  447. {
  448. keyValues.Add("PERIMETER", table["str28"].ToString());
  449. }
  450. if (strs[i] == "INSCR")
  451. {
  452. keyValues.Add("DINSCR", table["str29"].ToString());
  453. }
  454. if (strs[i] == "MEAN")
  455. {
  456. keyValues.Add("DMEAN", table["str30"].ToString());
  457. }
  458. if (strs[i] == "ELONG")
  459. {
  460. keyValues.Add("DELONG", table["str31"].ToString());
  461. }
  462. if (strs[i] == "ASPECT_ELONG")
  463. {
  464. keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
  465. }
  466. if (strs[i] == "Orientation")
  467. {
  468. keyValues.Add("ORIENTATION", table["str33"].ToString());
  469. }
  470. if (strs[i] == "XRayDataCount")
  471. {
  472. keyValues.Add("XRayDataCount", "XRay计数");
  473. }
  474. if (startFun == OTS_SysType_ID.TCCleannessA || startFun == OTS_SysType_ID.BatteryCleannessA)
  475. {
  476. if (strs[i] == "Hardness")
  477. {
  478. keyValues.Add("Hardness", table["str34"].ToString());
  479. }
  480. if (strs[i] == "Density")
  481. {
  482. keyValues.Add("Density", table["str35"].ToString());
  483. }
  484. if (strs[i] == "Electrical_conductivity")
  485. {
  486. keyValues.Add("Electrical_conductivity", table["str36"].ToString());
  487. }
  488. }
  489. }
  490. keyValues.Add("Element", "Element");
  491. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  492. for (int irow = 0; irow < keyValues.Count; irow++)
  493. {
  494. if (en.MoveNext())
  495. {
  496. if (en.Current.Key == "ParticleImage")
  497. {
  498. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  499. iconColumn.Name = en.Current.Key;
  500. iconColumn.HeaderText = en.Current.Value;
  501. dgV_ParticlesDevidePage.Columns.Add(iconColumn);
  502. }
  503. else if (en.Current.Key == "Element")
  504. {
  505. }
  506. else
  507. {
  508. dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
  509. if (en.Current.Key == "Area" || en.Current.Key == "EquivalentCircleDiameter" || en.Current.Key == "MaxDiameter" || en.Current.Key == "MinDiameter" || en.Current.Key == "DiameterRatio" || en.Current.Key == "FerretDiameter" || en.Current.Key == "PERP" || en.Current.Key == "PERI" || en.Current.Key == "INSCR" || en.Current.Key == "MEAN" || en.Current.Key == "ELONG" || en.Current.Key == "ASPECT_ELONG" || en.Current.Key == "Orientation")
  510. {
  511. int id = dgV_ParticlesDevidePage.Columns.Count;
  512. dgV_ParticlesDevidePage.Columns[id - 1].Tag = "NumericType";
  513. }
  514. }
  515. }
  516. }
  517. if (PageSize == -1)
  518. {
  519. PageSize = particlesAll.Rows.Count;
  520. }
  521. if (particlesAll == null)
  522. {
  523. return;
  524. }
  525. RecordCount = particlesAll.Rows.Count;
  526. particles = particlesAll.Clone();
  527. for (int fi = (PageIndex - 1) * pageSize; fi < PageIndex * pageSize; fi++)
  528. {
  529. if (fi > RecordCount - 1)
  530. {
  531. break;
  532. }
  533. particles.ImportRow(particlesAll.Rows[fi]);
  534. }
  535. string particleM = "";
  536. List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
  537. for (int i = 0; i < ElementTypeSort.Count; i++)
  538. {
  539. if (ElementTypeSort[0] == "")
  540. {
  541. ElementTypeSort.RemoveAt(0);
  542. break;
  543. }
  544. dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
  545. int id = dgV_ParticlesDevidePage.Columns.Count;
  546. dgV_ParticlesDevidePage.Columns[id - 1].Tag = "NumericType";
  547. }
  548. double jd = 95f / (double)particles.Rows.Count;
  549. string filePath = result.FilePath + "\\FIELD_FILES\\";
  550. KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  551. for (int i = 0; i < particles.Rows.Count; i++)
  552. {
  553. if (i % 10 == 0)
  554. m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "loading..");
  555. Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  556. int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
  557. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value = (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
  558. for (int k = 0; k < keyValues.Count; k++)
  559. {
  560. if (enl.MoveNext())
  561. {
  562. if (enl.Current.Key == "ParticleImage")
  563. {
  564. if (particles.Columns.Contains("SubParticles"))
  565. {
  566. string subt = particles.Rows[i]["SubParticles"].ToString();
  567. if (subt != null && subt != "")
  568. {
  569. double ScanFieldSize = result.GetScanFieldSizeX();
  570. string filePatht = result.FilePath + "\\FIELD_FILES\\";
  571. string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
  572. Bitmap tempbit = Particledata.ReadImageFile(imagePatht);
  573. int pixw = tempbit.Width;
  574. double xs = pixw / ScanFieldSize;
  575. particleM = particleM + "," + subt;
  576. Bitmap bmap = Particledata.GetBitmapForBig(subt, xs, result.FilePath, tempbit.Height, tempbit.Width);
  577. if (bmap != null)
  578. {
  579. string[] str = subt.Split(',');
  580. bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
  581. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  582. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  583. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  584. dgV_ParticlesDevidePage.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate;
  585. }
  586. else
  587. {
  588. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  589. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  590. }
  591. }
  592. }
  593. else
  594. {
  595. if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  596. {
  597. string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  598. FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), Particledata.ReadImageFile(imagePath));
  599. }
  600. 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"]) };
  601. Bitmap bmap = Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
  602. 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() };
  603. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  604. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = bmap.Height + 20;
  605. }
  606. }
  607. if (enl.Current.Key == "DiameterRatio")
  608. {
  609. double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  610. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  611. }
  612. if (en.Current.Key == "Element")
  613. {
  614. }
  615. if (enl.Current.Key == "ASPECT_ELONG")
  616. {
  617. double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  618. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  619. }
  620. if (particles.Columns.Contains(enl.Current.Key))
  621. {
  622. double num = 0;
  623. if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  624. {
  625. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  626. }
  627. else if (enl.Current.Key == "Element")
  628. {
  629. List<string> elementtemp = new List<string>(ElementTypeSort);
  630. string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  631. for (int j = 0; j < strcbo.Length; j++)
  632. {
  633. if (ElementTypeSort.Count == 0)
  634. {
  635. break;
  636. }
  637. string[] str = strcbo[j].Split('-');
  638. if (ElementTypeSort.Contains(str[0]))
  639. { dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
  640. elementtemp.Remove(str[0].ToString());
  641. }
  642. foreach (var ele in elementtemp)
  643. {
  644. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[ele].Value = "0";
  645. }
  646. }
  647. else
  648. {
  649. double val = 0;
  650. if (double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]), out val))
  651. {
  652. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = val;
  653. }
  654. else
  655. {
  656. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  657. }
  658. }
  659. }
  660. if (enl.Current.Key == "TypeName")
  661. {
  662. if (particles.Rows[i]["TypeId"].ToString() == "9")
  663. {
  664. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  665. }
  666. }
  667. if (enl.Current.Key == "Equivalent")
  668. {
  669. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  670. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  671. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  672. }
  673. if (enl.Current.Key == "Hardness")
  674. {
  675. string str = ChangeHardnessColor(particles.Rows[i]["Hardness"].ToString());
  676. {
  677. if (str == "#FF0000")
  678. {
  679. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.ForeColor = Color.Red;
  680. }
  681. }
  682. }
  683. if (enl.Current.Key == "AbPosX")
  684. {
  685. Point point = CalculateParticleCenterPosition(result, new Point(Convert.ToInt32(particles.Rows[i]["SEMPosX"]), Convert.ToInt32(particles.Rows[i]["SEMPosY"])), new Point(Convert.ToInt32(particles.Rows[i]["PosX"]), Convert.ToInt32(particles.Rows[i]["PosY"])));
  686. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells["AbPosX"].Value = point.X;
  687. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y;
  688. }
  689. }
  690. }
  691. }
  692. #region 加载进度条进度部份结束
  693. //加载完成设置鼠标为默认
  694. this.Cursor = Cursors.Default;
  695. string str8 = table["str8"].ToString();
  696. m_frm_userprogress.SetProgressValueAndText(100, str8);
  697. //加载完成,关闭进度条
  698. m_frm_userprogress.Close();
  699. #endregion
  700. dgV_ParticlesDevidePage.Visible = true;
  701. }
  702. /// <summary>
  703. /// 设置DataGridView样式
  704. /// </summary>
  705. private void SetDataGridViewStyle()
  706. {
  707. //用户不能调整标题的高度
  708. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  709. //用户不能调整 行高
  710. dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
  711. //点击选择整行
  712. dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  713. //居中显示
  714. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  715. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  716. dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
  717. dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  718. //再次重覆禁用拖动表头高度,居然有效果了
  719. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  720. //设置grid可以复制
  721. dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  722. //设置每列的宽度
  723. dgV_ParticlesDevidePage.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  724. dgV_ParticlesDevidePage.Columns[1].Width = 150;
  725. //设置序号列不排序
  726. dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  727. dgV_ParticlesDevidePage.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  728. //设置序号列不可以设置宽度
  729. dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
  730. dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
  731. }
  732. /// <summary>
  733. /// 计算颗粒中心的电镜坐标
  734. /// </summary>
  735. /// <param name="resultFile"></param>
  736. /// <param name="SEMPos"></param>
  737. /// <param name="ParticlePos"></param>
  738. /// <returns></returns>
  739. public static Point CalculateParticleCenterPosition(ResultFile resultFile, Point SEMPos, Point ParticlePos)
  740. {
  741. Point point = new Point();
  742. float ScanFieldSizeX = resultFile.GetScanFieldSizeX();
  743. string leftOrRight = resultFile.GetXAxisDir();
  744. string downOrUp = resultFile.GetYAxisDir();
  745. float ScanFieldSizeY = resultFile.GetScanFieldSizeY();
  746. float m_pixelSize = resultFile.GetPixelSize();
  747. if (leftOrRight == "RIGHT_TOWARD")
  748. {
  749. point.X = (int)(SEMPos.X - ScanFieldSizeX / 2 + ParticlePos.X * m_pixelSize);
  750. }
  751. else
  752. {
  753. point.X = (int)(SEMPos.X + ScanFieldSizeX / 2 - ParticlePos.X * m_pixelSize);
  754. }
  755. if (downOrUp == "UP_TOWARD")
  756. {
  757. point.Y = (int)(SEMPos.Y + ScanFieldSizeY / 2 - ParticlePos.Y * m_pixelSize);
  758. }
  759. else
  760. {
  761. point.Y = (int)(SEMPos.Y - ScanFieldSizeY / 2 + ParticlePos.Y * m_pixelSize);
  762. }
  763. return point;
  764. }
  765. #endregion
  766. #region 相关事件
  767. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  768. {
  769. //复制整个表
  770. CopyAll();
  771. }
  772. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  773. {
  774. //复制选择区域
  775. CopySelected();
  776. }
  777. /// <summary>
  778. /// 复制选择区域
  779. /// </summary>
  780. public void CopySelected()
  781. {
  782. //复制选择区域
  783. object oo = dgV_ParticlesDevidePage.GetClipboardContent();
  784. if (oo != null)
  785. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  786. }
  787. /// <summary>
  788. /// 复制所有
  789. /// </summary>
  790. public void CopyAll()
  791. {
  792. dgV_ParticlesDevidePage.SelectAll();
  793. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  794. }
  795. /// <summary>
  796. /// 以图像的方式将GridView进行截图
  797. /// </summary>
  798. public void CopyImage()
  799. {
  800. int height, width;
  801. width = dgV_ParticlesDevidePage.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 2;
  802. height = this.Height;
  803. Bitmap image = new Bitmap(width, height);
  804. dgV_ParticlesDevidePage.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  805. Clipboard.SetImage(image);
  806. }
  807. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  808. {
  809. //对gridview进行截图
  810. CopyImage();
  811. }
  812. private void dgV_ParticlesDevidePage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  813. {
  814. //排序中
  815. if (e.Column.Tag != null && e.Column.Tag.ToString() == "NumericType")
  816. {
  817. e.SortResult = double.Parse(e.CellValue1.ToString()).CompareTo(double.Parse(e.CellValue2.ToString()));
  818. e.Handled = true;
  819. }
  820. }
  821. #endregion
  822. #region 连接电镜相关
  823. /// <summary>
  824. /// 移动SEM到指定位置线程函数
  825. /// </summary>
  826. private void Thread_GO(object in_obj)
  827. {
  828. if (m_mythread_state == false)
  829. {
  830. m_mythread_state = true;
  831. Point sem_point = (Point)in_obj;
  832. //第一步,连接电镜
  833. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  834. Thread.Sleep(500);
  835. //第二步,移动到指定位置,先读取再设置
  836. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  837. {
  838. m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  839. }
  840. Thread.Sleep(1500);
  841. m_mythread_state = false;
  842. }
  843. }
  844. #endregion
  845. private void ToolStripMenuItem5_Click(object sender, EventArgs e)
  846. {
  847. /*注意:多数据源情况下,只获取第一个数据源的选择了多行的情况下,只获取最后一个选择行的,没有办法,这是为了符合李阳博士提出的要求*/
  848. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  849. string i_ls_fieldid = "";
  850. string i_ls_particleid = "";
  851. int cou = dgV_ParticlesDevidePage.SelectedRows.Count;
  852. if (cou > 0)
  853. {
  854. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[cou - 1];
  855. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  856. List<string> list_str = (List<string>)ls_bp.Tag;
  857. if (list_str != null)
  858. {
  859. i_ls_fieldid = list_str[0];
  860. i_ls_particleid = list_str[1];
  861. }
  862. }
  863. ParticleData particleData = new ParticleData(result.FilePath);
  864. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  865. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  866. if (m_mythread == null)
  867. {
  868. return;
  869. }
  870. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  871. {
  872. return;
  873. }
  874. if (m_mythread.ThreadState == ThreadState.Stopped)
  875. {
  876. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  877. }
  878. Point point = CalculateParticleCenterPosition(result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
  879. //改为线程调用,先判断线程状态
  880. m_mythread.Start(point);
  881. }
  882. private void ToolStripMenuItem_exportimagefile_Click(object sender, EventArgs e)
  883. {
  884. FolderBrowserDialog fbd = new FolderBrowserDialog();
  885. if (fbd.ShowDialog() == DialogResult.OK)
  886. {
  887. m_imagefilepath = fbd.SelectedPath;
  888. for (int i = 0; i < dgV_ParticlesDevidePage.Rows.Count; i++)
  889. {
  890. Bitmap ls_bp = new Bitmap(1, 1);
  891. ls_bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i].Cells[2].Value;
  892. ls_bp.Save(m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg");
  893. }
  894. string str9 = table["str9"].ToString();
  895. MessageBox.Show(str9 + dgV_ParticlesDevidePage.Rows.Count.ToString());
  896. }
  897. }
  898. private void testToolStripMenuItem_Click(object sender, EventArgs e)
  899. {
  900. }
  901. /// <summary>
  902. /// 判断条件输入 前<后
  903. /// </summary>
  904. /// <param name="min"></param>
  905. /// <param name="max"></param>
  906. /// <returns></returns>
  907. bool CompareInput(string min, string max)
  908. {
  909. int imax = 0;
  910. int imin = 0;
  911. double dmax = 0;
  912. double dmin = 0;
  913. if (int.TryParse(max, out imax))
  914. {
  915. dmax = (double)imax;
  916. }
  917. else
  918. {
  919. dmax = Convert.ToDouble(max);
  920. }
  921. if (int.TryParse(min, out imin))
  922. {
  923. dmin = (double)imin;
  924. }
  925. else
  926. {
  927. dmin = Convert.ToDouble(min);
  928. }
  929. if (dmin <= dmax)
  930. {
  931. return true;
  932. }
  933. else
  934. {
  935. return false;
  936. }
  937. }
  938. private void btn_Sel_Click(object sender, EventArgs e)
  939. {
  940. condition = "";
  941. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text))
  942. {
  943. double dnum = 0;
  944. int inum = 0;
  945. if (double.TryParse(tBx_AreaMin.Text, out dnum) && dnum >= 0)
  946. {
  947. condition += " and Area" + " > " + tBx_AreaMin.Text;
  948. }
  949. else if (int.TryParse(tBx_AreaMin.Text, out inum) && inum >= 0)
  950. {
  951. condition += " and Area" + " > " + tBx_AreaMin.Text;
  952. }
  953. else
  954. {
  955. MessageBox.Show(table["str10"].ToString());
  956. return;
  957. }
  958. }
  959. if (!string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  960. {
  961. double dnum = 0;
  962. int inum = 0;
  963. if (double.TryParse(Tbx_AreaMax.Text, out dnum) && dnum >= 0)
  964. {
  965. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  966. }
  967. else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
  968. {
  969. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  970. }
  971. else
  972. {
  973. MessageBox.Show(table["str10"].ToString());
  974. return;
  975. }
  976. }
  977. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text) && !string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  978. {
  979. if (!CompareInput(tBx_AreaMin.Text, Tbx_AreaMax.Text))
  980. {
  981. MessageBox.Show(table["str11"].ToString());
  982. return;
  983. }
  984. }
  985. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text))
  986. {
  987. double dnum = 0;
  988. int inum = 0;
  989. if (double.TryParse(tbx_DmaxMin.Text, out dnum) && dnum >= 0)
  990. {
  991. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  992. }
  993. else if (int.TryParse(tbx_DmaxMin.Text, out inum) && inum >= 0)
  994. {
  995. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  996. }
  997. else
  998. {
  999. MessageBox.Show(table["str10"].ToString());
  1000. return;
  1001. }
  1002. }
  1003. if (!string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1004. {
  1005. double dnum = 0;
  1006. int inum = 0;
  1007. if (double.TryParse(tbx_DmaxMax.Text, out dnum) && dnum > 0)
  1008. {
  1009. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1010. }
  1011. else if (int.TryParse(tbx_DmaxMax.Text, out inum) && inum >= 0)
  1012. {
  1013. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1014. }
  1015. else
  1016. {
  1017. MessageBox.Show(table["str10"].ToString());
  1018. return;
  1019. }
  1020. }
  1021. if (!string.IsNullOrWhiteSpace(tB_FieldId.Text))
  1022. {
  1023. int inum = 0;
  1024. if (int.TryParse(tB_FieldId.Text, out inum))
  1025. {
  1026. condition += " and FieldId =" + tB_FieldId.Text;
  1027. }
  1028. else
  1029. {
  1030. MessageBox.Show(table["str10"].ToString());
  1031. return;
  1032. }
  1033. }
  1034. if (!string.IsNullOrWhiteSpace(tB_ParticleId.Text))
  1035. {
  1036. int inum = 0;
  1037. if (int.TryParse(tB_ParticleId.Text, out inum))
  1038. {
  1039. condition += " and ParticleId =" + tB_ParticleId.Text;
  1040. }
  1041. else
  1042. {
  1043. MessageBox.Show(table["str10"].ToString());
  1044. return;
  1045. }
  1046. }
  1047. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text) && !string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1048. {
  1049. if (!CompareInput(tbx_DmaxMin.Text, tbx_DmaxMax.Text))
  1050. {
  1051. MessageBox.Show(table["str11"].ToString());
  1052. return;
  1053. }
  1054. }
  1055. if (!string.IsNullOrWhiteSpace(tbx_DferretMin.Text))
  1056. {
  1057. double dnum = 0;
  1058. int inum = 0;
  1059. if (double.TryParse(tbx_DferretMin.Text, out dnum) && dnum >= 0)
  1060. {
  1061. condition += " and DFERET" + ">" + tbx_DferretMin.Text;
  1062. }
  1063. else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
  1064. {
  1065. condition += " and DFERET" + ">" + tbx_DferretMin.Text;
  1066. }
  1067. else
  1068. {
  1069. MessageBox.Show(table["str10"].ToString());
  1070. return;
  1071. }
  1072. }
  1073. if (!string.IsNullOrWhiteSpace(tbx_DferretMax.Text))
  1074. {
  1075. double dnum = 0;
  1076. int inum = 0;
  1077. if (double.TryParse(tbx_DferretMax.Text, out dnum) && dnum >= 0)
  1078. {
  1079. condition += " and DFERET" + "<" + tbx_DferretMax.Text;
  1080. }
  1081. else if (int.TryParse(tbx_DferretMax.Text, out inum) && inum >= 0)
  1082. {
  1083. condition += " and DFERET" + "<" + tbx_DferretMax.Text;
  1084. }
  1085. else
  1086. {
  1087. MessageBox.Show(table["str10"].ToString());
  1088. return;
  1089. }
  1090. }
  1091. if (!string.IsNullOrWhiteSpace(tbx_DferretMin.Text) && !string.IsNullOrWhiteSpace(tbx_DferretMax.Text))
  1092. {
  1093. if (!CompareInput(tbx_DferretMin.Text, tbx_DferretMax.Text))
  1094. {
  1095. MessageBox.Show(table["str11"].ToString());
  1096. return;
  1097. }
  1098. }
  1099. if (!string.IsNullOrWhiteSpace(tbx_ECDMin.Text))
  1100. {
  1101. double dnum = 0;
  1102. int inum = 0;
  1103. if (double.TryParse(tbx_ECDMin.Text, out dnum) && dnum >= 0)
  1104. {
  1105. double area = Math.PI * dnum / 2 * dnum / 2;
  1106. condition += " and Area" + ">" + area.ToString();
  1107. }
  1108. else if (int.TryParse(tbx_ECDMin.Text, out inum) && inum >= 0)
  1109. {
  1110. double area = Math.PI * dnum / 2 * dnum / 2;
  1111. condition += " and Area" + ">" + area.ToString();
  1112. }
  1113. else
  1114. {
  1115. MessageBox.Show(table["str10"].ToString());
  1116. return;
  1117. }
  1118. }
  1119. if (!string.IsNullOrWhiteSpace(tbx_ECDMax.Text))
  1120. {
  1121. double dnum = 0; int inum = 0;
  1122. if (double.TryParse(tbx_ECDMax.Text, out dnum) && dnum >= 0)
  1123. {
  1124. double area = Math.PI * dnum / 2 * dnum / 2;
  1125. condition += " and Area" + "<" + area.ToString();
  1126. }
  1127. else if (int.TryParse(tbx_ECDMax.Text, out inum) && inum >= 0)
  1128. {
  1129. double area = Math.PI * dnum / 2 * dnum / 2;
  1130. condition += " and Area" + "<" + area.ToString();
  1131. }
  1132. else
  1133. {
  1134. MessageBox.Show(table["str10"].ToString());
  1135. return;
  1136. }
  1137. }
  1138. if (!string.IsNullOrWhiteSpace(tbx_ECDMin.Text) && !string.IsNullOrWhiteSpace(tbx_ECDMax.Text))
  1139. {
  1140. if (!CompareInput(tbx_ECDMin.Text, tbx_ECDMax.Text))
  1141. {
  1142. MessageBox.Show(table["str11"].ToString());
  1143. return;
  1144. }
  1145. }
  1146. if (!string.IsNullOrWhiteSpace(tbx_Type.Text))
  1147. {
  1148. string[] tr = tbx_Type.Text.Split('$');
  1149. condition += " and (";
  1150. for (int i = 0; i < tr.Length; i++)
  1151. {
  1152. if (i == 0)
  1153. {
  1154. condition += " TypeName = '" + tr[i] + "'";
  1155. }
  1156. else
  1157. {
  1158. condition += " or TypeName = '" + tr[i] + "'";
  1159. }
  1160. }
  1161. condition += ")";
  1162. }
  1163. if (m_frm_userprogress.IsDisposed)
  1164. {
  1165. ProgressStart();
  1166. }
  1167. UpdateTable();
  1168. lnkFirst_Click(null, null);
  1169. SetDataGridViewStyle();
  1170. }
  1171. void ProgressStart()
  1172. {
  1173. #region 加载显示进度条部份
  1174. this.Cursor = Cursors.WaitCursor;
  1175. m_frm_userprogress = new Frm_UserProgress();
  1176. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  1177. if (ls_main_form == null)
  1178. {
  1179. m_frm_userprogress.Visible = false;
  1180. }
  1181. else
  1182. {
  1183. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  1184. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  1185. m_frm_userprogress.Show();
  1186. m_frm_userprogress.SetProgressValueAndText(0, "Loading data of particles...");
  1187. }
  1188. #endregion
  1189. }
  1190. /// <summary>
  1191. /// 页面控件呈现
  1192. /// </summary>
  1193. private void DrawControl(bool callEvent)
  1194. {
  1195. BindDataGridView();
  1196. lblTotalCount.Text = RecordCount.ToString();
  1197. lblPageCount.Text = PageCount.ToString();
  1198. txtPageNum.Text = PageIndex.ToString();
  1199. SetFormCtrEnabled();
  1200. if (PageCount == 0 || PageCount == 1)//有且仅有一页
  1201. {
  1202. lnkFirst.Enabled = false;
  1203. lnkPrev.Enabled = false;
  1204. lnkNext.Enabled = false;
  1205. lnkLast.Enabled = false;
  1206. btnGo.Enabled = false;
  1207. }
  1208. else if (PageIndex == 1)//第一页
  1209. {
  1210. lnkFirst.Enabled = false;
  1211. lnkPrev.Enabled = false;
  1212. }
  1213. else if (PageIndex == PageCount)//最后一页
  1214. {
  1215. lnkNext.Enabled = false;
  1216. lnkLast.Enabled = false;
  1217. }
  1218. }
  1219. private void SetFormCtrEnabled()
  1220. {
  1221. lnkFirst.Enabled = true;
  1222. lnkPrev.Enabled = true;
  1223. lnkNext.Enabled = true;
  1224. lnkLast.Enabled = true;
  1225. btnGo.Enabled = true;
  1226. }
  1227. /// <summary>
  1228. /// 分页属性改变了。
  1229. /// </summary>
  1230. private void txtPageSize_TextChanged(object sender, EventArgs e)
  1231. {
  1232. int num = 0;
  1233. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1234. {
  1235. }
  1236. else { txtPageNum.Text = "1"; }
  1237. }
  1238. private void lnkFirst_Click(object sender, EventArgs e)
  1239. {
  1240. PageIndex = 1;
  1241. DrawControl(true);
  1242. }
  1243. private void lnkPrev_Click(object sender, EventArgs e)
  1244. {
  1245. PageIndex = Math.Max(1, PageIndex - 1);
  1246. DrawControl(true);
  1247. }
  1248. private void lnkNext_Click(object sender, EventArgs e)
  1249. {
  1250. PageIndex = Math.Min(PageCount, PageIndex + 1);
  1251. DrawControl(true);
  1252. }
  1253. private void lnkLast_Click(object sender, EventArgs e)
  1254. {
  1255. PageIndex = PageCount;
  1256. DrawControl(true);
  1257. }
  1258. /// <summary>
  1259. /// 跳转
  1260. /// </summary>
  1261. /// <param name="sender"></param>
  1262. /// <param name="e"></param>
  1263. private void btnGo_Click(object sender, EventArgs e)
  1264. {
  1265. int num = 0;
  1266. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1267. {
  1268. if (num > PageCount)
  1269. {
  1270. num = PageCount;
  1271. txtPageNum.Text = PageCount.ToString();
  1272. }
  1273. PageIndex = num;
  1274. DrawControl(true);
  1275. }
  1276. }
  1277. private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
  1278. {
  1279. DisplayData();
  1280. }
  1281. private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
  1282. {
  1283. OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation sfd = new OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation();
  1284. if (sfd.ShowDialog() == DialogResult.OK)
  1285. {
  1286. Cursor = Cursors.WaitCursor;
  1287. if (m_frm_userprogress.IsDisposed)
  1288. {
  1289. ProgressStart();
  1290. }
  1291. IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(); //用于创建.xlsx office2007开始以后的
  1292. ISheet sheet;
  1293. FileStream fs = File.Create(sfd.FileName);
  1294. fs.Close();
  1295. sheet = workbook.CreateSheet("Particles");//创建工作表
  1296. ICellStyle cellStyle = workbook.CreateCellStyle();
  1297. cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  1298. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  1299. //设置上4边
  1300. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1301. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1302. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1303. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1304. //设置字符大小和颜色
  1305. IFont font = workbook.CreateFont();
  1306. font.FontName = "黑体";
  1307. font.FontHeightInPoints = 10;
  1308. cellStyle.SetFont(font);
  1309. //设置颗粒名列宽
  1310. sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
  1311. sheet.SetColumnWidth(2, 7 * 256);//图像列宽
  1312. IRow row;
  1313. ICell cell;
  1314. //插入表头
  1315. row = sheet.CreateRow(1);//从第15行添加一行
  1316. IDrawing patriarch;
  1317. patriarch = sheet.CreateDrawingPatriarch();
  1318. row.Height = 30 * 20;
  1319. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1320. {
  1321. cell = row.CreateCell(i_cell);
  1322. cell.CellStyle = cellStyle;
  1323. cell.SetCellValue(dgV_ParticlesDevidePage.Columns[i_cell].HeaderText);
  1324. }
  1325. m_frm_userprogress.SetProgressValueAndText(0, "export:" + "0" + "/total:" + dgV_ParticlesDevidePage.Rows.Count);
  1326. IClientAnchor anchor;
  1327. int pictureIdx;
  1328. Bitmap bp;
  1329. byte[] bytes;
  1330. IPicture pict;
  1331. //插入表内容
  1332. for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
  1333. {
  1334. if (dgV_ParticlesDevidePage.Rows.Count > 100)
  1335. {
  1336. if (i_row % (dgV_ParticlesDevidePage.Rows.Count / 100) == 0)
  1337. m_frm_userprogress.SetProgressValueAndText(i_row * 100 / dgV_ParticlesDevidePage.Rows.Count, "export:" + i_row + "/total:" + dgV_ParticlesDevidePage.Rows.Count);
  1338. }
  1339. row = sheet.CreateRow(2 + i_row);
  1340. row.Height = 45 * 20;
  1341. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1342. {
  1343. cell = row.CreateCell(i_cell);
  1344. cell.CellStyle = cellStyle;
  1345. if (dgV_ParticlesDevidePage[i_cell, i_row].Value == null)
  1346. continue;
  1347. if (i_cell == 2)
  1348. {
  1349. if (sfd.IfExportPicture)
  1350. {
  1351. //颗粒图像列
  1352. bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
  1353. bytes = ImageConvertToBytes(bp);
  1354. //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
  1355. pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
  1356. //第三步,在sheet中创建画布
  1357. //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
  1358. anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
  1359. //第五步,创建图片
  1360. pict = patriarch.CreatePicture(anchor, pictureIdx);
  1361. }
  1362. }
  1363. else
  1364. {
  1365. //非图像列
  1366. cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
  1367. }
  1368. }
  1369. }
  1370. if (sfd.IfExportSpectrumData)
  1371. {
  1372. ISheet sheet2;
  1373. sheet2 = workbook.CreateSheet("Peak spectrum Data");//创建工作表
  1374. //插入表头
  1375. row = sheet2.CreateRow(1);
  1376. row.Height = 30 * 20;
  1377. cell = row.CreateCell(0);
  1378. cell.CellStyle = cellStyle;
  1379. cell.SetCellValue("rowid");
  1380. for (int i_cell = 1; i_cell < 2001; i_cell++)
  1381. {
  1382. cell = row.CreateCell(i_cell);
  1383. cell.CellStyle = cellStyle;
  1384. if (i_cell == 1)
  1385. {
  1386. cell.SetCellValue("PeakSpectrumData");
  1387. }
  1388. }
  1389. sheet2.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 1, 1, 2000));
  1390. for (int j = 0; j < particles.Rows.Count; j++)
  1391. {
  1392. row = sheet2.CreateRow(2 + j);
  1393. cell = row.CreateCell(0);
  1394. cell.CellStyle = cellStyle;
  1395. cell.SetCellValue(j + 1);
  1396. var tmpPart = Particledata.GetParticleXrayDataByFidAndPid(particles.Rows[j]["fieldid"].ToString(), particles.Rows[j]["particleid"].ToString());
  1397. if (tmpPart != null)
  1398. {
  1399. if (tmpPart.XrayId > -1)
  1400. {
  1401. uint[] Analysis_xray = new uint[2000];
  1402. for (int i = 0; i < 2000; i++)
  1403. {
  1404. Analysis_xray[i] = BitConverter.ToUInt32(tmpPart.XRayData, i * 4);
  1405. cell = row.CreateCell(i + 1);
  1406. cell.CellStyle = cellStyle;
  1407. cell.SetCellValue(Analysis_xray[i]);
  1408. }
  1409. }
  1410. }
  1411. }
  1412. }
  1413. if (sfd.IfExportSpectrumConfirmation)
  1414. {
  1415. ISheet sheet3;
  1416. sheet3 = workbook.CreateSheet("Peak spectrum");
  1417. sheet3.SetColumnWidth(1, 200 * 256);//图像列宽
  1418. //插入表头
  1419. row = sheet3.CreateRow(1);
  1420. row.Height = 30 * 20;
  1421. cell = row.CreateCell(0);
  1422. cell.CellStyle = cellStyle;
  1423. cell.SetCellValue("rowid");
  1424. cell = row.CreateCell(1);
  1425. cell.CellStyle = cellStyle;
  1426. cell.SetCellValue("PeakSpectrum");
  1427. IDrawing drawing;
  1428. IClientAnchor anchor3;
  1429. for (int j = 0; j < particles.Rows.Count; j++)
  1430. {
  1431. row = sheet3.CreateRow(j + 2);
  1432. row.Height = 120 * 20;
  1433. cell = row.CreateCell(0);
  1434. cell.CellStyle = cellStyle;
  1435. cell.SetCellValue(j + 1);
  1436. cell = row.CreateCell(1);
  1437. cell = row.CreateCell(2);
  1438. cell = row.CreateCell(3);
  1439. drawing = sheet3.CreateDrawingPatriarch();
  1440. //锚点
  1441. anchor3 = drawing.CreateAnchor(0, 0, 0, 0, 1, j + 2, 2, j + 3);//XSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2);参数说明:dx1 dy1 起始单元格中的x,y坐标.dx2 dy2 结束单元格中的x,y坐标col1, row1 指定起始的单元格,下标从0开始col2, row2 指定结束的单元格,下标从0开始
  1442. CreateChart(drawing, sheet3, anchor3, j + 2);
  1443. }
  1444. }
  1445. //完成后,对Excel进行保存
  1446. FileStream file = new FileStream(sfd.FileName, FileMode.Create);
  1447. workbook.Write(file);
  1448. file.Close();
  1449. m_frm_userprogress.SetProgressValueAndText(100, "export:" + dgV_ParticlesDevidePage.Rows.Count + "/total:" + dgV_ParticlesDevidePage.Rows.Count);
  1450. //加载完成,关闭进度条
  1451. m_frm_userprogress.Close();
  1452. Cursor = Cursors.Default;
  1453. //导出完成后,打开Excel文件
  1454. if (File.Exists(sfd.FileName))
  1455. {
  1456. //打开刚才导出的文件
  1457. System.Diagnostics.Process.Start(sfd.FileName);
  1458. }
  1459. }
  1460. }
  1461. /// <summary>
  1462. /// 读取标准库的ClassifySTD表
  1463. /// </summary>
  1464. /// <param name="a_address"></param>
  1465. /// <returns></returns>
  1466. private DataTable ReadClassification(string a_address ,string STDName)
  1467. {
  1468. DataTable dt_STDGroups = new DataTable();
  1469. DataTable dt_ClassifySTD = new DataTable();
  1470. DataTable dt_IncAData = new DataTable();
  1471. var systype = m_ReportApp.m_RptConfigFile.Systype;
  1472. if (systype == OTS_SysType_ID.IncA)
  1473. {
  1474. dt_ClassifySTD.Columns.Add("STDId");
  1475. dt_ClassifySTD.Columns.Add("StrName");
  1476. dt_ClassifySTD.Columns.Add("Color");
  1477. dt_ClassifySTD.Columns.Add("KeyElementList");
  1478. dt_ClassifySTD.Columns.Add("SubElementList");
  1479. dt_ClassifySTD.Columns.Add("UsingImgPropertyList");
  1480. dt_ClassifySTD.Columns.Add("UsingOtherPropertyList");
  1481. dt_ClassifySTD.Columns.Add("Expression");
  1482. dt_ClassifySTD.Columns.Add("Hardness");
  1483. dt_ClassifySTD.Columns.Add("Density");
  1484. dt_ClassifySTD.Columns.Add("Electrical_conductivity");
  1485. dt_ClassifySTD.Columns.Add("BSE");
  1486. dt_ClassifySTD.Columns.Add("Formula");
  1487. dt_ClassifySTD.Columns.Add("Element");
  1488. dt_ClassifySTD.Columns.Add("IfElementAnalysis");
  1489. dt_ClassifySTD.Columns.Add("ListNum");
  1490. dt_ClassifySTD.Columns.Add("GroupId");
  1491. dt_ClassifySTD.Columns.Add("GroupName");
  1492. dt_ClassifySTD.Columns.Add("GroupColor");
  1493. DataTable da = Particledata.GetParticleListForParticlSizeID("area", "");
  1494. for (int i = 0; i < da.Rows.Count; i++)
  1495. {
  1496. if (Convert.ToInt64(da.Rows[i]["TypeId"]) > 9)
  1497. {
  1498. DataRow newRow = dt_ClassifySTD.NewRow();
  1499. newRow["STDId"] = da.Rows[i]["TypeId"];
  1500. newRow["StrName"] = da.Rows[i]["TypeName"];
  1501. newRow["Color"] = da.Rows[i]["TypeColor"];
  1502. newRow["GroupId"] = da.Rows[i]["GroupId"];
  1503. newRow["GroupName"] = da.Rows[i]["GroupName"];
  1504. newRow["GroupColor"] = da.Rows[i]["GroupColor"];
  1505. dt_ClassifySTD.Rows.Add(newRow);
  1506. }
  1507. }
  1508. }
  1509. else
  1510. {
  1511. SqLiteHelper sh_STDGroups = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'");
  1512. dt_STDGroups = sh_STDGroups.ExecuteQuery("select * from STDGroups");
  1513. SqLiteHelper sh_ClassifySTD = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'");
  1514. dt_ClassifySTD = sh_ClassifySTD.ExecuteQuery("select * from ClassifySTD");
  1515. dt_ClassifySTD.Columns.Add("GroupName");
  1516. dt_ClassifySTD.Columns.Add("GroupColor");
  1517. for (int i = 0; i < dt_ClassifySTD.Rows.Count; i++)
  1518. {
  1519. for (int a = 0; a < dt_STDGroups.Rows.Count; a++)
  1520. {
  1521. if (dt_ClassifySTD.Rows[i]["GroupId"].ToString() == dt_STDGroups.Rows[a]["id"].ToString())
  1522. {
  1523. dt_ClassifySTD.Rows[i]["GroupName"] = dt_STDGroups.Rows[a]["name"].ToString();
  1524. dt_ClassifySTD.Rows[i]["GroupColor"] = dt_STDGroups.Rows[a]["color"].ToString();
  1525. continue;
  1526. }
  1527. }
  1528. }
  1529. SqLiteHelper sh_Inclusion = new SqLiteHelper("data source='" + a_address + "\\FIELD_FILES\\Inclusion.db" + "'");
  1530. dt_IncAData = sh_Inclusion.ExecuteQuery("select * from IncAData");
  1531. for (int i = 0; i < dt_IncAData.Rows.Count; i++)
  1532. {
  1533. if (Convert.ToInt64(dt_IncAData.Rows[i]["TypeId"]) > 50000)
  1534. {
  1535. DataRow newRow = dt_ClassifySTD.NewRow();
  1536. newRow["STDId"] = dt_IncAData.Rows[i]["TypeId"];
  1537. newRow["StrName"] = dt_IncAData.Rows[i]["TypeName"];
  1538. newRow["Color"] = dt_IncAData.Rows[i]["TypeColor"];
  1539. newRow["GroupId"] = dt_IncAData.Rows[i]["GroupId"];
  1540. newRow["GroupName"] = dt_IncAData.Rows[i]["GroupName"];
  1541. newRow["GroupColor"] = dt_IncAData.Rows[i]["GroupColor"];
  1542. dt_ClassifySTD.Rows.Add(newRow);
  1543. }
  1544. }
  1545. }
  1546. return dt_ClassifySTD;
  1547. }
  1548. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  1549. {
  1550. //如果没有选中颗粒退出
  1551. if (dgV_ParticlesDevidePage.SelectedRows.Count == 0)
  1552. {
  1553. return;
  1554. }
  1555. string CategoryName = "";
  1556. //循环选中颗粒
  1557. for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
  1558. {
  1559. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
  1560. CategoryName = dgvr.Cells[1].Value.ToString();
  1561. }
  1562. string TypeId = "";
  1563. string TypeName = "";
  1564. string TypeColor = "";
  1565. string GroupName = "";
  1566. string GroupID = "";
  1567. string GroupColor = "";
  1568. string[] resulta = result.GetSTDName().Split('.');
  1569. DataTable data = ReadClassification(result.FilePath, resulta[0]);
  1570. ModifyCategoryForm modifyCategoryForm = new ModifyCategoryForm(data, CategoryName);
  1571. DialogResult result1 = modifyCategoryForm.ShowDialog();
  1572. if (modifyCategoryForm.DoYouWantToModifyIt)
  1573. {
  1574. TypeId = modifyCategoryForm.OutTypeAndName[0];
  1575. TypeName = modifyCategoryForm.OutTypeAndName[1];
  1576. TypeColor = modifyCategoryForm.OutTypeAndName[2];
  1577. GroupName = modifyCategoryForm.OutTypeAndName[3];
  1578. GroupID = modifyCategoryForm.OutTypeAndName[4];
  1579. GroupColor= modifyCategoryForm.OutTypeAndName[5];
  1580. List<string> strings = new List<string>();
  1581. strings.Add(TypeId);
  1582. strings.Add(TypeName);
  1583. strings.Add(TypeColor);
  1584. strings.Add(GroupName);
  1585. strings.Add(GroupID);
  1586. strings.Add(GroupColor);
  1587. DialogResult result2 = MessageBox.Show("是否寻找相似颗粒并重命名?", "Tip", MessageBoxButtons.YesNo);
  1588. if (result2 == DialogResult.Yes)
  1589. {
  1590. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  1591. if (sel == (int)SelItem.MergeParticles)
  1592. {
  1593. return;
  1594. }
  1595. var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
  1596. uint[] Search_xray = new uint[2000];
  1597. int classifyid = -1;
  1598. if (SelectRows.Count != 0)
  1599. {
  1600. if (SelectRows.Count == 1)
  1601. {
  1602. DataGridViewRow dgvr = SelectRows[0];
  1603. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1604. List<string> list_str = (List<string>)ls_bp.Tag;
  1605. classifyid = Convert.ToInt32(list_str[2]);
  1606. uint[] Analysis_xray = new uint[2000];
  1607. int i_xray_id = 0;
  1608. List<Element> list_celementchemistryclr = new List<Element>();
  1609. ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  1610. }
  1611. }
  1612. ListOfSimilarParticles Form_listOfSimilarParticles = new ListOfSimilarParticles(this, Search_xray, classifyid,strings, m_ReportApp);
  1613. DialogResult result3=Form_listOfSimilarParticles.ShowDialog();
  1614. if(result3== DialogResult.OK)
  1615. {
  1616. }
  1617. else
  1618. {
  1619. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  1620. for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
  1621. {
  1622. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
  1623. dgvr.Cells[1].Value = TypeName;
  1624. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1625. List<string> list_str = (List<string>)ls_bp.Tag;
  1626. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1627. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1628. List<int> ints = new List<int>();
  1629. ints.Add(i_ls_fieldid);
  1630. ints.Add(i_ls_particleid);
  1631. var cmd = Particledata.GetUpdataAIncACmd(ints, strings);
  1632. cmdlist.Add(cmd);
  1633. }
  1634. Particledata.ExecuteNonQueryBatch(cmdlist);
  1635. }
  1636. }
  1637. else
  1638. {
  1639. List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
  1640. for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
  1641. {
  1642. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
  1643. dgvr.Cells[1].Value = TypeName;
  1644. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1645. List<string> list_str = (List<string>)ls_bp.Tag;
  1646. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1647. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1648. List<int> ints = new List<int>();
  1649. ints.Add(i_ls_fieldid);
  1650. ints.Add(i_ls_particleid);
  1651. var cmd = Particledata.GetUpdataAIncACmd(ints, strings);
  1652. cmdlist.Add(cmd);
  1653. }
  1654. Particledata.ExecuteNonQueryBatch(cmdlist);
  1655. }
  1656. UpdateTable();
  1657. lnkFirst_Click(null, null);
  1658. SetDataGridViewStyle();
  1659. DataTable table = GetClassificationOfAllParticles();
  1660. if (table != null)
  1661. {
  1662. if (table.Rows.Count > 0)
  1663. {
  1664. foreach (DataRow row in table.Rows)
  1665. {
  1666. tbx_Type.Text += row["TypeName"].ToString() + '$';
  1667. }
  1668. }
  1669. if (tbx_Type.Text != "")
  1670. {
  1671. tbx_Type.Text = tbx_Type.Text.Remove(tbx_Type.Text.Length - 1);
  1672. }
  1673. }
  1674. dgV_ParticlesDevidePage.Focus();
  1675. }
  1676. }
  1677. void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, int rowid)
  1678. {
  1679. var chart = drawing.CreateChart(anchor) as XSSFChart;
  1680. //图表
  1681. var data = chart.ChartDataFactory.CreateLineChartData<double, double>(); //折线图
  1682. IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
  1683. IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
  1684. leftAxis.Crosses = AxisCrosses.AutoZero;
  1685. leftAxis.IsVisible = true;
  1686. bottomAxis.IsVisible = true;
  1687. //数据源
  1688. IChartDataSource<double> ys = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(rowid, rowid, 1, 2001));
  1689. Double[] doubles = new Double[2000];
  1690. for (int i = 0; i < 2000; i++)
  1691. {
  1692. doubles[i] = i;
  1693. }
  1694. IChartDataSource<double> xs = DataSources.FromArray(doubles);
  1695. //数据系列
  1696. var s1 = data.AddSeries(xs, ys);
  1697. }
  1698. /// <summary>
  1699. /// 将image转成bytes
  1700. /// </summary>
  1701. /// <param name="in_img"></param>
  1702. /// <returns></returns>
  1703. public byte[] ImageConvertToBytes(System.Drawing.Image in_img)
  1704. {
  1705. MemoryStream ms = new MemoryStream();
  1706. in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1707. return ms.ToArray();
  1708. }
  1709. private void ToolStripMenuItem_Delete_Particle_Click(object sender, EventArgs e)
  1710. {
  1711. string path = result.FilePath;
  1712. ParticleData fielddata = new ParticleData(result.FilePath);
  1713. List<Particle> particles = fielddata.GetParticleAllList();
  1714. DialogResult dr = MessageBox.Show("Remove all these particles permanently?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1715. if (dr == DialogResult.OK)
  1716. {
  1717. List<Particle> list_Part = new List<Particle>();
  1718. for (int ii = 0; ii < dgV_ParticlesDevidePage.SelectedRows.Count; ii++)
  1719. {
  1720. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[ii];
  1721. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1722. List<string> list_str = (List<string>)ls_bp.Tag;
  1723. if (list_str != null)
  1724. {
  1725. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1726. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1727. foreach (Particle item in particles)
  1728. {
  1729. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  1730. {
  1731. if (DeleteParticlesFromLibrary(item.ParticleId, item.FieldId))
  1732. {
  1733. for (int i = 0; i < particlesAll.Rows.Count; i++)
  1734. {
  1735. if (particlesAll.Rows[i]["Fieldid"].ToString() == item.FieldId.ToString() && particlesAll.Rows[i]["Particleid"].ToString() == item.ParticleId.ToString())
  1736. {
  1737. particlesAll.Rows.RemoveAt(i);
  1738. list_Part.Add(item);
  1739. }
  1740. }
  1741. }
  1742. else
  1743. {
  1744. MessageBox.Show("Delete failed");
  1745. }
  1746. break;
  1747. }
  1748. }
  1749. }
  1750. }
  1751. RecordCount = recordCount - dgV_ParticlesDevidePage.SelectedRows.Count;
  1752. lblTotalCount.Text = RecordCount.ToString();
  1753. foreach (DataGridViewRow Row in dgV_ParticlesDevidePage.SelectedRows)
  1754. {
  1755. dgV_ParticlesDevidePage.Rows.Remove(Row);
  1756. }
  1757. if (dgV_ParticlesDevidePage.Rows.Count == 0)
  1758. {
  1759. DisplayData();
  1760. }
  1761. for (int j = 0; j < dgV_ParticlesDevidePage.Rows.Count; j++)
  1762. {
  1763. dgV_ParticlesDevidePage.Rows[j].Cells[0].Value = (pageSize * (PageIndex - 1) + j + 1).ToString();
  1764. }
  1765. if (m_ReportApp.im_Control_DrawDistrbutionImageAndBSE != null)
  1766. {
  1767. m_ReportApp.im_Control_DrawDistrbutionImageAndBSE.DeletesParticlesSynchronously(list_Part);
  1768. }
  1769. else
  1770. {
  1771. var _Control_DrawDistrbutionImageAndBSE = new OTSIncAReportGraph.Controls.Control_DrawDistrbutionImageAndBSE(m_ReportApp);
  1772. foreach (var p in list_Part)
  1773. {
  1774. _Control_DrawDistrbutionImageAndBSE.DeleteParticlesFromLibrary(p.ParticleId, p.FieldId);
  1775. }
  1776. }
  1777. }
  1778. }
  1779. private bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
  1780. {
  1781. bool DoesItExist = false;
  1782. for (int i = 1; i < 201; i++)
  1783. {
  1784. if (System.IO.Directory.Exists(result.FilePath + "\\FIELD_FILES\\Backups" + i.ToString()))
  1785. {
  1786. DoesItExist = true;
  1787. break;
  1788. }
  1789. }
  1790. if (!DoesItExist)
  1791. {
  1792. //备份数据库
  1793. BackupDatabase();
  1794. }
  1795. DoesItExist = false;
  1796. //防止为空校验判断
  1797. if (result.List_OTSField == null)
  1798. return false;
  1799. Particle particle = result.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  1800. if (new ParticleData(result.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
  1801. {
  1802. return true;
  1803. }
  1804. else
  1805. {
  1806. return false;
  1807. }
  1808. }
  1809. private bool BackupDatabase()
  1810. {
  1811. //创建备份数据库文件夹
  1812. string sourcePath = result.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  1813. string sourceName = "Inclusion.db";//源文件名称
  1814. string folderPath = result.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  1815. string Fields = "";
  1816. for (int i = 1; i < 201; i++)
  1817. {
  1818. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  1819. {
  1820. Fields = folderPath + i.ToString();
  1821. continue;
  1822. }
  1823. else
  1824. {
  1825. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  1826. Fields = folderPath + i.ToString();
  1827. break;
  1828. }
  1829. }
  1830. if (Fields == "")
  1831. {
  1832. return false;
  1833. }
  1834. //复制数据库文件
  1835. string targetPath = Path.Combine(Fields, sourceName);
  1836. FileInfo file = new FileInfo(sourcePath);
  1837. if (file.Exists)
  1838. {
  1839. file.CopyTo(targetPath, true);
  1840. }
  1841. return true;
  1842. }
  1843. private void DisplayData()
  1844. {
  1845. if (cbB_PageSize.SelectedItem.ToString() == "All")
  1846. {
  1847. pageSize = -1;
  1848. }
  1849. else
  1850. {
  1851. pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
  1852. }
  1853. lnkFirst_Click(null, null);
  1854. SetDataGridViewStyle();
  1855. }
  1856. string ChangeHardnessColor(string Hardness)
  1857. {
  1858. string str = System.Text.RegularExpressions.Regex.Replace(Hardness, @"[^\d.\d]", "");
  1859. double hd;
  1860. if (double.TryParse(str, out hd))
  1861. {
  1862. if (hd >= 1000)
  1863. {
  1864. return "#FF0000";
  1865. }
  1866. else return "";
  1867. }
  1868. else
  1869. return "";
  1870. }
  1871. /// <summary>
  1872. ///
  1873. /// </summary>
  1874. /// <param name="str_resultPath"></param>
  1875. /// <param name="dataTable"></param>
  1876. /// <param name="vs"></param>
  1877. /// <param name="dt_FIeld"></param>
  1878. public void Out_MarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable, out List<string> vs, out DataTable dt_FIeld)
  1879. {
  1880. Init();
  1881. List<string> maxlength = new List<string>();
  1882. for (int i = 0; i < dataTable.Rows.Count; i++)
  1883. {
  1884. if (Convert.ToInt32(dataTable.Rows[i]["TypeId"]) > 9)
  1885. {
  1886. if (maxlength.Count < 10)
  1887. {
  1888. maxlength.Add(dataTable.Rows[i]["Fieldid"].ToString());
  1889. }
  1890. else
  1891. {
  1892. break;
  1893. }
  1894. }
  1895. }
  1896. List<string> max_list = maxlength.Distinct().ToList();
  1897. string str_path_FIELD_FILES = str_resultPath + "\\FIELD_FILES\\";
  1898. int intQuantity = 0;
  1899. dt_FIeld = new DataTable();
  1900. vs = new List<string>();
  1901. ResultFile resfile = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  1902. float PixelSize = resfile.GetPixelSize();
  1903. float ScanFieldSizeX = resfile.GetScanFieldSizeX();
  1904. int gauge = RulerSelection(ScanFieldSizeX);
  1905. float RulerPixels = gauge / PixelSize;
  1906. DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
  1907. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
  1908. if (theFolder.Exists)
  1909. {
  1910. DataTable dt = new DataTable();
  1911. dt.Columns.Add("fieldid");
  1912. dt.Columns.Add("id");
  1913. dt.Columns.Add("fieldName");
  1914. dt.Columns.Add("cunt", typeof(int));
  1915. dt.Columns.Add("fieldFullName");
  1916. for (int i = 0; i < max_list.Count; i++)
  1917. {
  1918. foreach (FileInfo nextifile in theFolder.GetFiles())
  1919. {
  1920. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  1921. {
  1922. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  1923. str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
  1924. bool bl = false;
  1925. if (str_fieldid == max_list[i].ToString())
  1926. {
  1927. bl = true;
  1928. }
  1929. if (bl)
  1930. {
  1931. DataRow dr = dt.NewRow();
  1932. dr["fieldid"] = " fieldid = " + str_fieldid;
  1933. int drcunt = 0;
  1934. for (int ia = 0; ia < dataTable.Rows.Count; ia++)
  1935. {
  1936. if (dataTable.Rows[ia]["fieldid"].ToString() == str_fieldid.ToString())
  1937. {
  1938. drcunt++;
  1939. }
  1940. }
  1941. dr["cunt"] = drcunt;
  1942. dr["fieldName"] = nextifile.Name;
  1943. dr["fieldFullName"] = nextifile.FullName;
  1944. dr["id"] = str_fieldid;
  1945. dt.Rows.Add(dr);
  1946. }
  1947. }
  1948. }
  1949. }
  1950. dt_FIeld = dt.Copy();
  1951. dt_FIeld.Columns.Add("Field_pic", typeof(Bitmap));
  1952. for (int i = 0; i < dt_FIeld.Rows.Count; i++)
  1953. {
  1954. int drCount = 0;
  1955. for (int ia = 0; ia < dataTable.Rows.Count; ia++)
  1956. if (Convert.ToInt32(dt_FIeld.Rows[i]["id"]) == Convert.ToInt32(dataTable.Rows[ia]["fieldid"]))
  1957. drCount++;
  1958. if (drCount > 0)
  1959. {
  1960. vs.Add(dt_FIeld.Rows[i]["id"].ToString());
  1961. Image img = Image.FromFile(dt_FIeld.Rows[i]["fieldFullName"].ToString());
  1962. Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  1963. using (Graphics g = Graphics.FromImage(ls_fieldbp))
  1964. {
  1965. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1966. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1967. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1968. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
  1969. }
  1970. img.Dispose();
  1971. img = null;
  1972. //循环将颗粒,进行标记到bitmap图上
  1973. DataRow[] drlist = dt_AllParticle.Select(dt_FIeld.Rows[i]["fieldid"].ToString());
  1974. if (drlist.Count() > 0)
  1975. intQuantity = intQuantity + 1;
  1976. for (int i_row = 0; i_row < drlist.Count(); i_row++)
  1977. {
  1978. string str_particleid = drlist[i_row]["particleid"].ToString();
  1979. string str_stdtypeid = drlist[i_row]["typeid"].ToString();
  1980. string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
  1981. string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
  1982. string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
  1983. string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
  1984. //确定需要标记颗粒的定位
  1985. Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
  1986. Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
  1987. //向帧图进行标记颗粒位置
  1988. Graphics g = Graphics.FromImage(ls_fieldbp);
  1989. g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
  1990. //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
  1991. int ls_offsetx = offset_rect.X + offset_rect.Width;
  1992. if (ls_offsetx > ls_fieldbp.Width - 10)
  1993. {
  1994. ls_offsetx = offset_rect.X - 10;
  1995. }
  1996. g.DrawString(dt_FIeld.Rows[i]["id"].ToString() + "" + str_particleid.ToString(), new Font("黑体", 8), new SolidBrush(Color.Aqua), new PointF(ls_offsetx, offset_rect.Y));
  1997. var bitmap = DrawRuler(ls_fieldbp, (int)(RulerPixels / 2), 2, (gauge / 2).ToString() + "μm");
  1998. dt_FIeld.Rows[i]["Field_pic"] = bitmap;
  1999. }
  2000. }
  2001. }
  2002. }
  2003. GC.Collect();
  2004. GC.WaitForPendingFinalizers();
  2005. }
  2006. /// <summary>
  2007. /// 在图片上绘制标尺
  2008. /// </summary>
  2009. /// <param name="bitmap">图片</param>
  2010. /// <param name="LineLength">线长(像素)</param>
  2011. /// <param name="LineWidth">线宽(像素)</param>
  2012. /// <returns></returns>
  2013. private Bitmap DrawRuler(Bitmap bitmap, int LineLength, int LineWidth, string a_str)
  2014. {
  2015. if (bitmap == null)
  2016. throw new ArgumentNullException(nameof(bitmap));
  2017. // 创建一个新的Bitmap,并设置其大小与原图相同
  2018. Bitmap rgbBitmap = new Bitmap(bitmap.Width, bitmap.Height);
  2019. using (Graphics graphics = Graphics.FromImage(rgbBitmap))
  2020. {
  2021. // 将原图转换为RGB格式,并绘制到新的Bitmap上
  2022. graphics.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
  2023. Color color = FromHex("#00FF00");
  2024. //Color color = FromHex("#00FF00");
  2025. // 设置线条颜色和宽度
  2026. Pen pen = new Pen(color, LineWidth);
  2027. Font font = new Font("Arial", 20, GraphicsUnit.Pixel);
  2028. Brush brush = new SolidBrush(color);
  2029. StringFormat stringFormat = new StringFormat();
  2030. stringFormat.Alignment = StringAlignment.Center; // 居中对齐
  2031. stringFormat.LineAlignment = StringAlignment.Center; // 居中对齐行
  2032. // 绘制文字
  2033. SizeF textSize = Graphics.FromImage(bitmap).MeasureString(a_str, font);
  2034. PointF point = new PointF();
  2035. // 计算文本应该开始的位置,使其居中
  2036. point.X = (bitmap.Width - LineLength - 20) + ((LineLength - textSize.Width) / 2);
  2037. point.Y = bitmap.Height - 80;
  2038. graphics.DrawString(a_str, font, new SolidBrush(color), point);
  2039. graphics.DrawLine(pen, bitmap.Width - LineLength - 20, bitmap.Height - 40, bitmap.Width - 20, bitmap.Height - 40);
  2040. graphics.DrawLine(pen, bitmap.Width - LineLength - 20, bitmap.Height - 40, bitmap.Width - LineLength - 20, bitmap.Height - 50);
  2041. graphics.DrawLine(pen, bitmap.Width - 20, bitmap.Height - 40, bitmap.Width - 20, bitmap.Height - 50);
  2042. }
  2043. return rgbBitmap;
  2044. }
  2045. private static Color FromHex(string hex)
  2046. {
  2047. hex = hex.Replace("#", ""); // 移除 # 前缀
  2048. byte a = 255; // 默认Alpha值为255(不透明)
  2049. byte r = Convert.ToByte(hex.Substring(0, 2), 16);
  2050. byte g = Convert.ToByte(hex.Substring(2, 2), 16);
  2051. byte b = Convert.ToByte(hex.Substring(4, 2), 16);
  2052. return Color.FromArgb(a, r, g, b);
  2053. }
  2054. /// <summary>
  2055. /// 判断当前图片应该使用多大标尺
  2056. /// </summary>
  2057. /// <param name="a_value"> </param>
  2058. /// <returns></returns>
  2059. private int RulerSelection(float a_value)
  2060. {
  2061. int value = 0;
  2062. a_value = a_value / 2;
  2063. for (int i = 10; i < 5000; i += 5)
  2064. {
  2065. if (a_value < i)
  2066. {
  2067. value = i - 5;
  2068. break;
  2069. }
  2070. }
  2071. if (value == 0)
  2072. {
  2073. value = 5000;
  2074. }
  2075. return value;
  2076. }
  2077. private void dgV_ParticlesDevidePage_MouseDown(object sender, MouseEventArgs e)
  2078. {
  2079. var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
  2080. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  2081. {
  2082. if (sel != (int)SelItem.MergeParticles)
  2083. {
  2084. if (SelectRows != null && SelectRows.Count == 1)
  2085. {
  2086. DataGridViewRow dgvr = SelectRows[0];
  2087. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  2088. List<string> list_str = (List<string>)ls_bp.Tag;
  2089. }
  2090. ToolStripMenuItemDelete_Particle.Visible = true;
  2091. }
  2092. else
  2093. {
  2094. ToolStripMenuItemDelete_Particle.Visible = false;
  2095. }
  2096. }
  2097. }
  2098. /// <summary>
  2099. /// 去除拼接颗粒组成颗粒
  2100. /// </summary>
  2101. /// <param name="dataTable_Particle"></param>
  2102. /// <param name="dataTable_MergeParticles"></param>
  2103. public void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
  2104. {
  2105. foreach (DataRow row in dataTable_Particle.Rows)
  2106. {
  2107. foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
  2108. {
  2109. string subt = MergeParticlesRow["SubParticles"].ToString();
  2110. string[] sub = subt.Split(',');
  2111. if (row.RowState == DataRowState.Deleted)
  2112. {
  2113. break;
  2114. }
  2115. if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
  2116. {
  2117. row.Delete();
  2118. break;
  2119. }
  2120. if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
  2121. {
  2122. row.Delete();
  2123. break; ;
  2124. }
  2125. }
  2126. }
  2127. dataTable_Particle.AcceptChanges();
  2128. }
  2129. private void btn_showconfig_Click(object sender, EventArgs e)
  2130. {
  2131. var p = particles; List<string> ele = new List<string>();
  2132. string elementsstr = "";
  2133. foreach (DataRow row in particles.Rows)
  2134. {
  2135. string[] strcbo = row["Element"].ToString().Split(';');
  2136. for (int j = 0; j < strcbo.Length; j++)
  2137. {
  2138. string[] str = strcbo[j].Split('-');
  2139. if (!ele.Contains(str[0]) && str[0] != "")
  2140. {
  2141. if (str[1] != "" && double.Parse(str[1]) != 0) //咨询demo后,元素含量返回值为零时一般去除此元素
  2142. { ele.Add(str[0]); }
  2143. }
  2144. }
  2145. }
  2146. foreach (var el in ele)
  2147. {
  2148. elementsstr += el.ToString() + ',';
  2149. }
  2150. if (elementsstr != "")
  2151. {
  2152. elementsstr = elementsstr.Remove(elementsstr.Length - 1, 1);
  2153. }
  2154. m_particlesGridDevidePageShowConfig = new ParticlesGridDevidePageShowConfig(m_ReportApp.m_RptConfigFile.Systype, elementsstr);
  2155. m_particlesGridDevidePageShowConfig.ShowDialog();
  2156. if (m_particlesGridDevidePageShowConfig.DialogResult == DialogResult.OK)
  2157. {
  2158. dgV_ParticlesDevidePage.Rows.Clear();
  2159. dgV_ParticlesDevidePage.Columns.Clear();
  2160. BindDataGridView();
  2161. SetDataGridViewStyle();
  2162. }
  2163. }
  2164. private void SaveParticleslist_select()
  2165. {
  2166. ParticleData fielddata = new ParticleData(result.FilePath);
  2167. List<Particle> particles = fielddata.GetParticleAllList();
  2168. Particleslist_selecttodisplay.Clear();
  2169. for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
  2170. {
  2171. //从事先加载的Bitmap对象的Tag中取出List<string>
  2172. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
  2173. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  2174. List<string> list_str = (List<string>)ls_bp.Tag;
  2175. if (list_str != null)
  2176. {
  2177. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  2178. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  2179. foreach (Particle item in particles)
  2180. {
  2181. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  2182. {
  2183. Particleslist_selecttodisplay.Add(item);
  2184. break;
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. public List<Particle> GetParticleslist_select()
  2191. {
  2192. return Particleslist_selecttodisplay;
  2193. }
  2194. private void dgV_ParticlesDevidePage_MouseUp(object sender, MouseEventArgs e)
  2195. {
  2196. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  2197. if (sel == (int)SelItem.MergeParticles)
  2198. {
  2199. return;
  2200. }
  2201. var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
  2202. if (SelectRows.Count != 0)
  2203. {
  2204. if (SelectRows.Count == 1)
  2205. {
  2206. DataGridViewRow dgvr = SelectRows[0];
  2207. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  2208. List<string> list_str = (List<string>)ls_bp.Tag;
  2209. uint[] Search_xray = new uint[2000];
  2210. uint[] Analysis_xray = new uint[2000];
  2211. int i_xray_id = 0;
  2212. List<Element> list_celementchemistryclr = new List<Element>();
  2213. ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  2214. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  2215. for (int i = 0; i < list_celementchemistryclr.Count; i++)
  2216. {
  2217. ShowElementInfo ls_sei = new ShowElementInfo();
  2218. ls_sei.ElementName = list_celementchemistryclr[i].Name;
  2219. ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  2220. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  2221. double de_sx2 = 0;
  2222. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  2223. {
  2224. de_sx2 = 0;
  2225. }
  2226. else
  2227. {
  2228. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  2229. }
  2230. ls_sei.dLF = de_sx2;
  2231. list_showelementinfo.Add(ls_sei);
  2232. }
  2233. list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
  2234. string str_IncAName = "";
  2235. str_IncAName = Convert.ToString(dgvr.Cells[1].Value);
  2236. Particle particle = result.List_OTSField.Find(x => x.FieldID == Convert.ToInt32(dgvr.Cells["fieldid"].Value)).ParticleList.Find(x => x.ParticleId == Convert.ToInt32(dgvr.Cells["particleId"].Value));
  2237. if (particle == null)
  2238. {
  2239. return;
  2240. }
  2241. control_XRayTable1.SetParticleInfo("Area:" + Math.Round(particle.Area, 2) + " " + "DMAX:" + Math.Round(particle.DMAX, 2) + " " + "DELONG:" + Math.Round(particle.DELONG, 2) + " " + "DFERET:" + Math.Round(particle.DFERET, 2) + " " + "DINSCR:" + Math.Round(particle.DINSCR, 2) + "\n" + "DMEAN:" + Math.Round(particle.DMEAN, 2) + " " + "DMIN:" + Math.Round(particle.DMIN, 2) + " " + "DPERP:" + Math.Round(particle.DPERP, 2) + " " + "ORIENTATION:" + Math.Round(particle.ORIENTATION, 2) + " " + "PERIMETER:" + Math.Round(particle.PERIMETER, 2));
  2242. control_XRayTable1.Visible = true;
  2243. control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
  2244. //颗粒国标信息
  2245. control_XRayTable1.GBInfoStr = "";
  2246. control_XRayTable1.MaterialName = str_IncAName;//杂夹物
  2247. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  2248. string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
  2249. DataRow[] drs = particles.Select(str);
  2250. if (drs.Length > 0)
  2251. {
  2252. Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
  2253. Bitmap dpImage = new Bitmap(result.GetImageWidth(), result.GetImageHeight());
  2254. using (Graphics graphics = Graphics.FromImage(dpImage))
  2255. {
  2256. graphics.Clear(Color.White); // 清除位图背景为白色
  2257. }
  2258. string filePath = result.FilePath + "\\FIELD_FILES\\";
  2259. string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
  2260. Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
  2261. foreach (Segment seg in particle.SegmentList)
  2262. {
  2263. int f_length = seg.Length;
  2264. for (int m = 0; m < f_length; m++)
  2265. {
  2266. int lsjs_x = seg.Start + m;
  2267. int lsjs_y = seg.Height;
  2268. var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y);
  2269. dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
  2270. }
  2271. }
  2272. Bitmap bmap = Particledata.GetBitmapByParticle(dpImage, rectangle);
  2273. Bitmap bmap1 = Particledata.GetBitmapByParticle(m_originalImage, rectangle);
  2274. control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
  2275. Invalidate();
  2276. }
  2277. else
  2278. {
  2279. control_XRayTable1.Visible = false;
  2280. }
  2281. }
  2282. SaveParticleslist_select();
  2283. }
  2284. }
  2285. private void dgV_ParticlesDevidePage_KeyDown(object sender, KeyEventArgs e)
  2286. {
  2287. if (e.KeyData == Keys.Delete)
  2288. {
  2289. ToolStripMenuItem_Delete_Particle_Click(null, null);
  2290. }
  2291. }
  2292. private void dgV_ParticlesDevidePage_KeyUp(object sender, KeyEventArgs e)
  2293. {
  2294. if (e.KeyData == Keys.Down)
  2295. {
  2296. dgV_ParticlesDevidePage_MouseUp(null, null);
  2297. }
  2298. if (e.KeyData == Keys.Up)
  2299. {
  2300. dgV_ParticlesDevidePage_MouseUp(null, null);
  2301. }
  2302. }
  2303. private void tbx_Type_Click(object sender, EventArgs e)
  2304. {
  2305. ParticleClassificationSelect particleClassificationSelect = new ParticleClassificationSelect(this, tbx_Type.Text);
  2306. DialogResult result = particleClassificationSelect.ShowDialog();
  2307. if (result == DialogResult.OK)
  2308. {
  2309. condition = "";
  2310. tbx_Type.Text = particleClassificationSelect.ParticleClassificationSelected;
  2311. string[] tr = tbx_Type.Text.Split(',');
  2312. condition += " and (";
  2313. for (int i = 0; i < tr.Length; i++)
  2314. {
  2315. if (i == 0)
  2316. {
  2317. condition += " TypeName = '" + tr[i] + "'";
  2318. }
  2319. else
  2320. {
  2321. condition += " or TypeName = '" + tr[i] + "'";
  2322. }
  2323. }
  2324. condition += ")";
  2325. if (m_frm_userprogress.IsDisposed)
  2326. {
  2327. ProgressStart();
  2328. }
  2329. UpdateTable();
  2330. lnkFirst_Click(null, null);
  2331. SetDataGridViewStyle();
  2332. }
  2333. }
  2334. private void btn_particletypesel_Click(object sender, EventArgs e)
  2335. {
  2336. ParticleClassificationSelect particleClassificationSelect = new ParticleClassificationSelect(this, tbx_Type.Text);
  2337. DialogResult result = particleClassificationSelect.ShowDialog();
  2338. if (result == DialogResult.OK)
  2339. {
  2340. condition = "";
  2341. tbx_Type.Text = "";
  2342. if (particleClassificationSelect.ParticleClassificationSelected != "")
  2343. {
  2344. tbx_Type.Text = particleClassificationSelect.ParticleClassificationSelected;
  2345. btn_Sel_Click(null, null);
  2346. }
  2347. }
  2348. }
  2349. public DataTable GetClassificationOfAllParticles()
  2350. {
  2351. string str = "";
  2352. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  2353. if (sel == (int)SelItem.analyticalParticle)
  2354. {
  2355. str = "where xrayid > -1 and typeid !=9 and typeid !=-1 and typeid !=4";
  2356. }
  2357. else if (sel == (int)SelItem.otherParticles)
  2358. {
  2359. str = "where typeid =9 or typeid =-1 or typeid =4";
  2360. }
  2361. else
  2362. {
  2363. }
  2364. DataTable table = Particledata.GetClassificationOfAllParticles(str);
  2365. return table;
  2366. }
  2367. private void 根据相似度批量修改ToolStripMenuItem_Click(object sender, EventArgs e)
  2368. {
  2369. //如果没有选中颗粒退出
  2370. if (dgV_ParticlesDevidePage.SelectedRows.Count == 0)
  2371. {
  2372. return;
  2373. }
  2374. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  2375. if (sel == (int)SelItem.MergeParticles)
  2376. {
  2377. return;
  2378. }
  2379. var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
  2380. uint[] Search_xray = new uint[2000];
  2381. int classifyid = -1;
  2382. if (SelectRows.Count != 0)
  2383. {
  2384. if (SelectRows.Count == 1)
  2385. {
  2386. DataGridViewRow dgvr = SelectRows[0];
  2387. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  2388. List<string> list_str = (List<string>)ls_bp.Tag;
  2389. classifyid = Convert.ToInt32(list_str[2]);
  2390. uint[] Analysis_xray = new uint[2000];
  2391. int i_xray_id = 0;
  2392. List<Element> list_celementchemistryclr = new List<Element>();
  2393. ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  2394. }
  2395. }
  2396. ListOfSimilarParticles Form_listOfSimilarParticles = new ListOfSimilarParticles(this, Search_xray, classifyid, m_ReportApp);
  2397. DialogResult result3 = Form_listOfSimilarParticles.ShowDialog();
  2398. if (result3 == DialogResult.OK)
  2399. {
  2400. UpdateTable();
  2401. lnkFirst_Click(null, null);
  2402. SetDataGridViewStyle();
  2403. DataTable table = GetClassificationOfAllParticles();
  2404. if (table != null)
  2405. {
  2406. if (table.Rows.Count > 0)
  2407. {
  2408. foreach (DataRow row in table.Rows)
  2409. {
  2410. tbx_Type.Text += row["TypeName"].ToString() + '$';
  2411. }
  2412. }
  2413. if (tbx_Type.Text != "")
  2414. {
  2415. tbx_Type.Text = tbx_Type.Text.Remove(tbx_Type.Text.Length - 1);
  2416. }
  2417. }
  2418. dgV_ParticlesDevidePage.Focus();
  2419. }
  2420. else
  2421. {
  2422. }
  2423. }
  2424. }
  2425. }