ParticlesGridDevidePage.cs 101 KB

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