ParticlesGridDevidePage.cs 101 KB

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