ParticlesGridDevidePage.cs 111 KB

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