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