ParticlesGridDevidePage.cs 108 KB

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