ParticlesGridDevidePage.cs 102 KB

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