ParticlesGridDevidePage.cs 79 KB

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