ParticlesGridDevidePage.cs 112 KB

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