ParticlesGridDevidePage.cs 84 KB

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