ParticlesGridDevidePage.cs 94 KB

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