ParticlesGridDevidePage.cs 102 KB

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