ParticlesGridDevidePage.cs 113 KB

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