ParticlesGridDevidePage.cs 88 KB

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