ParticlesGridDevidePage.cs 120 KB

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