ParticlesGridDevidePage.cs 63 KB

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