ParticlesGridDevidePage.cs 120 KB

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