ParticlesGridDevidePage.cs 67 KB

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