ParticlesGridDevidePage.cs 67 KB

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