ParticlesGridDevidePage.cs 116 KB

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