ParticlesGridDevidePage.cs 118 KB

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