ParticlesGridDevidePage.cs 107 KB

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