ParticlesGridDevidePage.cs 102 KB

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