ParticlesGridDevidePage.cs 100 KB

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