ParticlesGridDevidePage.cs 102 KB

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