ParticlesGridDevidePage.cs 83 KB

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