ParticlesGridDevidePage.cs 105 KB

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