ParticlesGridDevidePage.cs 81 KB

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