ParticlesGridDevidePage.cs 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030
  1. using NPOI.HSSF.UserModel;
  2. using NPOI.SS.UserModel;
  3. using OTSIncAReportApp;
  4. using OTSIncAReportApp._1_UI;
  5. using OTSIncAReportApp.DataOperation.DataAccess;
  6. using OTSCommon.Model;
  7. using OTSIncAReportApp.SysMgrTools;
  8. using OTSIncAReportGraph.Class;
  9. using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
  10. using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
  11. using OTSIncAReportMailInterface;
  12. using System;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Drawing.Imaging;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Reflection;
  21. using System.Threading;
  22. using System.Windows.Forms;
  23. namespace OTSIncAReportGrids
  24. {
  25. public partial class ParticlesGridDevidePage : UserControl
  26. {
  27. #region 枚举定义
  28. /// <summary>
  29. /// 样品台X轴方向
  30. /// </summary>
  31. enum OTS_X_AXIS_DIRECTION
  32. {
  33. LEFT_TOWARD = 0,
  34. RIGHT_TOWARD = 1
  35. }
  36. /// <summary>
  37. /// 样品台Y轴方向
  38. /// </summary>
  39. enum OTS_Y_AXIS_DIRECTION
  40. {
  41. UP_TOWARD = 0,
  42. DOWN_TOWARD = 1
  43. }
  44. #endregion
  45. //设置模拟数据表
  46. public DataTable m_dt = new DataTable();
  47. //底层操作类
  48. OTSReportGridsFun m_OTSIncAReportGridsFun = null;
  49. //进度条窗体
  50. public Frm_UserProgress m_frm_userprogress;
  51. //移动SEM到指定位置发生线程
  52. private Thread m_mythread;
  53. //记录线程是否已经运行完成的状态
  54. private bool m_mythread_state = false;
  55. //导出图像文件的路径
  56. private string m_imagefilepath = "";
  57. //显示元素列表
  58. public List<string> m_list_elementscolname = null;
  59. //单个数据源所拥有的列数,这里保存下来,供导出模块使用
  60. public int m_oneresult_columncount = 0;
  61. OTSImageDisHelp m_ReportFun = null;
  62. private OTSImageDisHelp ReportFun { get => m_ReportFun; set => m_ReportFun = value; }
  63. //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
  64. public List<int> m_list_oneresult_columncount;
  65. //国际化
  66. Language lan;
  67. Hashtable table;
  68. //测量结果
  69. ResultFile result = null;
  70. //二次测量参数页面
  71. frmReMeasure frmReMeasure = new frmReMeasure();
  72. frmReportConditionChoose m_condition;
  73. FieldData fieldData;
  74. DataTable particlesAll;
  75. ParticleData Particledata;
  76. UserLibraryData userLibrary;
  77. DataTable userLibraryData;
  78. NLog.Logger log= NLog.LogManager.GetCurrentClassLogger();
  79. #region 分页器相关
  80. #region 分页字段和属性
  81. string condition = "";
  82. public string FileName = null;
  83. private int pageIndex = 1;
  84. /// <summary>
  85. /// 当前页面
  86. /// </summary>
  87. public virtual int PageIndex
  88. {
  89. get { return pageIndex; }
  90. set { pageIndex = value; }
  91. }
  92. private int pageSize = 20;
  93. /// <summary>
  94. /// 每页记录数
  95. /// </summary>
  96. public virtual int PageSize
  97. {
  98. get { return pageSize; }
  99. set { pageSize = value; }
  100. }
  101. //string OrderFunction = "fieldid,particleid";
  102. private int recordCount = 0;
  103. /// <summary>
  104. /// 总记录数
  105. /// </summary>
  106. public virtual int RecordCount
  107. {
  108. get { return recordCount; }
  109. set { recordCount = value; }
  110. }
  111. private int pageCount = 0;
  112. /// <summary>
  113. /// 总页数
  114. /// </summary>
  115. public int PageCount
  116. {
  117. get
  118. {
  119. pageCount = GetPageCount();
  120. return pageCount;
  121. }
  122. }
  123. /// <summary>
  124. /// 计算总页数
  125. /// </summary>
  126. /// <returns></returns>
  127. private int GetPageCount()
  128. {
  129. if (PageSize == 0)
  130. {
  131. return 0;
  132. }
  133. int pageCount = RecordCount / PageSize;
  134. if (RecordCount % PageSize == 0)
  135. {
  136. pageCount = RecordCount / PageSize;
  137. }
  138. else
  139. {
  140. pageCount = RecordCount / PageSize + 1;
  141. }
  142. return pageCount;
  143. }
  144. #endregion
  145. frmReportApp m_ReportApp;
  146. ResultFile resultFile = null;
  147. #endregion
  148. public ParticlesGridDevidePage(frmReportApp ReportApp)
  149. {
  150. m_ReportApp = ReportApp;
  151. m_condition = ReportApp.m_conditionChoose;
  152. resultFile = ReportApp.m_rstDataMgr.CurResultFile;
  153. ReportFun = new OTSImageDisHelp(resultFile);
  154. string sou=m_condition.m_CurrentConditions[OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  155. if (sou.Contains("+"))
  156. {
  157. result=m_ReportApp.m_rstDataMgr.ResultFilesList[0];
  158. }else
  159. {
  160. for(int i=0;i < m_ReportApp.m_rstDataMgr.ResultFilesList.Count;i++)
  161. {
  162. if (sou== m_ReportApp.m_rstDataMgr.ResultFilesList[i].FileName.ToString())
  163. {
  164. result = m_ReportApp.m_rstDataMgr.ResultFilesList[i];
  165. }
  166. }
  167. }
  168. //result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()];
  169. //设置窗体的双缓冲,以保证大数据时拖动不卡
  170. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  171. this.UpdateStyles();
  172. InitializeComponent();
  173. //利用反射设置DataGridView的双缓冲
  174. Type dgvType = this.dgV_ParticlesDevidePage.GetType();
  175. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  176. pi.SetValue(this.dgV_ParticlesDevidePage, true, null);
  177. }
  178. bool Init()
  179. {
  180. try
  181. {
  182. lan = new Language(this);
  183. table = lan.GetNameTable(this.Name);
  184. m_mythread_state = false;
  185. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  186. //m_frm_userprogress = new Frm_UserProgress();
  187. fieldData = new FieldData(result.FilePath);
  188. Particledata = new ParticleData(result.FilePath);
  189. string str_libraryName = ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["MsrParams"])["STDName"].ToString();
  190. userLibrary = new UserLibraryData(str_libraryName);
  191. if(userLibrary!=null)
  192. {
  193. userLibraryData = userLibrary.GetSubAttributeFromDatabase();
  194. }
  195. else
  196. {
  197. userLibraryData = null;
  198. }
  199. //初始化底层操作类
  200. m_OTSIncAReportGridsFun = new OTSReportGridsFun(m_ReportApp, this);
  201. return true;
  202. }
  203. catch(Exception ex)
  204. {
  205. log.Error(ex.ToString());
  206. return false;
  207. }
  208. }
  209. private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
  210. {
  211. if (!Init())
  212. {
  213. return;
  214. }
  215. ProgressStart();//进度条关闭通过cbB_PageSize.SelectedIndex事件
  216. if (!UpdateTable())
  217. {
  218. return;
  219. }
  220. cbB_PageSize.Items.Add("20");
  221. cbB_PageSize.Items.Add("100");
  222. cbB_PageSize.Items.Add("500");
  223. cbB_PageSize.Items.Add("1000");
  224. cbB_PageSize.Items.Add("5000");
  225. cbB_PageSize.Items.Add("All");
  226. cbB_PageSize.SelectedIndex = 0;
  227. }
  228. #region 自定义方法
  229. bool UpdateTable()
  230. {
  231. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  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. }
  304. else
  305. {
  306. //多次测试发现 读取数据库时间耗时长,但读取条数目对读取数据库时长影响不大,故此处直接读取所有数据库信息,以取代多次连接数据库方式,优化分页速度
  307. particlesAll = new DataTable();
  308. particlesAll = Particledata.GetInfoForPartucleDevidePage2(condition);
  309. particlesAll.Columns.Add("Hardness");
  310. particlesAll.Columns.Add("Density");
  311. particlesAll.Columns.Add("Electrical_conductivity");
  312. if(userLibraryData != null)
  313. {
  314. for(int i=0;i< particlesAll.Rows.Count;i++)
  315. {
  316. DataRow[] dr = userLibraryData.Select("STDId=" + particlesAll.Rows[i]["TypeId"].ToString());
  317. if (dr.Length>0)
  318. {
  319. particlesAll.Rows[i]["Hardness"] = System.Text.RegularExpressions.Regex.Replace(dr[0]["Hardness"].ToString(), @"[^\d.\d]", "");
  320. particlesAll.Rows[i]["Density"] = System.Text.RegularExpressions.Regex.Replace(dr[0]["Density"].ToString(), @"[^\d.\d]", "");
  321. particlesAll.Rows[i]["Electrical_conductivity"] = System.Text.RegularExpressions.Regex.Replace(dr[0]["Electrical_conductivity"].ToString(), @"[^\d.\d]", "");
  322. }
  323. else
  324. {
  325. particlesAll.Rows[i]["Hardness"] = "";
  326. particlesAll.Rows[i]["Density"] = "";
  327. particlesAll.Rows[i]["Electrical_conductivity"] = "";
  328. }
  329. }
  330. }
  331. else
  332. {
  333. for (int i = 0; i < particlesAll.Rows.Count; i++)
  334. {
  335. particlesAll.Rows[i]["Hardness"] = "";
  336. particlesAll.Rows[i]["Density"] = "";
  337. particlesAll.Rows[i]["Electrical_conductivity"] = "";
  338. }
  339. }
  340. btn_Sel.Enabled = true;
  341. }
  342. if(particlesAll==null)
  343. {
  344. log.Error("There is an exception in the data of the database!");
  345. #region 加载进度条进度部份结束
  346. //加载完成设置鼠标为默认
  347. this.Cursor = Cursors.Default;
  348. //加载完成,关闭进度条
  349. m_frm_userprogress.Close();
  350. #endregion
  351. return false;
  352. }
  353. DataTable elementchemistry = Particledata.GetElementChemistry();
  354. for (int i = 0; i < particlesAll.Rows.Count; i++)
  355. {
  356. string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
  357. DataRow[] drs = elementchemistry.Select(str);
  358. string ConcatenatedString = "";
  359. for (int j = 0; j < drs.Length; j++)
  360. {
  361. ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
  362. }
  363. particlesAll.Rows[i]["Element"] = ConcatenatedString;
  364. }
  365. return true;
  366. }
  367. /// <summary>
  368. /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
  369. /// </summary>
  370. /// <param name="in_cotsparticleclr"></param>
  371. /// <returns></returns>
  372. public Bitmap GetBitmapByParticle(string fieldImage, Rectangle offset_rect)
  373. {
  374. //然后将取出的数据,转换成Bitmap对象
  375. Bitmap ls_bt = DrawFunction.ReadImageFile(fieldImage);
  376. //为了能把整个颗粒显示完整
  377. offset_rect.X = offset_rect.X - 5;
  378. offset_rect.Y = offset_rect.Y - 5;
  379. offset_rect.Width = offset_rect.Width + 10;
  380. offset_rect.Height = offset_rect.Height + 10;
  381. //防止计算偏差后,有坐标溢出现象
  382. if (offset_rect.X < 0)
  383. offset_rect.X = 0;
  384. if (offset_rect.Y < 0)
  385. offset_rect.Y = 0;
  386. if (offset_rect.X + offset_rect.Width > ls_bt.Width)
  387. {
  388. offset_rect.Width = ls_bt.Width - offset_rect.X;
  389. }
  390. if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
  391. {
  392. offset_rect.Height = ls_bt.Height - offset_rect.Y;
  393. }
  394. //
  395. Bitmap new_ret_bp;
  396. //防止为0后面计算出错
  397. if (offset_rect.Width > 0 && offset_rect.Height > 0)
  398. {
  399. //最后通过list_showsegment组建成新的图片,进行返回
  400. new_ret_bp = ls_bt.Clone(offset_rect, PixelFormat.Format8bppIndexed);
  401. }
  402. else
  403. {
  404. new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
  405. }
  406. return new_ret_bp;
  407. }
  408. public Bitmap GetBitmapForBig(string sub, ParticleData fielddata, double xs)
  409. {
  410. string vs = "," + sub.Replace(':', '-') + ",";
  411. DataTable dataTable = fielddata.GetParticleAll(vs);
  412. if (dataTable.Rows.Count == 0)
  413. {
  414. return null;
  415. }
  416. string path = result.FilePath;
  417. //内接矩形
  418. double max_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs - Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  419. double max_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs + Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  420. double min_Y = max_Y;
  421. double min_X = max_X;
  422. //拼接field矩形
  423. double MAX_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  424. double MAX_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  425. double MIN_Y = MAX_Y;
  426. double MIN_X = MAX_X;
  427. foreach (DataRow item in dataTable.Rows)
  428. {
  429. //颗粒外接矩形
  430. double lefttopX = Convert.ToInt64(item["FieldPosX"]) * xs + Convert.ToInt64(item["RectLeft"]);
  431. if (lefttopX < min_X)
  432. {
  433. min_X = lefttopX;
  434. }
  435. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  436. {
  437. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  438. }
  439. double lrfttopY = Convert.ToInt64(item["FieldPosY"]) * xs - Convert.ToInt64(item["RectTop"]);
  440. if (max_Y < lrfttopY)
  441. {
  442. max_Y = lrfttopY;
  443. }
  444. if (min_Y > lrfttopY - Convert.ToInt64(item["RectHeight"]))
  445. {
  446. min_Y = lrfttopY - Convert.ToInt64(item["RectHeight"]);
  447. }
  448. //画布
  449. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  450. if (lefttopXH > MAX_X)
  451. {
  452. MAX_X = lefttopXH;
  453. }
  454. if (lefttopXH < MIN_X)
  455. {
  456. MIN_X = lefttopXH;
  457. }
  458. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  459. if (MAX_Y < lrfttopYH)
  460. {
  461. MAX_Y = lrfttopYH;
  462. }
  463. if (MIN_Y > lrfttopYH)
  464. {
  465. MIN_Y = lrfttopYH;
  466. }
  467. }
  468. int WIDTH = Convert.ToInt32(MAX_X - MIN_X) + 1024;
  469. int HEIGHT = Convert.ToInt32(MAX_Y - MIN_Y) + 768;
  470. //构造最终的图片白板
  471. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  472. Graphics graph = Graphics.FromImage(tableChartImage);
  473. //初始化这个大图
  474. graph.DrawImage(tableChartImage, 0, 0);
  475. int width = Convert.ToInt32(max_X - min_X);
  476. int height = Convert.ToInt32(max_Y - min_Y);
  477. int X = Convert.ToInt32(min_X - MIN_X);
  478. int Y = Convert.ToInt32(MAX_Y - max_Y);
  479. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  480. foreach (DataRow item in dataTable.Rows)
  481. {
  482. string filePath = path + "\\FIELD_FILES\\";
  483. string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
  484. //然后将取出的数据,转换成Bitmap对象
  485. Bitmap ls_bt = DrawFunction.ReadImageFile(imagePath);
  486. int x = Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - MIN_X);
  487. int y = System.Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - MAX_Y));
  488. try
  489. {
  490. graph.DrawImage(ls_bt, x, y);
  491. }
  492. catch /*(Exception e)*/
  493. {
  494. throw;
  495. }
  496. }
  497. Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
  498. return bmap;
  499. }
  500. private void BindDataGridView()
  501. {
  502. dgV_ParticlesDevidePage.Visible = false;
  503. if (m_frm_userprogress.IsDisposed)
  504. {
  505. ProgressStart();
  506. }
  507. dgV_ParticlesDevidePage.Rows.Clear();
  508. dgV_ParticlesDevidePage.Columns.Clear();
  509. string startFun = ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["MsrParams"])["SysType"].ToString();
  510. //从报告xml文件中加载,显示计算列,显示元素信息
  511. string str_DefaultComputedColName = "", str_ElementsColName = "";
  512. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXmlData(Application.StartupPath + m_ReportApp.m_OTSReportMgrParamFile, "XMLData");
  513. DataTable dt = ds.Tables["Member"];
  514. foreach (DataRow element in dt.Rows)
  515. {
  516. string RegName = element["RegName"].ToString();
  517. if (RegName == "DefaultComputedColName")
  518. {
  519. str_DefaultComputedColName = element["strValue"].ToString();
  520. }
  521. if (RegName == "ElementsColName")
  522. {
  523. str_ElementsColName = element["strValue"].ToString();
  524. }
  525. }
  526. //获取需要显示的计算列
  527. string[] strs = str_DefaultComputedColName.Split(',');
  528. //列名
  529. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  530. keyValues.Add("rowid", table["str4"].ToString());
  531. keyValues.Add("TypeName", table["str6"].ToString());
  532. keyValues.Add("ParticleImage", table["str5"].ToString());
  533. keyValues.Add("FieldID", "FieldID");
  534. keyValues.Add("SEMPosX", "SEMPosX");
  535. keyValues.Add("SEMPosY", "SEMPosY");
  536. for (int i = 0; i < strs.Count(); i++)
  537. {
  538. if (strs[i] == "Area")
  539. {
  540. keyValues.Add("Area", table["str21"].ToString());
  541. }
  542. if (strs[i] == "EquivalentCircleDiameter")
  543. {
  544. keyValues.Add("Equivalent", table["str22"].ToString());
  545. }
  546. if (strs[i] == "MaxDiameter")
  547. {
  548. keyValues.Add("DMAX", table["str23"].ToString());
  549. }
  550. if (strs[i] == "MinDiameter")
  551. {
  552. keyValues.Add("DMIN", table["str24"].ToString());
  553. }
  554. if (strs[i] == "DiameterRatio")
  555. {
  556. keyValues.Add("DiameterRatio", table["str25"].ToString());
  557. }
  558. if (strs[i] == "FerretDiameter")
  559. {
  560. keyValues.Add("DFERET", table["str26"].ToString());
  561. }
  562. if (strs[i] == "PERP")
  563. {
  564. keyValues.Add("DPERP", table["str27"].ToString());
  565. }
  566. if (strs[i] == "PERI")
  567. {
  568. keyValues.Add("PERIMETER", table["str28"].ToString());
  569. }
  570. if (strs[i] == "INSCR")
  571. {
  572. keyValues.Add("DINSCR", table["str29"].ToString());
  573. }
  574. if (strs[i] == "MEAN")
  575. {
  576. keyValues.Add("DMEAN", table["str30"].ToString());
  577. }
  578. if (strs[i] == "ELONG")
  579. {
  580. keyValues.Add("DELONG", table["str31"].ToString());
  581. }
  582. if (strs[i] == "ASPECT_ELONG")
  583. {
  584. keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
  585. }
  586. if (strs[i] == "Orientation")
  587. {
  588. keyValues.Add("ORIENTATION", table["str33"].ToString());
  589. }
  590. if (startFun == "1:CleannessA")
  591. {
  592. if (strs[i] == "Hardness")
  593. {
  594. keyValues.Add("Hardness", table["str34"].ToString());
  595. }
  596. if (strs[i] == "Density")
  597. {
  598. keyValues.Add("Density", table["str35"].ToString());
  599. }
  600. if (strs[i] == "Electrical_conductivity")
  601. {
  602. keyValues.Add("Electrical_conductivity", table["str36"].ToString());
  603. }
  604. }
  605. }
  606. keyValues.Add("Element", "Element");
  607. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  608. for (int irow = 0; irow < keyValues.Count; irow++)
  609. {
  610. if (en.MoveNext())
  611. {
  612. if (en.Current.Key == "ParticleImage")
  613. {
  614. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  615. iconColumn.Name = en.Current.Key;
  616. iconColumn.HeaderText = en.Current.Value;
  617. dgV_ParticlesDevidePage.Columns.Add(iconColumn);
  618. }
  619. else if (en.Current.Key == "Element")
  620. {
  621. }
  622. else
  623. {
  624. int columndid = dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
  625. }
  626. }
  627. }
  628. if(PageSize==-1)
  629. {
  630. PageSize = particlesAll.Rows.Count;
  631. }
  632. if (particlesAll == null)
  633. {
  634. return;
  635. }
  636. RecordCount = particlesAll.Rows.Count;
  637. DataTable particles = particlesAll.Clone();
  638. for (int fi = (PageIndex - 1) * pageSize; fi < PageIndex * pageSize; fi++)
  639. {
  640. if (fi > RecordCount - 1)
  641. {
  642. break;
  643. }
  644. particles.ImportRow(particlesAll.Rows[fi]);
  645. }
  646. string particleM = "";
  647. //获取需要显示的元素名
  648. List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
  649. for (int i = 0; i < ElementTypeSort.Count; i++)
  650. {
  651. dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
  652. }
  653. double jd = 95f / (double)particles.Rows.Count;//计算进度刻度
  654. string filePath = result.FilePath + "\\FIELD_FILES\\";
  655. KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  656. for (int i = 0; i < particles.Rows.Count; i++)
  657. {
  658. //更新进度,每100条记录加载完,更新一次进度
  659. if (i % 10 == 0)
  660. m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "loading..");
  661. Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  662. int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
  663. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value = (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
  664. for (int k = 0; k < keyValues.Count; k++)
  665. {
  666. if (enl.MoveNext())
  667. {
  668. if (enl.Current.Key == "rowid")
  669. {
  670. //dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = i + 1;
  671. }
  672. if (enl.Current.Key == "ParticleImage")
  673. {
  674. string subt = particles.Rows[i]["SubParticles"].ToString();
  675. if (subt != null && subt != "")
  676. {
  677. double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
  678. string filePatht = result.FilePath + "\\FIELD_FILES\\";
  679. string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
  680. //然后将取出的数据,转换成Bitmap对象
  681. Bitmap tempbit = Particledata.ReadImageFile(imagePatht);
  682. int pixw = tempbit.Width;
  683. double xs = pixw / ScanFieldSize;
  684. particleM = particleM + "," + subt;
  685. Bitmap bmap = Particledata.GetBitmapForBig(subt, xs, result.FilePath, tempbit.Height, tempbit.Width);
  686. if (bmap != null)
  687. {
  688. string[] str = subt.Split(',');
  689. bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
  690. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  691. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  692. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  693. dgV_ParticlesDevidePage.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate;
  694. }
  695. else
  696. {
  697. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  698. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  699. }
  700. }
  701. else
  702. {
  703. if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  704. {
  705. string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  706. FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), Particledata.ReadImageFile(imagePath));
  707. }
  708. 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"]) };
  709. Bitmap bmap = Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
  710. bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString() };
  711. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  712. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = bmap.Height + 20;
  713. }
  714. }
  715. if (enl.Current.Key == "DiameterRatio")
  716. {
  717. double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  718. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  719. }
  720. if (enl.Current.Key == "ASPECT_ELONG")
  721. {
  722. double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  723. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  724. }
  725. if (particles.Columns.Contains(enl.Current.Key))
  726. {
  727. double num = 0;
  728. if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  729. {
  730. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  731. }
  732. else if (enl.Current.Key == "Element")
  733. {
  734. List<string> elementtemp = new List<string>(ElementTypeSort);
  735. string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  736. for (int j = 0; j < strcbo.Length; j++)
  737. {
  738. string[] str = strcbo[j].Split('-');
  739. if (ElementTypeSort.Contains(str[0]))
  740. { dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
  741. elementtemp.Remove(str[0].ToString());
  742. }
  743. foreach (var ele in elementtemp)
  744. {
  745. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[ele].Value = "0";
  746. }
  747. }
  748. else
  749. {
  750. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  751. }
  752. }
  753. if (enl.Current.Key == "TypeName")
  754. {
  755. if (particles.Rows[i]["TypeId"].ToString() == "9")
  756. {
  757. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  758. }
  759. }
  760. if (enl.Current.Key == "Equivalent")
  761. {
  762. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  763. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  764. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  765. }
  766. }
  767. }
  768. }
  769. #region 加载进度条进度部份结束
  770. //加载完成设置鼠标为默认
  771. this.Cursor = Cursors.Default;
  772. string str8 = table["str8"].ToString();
  773. m_frm_userprogress.SetProgressValueAndText(100, str8);
  774. //加载完成,关闭进度条
  775. m_frm_userprogress.Close();
  776. #endregion
  777. dgV_ParticlesDevidePage.Visible = true;
  778. }
  779. /// <summary>
  780. /// 设置DataGridView样式
  781. /// </summary>
  782. private void SetDataGridViewStyle()
  783. {
  784. //用户不能调整标题的高度
  785. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  786. //用户不能调整 行高
  787. dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
  788. //点击选择整行
  789. dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  790. //居中显示
  791. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  792. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  793. dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
  794. dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  795. //再次重覆禁用拖动表头高度,居然有效果了
  796. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  797. //设置grid可以复制
  798. dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  799. //设置每列的宽度
  800. dgV_ParticlesDevidePage.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  801. dgV_ParticlesDevidePage.Columns[1].Width = 150;
  802. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].Width = 450;
  803. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  804. //设置序号列不排序
  805. dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  806. //设置序号列不可以设置宽度
  807. dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
  808. dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
  809. }
  810. #endregion
  811. #region 相关事件
  812. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  813. {
  814. //复制整个表
  815. CopyAll();
  816. }
  817. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  818. {
  819. //复制选择区域
  820. CopySelected();
  821. }
  822. /// <summary>
  823. /// 复制选择区域
  824. /// </summary>
  825. public void CopySelected()
  826. {
  827. //复制选择区域
  828. object oo = dgV_ParticlesDevidePage.GetClipboardContent();
  829. if (oo != null)
  830. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  831. }
  832. /// <summary>
  833. /// 复制所有
  834. /// </summary>
  835. public void CopyAll()
  836. {
  837. dgV_ParticlesDevidePage.SelectAll();
  838. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  839. }
  840. /// <summary>
  841. /// 以图像的方式将GridView进行截图
  842. /// </summary>
  843. public void CopyImage()
  844. {
  845. int height, width;
  846. width = dgV_ParticlesDevidePage.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 2;
  847. height = this.Height;
  848. Bitmap image = new Bitmap(width, height);
  849. dgV_ParticlesDevidePage.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  850. Clipboard.SetImage(image);
  851. }
  852. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  853. {
  854. //对gridview进行截图
  855. CopyImage();
  856. }
  857. private void dgV_ParticlesDevidePage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  858. {
  859. //排序中
  860. if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag.ToString() == "统计行")
  861. {
  862. //ROW1>ROW2
  863. e.SortResult = 1;
  864. if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
  865. e.SortResult = -1;
  866. e.Handled = true;
  867. return;
  868. }
  869. if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag.ToString() == "统计行")
  870. {
  871. //ROW1<ROW2
  872. e.SortResult = -1;
  873. if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
  874. e.SortResult = 1;
  875. e.Handled = true;
  876. return;
  877. }
  878. }
  879. /// <summary>
  880. /// 将OTS坐标转换为Sem 坐标
  881. /// </summary>
  882. /// <param name="POTSCoord"></param>
  883. /// <returns></returns>
  884. public Point ChangeOTSToSemCoord(Point POTSCoord)
  885. {
  886. //first if m_semstagedata is null to get stage inforation
  887. Convert.ToDouble(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["scanFieldSize"]);
  888. //after obtaining stage info,calc stage point data
  889. Point ret_SEM_point = new Point();
  890. // get center point, um
  891. long xStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["start"]);
  892. long xEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["end"]);
  893. long xCenter = (xStart + xEnd) / 2;
  894. long yStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["start"]);
  895. long yEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["end"]);
  896. long yCenter = (yStart + yEnd) / 2;
  897. // delte = SEM - OTSa
  898. long deltex = xCenter - 0;
  899. long deltey = yCenter - 0;
  900. int xdir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["xAxisDir"]);
  901. int ydir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["yAxisDir"]);
  902. if (xdir == (int)OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  903. {
  904. ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
  905. }
  906. else if (xdir == (int)OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
  907. {
  908. ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
  909. }
  910. if (ydir == (int)OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  911. {
  912. ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
  913. }
  914. else if (ydir == (int)OTS_Y_AXIS_DIRECTION.DOWN_TOWARD)
  915. {
  916. ret_SEM_point.Y = -1 * (POTSCoord.Y - Convert.ToInt32(deltey));
  917. }
  918. return ret_SEM_point;
  919. }
  920. #endregion
  921. #region 获取向导出模块提供的DataTable和GridView对象
  922. /// <summary>
  923. /// 获取到该模块输出后形成的DataTable,和GridView
  924. /// </summary>
  925. /// <param name="out_dt"></param>
  926. /// <param name="out_dg"></param>
  927. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  928. {
  929. out_dt = m_dt;
  930. out_dg = this.dgV_ParticlesDevidePage;//同样通过 dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[2].Value 来获取bitmap对象
  931. }
  932. #endregion
  933. #region 连接电镜相关
  934. /// <summary>
  935. /// 移动SEM到指定位置线程函数
  936. /// </summary>
  937. private void Thread_GO(object in_obj)
  938. {
  939. if (m_mythread_state == false)
  940. {
  941. m_mythread_state = true;
  942. Point sem_point = (Point)in_obj;
  943. //第一步,连接电镜
  944. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  945. Thread.Sleep(500);
  946. //第二步,移动到指定位置,先读取再设置
  947. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  948. {
  949. m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  950. }
  951. Thread.Sleep(1500);
  952. //第三步,断开电镜连接
  953. m_OTSIncAReportGridsFun.DisConnectSEM_ForParticlesGrid();
  954. //Thread.Sleep(500);
  955. m_mythread_state = false;
  956. }
  957. }
  958. /// <summary>
  959. /// 二次测量线程函数
  960. /// </summary>
  961. private void Thread_ReMeasure(object particles)
  962. {
  963. if (m_mythread_state == false)
  964. {
  965. m_mythread_state = true;
  966. //颗粒信息
  967. List<Particle> ParticleList = (List<Particle>)particles;
  968. Dictionary<int, List<Particle>> keyValues = new Dictionary<int, List<Particle>>();
  969. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"]);
  970. Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
  971. string ImageResolution = imageScanParam["ImageResolution"].ToString();
  972. double width = Convert.ToDouble(ImageResolution.Split('_')[1]);
  973. double height = Convert.ToDouble(ImageResolution.Split('_')[2]);
  974. ParticleList.OrderBy(a => a.FieldId).ToList();
  975. for (int i = 0; i < ParticleList.Count; i++)
  976. {
  977. if (keyValues.ContainsKey(ParticleList[i].FieldId))
  978. {
  979. List<Particle> Particles = keyValues[ParticleList[i].FieldId];
  980. Particles.Add(ParticleList[i]);
  981. keyValues[ParticleList[i].FieldId] = Particles;
  982. }
  983. else
  984. {
  985. List<Particle> Particles = new List<Particle>();
  986. Particles.Add(ParticleList[i]);
  987. keyValues.Add(ParticleList[i].FieldId, Particles);
  988. }
  989. }
  990. //第一步,连接电镜
  991. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  992. Thread.Sleep(500);
  993. //第二步,移动到指定位置,先读取再设置
  994. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  995. {
  996. m_OTSIncAReportGridsFun.ReMeasure(result.FilePath + "\\FIELD_FILES\\", (int)width, (int)height, keyValues, frmReMeasure.IMGSCANSPEED_INDEX, frmReMeasure.XRAYSCANMODE_INDEX, frmReMeasure.NUD_SCANTIME_COUNT);
  997. }
  998. Thread.Sleep(1500);
  999. //第三步,断开电镜连接
  1000. m_OTSIncAReportGridsFun.DisConnectSEM_ForParticlesGrid();
  1001. //Thread.Sleep(500);
  1002. m_mythread_state = false;
  1003. }
  1004. }
  1005. #endregion
  1006. private void ToolStripMenuItem_exportzoomimagefile_Click(object sender, EventArgs e)
  1007. {
  1008. //导出放大图像
  1009. FolderBrowserDialog fbd = new FolderBrowserDialog();
  1010. if (fbd.ShowDialog() == DialogResult.OK)
  1011. {
  1012. m_imagefilepath = fbd.SelectedPath;
  1013. for (int i = 0; i < m_dt.Rows.Count; i++)
  1014. {
  1015. Bitmap ls_bp = new Bitmap(1, 1);
  1016. ls_bp = (Bitmap)m_dt.Rows[i][1];
  1017. string strPath = m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg";
  1018. string strPath2 = m_imagefilepath + "\\" + (i + 1).ToString() + "s.jpg";
  1019. ls_bp.Save(strPath);
  1020. //m_COTSReportProjFileMgrClr.ReZoom(strPath, strPath2);
  1021. System.IO.File.Delete(strPath);//再将文件删除
  1022. }
  1023. string str1 = table["str9"].ToString();
  1024. MessageBox.Show(str1 + m_dt.Rows.Count.ToString());
  1025. }
  1026. }
  1027. /// <summary>
  1028. /// 导出二次放大图像
  1029. /// </summary>
  1030. /// <param name="str_srcPathName"></param>
  1031. /// <param name="str_outPathName"></param>
  1032. public void ParticleReZoom(string str_srcPathName, string str_outPathName)
  1033. {
  1034. //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
  1035. }
  1036. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  1037. {
  1038. //恢复至初始状态
  1039. dgV_ParticlesDevidePage.Rows.Clear();
  1040. dgV_ParticlesDevidePage.Columns.Clear();
  1041. BindDataGridView();
  1042. SetDataGridViewStyle();
  1043. }
  1044. private void ToolStripMenuItem5_Click(object sender, EventArgs e)
  1045. {
  1046. /*注意:多数据源情况下,只获取第一个数据源的选择了多行的情况下,只获取最后一个选择行的,没有办法,这是为了符合李阳博士提出的要求*/
  1047. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  1048. string i_ls_fieldid = "";
  1049. string i_ls_particleid = "";
  1050. int cou = dgV_ParticlesDevidePage.SelectedRows.Count;
  1051. if (cou > 0)
  1052. {
  1053. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[cou - 1];
  1054. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1055. List<string> list_str = (List<string>)ls_bp.Tag;
  1056. if (list_str != null)
  1057. {
  1058. i_ls_fieldid = list_str[0];
  1059. i_ls_particleid = list_str[1];
  1060. }
  1061. }
  1062. ParticleData particleData = new ParticleData(result.FilePath);
  1063. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  1064. ////然后遍历所有的Field
  1065. //Point ls_ots_point = new Point() { X = particle.PosX, Y = particle.PosY };
  1066. ////将该坐标转成SEM坐标
  1067. //Point ls_sem_point = ChangeOTSToSemCoord(ls_ots_point);
  1068. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  1069. if (m_mythread == null)
  1070. {
  1071. return;
  1072. }
  1073. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  1074. {
  1075. return;
  1076. }
  1077. if (m_mythread.ThreadState == ThreadState.Stopped)
  1078. {
  1079. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1080. }
  1081. //改为线程调用,先判断线程状态
  1082. m_mythread.Start(new Point(particle.SEMPosX, particle.SEMPosY));
  1083. }
  1084. private void ToolStripMenuItem_selectparticle_Click(object sender, EventArgs e)
  1085. {
  1086. string path = result.FilePath;
  1087. ParticleData fielddata = new ParticleData(result.FilePath);
  1088. List<Particle> particles = fielddata.GetParticleAllList();
  1089. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  1090. for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
  1091. {
  1092. //从事先加载的Bitmap对象的Tag中取出List<string>
  1093. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
  1094. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1095. List<string> list_str = (List<string>)ls_bp.Tag;
  1096. if (list_str != null)
  1097. {
  1098. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1099. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1100. foreach (Particle item in particles)
  1101. {
  1102. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  1103. {
  1104. ls_list_cotsparticleclr.Add(item);
  1105. break;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. m_ReportApp.SetSelectedParticles(ls_list_cotsparticleclr);
  1111. string str1 = table["str1"].ToString();
  1112. //然后循环得出,list cotsparticleclr列表,返回给框架
  1113. //m_sec.SendCall(str1, "", "", ls_list_cotsparticleclr);
  1114. string str2 = table["str2"].ToString();
  1115. string str3 = table["str3"].ToString();
  1116. MessageBox.Show(str2 + ls_list_cotsparticleclr.Count.ToString() + str3);
  1117. }
  1118. private void ToolStripMenuItem_exportimagefile_Click(object sender, EventArgs e)
  1119. {
  1120. FolderBrowserDialog fbd = new FolderBrowserDialog();
  1121. if (fbd.ShowDialog() == DialogResult.OK)
  1122. {
  1123. m_imagefilepath = fbd.SelectedPath;
  1124. for (int i = 0; i < dgV_ParticlesDevidePage.Rows.Count; i++)
  1125. {
  1126. Bitmap ls_bp = new Bitmap(1, 1);
  1127. ls_bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i].Cells[2].Value;
  1128. ls_bp.Save(m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg");
  1129. }
  1130. string str9 = table["str9"].ToString();
  1131. MessageBox.Show(str9 + dgV_ParticlesDevidePage.Rows.Count.ToString());
  1132. }
  1133. }
  1134. private void testToolStripMenuItem_Click(object sender, EventArgs e)
  1135. {
  1136. ////测试导出指定颗粒的能谱图,测试相关代码
  1137. //OTSIncAReportGraph.DParticle ls_dparticle = new OTSIncAReportGraph.DParticle();
  1138. //for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
  1139. //{
  1140. // //获取选择行颗粒的fieldid,和particleid
  1141. // string str_fieldid = "";
  1142. // string str_particleid = "";
  1143. // string str_stdtypeid = "";
  1144. // DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
  1145. // Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1146. // List<string> list_str = (List<string>)ls_bp.Tag;
  1147. // if (list_str != null)
  1148. // {
  1149. // str_fieldid = list_str[0];
  1150. // str_particleid = list_str[1];
  1151. // str_stdtypeid = list_str[2];
  1152. // }
  1153. // ls_dparticle.CLRFieldID = Convert.ToInt32(str_fieldid);
  1154. // ls_dparticle.CLRTagID = Convert.ToInt32(str_particleid);
  1155. // ls_dparticle.STDTypeID = Convert.ToInt32(str_stdtypeid);
  1156. //}
  1157. ////显示xray能谱
  1158. //ShowXRay(ls_dparticle);
  1159. //Bitmap ls_bpex = new Bitmap(control_XRayTable1.Width, control_XRayTable1.Height);
  1160. //control_XRayTable1.DrawToBitmap(ls_bpex, new Rectangle(0, 0, control_XRayTable1.Width, control_XRayTable1.Height));
  1161. ////Bitmap ls_bpex = control_XRayTable1.ExportXRayImage();
  1162. //ls_bpex.Save("e:\\test222.jpg");
  1163. }
  1164. /// <summary>
  1165. /// 判断条件输入 前<后
  1166. /// </summary>
  1167. /// <param name="min"></param>
  1168. /// <param name="max"></param>
  1169. /// <returns></returns>
  1170. bool CompareInput(string min,string max)
  1171. {
  1172. int imax = 0;
  1173. int imin = 0;
  1174. double dmax = 0;
  1175. double dmin = 0;
  1176. if (int.TryParse(max, out imax))
  1177. {
  1178. dmax = (double)imax;
  1179. }
  1180. else
  1181. {
  1182. dmax = Convert.ToDouble(max);
  1183. }
  1184. if (int.TryParse(min, out imin))
  1185. {
  1186. dmin = (double)imin;
  1187. }
  1188. else
  1189. {
  1190. dmin = Convert.ToDouble(min);
  1191. }
  1192. if(dmin<=dmax)
  1193. {
  1194. return true;
  1195. }
  1196. else
  1197. {
  1198. return false;
  1199. }
  1200. }
  1201. private void btn_Sel_Click(object sender, EventArgs e)
  1202. {
  1203. condition = "";
  1204. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text))
  1205. {
  1206. double dnum = 0;
  1207. int inum = 0;
  1208. if (double.TryParse(tBx_AreaMin.Text, out dnum) && dnum >= 0)
  1209. {
  1210. condition += " and Area" + " > " + tBx_AreaMin.Text;
  1211. }
  1212. else if(int.TryParse(tBx_AreaMin.Text, out inum) && inum >= 0)
  1213. {
  1214. condition += " and Area" + " > " + tBx_AreaMin.Text;
  1215. }
  1216. else
  1217. {
  1218. MessageBox.Show(table["str10"].ToString());
  1219. return;
  1220. }
  1221. }
  1222. if (!string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  1223. {
  1224. double dnum = 0;
  1225. int inum = 0;
  1226. if (double.TryParse(Tbx_AreaMax.Text, out dnum) && dnum >= 0)
  1227. {
  1228. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  1229. }
  1230. else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
  1231. {
  1232. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  1233. }
  1234. else
  1235. {
  1236. MessageBox.Show(table["str10"].ToString());
  1237. return;
  1238. }
  1239. }
  1240. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text) && !string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  1241. {
  1242. if (!CompareInput(tBx_AreaMin.Text, Tbx_AreaMax.Text))
  1243. {
  1244. MessageBox.Show(table["str11"].ToString());
  1245. return;
  1246. }
  1247. }
  1248. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text))
  1249. {
  1250. double dnum = 0;
  1251. int inum = 0;
  1252. if (double.TryParse(tbx_DmaxMin.Text, out dnum) && dnum >= 0)
  1253. {
  1254. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  1255. }
  1256. else if(int.TryParse(tbx_DmaxMin.Text, out inum)&& inum >= 0)
  1257. {
  1258. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  1259. }
  1260. else
  1261. {
  1262. MessageBox.Show(table["str10"].ToString());
  1263. return;
  1264. }
  1265. }
  1266. if (!string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1267. {
  1268. double dnum = 0;
  1269. int inum = 0;
  1270. if (double.TryParse(tbx_DmaxMax.Text, out dnum) && dnum > 0)
  1271. {
  1272. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1273. }
  1274. else if(int.TryParse(tbx_DmaxMax.Text, out inum)&& inum >= 0)
  1275. {
  1276. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1277. }
  1278. else
  1279. {
  1280. MessageBox.Show(table["str10"].ToString());
  1281. return;
  1282. }
  1283. }
  1284. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text) && !string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1285. {
  1286. if (!CompareInput(tbx_DmaxMin.Text, tbx_DmaxMax.Text))
  1287. {
  1288. MessageBox.Show(table["str11"].ToString());
  1289. return;
  1290. }
  1291. }
  1292. if (!string.IsNullOrWhiteSpace(tbx_Type.Text))
  1293. {
  1294. condition += " and TypeName Like \"%" + tbx_Type.Text + "%\" ";
  1295. }
  1296. if (m_frm_userprogress.IsDisposed)
  1297. {
  1298. ProgressStart();
  1299. }
  1300. UpdateTable();
  1301. lnkFirst_Click(null, null);
  1302. SetDataGridViewStyle();
  1303. }
  1304. void ProgressStart()
  1305. {
  1306. #region 加载显示进度条部份
  1307. this.Cursor = Cursors.WaitCursor;
  1308. m_frm_userprogress = new Frm_UserProgress();
  1309. //显示进度条,计算进度条应该显示的位置和宽度
  1310. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  1311. if (ls_main_form == null)
  1312. {
  1313. m_frm_userprogress.Visible = false;
  1314. }
  1315. else
  1316. {
  1317. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  1318. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 200, ls_main_form.Location.Y + 200 + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  1319. m_frm_userprogress.Show();
  1320. m_frm_userprogress.SetProgressValueAndText(0, "Loading data of particles...");
  1321. }
  1322. #endregion
  1323. }
  1324. private void cbB_order_SelectedIndexChanged(object sender, EventArgs e)
  1325. {
  1326. //int ordernum = cbB_order.SelectedIndex;
  1327. //if (ordernum == 0)
  1328. //{
  1329. // OrderFunction = "fieldid,particleid";
  1330. //}
  1331. //else if (ordernum == 1)
  1332. //{
  1333. // OrderFunction = "TypeName";
  1334. //}
  1335. //else if (ordernum == 2)
  1336. //{
  1337. // OrderFunction = "DMAX";
  1338. //}
  1339. //else if (ordernum == 3)
  1340. //{
  1341. // OrderFunction = "DMAX desc";
  1342. //}
  1343. //else if (ordernum == 4)
  1344. //{
  1345. // OrderFunction = "Area";
  1346. //}
  1347. //else if (ordernum == 5)
  1348. //{
  1349. // OrderFunction = "Area desc";
  1350. //}
  1351. lnkFirst_Click(null, null);
  1352. SetDataGridViewStyle();
  1353. }
  1354. /// <summary>
  1355. /// 页面控件呈现
  1356. /// </summary>
  1357. private void DrawControl(bool callEvent)
  1358. {
  1359. BindDataGridView();
  1360. lblTotalCount.Text = RecordCount.ToString();
  1361. lblPageCount.Text = PageCount.ToString();
  1362. txtPageNum.Text = PageIndex.ToString();
  1363. SetFormCtrEnabled();
  1364. if (PageCount == 0 || PageCount == 1)//有且仅有一页
  1365. {
  1366. lnkFirst.Enabled = false;
  1367. lnkPrev.Enabled = false;
  1368. lnkNext.Enabled = false;
  1369. lnkLast.Enabled = false;
  1370. btnGo.Enabled = false;
  1371. }
  1372. else if (PageIndex == 1)//第一页
  1373. {
  1374. lnkFirst.Enabled = false;
  1375. lnkPrev.Enabled = false;
  1376. }
  1377. else if (PageIndex == PageCount)//最后一页
  1378. {
  1379. lnkNext.Enabled = false;
  1380. lnkLast.Enabled = false;
  1381. }
  1382. }
  1383. private void SetFormCtrEnabled()
  1384. {
  1385. lnkFirst.Enabled = true;
  1386. lnkPrev.Enabled = true;
  1387. lnkNext.Enabled = true;
  1388. lnkLast.Enabled = true;
  1389. btnGo.Enabled = true;
  1390. }
  1391. /// <summary>
  1392. /// 分页属性改变了。
  1393. /// </summary>
  1394. private void txtPageSize_TextChanged(object sender, EventArgs e)
  1395. {
  1396. int num = 0;
  1397. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1398. {
  1399. }
  1400. else { txtPageNum.Text = "1"; }
  1401. }
  1402. private void lnkFirst_Click(object sender, EventArgs e)
  1403. {
  1404. PageIndex = 1;
  1405. DrawControl(true);
  1406. }
  1407. private void lnkPrev_Click(object sender, EventArgs e)
  1408. {
  1409. PageIndex = Math.Max(1, PageIndex - 1);
  1410. DrawControl(true);
  1411. }
  1412. private void lnkNext_Click(object sender, EventArgs e)
  1413. {
  1414. PageIndex = Math.Min(PageCount, PageIndex + 1);
  1415. DrawControl(true);
  1416. }
  1417. private void lnkLast_Click(object sender, EventArgs e)
  1418. {
  1419. PageIndex = PageCount;
  1420. DrawControl(true);
  1421. }
  1422. /// <summary>
  1423. /// 跳转
  1424. /// </summary>
  1425. /// <param name="sender"></param>
  1426. /// <param name="e"></param>
  1427. private void btnGo_Click(object sender, EventArgs e)
  1428. {
  1429. int num = 0;
  1430. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1431. {
  1432. if (num > PageCount)
  1433. {
  1434. num = PageCount;
  1435. txtPageNum.Text = PageCount.ToString();
  1436. }
  1437. PageIndex = num;
  1438. DrawControl(true);
  1439. }
  1440. }
  1441. private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
  1442. {
  1443. if (cbB_PageSize.SelectedItem.ToString() == "All")
  1444. {
  1445. pageSize = -1;
  1446. }
  1447. else
  1448. {
  1449. pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
  1450. }
  1451. lnkFirst_Click(null, null);
  1452. SetDataGridViewStyle();
  1453. }
  1454. /// <summary>
  1455. /// 在帧图上标记颗粒的位置矩形,并保存到FIELD_FILES_MARK文件夹中
  1456. /// </summary>
  1457. public void SaveMarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable ,out List<string> vs , out DataTable dt_FIeld)
  1458. {
  1459. Init();
  1460. List<string> maxlength = new List<string>();
  1461. for (int i=0;i< dataTable.Rows.Count;i++)
  1462. {
  1463. if (dataTable.Rows[i]["TypeName"].ToString()!= "Not Identified")
  1464. {
  1465. if (maxlength.Count<10)
  1466. {
  1467. maxlength.Add(dataTable.Rows[i]["Fieldid"].ToString());
  1468. }
  1469. else
  1470. {
  1471. break;
  1472. }
  1473. }
  1474. }
  1475. List<string> max_list = maxlength.Distinct().ToList();
  1476. string str_path_FIELD_FILES = str_resultPath + "\\FIELD_FILES\\";
  1477. string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
  1478. int intQuantity = 0;
  1479. //List<string> vs = new List<string>();
  1480. dt_FIeld = new DataTable();
  1481. vs = new List<string>();
  1482. ////判断是否已经有导出过的标记帧图文件夹,如果已经存在,则直接返回不输出,先不加
  1483. DirectoryInfo theFolder_FieldMark = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  1484. if (!theFolder_FieldMark.Exists)
  1485. {
  1486. //创建
  1487. theFolder_FieldMark.Create();
  1488. }
  1489. else
  1490. {
  1491. theFolder_FieldMark.Delete(true);
  1492. //创建
  1493. theFolder_FieldMark.Create();
  1494. //已经存在的话,直接返回
  1495. //return;
  1496. }
  1497. //查找该field下对应所有的颗粒
  1498. DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
  1499. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
  1500. if (theFolder.Exists)
  1501. {
  1502. DataTable dt = new DataTable();
  1503. dt.Columns.Add("fieldid");
  1504. dt.Columns.Add("id");
  1505. dt.Columns.Add("fieldName");
  1506. dt.Columns.Add("cunt",typeof(int));
  1507. dt.Columns.Add("fieldFullName");
  1508. for (int i = 0; i < max_list.Count; i++)
  1509. {
  1510. foreach (FileInfo nextifile in theFolder.GetFiles())
  1511. {
  1512. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  1513. {
  1514. //确认对应的帧图名
  1515. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  1516. str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
  1517. bool bl = false;
  1518. if (str_fieldid == max_list[i].ToString())
  1519. {
  1520. bl = true;
  1521. }
  1522. if (bl)
  1523. {
  1524. DataRow dr = dt.NewRow();
  1525. dr["fieldid"] = " fieldid = " + str_fieldid;
  1526. dr["cunt"] = dataTable.Select(" fieldid = " + str_fieldid).Count();
  1527. dr["fieldName"] = nextifile.Name;
  1528. dr["fieldFullName"] = nextifile.FullName;
  1529. dr["id"] = str_fieldid;
  1530. dt.Rows.Add(dr);
  1531. }
  1532. }
  1533. }
  1534. }
  1535. //DataView dv = dt.DefaultView;
  1536. //dv.Sort = "cunt DESC";
  1537. dt_FIeld = dt.Copy();
  1538. for (int i=0;i< dt_FIeld.Rows.Count; i++)
  1539. {
  1540. if (dataTable.Select(dt_FIeld.Rows[i]["fieldid"].ToString()).Count() > 0)
  1541. {
  1542. vs.Add(dt_FIeld.Rows[i]["id"].ToString());
  1543. Image img = Image.FromFile(dt_FIeld.Rows[i]["fieldFullName"].ToString());
  1544. //img.Save(@"D:\1.bmp");
  1545. Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  1546. using (Graphics g = Graphics.FromImage(ls_fieldbp))
  1547. {
  1548. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1549. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1550. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1551. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
  1552. }
  1553. //ls_fieldbp.Save(@"D:\1.bmp");
  1554. img.Dispose();
  1555. img = null;
  1556. //循环将颗粒,进行标记到bitmap图上
  1557. DataRow[] drlist = dt_AllParticle.Select(dt_FIeld.Rows[i]["fieldid"].ToString());
  1558. if (drlist.Count() > 0)
  1559. intQuantity = intQuantity + 1;
  1560. for (int i_row = 0; i_row < drlist.Count(); i_row++)
  1561. {
  1562. //string str_fieldid = drlist[i_row]["fieldid"].ToString();
  1563. string str_particleid = drlist[i_row]["particleid"].ToString();
  1564. string str_stdtypeid = drlist[i_row]["typeid"].ToString();
  1565. string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
  1566. string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
  1567. string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
  1568. string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
  1569. //确定需要标记颗粒的定位
  1570. Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
  1571. Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
  1572. //向帧图进行标记颗粒位置
  1573. Graphics g = Graphics.FromImage(ls_fieldbp);
  1574. g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
  1575. //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
  1576. int ls_offsetx = offset_rect.X + offset_rect.Width;
  1577. if (ls_offsetx > ls_fieldbp.Width - 10)
  1578. {
  1579. ls_offsetx = offset_rect.X - 10;
  1580. }
  1581. g.DrawString(dt_FIeld.Rows[i]["id"].ToString() + "" + str_particleid.ToString(),
  1582. new Font("黑体", 8), new SolidBrush(Color.Aqua), new PointF(ls_offsetx, offset_rect.Y));
  1583. //保存带有标记的帧图
  1584. ls_fieldbp.Save(str_path_FIELD_FILES_MARK + dt_FIeld.Rows[i]["id"].ToString() + ".bmp");
  1585. //ls_fieldbp.Dispose();
  1586. }
  1587. }
  1588. }
  1589. }
  1590. //
  1591. GC.Collect();
  1592. GC.WaitForPendingFinalizers();
  1593. }
  1594. private void testToolStripMenuItem1_Click(object sender, EventArgs e)
  1595. {
  1596. //SaveMarkParticleRectangleOnFieldFile();
  1597. MessageBox.Show("Export completed!");
  1598. }
  1599. private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
  1600. {
  1601. //将所有的数据导出到EXCEL中
  1602. SaveFileDialog sfd = new SaveFileDialog();
  1603. sfd.Filter = "Excel File(*.xls)|*.xls";
  1604. //设置默认文件类型显示顺序
  1605. sfd.FilterIndex = 1;
  1606. //保存对话框是否记忆上次打开的目录
  1607. sfd.RestoreDirectory = true;
  1608. if (sfd.ShowDialog() == DialogResult.OK)
  1609. {
  1610. IWorkbook workbook = new HSSFWorkbook(); //用于创建.xls office2003开始以前的
  1611. //IWorkbook workbook = new XSSFWorkbook(); //用于创建.xlsx office2007开始以后的
  1612. ISheet sheet;
  1613. //创建Excel文件
  1614. FileStream fs = File.Create(sfd.FileName);
  1615. fs.Close();
  1616. sheet = workbook.CreateSheet("Particles");//创建工作表
  1617. //创建表格边框样式风格
  1618. ICellStyle cellStyle = workbook.CreateCellStyle();
  1619. cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  1620. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  1621. //设置上4边
  1622. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1623. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1624. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1625. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1626. //设置字符大小和颜色
  1627. IFont font = workbook.CreateFont();
  1628. font.FontName = "黑体";
  1629. font.FontHeightInPoints = 10;
  1630. cellStyle.SetFont(font);
  1631. //设置颗粒名列宽
  1632. sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
  1633. sheet.SetColumnWidth(2, 3 * 256);//图像列宽
  1634. IRow row;
  1635. ICell cell;
  1636. //插入表头
  1637. row = sheet.CreateRow(1);//从第15行添加一行
  1638. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1639. {
  1640. cell = row.CreateCell(i_cell);
  1641. cell.CellStyle = cellStyle;
  1642. cell.SetCellValue(dgV_ParticlesDevidePage.Columns[i_cell].Name);
  1643. }
  1644. //插入表内容
  1645. for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
  1646. {
  1647. row = sheet.CreateRow(2 + i_row);
  1648. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1649. {
  1650. cell = row.CreateCell(i_cell);
  1651. cell.CellStyle = cellStyle;
  1652. if (dgV_ParticlesDevidePage[i_cell, i_row].Value == null)
  1653. continue;
  1654. if (i_cell == 2)
  1655. {
  1656. //颗粒图像列
  1657. Bitmap bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
  1658. byte[] bytes = ImageConvertToBytes(bp);
  1659. //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
  1660. int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
  1661. //第三步,在sheet中创建画布
  1662. IDrawing patriarch = sheet.CreateDrawingPatriarch();
  1663. //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
  1664. IClientAnchor anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
  1665. //第五步,创建图片
  1666. IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
  1667. //图像效果不好,自己另外导出吧,这里对该列宽进行了设置0
  1668. }
  1669. else
  1670. {
  1671. //非图像列
  1672. double dbl = 0;
  1673. if(double.TryParse(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString(),out dbl))
  1674. {
  1675. cell.SetCellValue(dbl);
  1676. }
  1677. else
  1678. {
  1679. cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
  1680. }
  1681. }
  1682. }
  1683. }
  1684. ISheet sheet2;
  1685. sheet2 = workbook.CreateSheet("Peak spectrum");//创建工作表
  1686. //设置颗粒名列宽
  1687. sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
  1688. //完成后,对Excel进行保存
  1689. FileStream file = new FileStream(sfd.FileName, FileMode.Create);
  1690. workbook.Write(file);
  1691. file.Close();
  1692. MessageBox.Show("Export complete!");
  1693. //导出完成后,打开Excel文件
  1694. if (File.Exists(sfd.FileName))
  1695. {
  1696. //打开刚才导出的文件
  1697. System.Diagnostics.Process.Start(sfd.FileName);
  1698. }
  1699. }
  1700. }
  1701. /// <summary>
  1702. /// 将image转成bytes
  1703. /// </summary>
  1704. /// <param name="in_img"></param>
  1705. /// <returns></returns>
  1706. public byte[] ImageConvertToBytes(System.Drawing.Image in_img)
  1707. {
  1708. MemoryStream ms = new MemoryStream();
  1709. in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1710. return ms.ToArray();
  1711. }
  1712. public bool CheckParamExist<T>(T Param)
  1713. {
  1714. if (Param == null)
  1715. {
  1716. return false;
  1717. }
  1718. else
  1719. {
  1720. return true;
  1721. }
  1722. }
  1723. private void ToolStripMenuItem_Delete_Particle_Click(object sender, EventArgs e)
  1724. {
  1725. string path = result.FilePath;
  1726. ParticleData fielddata = new ParticleData(result.FilePath);
  1727. List<Particle> particles = fielddata.GetParticleAllList();
  1728. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  1729. for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
  1730. {
  1731. //从事先加载的Bitmap对象的Tag中取出List<string>
  1732. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
  1733. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1734. List<string> list_str = (List<string>)ls_bp.Tag;
  1735. if (list_str != null)
  1736. {
  1737. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1738. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1739. foreach (Particle item in particles)
  1740. {
  1741. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  1742. {
  1743. if (ReportFun.DeleteParticlesFromLibrary(item.ParticleId, item.FieldId))
  1744. {
  1745. MessageBox.Show("Deleted successfully");
  1746. }
  1747. else
  1748. {
  1749. MessageBox.Show("Delete failed");
  1750. }
  1751. break;
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. private void btn_ReMeasure_Click(object sender, EventArgs e)
  1758. {
  1759. frmReMeasure.TopMost = true;//设置置顶
  1760. DialogResult dialogResult = frmReMeasure.ShowDialog();
  1761. if (dialogResult == DialogResult.OK)
  1762. {
  1763. m_mythread = new Thread(Thread_ReMeasure);
  1764. //改为线程调用,先判断线程状态
  1765. m_mythread.Start(m_ReportApp.GetSelectedParticles());
  1766. }
  1767. }
  1768. }
  1769. }