ParticlesGridDevidePage.cs 114 KB

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