ParticlesGridDevidePage.cs 81 KB

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