ParticlesGridDevidePage.cs 114 KB

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