ParticlesGridDevidePage.cs 114 KB

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