ParticlesGridDevidePage.cs 114 KB

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