ParticlesGridDevidePage.cs 109 KB

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