ParticlesGridDevidePage.cs 95 KB

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