ParticlesGridDevidePage.cs 114 KB

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