ParticlesGridDevidePage.cs 102 KB

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