ParticlesGridDevidePage.cs 106 KB

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