ParticlesGridDevidePage.cs 81 KB

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