ParticlesGridDevidePage.cs 119 KB

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