ParticlesGridDevidePage.cs 79 KB

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