ParticlesGridDevidePage.cs 81 KB

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