ParticlesGridDevidePage.cs 94 KB

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