ParticlesGridDevidePage.cs 111 KB

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