ParticlesGridDevidePage.cs 77 KB

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