ParticlesGridDevidePage.cs 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  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. ////判断是否已经有导出过的标记帧图文件夹,如果已经存在,则直接返回不输出,先不加
  1267. DirectoryInfo theFolder_FieldMark = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  1268. if (!theFolder_FieldMark.Exists)
  1269. {
  1270. //创建
  1271. theFolder_FieldMark.Create();
  1272. }
  1273. else
  1274. {
  1275. //已经存在的话,直接返回
  1276. //return;
  1277. }
  1278. //查找该field下对应所有的颗粒
  1279. DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
  1280. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
  1281. if (theFolder.Exists)
  1282. {
  1283. //循环帧图,再循环各帧图中的颗粒,进行标记,保存
  1284. foreach (FileInfo nextifile in theFolder.GetFiles())
  1285. {
  1286. //找出所有的用户库文件,在这个目录中
  1287. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  1288. {
  1289. //确认对应的帧图名
  1290. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  1291. str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
  1292. if (Convert.ToInt32(str_fieldid.ToString()) > 10)
  1293. continue;
  1294. if (dataTable.Select(" fieldid = " + str_fieldid).Count() > 0)
  1295. {
  1296. Image img = Image.FromFile(nextifile.FullName);
  1297. Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  1298. using (Graphics g = Graphics.FromImage(ls_fieldbp))
  1299. {
  1300. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1301. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1302. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1303. g.DrawImage(img, 0, 0);
  1304. }
  1305. img.Dispose();
  1306. img = null;
  1307. //循环将颗粒,进行标记到bitmap图上
  1308. DataRow[] drlist = dt_AllParticle.Select(" fieldid = " + str_fieldid);
  1309. for (int i_row = 0; i_row < drlist.Count(); i_row++)
  1310. {
  1311. //string str_fieldid = drlist[i_row]["fieldid"].ToString();
  1312. string str_particleid = drlist[i_row]["particleid"].ToString();
  1313. string str_stdtypeid = drlist[i_row]["typeid"].ToString();
  1314. string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
  1315. string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
  1316. string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
  1317. string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
  1318. //确定需要标记颗粒的定位
  1319. Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
  1320. Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
  1321. //向帧图进行标记颗粒位置
  1322. Graphics g = Graphics.FromImage(ls_fieldbp);
  1323. g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
  1324. //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
  1325. int ls_offsetx = offset_rect.X + offset_rect.Width;
  1326. if (ls_offsetx > ls_fieldbp.Width - 10)
  1327. {
  1328. ls_offsetx = offset_rect.X - 10;
  1329. }
  1330. g.DrawString(str_fieldid + "" + str_particleid.ToString(),
  1331. new Font("黑体", 8), new SolidBrush(Color.Aqua), new PointF(ls_offsetx, offset_rect.Y));
  1332. //保存带有标记的帧图
  1333. ls_fieldbp.Save(str_path_FIELD_FILES_MARK + str_fieldid.ToString() + ".bmp");
  1334. //ls_fieldbp.Dispose();
  1335. }
  1336. }
  1337. }
  1338. }
  1339. }
  1340. //
  1341. GC.Collect();
  1342. GC.WaitForPendingFinalizers();
  1343. }
  1344. private void testToolStripMenuItem1_Click(object sender, EventArgs e)
  1345. {
  1346. //SaveMarkParticleRectangleOnFieldFile();
  1347. MessageBox.Show("导出完成!");
  1348. }
  1349. private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
  1350. {
  1351. //将所有的数据导出到EXCEL中
  1352. SaveFileDialog sfd = new SaveFileDialog();
  1353. sfd.Filter = "Excel File(*.xls)|*.xls";
  1354. //设置默认文件类型显示顺序
  1355. sfd.FilterIndex = 1;
  1356. //保存对话框是否记忆上次打开的目录
  1357. sfd.RestoreDirectory = true;
  1358. if (sfd.ShowDialog() == DialogResult.OK)
  1359. {
  1360. IWorkbook workbook = new HSSFWorkbook(); //用于创建.xls office2003开始以前的
  1361. //IWorkbook workbook = new XSSFWorkbook(); //用于创建.xlsx office2007开始以后的
  1362. ISheet sheet;
  1363. //创建Excel文件
  1364. FileStream fs = File.Create(sfd.FileName);
  1365. fs.Close();
  1366. sheet = workbook.CreateSheet("Particles");//创建工作表
  1367. //创建表格边框样式风格
  1368. ICellStyle cellStyle = workbook.CreateCellStyle();
  1369. cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  1370. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  1371. //设置上4边
  1372. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1373. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1374. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1375. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1376. //设置字符大小和颜色
  1377. IFont font = workbook.CreateFont();
  1378. font.FontName = "黑体";
  1379. font.FontHeightInPoints = 10;
  1380. cellStyle.SetFont(font);
  1381. //设置颗粒名列宽
  1382. sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
  1383. sheet.SetColumnWidth(2, 3 * 256);//图像列宽
  1384. IRow row;
  1385. ICell cell;
  1386. //插入表头
  1387. row = sheet.CreateRow(1);//从第15行添加一行
  1388. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1389. {
  1390. cell = row.CreateCell(i_cell);
  1391. cell.CellStyle = cellStyle;
  1392. cell.SetCellValue(dgV_ParticlesDevidePage.Columns[i_cell].Name);
  1393. }
  1394. //插入表内容
  1395. for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
  1396. {
  1397. row = sheet.CreateRow(2 + i_row);
  1398. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1399. {
  1400. cell = row.CreateCell(i_cell);
  1401. cell.CellStyle = cellStyle;
  1402. if (dgV_ParticlesDevidePage[i_cell, i_row].Value == null)
  1403. continue;
  1404. if (i_cell == 2)
  1405. {
  1406. //颗粒图像列
  1407. Bitmap bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
  1408. byte[] bytes = ImageConvertToBytes(bp);
  1409. //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
  1410. int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
  1411. //第三步,在sheet中创建画布
  1412. IDrawing patriarch = sheet.CreateDrawingPatriarch();
  1413. //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
  1414. IClientAnchor anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
  1415. //第五步,创建图片
  1416. IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
  1417. //图像效果不好,自己另外导出吧,这里对该列宽进行了设置0
  1418. }
  1419. else
  1420. {
  1421. //非图像列
  1422. cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
  1423. }
  1424. }
  1425. }
  1426. //完成后,对Excel进行保存
  1427. FileStream file = new FileStream(sfd.FileName, FileMode.Create);
  1428. workbook.Write(file);
  1429. file.Close();
  1430. MessageBox.Show("Export complete!");
  1431. //导出完成后,打开Excel文件
  1432. if (File.Exists(sfd.FileName))
  1433. {
  1434. //打开刚才导出的文件
  1435. System.Diagnostics.Process.Start(sfd.FileName);
  1436. }
  1437. }
  1438. }
  1439. /// <summary>
  1440. /// 将image转成bytes
  1441. /// </summary>
  1442. /// <param name="in_img"></param>
  1443. /// <returns></returns>
  1444. public byte[] ImageConvertToBytes(System.Drawing.Image in_img)
  1445. {
  1446. MemoryStream ms = new MemoryStream();
  1447. in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1448. return ms.ToArray();
  1449. }
  1450. }
  1451. }