ParticlesGridDevidePage.cs 106 KB

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