ParticlesGridDevidePage.cs 62 KB

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