ParticlesGridDevidePage.cs 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  1. using NPOI.HSSF.UserModel;
  2. using NPOI.SS.UserModel;
  3. using OTSIncAReportApp;
  4. using OTSIncAReportApp.DataOperation.DataAccess;
  5. using OTSIncAReportApp.DataOperation.Model;
  6. using OTSIncAReportApp.SysMgrTools;
  7. using OTSIncAReportGraph.Class;
  8. using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
  9. using OTSIncAReportMailInterface;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Drawing.Imaging;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Threading;
  19. using System.Windows.Forms;
  20. namespace OTSIncAReportGrids
  21. {
  22. public partial class ParticlesGridDevidePage : UserControl
  23. {
  24. #region 枚举定义
  25. /// <summary>
  26. /// 样品台X轴方向
  27. /// </summary>
  28. enum OTS_X_AXIS_DIRECTION
  29. {
  30. LEFT_TOWARD = 0,
  31. RIGHT_TOWARD = 1
  32. }
  33. /// <summary>
  34. /// 样品台Y轴方向
  35. /// </summary>
  36. enum OTS_Y_AXIS_DIRECTION
  37. {
  38. UP_TOWARD = 0,
  39. DOWN_TOWARD = 1
  40. }
  41. #endregion
  42. //设置模拟数据表
  43. public DataTable m_dt = new DataTable();
  44. //底层操作类
  45. OTSIncAReportGridsFun m_OTSIncAReportGridsFun = null;
  46. //进度条窗体
  47. public Frm_UserProgress m_frm_userprogress;
  48. //移动SEM到指定位置发生线程
  49. private Thread m_mythread;
  50. //记录线程是否已经运行完成的状态
  51. private bool m_mythread_state = false;
  52. //导出图像文件的路径
  53. private string m_imagefilepath = "";
  54. //显示元素列表
  55. public List<string> m_list_elementscolname = null;
  56. //单个数据源所拥有的列数,这里保存下来,供导出模块使用
  57. public int m_oneresult_columncount = 0;
  58. //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
  59. public List<int> m_list_oneresult_columncount;
  60. //国际化
  61. Language lan;
  62. Hashtable table;
  63. //测量结果
  64. ResultFile result = null;
  65. FieldData fieldData;
  66. private string m_filename = "";
  67. #region 分页器相关
  68. #region 分页字段和属性
  69. string condition = "";
  70. public string FileName = null;
  71. private int pageIndex = 1;
  72. /// <summary>
  73. /// 当前页面
  74. /// </summary>
  75. public virtual int PageIndex
  76. {
  77. get { return pageIndex; }
  78. set { pageIndex = value; }
  79. }
  80. private int pageSize = 20;
  81. /// <summary>
  82. /// 每页记录数
  83. /// </summary>
  84. public virtual int PageSize
  85. {
  86. get { return pageSize; }
  87. set { pageSize = value; }
  88. }
  89. string OrderFunction = "fieldid,particleid";
  90. private int recordCount = 0;
  91. /// <summary>
  92. /// 总记录数
  93. /// </summary>
  94. public virtual int RecordCount
  95. {
  96. get { return recordCount; }
  97. set { recordCount = value; }
  98. }
  99. private int pageCount = 0;
  100. /// <summary>
  101. /// 总页数
  102. /// </summary>
  103. public int PageCount
  104. {
  105. get
  106. {
  107. pageCount = GetPageCount();
  108. return pageCount;
  109. }
  110. }
  111. /// <summary>
  112. /// 计算总页数
  113. /// </summary>
  114. /// <returns></returns>
  115. private int GetPageCount()
  116. {
  117. if (PageSize == 0)
  118. {
  119. return 0;
  120. }
  121. int pageCount = RecordCount / PageSize;
  122. if (RecordCount % PageSize == 0)
  123. {
  124. pageCount = RecordCount / PageSize;
  125. }
  126. else
  127. {
  128. pageCount = RecordCount / PageSize + 1;
  129. }
  130. return pageCount;
  131. }
  132. #endregion
  133. frmReportApp m_ReportApp;
  134. #endregion
  135. public ParticlesGridDevidePage(frmReportApp ReportApp)
  136. {
  137. m_ReportApp = ReportApp;
  138. result = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult];
  139. InitializeComponent();
  140. m_frm_userprogress = new Frm_UserProgress();
  141. m_mythread_state = false;
  142. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  143. lan = new Language(this);
  144. table = lan.GetNameTable(this.Name);
  145. fieldData = new FieldData(result.FilePath);
  146. }
  147. private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
  148. {
  149. ////显示进度条,计算进度条应该显示的位置和宽度
  150. //Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  151. //if (ls_main_form == null)
  152. //{
  153. // m_frm_userprogress.Visible = false;
  154. //}
  155. //else
  156. //{
  157. // string str7 = table["str7"].ToString();
  158. // m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  159. // m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  160. // m_frm_userprogress.Show();
  161. // m_frm_userprogress.SetProgressValueAndText(0, str7);
  162. //}
  163. //string str2 = "加载颗粒列表,开始从底层加载数据....";
  164. //str2 = table["str2"].ToString();
  165. //m_frm_userprogress.SetProgressValueAndText(1, str2);
  166. m_OTSIncAReportGridsFun = new OTSIncAReportGridsFun(m_ReportApp, this);
  167. if (Language.ReadDefaultLanguage() == "EN")
  168. {
  169. cbB_order.Items.Add("Default");
  170. cbB_order.Items.Add("ParticlesName");
  171. cbB_order.Items.Add("Dmax Ascend");
  172. cbB_order.Items.Add("Dmax Descend");
  173. cbB_order.Items.Add("Area Ascend");
  174. cbB_order.Items.Add("Area Descend");
  175. }
  176. else
  177. {
  178. cbB_order.Items.Add("默认");
  179. cbB_order.Items.Add("颗粒名称");
  180. cbB_order.Items.Add("最大直径 升序");
  181. cbB_order.Items.Add("最大直径 降序");
  182. cbB_order.Items.Add("面积 升序");
  183. cbB_order.Items.Add("面积 降序");
  184. }
  185. cbB_order.SelectedIndex = 0;
  186. cbB_PageSize.Items.Add("20");
  187. cbB_PageSize.Items.Add("100");
  188. cbB_PageSize.Items.Add("500");
  189. cbB_PageSize.Items.Add("1000");
  190. cbB_PageSize.Items.Add("5000");
  191. cbB_PageSize.Items.Add("All");
  192. cbB_PageSize.SelectedIndexChanged -= new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
  193. cbB_PageSize.SelectedIndex = 0;
  194. cbB_PageSize.SelectedIndexChanged += new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
  195. //string str8 = table["str8"].ToString();
  196. //m_frm_userprogress.SetProgressValueAndText(100, str8);
  197. ////加载完成,关闭进度条
  198. //m_frm_userprogress.Close();
  199. }
  200. #region 自定义方法
  201. /// <summary>
  202. /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
  203. /// </summary>
  204. /// <param name="in_cotsparticleclr"></param>
  205. /// <returns></returns>
  206. public Bitmap GetBitmapByParticle(string fieldImage, Rectangle offset_rect)
  207. {
  208. //然后将取出的数据,转换成Bitmap对象
  209. Bitmap ls_bt = DrawFuncation.ReadImageFile(fieldImage);
  210. //为了能把整个颗粒显示完整
  211. offset_rect.X = offset_rect.X - 5;
  212. offset_rect.Y = offset_rect.Y - 5;
  213. offset_rect.Width = offset_rect.Width + 10;
  214. offset_rect.Height = offset_rect.Height + 10;
  215. //防止计算偏差后,有坐标溢出现象
  216. if (offset_rect.X < 0)
  217. offset_rect.X = 0;
  218. if (offset_rect.Y < 0)
  219. offset_rect.Y = 0;
  220. if (offset_rect.X + offset_rect.Width > ls_bt.Width)
  221. {
  222. offset_rect.Width = ls_bt.Width - offset_rect.X;
  223. }
  224. if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
  225. {
  226. offset_rect.Height = ls_bt.Height - offset_rect.Y;
  227. }
  228. //
  229. Bitmap new_ret_bp;
  230. //防止为0后面计算出错
  231. if (offset_rect.Width > 0 && offset_rect.Height > 0)
  232. {
  233. //最后通过list_showsegment组建成新的图片,进行返回
  234. new_ret_bp = ls_bt.Clone(offset_rect, PixelFormat.Format8bppIndexed);
  235. }
  236. else
  237. {
  238. new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
  239. }
  240. return new_ret_bp;
  241. }
  242. public Bitmap GetBitmapForBig(string sub, ParticleData fielddata, double xs)
  243. {
  244. string vs = "," + sub.Replace(':', '-') + ",";
  245. DataTable dataTable = fielddata.GetParticleAll(vs);
  246. if (dataTable.Rows.Count == 0)
  247. {
  248. return null;
  249. }
  250. string path = result.FilePath;
  251. //内接矩形
  252. double max_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs - Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
  253. double max_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs + Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
  254. double min_Y = max_Y;
  255. double min_X = max_X;
  256. //拼接field矩形
  257. double MAX_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
  258. double MAX_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
  259. double MIN_Y = MAX_Y;
  260. double MIN_X = MAX_X;
  261. foreach (DataRow item in dataTable.Rows)
  262. {
  263. //颗粒外接矩形
  264. double lefttopX = Convert.ToInt64(item["FieldPosX"]) * xs + Convert.ToInt64(item["RectLeft"]);
  265. if (lefttopX < min_X)
  266. {
  267. min_X = lefttopX;
  268. }
  269. if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
  270. {
  271. max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
  272. }
  273. double lrfttopY = Convert.ToInt64(item["FieldPosY"]) * xs - Convert.ToInt64(item["RectTop"]);
  274. if (max_Y < lrfttopY)
  275. {
  276. max_Y = lrfttopY;
  277. }
  278. if (min_Y > lrfttopY - Convert.ToInt64(item["RectHeight"]))
  279. {
  280. min_Y = lrfttopY - Convert.ToInt64(item["RectHeight"]);
  281. }
  282. //画布
  283. double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
  284. if (lefttopXH > MAX_X)
  285. {
  286. MAX_X = lefttopXH;
  287. }
  288. if (lefttopXH < MIN_X)
  289. {
  290. MIN_X = lefttopXH;
  291. }
  292. double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
  293. if (MAX_Y < lrfttopYH)
  294. {
  295. MAX_Y = lrfttopYH;
  296. }
  297. if (MIN_Y > lrfttopYH)
  298. {
  299. MIN_Y = lrfttopYH;
  300. }
  301. }
  302. int WIDTH = Convert.ToInt32(MAX_X - MIN_X) + 1024;
  303. int HEIGHT = Convert.ToInt32(MAX_Y - MIN_Y) + 768;
  304. //构造最终的图片白板
  305. Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
  306. Graphics graph = Graphics.FromImage(tableChartImage);
  307. //初始化这个大图
  308. graph.DrawImage(tableChartImage, 0, 0);
  309. int width = Convert.ToInt32(max_X - min_X);
  310. int height = Convert.ToInt32(max_Y - min_Y);
  311. int X = Convert.ToInt32(min_X - MIN_X);
  312. int Y = Convert.ToInt32(MAX_Y - max_Y);
  313. Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
  314. foreach (DataRow item in dataTable.Rows)
  315. {
  316. string filePath = path + "\\FIELD_FILES\\";
  317. string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
  318. //然后将取出的数据,转换成Bitmap对象
  319. Bitmap ls_bt = DrawFuncation.ReadImageFile(imagePath);
  320. int x = Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - MIN_X);
  321. int y = System.Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - MAX_Y));
  322. try
  323. {
  324. graph.DrawImage(ls_bt, x, y);
  325. }
  326. catch (Exception e)
  327. {
  328. throw;
  329. }
  330. }
  331. Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
  332. return bmap;
  333. }
  334. ///// <summary>
  335. ///// 绑定datagridview数据--
  336. ///// </summary>
  337. //private void BindDataGridView()
  338. //{
  339. // #region 加载显示进度条部份
  340. // //m_sec.SendCall("设置鼠标样式", "", "WaitCursor");
  341. // this.Cursor = Cursors.WaitCursor;
  342. // m_frm_userprogress = new Frm_UserProgress();
  343. // //显示进度条,计算进度条应该显示的位置和宽度
  344. // Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  345. // if (ls_main_form == null)
  346. // {
  347. // m_frm_userprogress.Visible = false;
  348. // }
  349. // else
  350. // {
  351. // string str7 = table["str7"].ToString();
  352. // m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  353. // m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  354. // m_frm_userprogress.Show();
  355. // m_frm_userprogress.SetProgressValueAndText(0, str7);
  356. // }
  357. // string str2 = "加载颗粒列表,开始从底层加载数据....";
  358. // str2 = table["str2"].ToString();
  359. // m_frm_userprogress.SetProgressValueAndText(1, str2);
  360. // #endregion
  361. // dgV_ParticlesDevidePage.Rows.Clear();
  362. // dgV_ParticlesDevidePage.Columns.Clear();
  363. // //列名
  364. // Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  365. // keyValues.Add("rowid", table["str4"].ToString());
  366. // keyValues.Add("TypeName", table["str6"].ToString());
  367. // keyValues.Add("ParticleImage", table["str5"].ToString());
  368. // keyValues.Add("Area", "Areaμm²");
  369. // keyValues.Add("DMAX", "DMAXμm");
  370. // keyValues.Add("DMIN", "DMINμm");
  371. // keyValues.Add("ASPECT_MAX", "ASPECT_MAX");
  372. // keyValues.Add("DFERET", "FERETμm");
  373. // keyValues.Add("DPERP", "DPERPμm");
  374. // keyValues.Add("PERIMETER", "PERIMETERμm");
  375. // keyValues.Add("DINSCR", "DINSCRμm");
  376. // keyValues.Add("DMEAN", "DMEANμm");
  377. // keyValues.Add("DELONG", "DELONGμm");
  378. // keyValues.Add("ASPECT_ELONG", "ASPECT_ELONG");
  379. // keyValues.Add("ORIENTATION", "ORIENTATION");
  380. // keyValues.Add("Element", "Element");
  381. // Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  382. // for (int irow = 0; irow < keyValues.Count; irow++)
  383. // {
  384. // if (en.MoveNext())
  385. // {
  386. // if (en.Current.Key == "ParticleImage")
  387. // {
  388. // DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  389. // iconColumn.Name = en.Current.Key;
  390. // iconColumn.HeaderText = en.Current.Value;
  391. // dgV_ParticlesDevidePage.Columns.Add(iconColumn);
  392. // }
  393. // else if (en.Current.Key == "Element")
  394. // {
  395. // }
  396. // else
  397. // {
  398. // int columndid = dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
  399. // }
  400. // }
  401. // }
  402. // ParticleData fielddata = new ParticleData(result.FilePath);
  403. // DataTable particles = fielddata.GetInfoForPartucleDevidePage(PageIndex, pageSize, OrderFunction, condition);
  404. // PageSize = particles.Rows.Count;
  405. // if (particles == null)
  406. // {
  407. // return;
  408. // }
  409. // List<string> ElementType = new List<string>();
  410. // for (int i = 0; i < particles.Rows.Count; i++)
  411. // {
  412. // string[] strcbo = particles.Rows[i]["Element"].ToString().Split(';');
  413. // for (int j = 0; j < strcbo.Length; j++)
  414. // {
  415. // string str = strcbo[j].Split('-')[0].ToString();
  416. // if (!ElementType.Contains(str))
  417. // {
  418. // ElementType.Add(str);
  419. // }
  420. // }
  421. // }
  422. // ElementType.Sort(delegate (string a, string b) { return ReturnsAtomicNumberByElementName(a).CompareTo(ReturnsAtomicNumberByElementName(b)); });
  423. // List<string> list_str = new List<string>(GetElementsColName().Distinct().ToList());//去重
  424. // List<string> ElementTypeSort = new List<string>(ElementType);
  425. // for (int i = 0; i < list_str.Count; i++)
  426. // {
  427. // for (int j = 0; j < ElementType.Count; j++)
  428. // {
  429. // if (list_str[i] == ElementType[j])
  430. // {
  431. // dgV_ParticlesDevidePage.Columns.Add(ElementType[j], ElementType[j]);
  432. // ElementTypeSort.Remove(ElementType[j]);
  433. // }
  434. // }
  435. // }
  436. // for (int i = 0; i < ElementTypeSort.Count; i++)
  437. // {
  438. // dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
  439. // }
  440. // RecordCount = fielddata.GetAllInfo(condition).Rows.Count;
  441. // string particleM = "";
  442. // double jd = 95f / (double)particles.Rows.Count;//计算进度刻度
  443. // //将datatable的数据,分别解析绑定到GridView上
  444. // KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  445. // for (int i = 0; i < particles.Rows.Count; i++)
  446. // {
  447. // //更新进度,每100条记录加载完,更新一次进度
  448. // if (i % 100 == 0)
  449. // m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "Loding..");
  450. // Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  451. // int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
  452. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value = (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
  453. // for (int k = 0; k < keyValues.Count; k++)
  454. // {
  455. // if (enl.MoveNext())
  456. // {
  457. // if (enl.Current.Key == "rowid")
  458. // {
  459. // //dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = i + 1;
  460. // }
  461. // if (enl.Current.Key == "ParticleImage")
  462. // {
  463. // string subt = particles.Rows[i]["SubParticles"].ToString();
  464. // if (subt != null && subt != "")
  465. // {
  466. // double ScanFieldSize = 1142;
  467. // //double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
  468. // string filePatht = result.FilePath + "\\FIELD_FILES\\";
  469. // string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
  470. // //然后将取出的数据,转换成Bitmap对象
  471. // Bitmap tempbit = fielddata.ReadImageFile(imagePatht);
  472. // int pixw = tempbit.Width;
  473. // double xs = pixw / ScanFieldSize;
  474. // particleM = particleM + "," + subt;
  475. // Bitmap bmap = fielddata.GetBitmapForBig(subt, xs, result.FilePath);
  476. // if (bmap != null)
  477. // {
  478. // bmap.Tag = new List<string>() { subt.Split(',')[0].Split(':')[0], subt.Split(',')[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
  479. // dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  480. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  481. // }
  482. // else
  483. // {
  484. // dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  485. // }
  486. // }
  487. // else
  488. // {
  489. // string filePath = result.FilePath + "\\FIELD_FILES\\";
  490. // if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  491. // {
  492. // string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  493. // FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), fielddata.ReadImageFile(imagePath));
  494. // }
  495. // 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"]) };
  496. // Bitmap bmap = fielddata.GetBitmapByParticle(FieldImage.Value, rectangle);
  497. // bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString() };
  498. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  499. // }
  500. // }
  501. // if (enl.Current.Key == "ASPECT_MAX")
  502. // {
  503. // double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  504. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  505. // }
  506. // if (enl.Current.Key == "ASPECT_ELONG")
  507. // {
  508. // double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  509. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  510. // }
  511. // if (particles.Columns.Contains(enl.Current.Key))
  512. // {
  513. // double num = 0;
  514. // if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  515. // {
  516. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  517. // }
  518. // else if (enl.Current.Key == "Element")
  519. // {
  520. // List<string> elementtemp = new List<string>(ElementType);
  521. // string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  522. // for (int j = 0; j < strcbo.Length; j++)
  523. // {
  524. // string[] str = strcbo[j].Split('-');
  525. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString();
  526. // elementtemp.Remove(str[0].ToString());
  527. // }
  528. // foreach (var ele in elementtemp)
  529. // {
  530. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[ele].Value = "0";
  531. // }
  532. // }
  533. // else
  534. // {
  535. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  536. // }
  537. // }
  538. // if (enl.Current.Key == "TypeName")
  539. // {
  540. // if (particles.Rows[i]["TypeId"].ToString() == "7")
  541. // {
  542. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = table["partcletype7"].ToString();
  543. // }
  544. // else if (particles.Rows[i]["TypeId"].ToString() == "8")
  545. // {
  546. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = table["partcletype8"].ToString();
  547. // }
  548. // else if (particles.Rows[i]["TypeId"].ToString() == "9")
  549. // {
  550. // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = table["partcletype9"].ToString();
  551. // }
  552. // }
  553. // }
  554. // }
  555. // //每加载2000条数据后,进行一次内存回收
  556. // if (i % 2000 == 0)
  557. // {
  558. // GC.Collect();
  559. // GC.WaitForPendingFinalizers();
  560. // }
  561. // }
  562. // #region 加载进度条进度部份结束
  563. // //加载完成设置鼠标为默认
  564. // //m_sec.SendCall("设置鼠标样式", "", "Default");
  565. // this.Cursor = Cursors.Default;
  566. // string str8 = table["str8"].ToString();
  567. // m_frm_userprogress.SetProgressValueAndText(100, str8);
  568. // //加载完成,关闭进度条
  569. // m_frm_userprogress.Close();
  570. // #endregion
  571. //}
  572. private void BindDataGridView()
  573. {
  574. #region 加载显示进度条部份
  575. this.Cursor = Cursors.WaitCursor;
  576. m_frm_userprogress = new Frm_UserProgress();
  577. //显示进度条,计算进度条应该显示的位置和宽度
  578. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  579. if (ls_main_form == null)
  580. {
  581. m_frm_userprogress.Visible = false;
  582. }
  583. else
  584. {
  585. string str7 = table["str7"].ToString();
  586. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  587. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  588. m_frm_userprogress.Show();
  589. m_frm_userprogress.SetProgressValueAndText(0, str7);
  590. }
  591. string str2 = "加载颗粒列表,开始从底层加载数据....";
  592. str2 = table["str2"].ToString();
  593. m_frm_userprogress.SetProgressValueAndText(1, str2);
  594. #endregion
  595. dgV_ParticlesDevidePage.Rows.Clear();
  596. dgV_ParticlesDevidePage.Columns.Clear();
  597. //从报告xml文件中加载,显示计算列,显示元素信息
  598. string str_DefaultComputedColName = "", str_ElementsColName = "";
  599. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXmlData(Application.StartupPath + m_ReportApp.m_OTSReportMgrParamFile, "XMLData");
  600. DataTable dt = ds.Tables["Member"];
  601. foreach (DataRow element in dt.Rows)
  602. {
  603. string RegName = element["RegName"].ToString();
  604. if (RegName == "DefaultComputedColName")
  605. {
  606. str_DefaultComputedColName = element["strValue"].ToString();
  607. }
  608. if (RegName == "ElementsColName")
  609. {
  610. str_ElementsColName = element["strValue"].ToString();
  611. }
  612. }
  613. //获取需要显示的计算列
  614. string[] strs = str_DefaultComputedColName.Split(',');
  615. //列名
  616. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  617. keyValues.Add("rowid", table["str4"].ToString());
  618. keyValues.Add("TypeName", table["str6"].ToString());
  619. keyValues.Add("ParticleImage", table["str5"].ToString());
  620. keyValues.Add("SEMPosX", "SEMPosX");
  621. keyValues.Add("SEMPosY", "SEMPosY");
  622. for (int i = 0; i < strs.Count(); i++)
  623. {
  624. if (strs[i] == "Area")
  625. {
  626. keyValues.Add("Area", table["str21"].ToString());
  627. }
  628. if (strs[i] == "EquivalentCircleDiameter")
  629. {
  630. keyValues.Add("Equivalent", table["str22"].ToString());
  631. }
  632. if (strs[i] == "MaxDiameter")
  633. {
  634. keyValues.Add("DMAX", table["str23"].ToString());
  635. }
  636. if (strs[i] == "MinDiameter")
  637. {
  638. keyValues.Add("DMIN", table["str24"].ToString());
  639. }
  640. if (strs[i] == "DiameterRatio")
  641. {
  642. keyValues.Add("DiameterRatio", table["str25"].ToString());
  643. }
  644. if (strs[i] == "FerretDiameter")
  645. {
  646. keyValues.Add("DFERET", table["str26"].ToString());
  647. }
  648. if (strs[i] == "PERP")
  649. {
  650. keyValues.Add("DPERP", table["str27"].ToString());
  651. }
  652. if (strs[i] == "PERI")
  653. {
  654. keyValues.Add("PERIMETER", table["str28"].ToString());
  655. }
  656. if (strs[i] == "INSCR")
  657. {
  658. keyValues.Add("DINSCR", table["str29"].ToString());
  659. }
  660. if (strs[i] == "MEAN")
  661. {
  662. keyValues.Add("DMEAN", table["str30"].ToString());
  663. }
  664. if (strs[i] == "ELONG")
  665. {
  666. keyValues.Add("DELONG", table["str31"].ToString());
  667. }
  668. if (strs[i] == "ASPECT_ELONG")
  669. {
  670. keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
  671. }
  672. if (strs[i] == "Orientation")
  673. {
  674. keyValues.Add("ORIENTATION", table["str33"].ToString());
  675. }
  676. }
  677. keyValues.Add("Element", "Element");
  678. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  679. for (int irow = 0; irow < keyValues.Count; irow++)
  680. {
  681. if (en.MoveNext())
  682. {
  683. if (en.Current.Key == "ParticleImage")
  684. {
  685. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  686. iconColumn.Name = en.Current.Key;
  687. iconColumn.HeaderText = en.Current.Value;
  688. dgV_ParticlesDevidePage.Columns.Add(iconColumn);
  689. }
  690. else if (en.Current.Key == "Element")
  691. {
  692. }
  693. else
  694. {
  695. int columndid = dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
  696. }
  697. }
  698. }
  699. ParticleData fielddata = new ParticleData(result.FilePath);
  700. DataTable particles = fielddata.GetInfoForPartucleDevidePage(PageIndex, pageSize, OrderFunction, condition);
  701. //PageSize = particles.Rows.Count;
  702. if (particles == null)
  703. {
  704. return;
  705. }
  706. //获取需要显示的元素名
  707. List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
  708. for (int i = 0; i < ElementTypeSort.Count; i++)
  709. {
  710. dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
  711. }
  712. ////禁止列排序
  713. //for (int i = 0; i < this.dgV_ParticlesDevidePage.Columns.Count; i++)
  714. //{
  715. // this.dgV_ParticlesDevidePage.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  716. //}
  717. RecordCount = fielddata.GetAllInfo(condition).Rows.Count;
  718. string particleM = "";
  719. //DataTable particlesNew = particles.Clone();
  720. double jd = 95f / (double)particles.Rows.Count;//计算进度刻度
  721. string filePath = result.FilePath + "\\FIELD_FILES\\";
  722. KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  723. for (int i = 0; i < particles.Rows.Count; i++)
  724. {
  725. //更新进度,每100条记录加载完,更新一次进度
  726. if (i % 100 == 0)
  727. m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "Loding..");
  728. Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  729. int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
  730. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value = (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
  731. for (int k = 0; k < keyValues.Count; k++)
  732. {
  733. if (enl.MoveNext())
  734. {
  735. if (enl.Current.Key == "rowid")
  736. {
  737. //dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = i + 1;
  738. }
  739. if (enl.Current.Key == "ParticleImage")
  740. {
  741. string subt = particles.Rows[i]["SubParticles"].ToString();
  742. if (subt != null && subt != "")
  743. {
  744. double ScanFieldSize = 1142;
  745. //double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
  746. string filePatht = result.FilePath + "\\FIELD_FILES\\";
  747. string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
  748. //然后将取出的数据,转换成Bitmap对象
  749. Bitmap tempbit = fielddata.ReadImageFile(imagePatht);
  750. int pixw = tempbit.Width;
  751. double xs = pixw / ScanFieldSize;
  752. particleM = particleM + "," + subt;
  753. Bitmap bmap = fielddata.GetBitmapForBig(subt, xs, result.FilePath);
  754. if (bmap != null)
  755. {
  756. bmap.Tag = new List<string>() { subt.Split(',')[0].Split(':')[0], subt.Split(',')[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
  757. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  758. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  759. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  760. }
  761. else
  762. {
  763. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  764. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  765. }
  766. }
  767. else
  768. {
  769. if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  770. {
  771. string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  772. FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), fielddata.ReadImageFile(imagePath));
  773. }
  774. 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"]) };
  775. Bitmap bmap = fielddata.GetBitmapByParticle(FieldImage.Value, rectangle);
  776. bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString() };
  777. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  778. }
  779. }
  780. if (enl.Current.Key == "DiameterRatio")
  781. {
  782. double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  783. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  784. }
  785. if (enl.Current.Key == "ASPECT_ELONG")
  786. {
  787. double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  788. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  789. }
  790. if (particles.Columns.Contains(enl.Current.Key))
  791. {
  792. double num = 0;
  793. if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  794. {
  795. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  796. }
  797. else if (enl.Current.Key == "Element")
  798. {
  799. List<string> elementtemp = new List<string>(ElementTypeSort);
  800. string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  801. for (int j = 0; j < strcbo.Length; j++)
  802. {
  803. string[] str = strcbo[j].Split('-');
  804. if (ElementTypeSort.Contains(str[0]))
  805. { dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
  806. elementtemp.Remove(str[0].ToString());
  807. }
  808. foreach (var ele in elementtemp)
  809. {
  810. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[ele].Value = "0";
  811. }
  812. }
  813. else
  814. {
  815. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  816. }
  817. }
  818. if (enl.Current.Key == "TypeName")
  819. {
  820. if (particles.Rows[i]["TypeId"].ToString() == "7")
  821. {
  822. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "SiC";
  823. }
  824. else if (particles.Rows[i]["TypeId"].ToString() == "8")
  825. {
  826. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "FeO";
  827. }
  828. else if (particles.Rows[i]["TypeId"].ToString() == "9")
  829. {
  830. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  831. }
  832. }
  833. if (enl.Current.Key == "Equivalent")
  834. {
  835. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  836. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  837. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  838. }
  839. }
  840. }
  841. //每加载2000条数据后,进行一次内存回收
  842. if (i % 2000 == 0)
  843. {
  844. GC.Collect();
  845. GC.WaitForPendingFinalizers();
  846. }
  847. }
  848. #region 加载进度条进度部份结束
  849. //加载完成设置鼠标为默认
  850. this.Cursor = Cursors.Default;
  851. string str8 = table["str8"].ToString();
  852. m_frm_userprogress.SetProgressValueAndText(100, str8);
  853. //加载完成,关闭进度条
  854. m_frm_userprogress.Close();
  855. #endregion
  856. }
  857. /// <summary>
  858. /// 设置DataGridView样式
  859. /// </summary>
  860. private void SetDataGridViewStyle()
  861. {
  862. //用户不能调整标题的高度
  863. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  864. //用户不能调整 行高
  865. dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
  866. //改变行的高度;
  867. //Gview_gz.RowTemplate.Height = 20;
  868. //点击选择整行
  869. dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  870. //居中显示
  871. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  872. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  873. dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
  874. dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  875. //再次重覆禁用拖动表头高度,居然有效果了
  876. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  877. //设置grid可以复制
  878. dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  879. //设置每列的宽度
  880. dgV_ParticlesDevidePage.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  881. dgV_ParticlesDevidePage.Columns[1].Width = 150;
  882. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].Width = 450;
  883. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  884. //设置序号列不排序
  885. dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  886. //设置序号列不可以设置宽度
  887. dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
  888. dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
  889. ////用户不能调整标题的高度
  890. //dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  891. ////用户不能调整 行高
  892. //dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
  893. ////点击选择整行
  894. //dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  895. ////居中显示
  896. //System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  897. //dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  898. //dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
  899. //dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  900. ////再次重覆禁用拖动表头高度,居然有效果了
  901. //dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  902. ////设置grid可以复制
  903. //dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  904. ////设置每列的宽度
  905. //dgV_ParticlesDevidePage.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  906. //dgV_ParticlesDevidePage.Columns[1].Width = 200;
  907. //dgV_ParticlesDevidePage.AutoResizeColumn(dgV_ParticlesDevidePage.Columns.Count - 1);
  908. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  909. ////设置序号列不排序
  910. //dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  911. ////设置序号列不可以设置宽度
  912. //dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
  913. //dgV_ParticlesDevidePage.AllowUserToAddRows = false;
  914. //dgV_ParticlesDevidePage.AllowUserToDeleteRows = false;
  915. //dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
  916. //dgV_ParticlesDevidePage.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
  917. //dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  918. //dgV_ParticlesDevidePage.ContextMenuStrip = this.contextMenuStrip1;
  919. //dgV_ParticlesDevidePage.BorderStyle = 0;
  920. //dgV_ParticlesDevidePage.Margin = new System.Windows.Forms.Padding(2);
  921. //dgV_ParticlesDevidePage.ReadOnly = true;
  922. //dgV_ParticlesDevidePage.RowHeadersVisible = false;
  923. //dgV_ParticlesDevidePage.RowHeadersWidth = 40;
  924. ////先设置一下头的高度,否则会太矮不好看
  925. //dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  926. //dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
  927. }
  928. #endregion
  929. #region 相关事件
  930. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  931. {
  932. //复制整个表
  933. CopyAll();
  934. }
  935. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  936. {
  937. //复制选择区域
  938. CopySelected();
  939. }
  940. /// <summary>
  941. /// 复制选择区域
  942. /// </summary>
  943. public void CopySelected()
  944. {
  945. //复制选择区域
  946. object oo = dgV_ParticlesDevidePage.GetClipboardContent();
  947. if (oo != null)
  948. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  949. }
  950. /// <summary>
  951. /// 复制所有
  952. /// </summary>
  953. public void CopyAll()
  954. {
  955. dgV_ParticlesDevidePage.SelectAll();
  956. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  957. }
  958. /// <summary>
  959. /// 以图像的方式将GridView进行截图
  960. /// </summary>
  961. public void CopyImage()
  962. {
  963. int height, width;
  964. width = dgV_ParticlesDevidePage.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 2;
  965. height = this.Height;
  966. Bitmap image = new Bitmap(width, height);
  967. dgV_ParticlesDevidePage.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  968. Clipboard.SetImage(image);
  969. }
  970. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  971. {
  972. //对gridview进行截图
  973. CopyImage();
  974. }
  975. private void dgV_ParticlesDevidePage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  976. {
  977. //排序中
  978. if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag.ToString() == "统计行")
  979. {
  980. //ROW1>ROW2
  981. e.SortResult = 1;
  982. if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
  983. e.SortResult = -1;
  984. e.Handled = true;
  985. return;
  986. }
  987. if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag.ToString() == "统计行")
  988. {
  989. //ROW1<ROW2
  990. e.SortResult = -1;
  991. if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
  992. e.SortResult = 1;
  993. e.Handled = true;
  994. return;
  995. }
  996. }
  997. /// <summary>
  998. /// 将OTS坐标转换为Sem 坐标
  999. /// </summary>
  1000. /// <param name="POTSCoord"></param>
  1001. /// <returns></returns>
  1002. public Point ChangeOTSToSemCoord(Point POTSCoord)
  1003. {
  1004. //first if m_semstagedata is null to get stage inforation
  1005. Convert.ToDouble(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["scanFieldSize"]);
  1006. //after obtaining stage info,calc stage point data
  1007. Point ret_SEM_point = new Point();
  1008. // get center point, um
  1009. long xStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["start"]);
  1010. long xEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["end"]);
  1011. long xCenter = (xStart + xEnd) / 2;
  1012. long yStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["start"]);
  1013. long yEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["end"]);
  1014. long yCenter = (yStart + yEnd) / 2;
  1015. // delte = SEM - OTSa
  1016. long deltex = xCenter - 0;
  1017. long deltey = yCenter - 0;
  1018. int xdir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["xAxisDir"]);
  1019. int ydir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["yAxisDir"]);
  1020. if (xdir == (int)OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  1021. {
  1022. ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
  1023. }
  1024. else if (xdir == (int)OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
  1025. {
  1026. ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
  1027. }
  1028. if (ydir == (int)OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  1029. {
  1030. ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
  1031. }
  1032. else if (ydir == (int)OTS_Y_AXIS_DIRECTION.DOWN_TOWARD)
  1033. {
  1034. ret_SEM_point.Y = -1 * (POTSCoord.Y - Convert.ToInt32(deltey));
  1035. }
  1036. return ret_SEM_point;
  1037. }
  1038. #endregion
  1039. #region 获取向导出模块提供的DataTable和GridView对象
  1040. /// <summary>
  1041. /// 获取到该模块输出后形成的DataTable,和GridView
  1042. /// </summary>
  1043. /// <param name="out_dt"></param>
  1044. /// <param name="out_dg"></param>
  1045. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  1046. {
  1047. out_dt = m_dt;
  1048. out_dg = this.dgV_ParticlesDevidePage;//同样通过 dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[2].Value 来获取bitmap对象
  1049. }
  1050. #endregion
  1051. #region 连接电镜相关
  1052. /// <summary>
  1053. /// 移动SEM到指定位置线程函数
  1054. /// </summary>
  1055. private void Thread_GO(object in_obj)
  1056. {
  1057. if (m_mythread_state == false)
  1058. {
  1059. m_mythread_state = true;
  1060. Point sem_point = (Point)in_obj;
  1061. //第一步,连接电镜
  1062. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  1063. Thread.Sleep(500);
  1064. //第二步,移动到指定位置,先读取再设置
  1065. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  1066. {
  1067. //m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  1068. bool MoveFlag = m_OTSIncAReportGridsFun.m_cfun.SetSemPositionXY(sem_point.X, sem_point.Y, 0);
  1069. }
  1070. Thread.Sleep(500);
  1071. //第三步,断开电镜连接
  1072. m_OTSIncAReportGridsFun.DisConnectSEM_ForParticlesGrid();
  1073. Thread.Sleep(1000);
  1074. m_mythread_state = false;
  1075. }
  1076. }
  1077. #endregion
  1078. private void ToolStripMenuItem_exportzoomimagefile_Click(object sender, EventArgs e)
  1079. {
  1080. //导出放大图像
  1081. FolderBrowserDialog fbd = new FolderBrowserDialog();
  1082. if (fbd.ShowDialog() == DialogResult.OK)
  1083. {
  1084. m_imagefilepath = fbd.SelectedPath;
  1085. for (int i = 0; i < m_dt.Rows.Count; i++)
  1086. {
  1087. Bitmap ls_bp = new Bitmap(1, 1);
  1088. ls_bp = (Bitmap)m_dt.Rows[i][1];
  1089. string strPath = m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg";
  1090. string strPath2 = m_imagefilepath + "\\" + (i + 1).ToString() + "s.jpg";
  1091. ls_bp.Save(strPath);
  1092. //m_COTSReportProjFileMgrClr.ReZoom(strPath, strPath2);
  1093. System.IO.File.Delete(strPath);//再将文件删除
  1094. }
  1095. string str1 = table["str9"].ToString();
  1096. MessageBox.Show(str1 + m_dt.Rows.Count.ToString());
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 导出二次放大图像
  1101. /// </summary>
  1102. /// <param name="str_srcPathName"></param>
  1103. /// <param name="str_outPathName"></param>
  1104. public void ParticleReZoom(string str_srcPathName, string str_outPathName)
  1105. {
  1106. //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
  1107. }
  1108. /// <summary>
  1109. /// 显示x-ray能谱图
  1110. /// </summary>
  1111. /// <param name="in_dparticle"></param>
  1112. //private void ShowXRay(OTSIncAReportGraph.DParticle in_dparticle)
  1113. //{
  1114. // //显示xray相关信息
  1115. // uint[] Search_xray = new uint[2000];
  1116. // uint[] Analysis_xray = new uint[2000];
  1117. // //
  1118. // int i_xray_id = 0;
  1119. // List<Element> list_celementchemistryclr = new List<Element>();
  1120. // //获取Xray数据
  1121. // m_OTSIncAReportGridsFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(in_dparticle.CLRTagID, in_dparticle.CLRFieldID, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
  1122. // //get CElementChemistryClr list
  1123. // List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1124. // for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1125. // {
  1126. // ShowElementInfo ls_sei = new ShowElementInfo();
  1127. // ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1128. // ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1129. // list_showelementinfo.Add(ls_sei);
  1130. // }
  1131. // //获取使用标准库的名称
  1132. // string str_stdname = "";
  1133. // string str_IncALibName = "";
  1134. // List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  1135. // List<string> NameList = new List<string>() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString() };
  1136. // if (in_dparticle.STDTypeID < 1000)
  1137. // {
  1138. // int index = FLID.IndexOf(in_dparticle.STDTypeID);
  1139. // if (index == -1)
  1140. // {
  1141. // index = 7;
  1142. // }
  1143. // string name = NameList[index];
  1144. // //小于1000,使用系统默认分类
  1145. // str_IncALibName = name;
  1146. // str_stdname = "Default standard library";
  1147. // }
  1148. // else if (in_dparticle.STDTypeID > 10000)
  1149. // {
  1150. // //大于10000时,使用用户标准库来分析夹杂物名称
  1151. // str_IncALibName = in_dparticle.TypeName;
  1152. // if (str_stdname == "")
  1153. // str_stdname = "System standard library";
  1154. // }
  1155. // //获取数据后,需要对xraytable设置
  1156. // control_XRayTable1.Visible = false;
  1157. // control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray);
  1158. // //颗粒国标信息
  1159. // control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  1160. // control_XRayTable1.GoodName = str_IncALibName;//杂夹物
  1161. // control_XRayTable1.STDName = str_stdname;//标准库
  1162. // control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1163. // control_XRayTable1.Visible = false;
  1164. // this.Refresh();
  1165. //}
  1166. ///// <summary>
  1167. ///// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
  1168. ///// </summary>
  1169. ///// <returns></returns>
  1170. //public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName)
  1171. //{
  1172. // Bitmap ret_bp;
  1173. // //显示xray相关信息
  1174. // uint[] Search_xray = new uint[2000];
  1175. // uint[] Analysis_xray = new uint[2000];
  1176. // //
  1177. // int i_xray_id = 0;
  1178. // List<Element> list_celementchemistryclr = new List<Element>();
  1179. // //获取Xray数据
  1180. // list_celementchemistryclr = new List<Element>();
  1181. // ParticleData particleData = new ParticleData(result.FilePath);
  1182. // Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
  1183. // if (list == null)
  1184. // {
  1185. // return null;
  1186. // }
  1187. // Particle particle = list;
  1188. // if (particle.XrayId > -1)
  1189. // {
  1190. // for (int i = 0; i < 2000; i++)
  1191. // {
  1192. // Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  1193. // }
  1194. // Search_xray = Analysis_xray;
  1195. // i_xray_id = particle.XrayId;
  1196. // list_celementchemistryclr = particle.ElementList;
  1197. // }
  1198. // //get CElementChemistryClr list
  1199. // List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1200. // for (int i = 0; i < list_celementchemistryclr.Count; i++)
  1201. // {
  1202. // ShowElementInfo ls_sei = new ShowElementInfo();
  1203. // ls_sei.ElementName = list_celementchemistryclr[i].Name;
  1204. // ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
  1205. // list_showelementinfo.Add(ls_sei);
  1206. // }
  1207. // //获取使用标准库的名称
  1208. // string str_stdname = "";
  1209. // string str_IncALibName = "";
  1210. // if (in_stdtypeid < 1000)
  1211. // {
  1212. // //小于1000,使用系统默认分类
  1213. // str_IncALibName = TypeName;
  1214. // str_stdname = "Default standard library";
  1215. // }
  1216. // else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
  1217. // {
  1218. // //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
  1219. // str_IncALibName = TypeName;
  1220. // str_stdname = "User defined standard library";
  1221. // }
  1222. // else if (in_stdtypeid > 10000)
  1223. // {
  1224. // //大于10000时,使用用户标准库来分析夹杂物名称
  1225. // str_IncALibName = TypeName;
  1226. // str_stdname = "System standard library";
  1227. // }
  1228. // //获取数据后,需要对xraytable设置
  1229. // control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray);
  1230. // //颗粒国标信息
  1231. // //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
  1232. // control_XRayTable1.GoodName = str_IncALibName;//杂夹物
  1233. // control_XRayTable1.STDName = str_stdname;//标准库
  1234. // control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1235. // control_XRayTable1.Visible = true;
  1236. // control_XRayTable1.Invalidate();
  1237. // control_XRayTable1.Refresh();
  1238. // //this.Controls.Add(control_XRayTable1);
  1239. // ret_bp = control_XRayTable1.ExportXRayImage();
  1240. // return ret_bp;
  1241. //}
  1242. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  1243. {
  1244. //恢复至初始状态
  1245. dgV_ParticlesDevidePage.Rows.Clear();
  1246. dgV_ParticlesDevidePage.Columns.Clear();
  1247. BindDataGridView();
  1248. SetDataGridViewStyle();
  1249. }
  1250. private void ToolStripMenuItem5_Click(object sender, EventArgs e)
  1251. {
  1252. /*注意:多数据源情况下,只获取第一个数据源的选择了多行的情况下,只获取最后一个选择行的,没有办法,这是为了符合李阳博士提出的要求*/
  1253. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  1254. string i_ls_fieldid = "";
  1255. string i_ls_particleid = "";
  1256. int cou = dgV_ParticlesDevidePage.SelectedRows.Count;
  1257. if (cou > 0)
  1258. {
  1259. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[cou - 1];
  1260. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1261. List<string> list_str = (List<string>)ls_bp.Tag;
  1262. if (list_str != null)
  1263. {
  1264. i_ls_fieldid = list_str[0];
  1265. i_ls_particleid = list_str[1];
  1266. }
  1267. }
  1268. ParticleData particleData = new ParticleData(result.FilePath);
  1269. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  1270. ////然后遍历所有的Field
  1271. //Point ls_ots_point = new Point() { X = particle.PosX, Y = particle.PosY };
  1272. ////将该坐标转成SEM坐标
  1273. //Point ls_sem_point = ChangeOTSToSemCoord(ls_ots_point);
  1274. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  1275. if (m_mythread == null)
  1276. {
  1277. return;
  1278. }
  1279. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  1280. {
  1281. return;
  1282. }
  1283. if (m_mythread.ThreadState == ThreadState.Stopped)
  1284. {
  1285. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1286. }
  1287. //改为线程调用,先判断线程状态
  1288. m_mythread.Start(new Point(particle.SEMPosX, particle.SEMPosY));
  1289. }
  1290. private void ToolStripMenuItem_selectparticle_Click(object sender, EventArgs e)
  1291. {
  1292. string path = result.FilePath;
  1293. ParticleData fielddata = new ParticleData(result.FilePath);
  1294. List<Particle> particles = fielddata.GetParticleAllList();
  1295. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  1296. for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
  1297. {
  1298. //从事先加载的Bitmap对象的Tag中取出List<string>
  1299. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
  1300. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1301. List<string> list_str = (List<string>)ls_bp.Tag;
  1302. if (list_str != null)
  1303. {
  1304. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1305. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1306. foreach (Particle item in particles)
  1307. {
  1308. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  1309. {
  1310. ls_list_cotsparticleclr.Add(item);
  1311. break;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. m_ReportApp.SelectedParticles = ls_list_cotsparticleclr;
  1317. string str1 = table["str1"].ToString();
  1318. //然后循环得出,list cotsparticleclr列表,返回给框架
  1319. //m_sec.SendCall(str1, "", "", ls_list_cotsparticleclr);
  1320. string str2 = table["str2"].ToString();
  1321. string str3 = table["str3"].ToString();
  1322. MessageBox.Show(str2 + ls_list_cotsparticleclr.Count.ToString() + str3);
  1323. }
  1324. private void ToolStripMenuItem_exportimagefile_Click(object sender, EventArgs e)
  1325. {
  1326. FolderBrowserDialog fbd = new FolderBrowserDialog();
  1327. if (fbd.ShowDialog() == DialogResult.OK)
  1328. {
  1329. m_imagefilepath = fbd.SelectedPath;
  1330. for (int i = 0; i < dgV_ParticlesDevidePage.Rows.Count; i++)
  1331. {
  1332. Bitmap ls_bp = new Bitmap(1, 1);
  1333. ls_bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i].Cells[2].Value;
  1334. ls_bp.Save(m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg");
  1335. }
  1336. string str9 = table["str9"].ToString();
  1337. MessageBox.Show(str9 + dgV_ParticlesDevidePage.Rows.Count.ToString());
  1338. }
  1339. }
  1340. private void testToolStripMenuItem_Click(object sender, EventArgs e)
  1341. {
  1342. ////测试导出指定颗粒的能谱图,测试相关代码
  1343. //OTSIncAReportGraph.DParticle ls_dparticle = new OTSIncAReportGraph.DParticle();
  1344. //for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
  1345. //{
  1346. // //获取选择行颗粒的fieldid,和particleid
  1347. // string str_fieldid = "";
  1348. // string str_particleid = "";
  1349. // string str_stdtypeid = "";
  1350. // DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
  1351. // Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1352. // List<string> list_str = (List<string>)ls_bp.Tag;
  1353. // if (list_str != null)
  1354. // {
  1355. // str_fieldid = list_str[0];
  1356. // str_particleid = list_str[1];
  1357. // str_stdtypeid = list_str[2];
  1358. // }
  1359. // ls_dparticle.CLRFieldID = Convert.ToInt32(str_fieldid);
  1360. // ls_dparticle.CLRTagID = Convert.ToInt32(str_particleid);
  1361. // ls_dparticle.STDTypeID = Convert.ToInt32(str_stdtypeid);
  1362. //}
  1363. ////显示xray能谱
  1364. //ShowXRay(ls_dparticle);
  1365. //Bitmap ls_bpex = new Bitmap(control_XRayTable1.Width, control_XRayTable1.Height);
  1366. //control_XRayTable1.DrawToBitmap(ls_bpex, new Rectangle(0, 0, control_XRayTable1.Width, control_XRayTable1.Height));
  1367. ////Bitmap ls_bpex = control_XRayTable1.ExportXRayImage();
  1368. //ls_bpex.Save("e:\\test222.jpg");
  1369. }
  1370. /// <summary>
  1371. /// 判断条件输入 前<后
  1372. /// </summary>
  1373. /// <param name="min"></param>
  1374. /// <param name="max"></param>
  1375. /// <returns></returns>
  1376. bool CompareInput(string min,string max)
  1377. {
  1378. int imax = 0;
  1379. int imin = 0;
  1380. double dmax = 0;
  1381. double dmin = 0;
  1382. if (int.TryParse(max, out imax))
  1383. {
  1384. dmax = (double)imax;
  1385. }
  1386. else
  1387. {
  1388. dmax = Convert.ToDouble(max);
  1389. }
  1390. if (int.TryParse(min, out imin))
  1391. {
  1392. dmin = (double)imin;
  1393. }
  1394. else
  1395. {
  1396. dmin = Convert.ToDouble(min);
  1397. }
  1398. if(dmin<=dmax)
  1399. {
  1400. return true;
  1401. }
  1402. else
  1403. {
  1404. return false;
  1405. }
  1406. }
  1407. private void btn_Sel_Click(object sender, EventArgs e)
  1408. {
  1409. condition = "";
  1410. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text))
  1411. {
  1412. double dnum = 0;
  1413. int inum = 0;
  1414. if (double.TryParse(tBx_AreaMin.Text, out dnum) && dnum >= 0)
  1415. {
  1416. condition += " and Area" + " > " + tBx_AreaMin.Text;
  1417. }
  1418. else if(int.TryParse(tBx_AreaMin.Text, out inum) && inum >= 0)
  1419. {
  1420. condition += " and Area" + " > " + tBx_AreaMin.Text;
  1421. }
  1422. else
  1423. {
  1424. MessageBox.Show(table["str10"].ToString());
  1425. return;
  1426. }
  1427. }
  1428. if (!string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  1429. {
  1430. double dnum = 0;
  1431. int inum = 0;
  1432. if (double.TryParse(Tbx_AreaMax.Text, out dnum) && dnum >= 0)
  1433. {
  1434. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  1435. }
  1436. else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
  1437. {
  1438. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  1439. }
  1440. else
  1441. {
  1442. MessageBox.Show(table["str10"].ToString());
  1443. return;
  1444. }
  1445. }
  1446. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text) && !string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  1447. {
  1448. if (!CompareInput(tBx_AreaMin.Text, Tbx_AreaMax.Text))
  1449. {
  1450. MessageBox.Show(table["str11"].ToString());
  1451. return;
  1452. }
  1453. }
  1454. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text))
  1455. {
  1456. double dnum = 0;
  1457. int inum = 0;
  1458. if (double.TryParse(tbx_DmaxMin.Text, out dnum) && dnum >= 0)
  1459. {
  1460. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  1461. }
  1462. else if(int.TryParse(tbx_DmaxMin.Text, out inum)&& inum >= 0)
  1463. {
  1464. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  1465. }
  1466. else
  1467. {
  1468. MessageBox.Show(table["str10"].ToString());
  1469. return;
  1470. }
  1471. }
  1472. if (!string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1473. {
  1474. double dnum = 0;
  1475. int inum = 0;
  1476. if (double.TryParse(tbx_DmaxMax.Text, out dnum) && dnum > 0)
  1477. {
  1478. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1479. }
  1480. else if(int.TryParse(tbx_DmaxMax.Text, out inum)&& inum >= 0)
  1481. {
  1482. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1483. }
  1484. else
  1485. {
  1486. MessageBox.Show(table["str10"].ToString());
  1487. return;
  1488. }
  1489. }
  1490. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text) && !string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1491. {
  1492. if (!CompareInput(tbx_DmaxMin.Text, tbx_DmaxMax.Text))
  1493. {
  1494. MessageBox.Show(table["str11"].ToString());
  1495. return;
  1496. }
  1497. }
  1498. if (!string.IsNullOrWhiteSpace(tbx_Type.Text))
  1499. {
  1500. condition += " and TypeName Like \"%" + tbx_Type.Text + "%\" ";
  1501. }
  1502. lnkFirst_Click(null, null);
  1503. SetDataGridViewStyle();
  1504. }
  1505. private void cbB_order_SelectedIndexChanged(object sender, EventArgs e)
  1506. {
  1507. int ordernum = cbB_order.SelectedIndex;
  1508. if (ordernum == 0)
  1509. {
  1510. OrderFunction = "fieldid,particleid";
  1511. }
  1512. else if (ordernum == 1)
  1513. {
  1514. OrderFunction = "TypeName";
  1515. }
  1516. else if (ordernum == 2)
  1517. {
  1518. OrderFunction = "DMAX";
  1519. }
  1520. else if (ordernum == 3)
  1521. {
  1522. OrderFunction = "DMAX desc";
  1523. }
  1524. else if (ordernum == 4)
  1525. {
  1526. OrderFunction = "Area";
  1527. }
  1528. else if (ordernum == 5)
  1529. {
  1530. OrderFunction = "Area desc";
  1531. }
  1532. lnkFirst_Click(null, null);
  1533. SetDataGridViewStyle();
  1534. }
  1535. /// <summary>
  1536. /// 页面控件呈现
  1537. /// </summary>
  1538. private void DrawControl(bool callEvent)
  1539. {
  1540. BindDataGridView();
  1541. lblTotalCount.Text = RecordCount.ToString();
  1542. lblPageCount.Text = PageCount.ToString();
  1543. txtPageNum.Text = PageIndex.ToString();
  1544. SetFormCtrEnabled();
  1545. if (PageCount == 0 || PageCount == 1)//有且仅有一页
  1546. {
  1547. lnkFirst.Enabled = false;
  1548. lnkPrev.Enabled = false;
  1549. lnkNext.Enabled = false;
  1550. lnkLast.Enabled = false;
  1551. btnGo.Enabled = false;
  1552. }
  1553. else if (PageIndex == 1)//第一页
  1554. {
  1555. lnkFirst.Enabled = false;
  1556. lnkPrev.Enabled = false;
  1557. }
  1558. else if (PageIndex == PageCount)//最后一页
  1559. {
  1560. lnkNext.Enabled = false;
  1561. lnkLast.Enabled = false;
  1562. }
  1563. }
  1564. private void SetFormCtrEnabled()
  1565. {
  1566. lnkFirst.Enabled = true;
  1567. lnkPrev.Enabled = true;
  1568. lnkNext.Enabled = true;
  1569. lnkLast.Enabled = true;
  1570. btnGo.Enabled = true;
  1571. }
  1572. bool isTextChanged = false;
  1573. /// <summary>
  1574. /// 分页属性改变了。
  1575. /// </summary>
  1576. private void txtPageSize_TextChanged(object sender, EventArgs e)
  1577. {
  1578. int num = 0;
  1579. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1580. {
  1581. }
  1582. else { txtPageNum.Text = "1"; }
  1583. }
  1584. /// <summary>
  1585. /// 光标离开分页属性
  1586. private void txtPageSize_Leave(object sender, EventArgs e)
  1587. {
  1588. if (isTextChanged)
  1589. {
  1590. isTextChanged = false;
  1591. lnkFirst_Click(null, null);
  1592. }
  1593. }
  1594. private void txtPageSize_KeyPress(object sender, KeyPressEventArgs e)
  1595. {
  1596. if (isTextChanged)
  1597. {
  1598. isTextChanged = false;
  1599. lnkFirst_Click(null, null);
  1600. }
  1601. }
  1602. private void lnkFirst_Click(object sender, EventArgs e)
  1603. {
  1604. PageIndex = 1;
  1605. DrawControl(true);
  1606. }
  1607. private void lnkPrev_Click(object sender, EventArgs e)
  1608. {
  1609. PageIndex = Math.Max(1, PageIndex - 1);
  1610. DrawControl(true);
  1611. }
  1612. private void lnkNext_Click(object sender, EventArgs e)
  1613. {
  1614. PageIndex = Math.Min(PageCount, PageIndex + 1);
  1615. DrawControl(true);
  1616. }
  1617. private void lnkLast_Click(object sender, EventArgs e)
  1618. {
  1619. PageIndex = PageCount;
  1620. DrawControl(true);
  1621. }
  1622. /// <summary>
  1623. /// 跳转
  1624. /// </summary>
  1625. /// <param name="sender"></param>
  1626. /// <param name="e"></param>
  1627. private void btnGo_Click(object sender, EventArgs e)
  1628. {
  1629. int num = 0;
  1630. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1631. {
  1632. if (num > PageCount)
  1633. {
  1634. num = PageCount;
  1635. txtPageNum.Text = PageCount.ToString();
  1636. }
  1637. PageIndex = num;
  1638. DrawControl(true);
  1639. }
  1640. }
  1641. /// <summary>
  1642. /// 跳转页数限制
  1643. /// </summary>
  1644. private void txtPageNum_TextChanged(object sender, EventArgs e)
  1645. {
  1646. int num = 0;
  1647. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1648. {
  1649. }
  1650. else { txtPageNum.Text = "1"; }
  1651. }
  1652. /// <summary>
  1653. /// enter键功能
  1654. /// </summary>
  1655. private void txtPageNum_KeyPress(object sender, KeyPressEventArgs e)
  1656. {
  1657. btnGo_Click(null, null);
  1658. }
  1659. private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
  1660. {
  1661. if (cbB_PageSize.SelectedItem.ToString() == "All")
  1662. {
  1663. pageSize = -1;
  1664. }
  1665. else
  1666. {
  1667. pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
  1668. }
  1669. lnkFirst_Click(null, null);
  1670. }
  1671. /// <summary>
  1672. /// 在帧图上标记颗粒的位置矩形,并保存到FIELD_FILES_MARK文件夹中
  1673. /// </summary>
  1674. public void SaveMarkParticleRectangleOnFieldFile()
  1675. {
  1676. string str_path_FIELD_FILES = result.FilePath + "\\FIELD_FILES\\";
  1677. string str_path_FIELD_FILES_MARK = result.FilePath + "\\FIELD_FILES_MARK\\";
  1678. ////判断是否已经有导出过的标记帧图文件夹,如果已经存在,则直接返回不输出,先不加
  1679. DirectoryInfo theFolder_FieldMark = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  1680. if (!theFolder_FieldMark.Exists)
  1681. {
  1682. //创建
  1683. theFolder_FieldMark.Create();
  1684. }
  1685. else
  1686. {
  1687. //已经存在的话,直接返回
  1688. //return;
  1689. }
  1690. //查找该field下对应所有的颗粒
  1691. DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
  1692. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
  1693. if (theFolder.Exists)
  1694. {
  1695. //循环帧图,再循环各帧图中的颗粒,进行标记,保存
  1696. foreach (FileInfo nextifile in theFolder.GetFiles())
  1697. {
  1698. //找出所有的用户库文件,在这个目录中
  1699. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  1700. {
  1701. Image img = Image.FromFile(nextifile.FullName);
  1702. Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  1703. using (Graphics g = Graphics.FromImage(ls_fieldbp))
  1704. {
  1705. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1706. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1707. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1708. g.DrawImage(img, 0, 0);
  1709. }
  1710. img.Dispose();
  1711. img = null;
  1712. //确认对应的帧图名
  1713. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  1714. str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
  1715. //循环将颗粒,进行标记到bitmap图上
  1716. DataRow[] drlist = dt_AllParticle.Select(" fieldid = " + str_fieldid);
  1717. for (int i_row = 0; i_row < drlist.Count(); i_row++)
  1718. {
  1719. //
  1720. //string str_fieldid = drlist[i_row]["fieldid"].ToString();
  1721. string str_particleid = drlist[i_row]["particleid"].ToString();
  1722. string str_stdtypeid = drlist[i_row]["typeid"].ToString();
  1723. string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
  1724. string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
  1725. string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
  1726. string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
  1727. //确定需要标记颗粒的定位
  1728. Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
  1729. Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
  1730. //向帧图进行标记颗粒位置
  1731. Graphics g = Graphics.FromImage(ls_fieldbp);
  1732. g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
  1733. //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
  1734. int ls_offsetx = offset_rect.X + offset_rect.Width;
  1735. if (ls_offsetx > ls_fieldbp.Width - 10)
  1736. {
  1737. ls_offsetx = offset_rect.X - 10;
  1738. }
  1739. g.DrawString(str_fieldid + "" + str_particleid.ToString(),
  1740. new Font("黑体", 8), new SolidBrush(Color.Aqua), new PointF(ls_offsetx, offset_rect.Y));
  1741. //保存带有标记的帧图
  1742. ls_fieldbp.Save(str_path_FIELD_FILES_MARK + str_fieldid.ToString() + ".bmp");
  1743. //ls_fieldbp.Dispose();
  1744. }
  1745. }
  1746. }
  1747. }
  1748. //
  1749. GC.Collect();
  1750. GC.WaitForPendingFinalizers();
  1751. }
  1752. private void testToolStripMenuItem1_Click(object sender, EventArgs e)
  1753. {
  1754. SaveMarkParticleRectangleOnFieldFile();
  1755. MessageBox.Show("导出完成!");
  1756. }
  1757. private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
  1758. {
  1759. //将所有的数据导出到EXCEL中
  1760. SaveFileDialog sfd = new SaveFileDialog();
  1761. sfd.Filter = "Excel文件(*.xls)|*.xls";
  1762. //设置默认文件类型显示顺序
  1763. sfd.FilterIndex = 1;
  1764. //保存对话框是否记忆上次打开的目录
  1765. sfd.RestoreDirectory = true;
  1766. if (sfd.ShowDialog() == DialogResult.OK)
  1767. {
  1768. IWorkbook workbook = new HSSFWorkbook(); //用于创建.xls office2003开始以前的
  1769. //IWorkbook workbook = new XSSFWorkbook(); //用于创建.xlsx office2007开始以后的
  1770. ISheet sheet;
  1771. //创建Excel文件
  1772. FileStream fs = File.Create(sfd.FileName);
  1773. fs.Close();
  1774. sheet = workbook.CreateSheet("Particles");//创建工作表
  1775. //创建表格边框样式风格
  1776. ICellStyle cellStyle = workbook.CreateCellStyle();
  1777. cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  1778. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  1779. //设置上4边
  1780. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1781. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1782. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1783. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1784. //设置字符大小和颜色
  1785. IFont font = workbook.CreateFont();
  1786. font.FontName = "黑体";
  1787. font.FontHeightInPoints = 10;
  1788. cellStyle.SetFont(font);
  1789. //设置颗粒名列宽
  1790. sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
  1791. sheet.SetColumnWidth(2, 3 * 256);//图像列宽
  1792. IRow row;
  1793. ICell cell;
  1794. //插入表头
  1795. row = sheet.CreateRow(1);//从第15行添加一行
  1796. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1797. {
  1798. cell = row.CreateCell(i_cell);
  1799. cell.CellStyle = cellStyle;
  1800. cell.SetCellValue(dgV_ParticlesDevidePage.Columns[i_cell].Name);
  1801. }
  1802. //插入表内容
  1803. for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
  1804. {
  1805. row = sheet.CreateRow(2 + i_row);
  1806. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1807. {
  1808. cell = row.CreateCell(i_cell);
  1809. cell.CellStyle = cellStyle;
  1810. if (dgV_ParticlesDevidePage[i_cell, i_row].Value == null)
  1811. continue;
  1812. if (i_cell == 2)
  1813. {
  1814. //颗粒图像列
  1815. Bitmap bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
  1816. byte[] bytes = ImageConvertToBytes(bp);
  1817. //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
  1818. int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
  1819. //第三步,在sheet中创建画布
  1820. IDrawing patriarch = sheet.CreateDrawingPatriarch();
  1821. //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
  1822. IClientAnchor anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
  1823. //第五步,创建图片
  1824. IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
  1825. //图像效果不好,自己另外导出吧,这里对该列宽进行了设置0
  1826. }
  1827. else
  1828. {
  1829. //非图像列
  1830. cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
  1831. }
  1832. }
  1833. }
  1834. //完成后,对Excel进行保存
  1835. FileStream file = new FileStream(sfd.FileName, FileMode.Create);
  1836. workbook.Write(file);
  1837. file.Close();
  1838. MessageBox.Show("导出完成!");
  1839. //导出完成后,打开Excel文件
  1840. if (File.Exists(sfd.FileName))
  1841. {
  1842. //打开刚才导出的文件
  1843. System.Diagnostics.Process.Start(sfd.FileName);
  1844. }
  1845. }
  1846. }
  1847. /// <summary>
  1848. /// 将image转成bytes
  1849. /// </summary>
  1850. /// <param name="in_img"></param>
  1851. /// <returns></returns>
  1852. public byte[] ImageConvertToBytes(System.Drawing.Image in_img)
  1853. {
  1854. MemoryStream ms = new MemoryStream();
  1855. in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1856. return ms.ToArray();
  1857. }
  1858. /// <summary>
  1859. /// 返回原子序数
  1860. /// </summary>
  1861. /// <param name="ElementName"></param>
  1862. /// <returns></returns>
  1863. int ReturnsAtomicNumberByElementName(string ElementName)
  1864. {
  1865. switch (ElementName)
  1866. {
  1867. case "H": return 1;
  1868. case "He": return 2;
  1869. case "Li": return 3;
  1870. case "Be": return 4;
  1871. case "B": return 5;
  1872. case "C": return 6;
  1873. case "N": return 7;
  1874. case "O": return 8;
  1875. case "F": return 9;
  1876. case "Ne": return 10;
  1877. case "Na": return 11;
  1878. case "Mg": return 12;
  1879. case "Al": return 13;
  1880. case "Si": return 14;
  1881. case "P": return 15;
  1882. case "S": return 16;
  1883. case "Cl": return 17;
  1884. case "Ar": return 18;
  1885. case "K": return 19;
  1886. case "Ca": return 20;
  1887. case "Sc": return 21;
  1888. case "Ti": return 22;
  1889. case "V": return 23;
  1890. case "Cr": return 24;
  1891. case "Mn": return 25;
  1892. case "Fe": return 26;
  1893. case "Co": return 27;
  1894. case "Ni": return 28;
  1895. case "Cu": return 29;
  1896. case "Zn": return 30;
  1897. case "Ga": return 31;
  1898. case "Ge": return 32;
  1899. case "As": return 33;
  1900. case "Se": return 34;
  1901. case "Br": return 35;
  1902. case "Kr": return 36;
  1903. case "Rb": return 37;
  1904. case "Sr": return 38;
  1905. case "Y": return 39;
  1906. case "Zr": return 40;
  1907. case "Nb": return 41;
  1908. case "Mo": return 42;
  1909. case "Tc": return 43;
  1910. case "Ru": return 44;
  1911. case "Rh": return 45;
  1912. case "Pd": return 46;
  1913. case "Ag": return 47;
  1914. case "Cd": return 48;
  1915. case "In": return 49;
  1916. case "Sn": return 50;
  1917. case "Sb": return 51;
  1918. case "Te": return 52;
  1919. case "I": return 53;
  1920. case "Xe": return 54;
  1921. case "Cs": return 55;
  1922. case "Ba": return 56;
  1923. case "La": return 57;
  1924. case "Ce": return 58;
  1925. case "Pr": return 59;
  1926. case "Nd": return 60;
  1927. case "Pm": return 61;
  1928. case "Sm": return 62;
  1929. case "Eu": return 63;
  1930. case "Gd": return 64;
  1931. case "Tb": return 65;
  1932. case "Dy": return 66;
  1933. case "Ho": return 67;
  1934. case "Er": return 68;
  1935. case "Tm": return 69;
  1936. case "Yb": return 70;
  1937. case "Lu": return 71;
  1938. case "Hf": return 72;
  1939. case "Ta": return 73;
  1940. case "W": return 74;
  1941. case "Re": return 75;
  1942. case "Os": return 76;
  1943. case "Ir": return 77;
  1944. case "Pt": return 78;
  1945. case "Au": return 79;
  1946. case "Hq": return 80;
  1947. case "TI": return 81;
  1948. case "Pb": return 82;
  1949. case "Bi": return 83;
  1950. case "Po": return 84;
  1951. case "At": return 85;
  1952. case "Rn": return 86;
  1953. case "Fr": return 87;
  1954. case "Ra": return 88;
  1955. case "Ac": return 89;
  1956. case "Th": return 90;
  1957. case "Pa": return 91;
  1958. case "U": return 92;
  1959. case "Np": return 93;
  1960. case "Pu": return 94;
  1961. case "Am": return 95;
  1962. case "Cm": return 96;
  1963. case "Bk": return 97;
  1964. case "Cf": return 98;
  1965. case "Es": return 99;
  1966. case "Fm": return 100;
  1967. case "Mc": return 101;
  1968. case "No": return 102;
  1969. case "Lr": return 103;
  1970. case "Rf": return 104;
  1971. case "Db": return 105;
  1972. case "Sg": return 106;
  1973. case "Bh": return 107;
  1974. case "Hs": return 108;
  1975. case "Mt": return 109;
  1976. case "Ds": return 110;
  1977. case "Rg": return 111;
  1978. case "Unb": return 112;
  1979. default: return 1000;
  1980. }
  1981. }
  1982. public List<string> GetElementsColName()
  1983. {
  1984. List<string> list_str = new List<string>();
  1985. // m_COTSReportProjFileMgrClr.GetPropertyParams().get
  1986. //CRptParamFileMgrClr crptparam = new CRptParamFileMgrClr();
  1987. //if (!crptparam.Load(0))
  1988. //{
  1989. // log.Error("(OTSDataMgrFun.CheckParamFile) m_pRptParamFileMgr.Load((int)OTS_SOFT_PACKAGE_ID.OTSIncA)");
  1990. //}
  1991. //string ls_str = crptparam.GetRptParamFile().GetElementsColName();
  1992. string ls_str = "Ar,Al,Si,B,P,C,S,N,Cl,O,F,Ne,He,Lr,Lu,Rn,Xe,Kr,Md,Tm,Po,Te,Se,Es,Ho,Pb,Sn,Ge,Np,Pm,Os,Ru,Fe,Bk,Tb,Hg,Cd,Zn,Pa,Pr,W,Mo,Cr,No,Yb,At,I,Br,Fm,Er,Bi,Sb,As,Hf,Zr,Ti,Am,Eu,Pt,Pd,Ni,U,Nd,Re,Tc,Mn,Cf,Dy,Tl,In,Ga,Ra,Ba,Sr,Ca,Cm,Gd,Au,Ag,Cu,Th,Ce,Ta,Pu,Nb,Sm,V,Ir,Rh,Co,Ac,La,Y,Sc,Fr,Cs,Rb,K,Na,Mg,Be,Li,H";
  1993. string[] strs = ls_str.Split(',');
  1994. for (int i = 0; i < strs.Count(); i++)
  1995. {
  1996. list_str.Add(strs[i]);
  1997. }
  1998. return list_str;
  1999. }
  2000. }
  2001. }