ParticlesGridDevidePage.cs 63 KB

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