ParticlesGridDevidePage.cs 85 KB

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