ParticlesGridDevidePage.cs 119 KB

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