ParticlesGridDevidePage.cs 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493
  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. keyValues.Add("ParticleId", "ParticleId");
  600. for (int i = 0; i < strs.Count(); i++)
  601. {
  602. if (strs[i] == "FiledCoordinate")
  603. {
  604. keyValues.Add("SEMPosX", "SEMPosX");
  605. keyValues.Add("SEMPosY", "SEMPosY");
  606. }
  607. if (strs[i] == "Area")
  608. {
  609. keyValues.Add("Area", table["str21"].ToString());
  610. }
  611. if (strs[i] == "EquivalentCircleDiameter")
  612. {
  613. keyValues.Add("Equivalent", table["str22"].ToString());
  614. }
  615. if (strs[i] == "MaxDiameter")
  616. {
  617. keyValues.Add("DMAX", table["str23"].ToString());
  618. }
  619. if (strs[i] == "MinDiameter")
  620. {
  621. keyValues.Add("DMIN", table["str24"].ToString());
  622. }
  623. if (strs[i] == "DiameterRatio")
  624. {
  625. keyValues.Add("DiameterRatio", table["str25"].ToString());
  626. }
  627. if (strs[i] == "FerretDiameter")
  628. {
  629. keyValues.Add("DFERET", table["str26"].ToString());
  630. }
  631. if (strs[i] == "PERP")
  632. {
  633. keyValues.Add("DPERP", table["str27"].ToString());
  634. }
  635. if (strs[i] == "PERI")
  636. {
  637. keyValues.Add("PERIMETER", table["str28"].ToString());
  638. }
  639. if (strs[i] == "INSCR")
  640. {
  641. keyValues.Add("DINSCR", table["str29"].ToString());
  642. }
  643. if (strs[i] == "MEAN")
  644. {
  645. keyValues.Add("DMEAN", table["str30"].ToString());
  646. }
  647. if (strs[i] == "ELONG")
  648. {
  649. keyValues.Add("DELONG", table["str31"].ToString());
  650. }
  651. if (strs[i] == "ASPECT_ELONG")
  652. {
  653. keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
  654. }
  655. if (strs[i] == "Orientation")
  656. {
  657. keyValues.Add("ORIENTATION", table["str33"].ToString());
  658. }
  659. if (str_SysType == "1:CleannessA")
  660. {
  661. if (strs[i] == "Hardness")
  662. {
  663. keyValues.Add("Hardness", table["str34"].ToString());
  664. }
  665. if (strs[i] == "Density")
  666. {
  667. keyValues.Add("Density", table["str35"].ToString());
  668. }
  669. if (strs[i] == "Electrical_conductivity")
  670. {
  671. keyValues.Add("Electrical_conductivity", table["str36"].ToString());
  672. }
  673. }
  674. }
  675. keyValues.Add("Element", "Element");
  676. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  677. for (int irow = 0; irow < keyValues.Count; irow++)
  678. {
  679. if (en.MoveNext())
  680. {
  681. if (en.Current.Key == "ParticleImage")
  682. {
  683. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  684. iconColumn.Name = en.Current.Key;
  685. iconColumn.HeaderText = en.Current.Value;
  686. dgV_ParticlesDevidePage.Columns.Add(iconColumn);
  687. }
  688. else if (en.Current.Key == "Element")
  689. {
  690. }
  691. else
  692. {
  693. int columndid = dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
  694. }
  695. }
  696. }
  697. if (PageSize == -1)
  698. {
  699. PageSize = particlesAll.Rows.Count;
  700. }
  701. if (particlesAll == null)
  702. {
  703. return;
  704. }
  705. RecordCount = particlesAll.Rows.Count;
  706. particles = particlesAll.Clone();
  707. for (int fi = (PageIndex - 1) * pageSize; fi < PageIndex * pageSize; fi++)
  708. {
  709. if (fi > RecordCount - 1)
  710. {
  711. break;
  712. }
  713. particles.ImportRow(particlesAll.Rows[fi]);
  714. }
  715. string particleM = "";
  716. //获取需要显示的元素名
  717. List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
  718. for (int i = 0; i < ElementTypeSort.Count; i++)
  719. {
  720. dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
  721. }
  722. double jd = 95f / (double)particles.Rows.Count;//计算进度刻度
  723. string filePath = result.FilePath + "\\FIELD_FILES\\";
  724. KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
  725. for (int i = 0; i < particles.Rows.Count; i++)
  726. {
  727. //更新进度,每100条记录加载完,更新一次进度
  728. if (i % 10 == 0)
  729. m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "loading..");
  730. Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
  731. int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
  732. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value = (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
  733. for (int k = 0; k < keyValues.Count; k++)
  734. {
  735. if (enl.MoveNext())
  736. {
  737. if (enl.Current.Key == "rowid")
  738. {
  739. //dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = i + 1;
  740. }
  741. if (enl.Current.Key == "ParticleImage")
  742. {
  743. if (particles.Columns.Contains("SubParticles"))
  744. {
  745. string subt = particles.Rows[i]["SubParticles"].ToString();
  746. if (subt != null && subt != "")
  747. {
  748. double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
  749. string filePatht = result.FilePath + "\\FIELD_FILES\\";
  750. string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
  751. //然后将取出的数据,转换成Bitmap对象
  752. Bitmap tempbit = Particledata.ReadImageFile(imagePatht);
  753. int pixw = tempbit.Width;
  754. double xs = pixw / ScanFieldSize;
  755. particleM = particleM + "," + subt;
  756. Bitmap bmap = Particledata.GetBitmapForBig(subt, xs, result.FilePath, tempbit.Height, tempbit.Width);
  757. if (bmap != null)
  758. {
  759. string[] str = subt.Split(',');
  760. bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
  761. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  762. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  763. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  764. dgV_ParticlesDevidePage.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate;
  765. }
  766. else
  767. {
  768. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
  769. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
  770. }
  771. }
  772. }
  773. else
  774. {
  775. if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
  776. {
  777. string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
  778. FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), Particledata.ReadImageFile(imagePath));
  779. }
  780. 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"]) };
  781. Bitmap bmap = Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
  782. 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() };
  783. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
  784. dgV_ParticlesDevidePage.Rows[add_rowindex].Height = bmap.Height + 20;
  785. }
  786. }
  787. if (enl.Current.Key == "DiameterRatio")
  788. {
  789. double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
  790. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  791. }
  792. if (enl.Current.Key == "ASPECT_ELONG")
  793. {
  794. double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
  795. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
  796. }
  797. if (particles.Columns.Contains(enl.Current.Key))
  798. {
  799. double num = 0;
  800. if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
  801. {
  802. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
  803. }
  804. else if (enl.Current.Key == "Element")
  805. {
  806. List<string> elementtemp = new List<string>(ElementTypeSort);
  807. string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
  808. for (int j = 0; j < strcbo.Length; j++)
  809. {
  810. string[] str = strcbo[j].Split('-');
  811. if (ElementTypeSort.Contains(str[0]))
  812. { dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
  813. elementtemp.Remove(str[0].ToString());
  814. }
  815. foreach (var ele in elementtemp)
  816. {
  817. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[ele].Value = "0";
  818. }
  819. }
  820. else
  821. {
  822. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
  823. }
  824. }
  825. if (enl.Current.Key == "TypeName")
  826. {
  827. if (particles.Rows[i]["TypeId"].ToString() == "9")
  828. {
  829. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "Not Identified";
  830. }
  831. }
  832. if (enl.Current.Key == "Equivalent")
  833. {
  834. double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
  835. double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
  836. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
  837. }
  838. if (enl.Current.Key == "Hardness")
  839. {
  840. string str = ChangeHardnessColor(particles.Rows[i]["Hardness"].ToString());
  841. {
  842. if (str == "#FF0000")
  843. {
  844. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.ForeColor = Color.Red;
  845. }
  846. dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i]["Hardness"].ToString();
  847. }
  848. }
  849. }
  850. }
  851. }
  852. #region 加载进度条进度部份结束
  853. //加载完成设置鼠标为默认
  854. this.Cursor = Cursors.Default;
  855. string str8 = table["str8"].ToString();
  856. m_frm_userprogress.SetProgressValueAndText(100, str8);
  857. //加载完成,关闭进度条
  858. m_frm_userprogress.Close();
  859. #endregion
  860. dgV_ParticlesDevidePage.Visible = true;
  861. }
  862. /// <summary>
  863. /// 设置DataGridView样式
  864. /// </summary>
  865. private void SetDataGridViewStyle()
  866. {
  867. //用户不能调整标题的高度
  868. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  869. //用户不能调整 行高
  870. dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
  871. //点击选择整行
  872. dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  873. //居中显示
  874. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  875. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  876. dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
  877. dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  878. //再次重覆禁用拖动表头高度,居然有效果了
  879. dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  880. //设置grid可以复制
  881. dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  882. //设置每列的宽度
  883. dgV_ParticlesDevidePage.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  884. dgV_ParticlesDevidePage.Columns[1].Width = 150;
  885. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].Width = 450;
  886. //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  887. //设置序号列不排序
  888. dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  889. //设置序号列不可以设置宽度
  890. dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
  891. dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
  892. }
  893. #endregion
  894. #region 相关事件
  895. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  896. {
  897. //复制整个表
  898. CopyAll();
  899. }
  900. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  901. {
  902. //复制选择区域
  903. CopySelected();
  904. }
  905. /// <summary>
  906. /// 复制选择区域
  907. /// </summary>
  908. public void CopySelected()
  909. {
  910. //复制选择区域
  911. object oo = dgV_ParticlesDevidePage.GetClipboardContent();
  912. if (oo != null)
  913. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  914. }
  915. /// <summary>
  916. /// 复制所有
  917. /// </summary>
  918. public void CopyAll()
  919. {
  920. dgV_ParticlesDevidePage.SelectAll();
  921. Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
  922. }
  923. /// <summary>
  924. /// 以图像的方式将GridView进行截图
  925. /// </summary>
  926. public void CopyImage()
  927. {
  928. int height, width;
  929. width = dgV_ParticlesDevidePage.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 2;
  930. height = this.Height;
  931. Bitmap image = new Bitmap(width, height);
  932. dgV_ParticlesDevidePage.DrawToBitmap(image, new Rectangle(0, 0, width, height));
  933. Clipboard.SetImage(image);
  934. }
  935. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  936. {
  937. //对gridview进行截图
  938. CopyImage();
  939. }
  940. private void dgV_ParticlesDevidePage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  941. {
  942. //排序中
  943. if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].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. if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag.ToString() == "统计行")
  953. {
  954. //ROW1<ROW2
  955. e.SortResult = -1;
  956. if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
  957. e.SortResult = 1;
  958. e.Handled = true;
  959. return;
  960. }
  961. }
  962. /// <summary>
  963. /// 将OTS坐标转换为Sem 坐标
  964. /// </summary>
  965. /// <param name="POTSCoord"></param>
  966. /// <returns></returns>
  967. public Point ChangeOTSToSemCoord(Point POTSCoord)
  968. {
  969. //first if m_semstagedata is null to get stage inforation
  970. Convert.ToDouble(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["scanFieldSize"]);
  971. //after obtaining stage info,calc stage point data
  972. Point ret_SEM_point = new Point();
  973. // get center point, um
  974. long xStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["start"]);
  975. long xEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["end"]);
  976. long xCenter = (xStart + xEnd) / 2;
  977. long yStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["start"]);
  978. long yEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["end"]);
  979. long yCenter = (yStart + yEnd) / 2;
  980. // delte = SEM - OTSa
  981. long deltex = xCenter - 0;
  982. long deltey = yCenter - 0;
  983. int xdir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["xAxisDir"]);
  984. int ydir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["yAxisDir"]);
  985. if (xdir == (int)OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  986. {
  987. ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
  988. }
  989. else if (xdir == (int)OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
  990. {
  991. ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
  992. }
  993. if (ydir == (int)OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  994. {
  995. ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
  996. }
  997. else if (ydir == (int)OTS_Y_AXIS_DIRECTION.DOWN_TOWARD)
  998. {
  999. ret_SEM_point.Y = -1 * (POTSCoord.Y - Convert.ToInt32(deltey));
  1000. }
  1001. return ret_SEM_point;
  1002. }
  1003. #endregion
  1004. #region 获取向导出模块提供的DataTable和GridView对象
  1005. /// <summary>
  1006. /// 获取到该模块输出后形成的DataTable,和GridView
  1007. /// </summary>
  1008. /// <param name="out_dt"></param>
  1009. /// <param name="out_dg"></param>
  1010. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  1011. {
  1012. out_dt = m_dt;
  1013. out_dg = this.dgV_ParticlesDevidePage;//同样通过 dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[2].Value 来获取bitmap对象
  1014. }
  1015. #endregion
  1016. #region 连接电镜相关
  1017. /// <summary>
  1018. /// 移动SEM到指定位置线程函数
  1019. /// </summary>
  1020. private void Thread_GO(object in_obj)
  1021. {
  1022. if (m_mythread_state == false)
  1023. {
  1024. m_mythread_state = true;
  1025. Point sem_point = (Point)in_obj;
  1026. //第一步,连接电镜
  1027. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  1028. Thread.Sleep(500);
  1029. //第二步,移动到指定位置,先读取再设置
  1030. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  1031. {
  1032. m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
  1033. }
  1034. Thread.Sleep(1500);
  1035. //第三步,断开电镜连接
  1036. //m_OTSIncAReportGridsFun.DisConnectSEM_ForParticlesGrid();
  1037. //Thread.Sleep(500);
  1038. m_mythread_state = false;
  1039. }
  1040. }
  1041. #endregion
  1042. private void ToolStripMenuItem_exportzoomimagefile_Click(object sender, EventArgs e)
  1043. {
  1044. //导出放大图像
  1045. FolderBrowserDialog fbd = new FolderBrowserDialog();
  1046. if (fbd.ShowDialog() == DialogResult.OK)
  1047. {
  1048. m_imagefilepath = fbd.SelectedPath;
  1049. for (int i = 0; i < m_dt.Rows.Count; i++)
  1050. {
  1051. Bitmap ls_bp = new Bitmap(1, 1);
  1052. ls_bp = (Bitmap)m_dt.Rows[i][1];
  1053. string strPath = m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg";
  1054. string strPath2 = m_imagefilepath + "\\" + (i + 1).ToString() + "s.jpg";
  1055. ls_bp.Save(strPath);
  1056. //m_COTSReportProjFileMgrClr.ReZoom(strPath, strPath2);
  1057. System.IO.File.Delete(strPath);//再将文件删除
  1058. }
  1059. string str1 = table["str9"].ToString();
  1060. MessageBox.Show(str1 + m_dt.Rows.Count.ToString());
  1061. }
  1062. }
  1063. /// <summary>
  1064. /// 导出二次放大图像
  1065. /// </summary>
  1066. /// <param name="str_srcPathName"></param>
  1067. /// <param name="str_outPathName"></param>
  1068. public void ParticleReZoom(string str_srcPathName, string str_outPathName)
  1069. {
  1070. //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
  1071. }
  1072. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  1073. {
  1074. //恢复至初始状态
  1075. dgV_ParticlesDevidePage.Rows.Clear();
  1076. dgV_ParticlesDevidePage.Columns.Clear();
  1077. BindDataGridView();
  1078. SetDataGridViewStyle();
  1079. }
  1080. private void ToolStripMenuItem5_Click(object sender, EventArgs e)
  1081. {
  1082. /*注意:多数据源情况下,只获取第一个数据源的选择了多行的情况下,只获取最后一个选择行的,没有办法,这是为了符合李阳博士提出的要求*/
  1083. //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
  1084. string i_ls_fieldid = "";
  1085. string i_ls_particleid = "";
  1086. int cou = dgV_ParticlesDevidePage.SelectedRows.Count;
  1087. if (cou > 0)
  1088. {
  1089. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[cou - 1];
  1090. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1091. List<string> list_str = (List<string>)ls_bp.Tag;
  1092. if (list_str != null)
  1093. {
  1094. i_ls_fieldid = list_str[0];
  1095. i_ls_particleid = list_str[1];
  1096. }
  1097. }
  1098. ParticleData particleData = new ParticleData(result.FilePath);
  1099. Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
  1100. ////然后遍历所有的Field
  1101. //Point ls_ots_point = new Point() { X = particle.PosX, Y = particle.PosY };
  1102. ////将该坐标转成SEM坐标
  1103. //Point ls_sem_point = ChangeOTSToSemCoord(ls_ots_point);
  1104. //取得Field的Position,然后执行线程移动SEM到当前Field的位置
  1105. if (m_mythread == null)
  1106. {
  1107. return;
  1108. }
  1109. if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
  1110. {
  1111. return;
  1112. }
  1113. if (m_mythread.ThreadState == ThreadState.Stopped)
  1114. {
  1115. m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
  1116. }
  1117. //改为线程调用,先判断线程状态
  1118. m_mythread.Start(new Point(particle.SEMPosX, particle.SEMPosY));
  1119. }
  1120. private void ToolStripMenuItem_selectparticle_Click(object sender, EventArgs e)
  1121. {
  1122. string path = result.FilePath;
  1123. ParticleData fielddata = new ParticleData(result.FilePath);
  1124. List<Particle> particles = fielddata.GetParticleAllList();
  1125. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  1126. for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
  1127. {
  1128. //从事先加载的Bitmap对象的Tag中取出List<string>
  1129. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
  1130. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1131. List<string> list_str = (List<string>)ls_bp.Tag;
  1132. if (list_str != null)
  1133. {
  1134. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1135. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1136. foreach (Particle item in particles)
  1137. {
  1138. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  1139. {
  1140. ls_list_cotsparticleclr.Add(item);
  1141. break;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. m_ReportApp.SetSelectedParticles(ls_list_cotsparticleclr);
  1147. string str1 = table["str1"].ToString();
  1148. //然后循环得出,list cotsparticleclr列表,返回给框架
  1149. //m_sec.SendCall(str1, "", "", ls_list_cotsparticleclr);
  1150. string str2 = table["str2"].ToString();
  1151. string str3 = table["str3"].ToString();
  1152. MessageBox.Show(str2 + ls_list_cotsparticleclr.Count.ToString() + str3);
  1153. }
  1154. private void ToolStripMenuItem_exportimagefile_Click(object sender, EventArgs e)
  1155. {
  1156. FolderBrowserDialog fbd = new FolderBrowserDialog();
  1157. if (fbd.ShowDialog() == DialogResult.OK)
  1158. {
  1159. m_imagefilepath = fbd.SelectedPath;
  1160. for (int i = 0; i < dgV_ParticlesDevidePage.Rows.Count; i++)
  1161. {
  1162. Bitmap ls_bp = new Bitmap(1, 1);
  1163. ls_bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i].Cells[2].Value;
  1164. ls_bp.Save(m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg");
  1165. }
  1166. string str9 = table["str9"].ToString();
  1167. MessageBox.Show(str9 + dgV_ParticlesDevidePage.Rows.Count.ToString());
  1168. }
  1169. }
  1170. private void testToolStripMenuItem_Click(object sender, EventArgs e)
  1171. {
  1172. ////测试导出指定颗粒的能谱图,测试相关代码
  1173. //OTSIncAReportGraph.DParticle ls_dparticle = new OTSIncAReportGraph.DParticle();
  1174. //for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
  1175. //{
  1176. // //获取选择行颗粒的fieldid,和particleid
  1177. // string str_fieldid = "";
  1178. // string str_particleid = "";
  1179. // string str_stdtypeid = "";
  1180. // DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
  1181. // Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1182. // List<string> list_str = (List<string>)ls_bp.Tag;
  1183. // if (list_str != null)
  1184. // {
  1185. // str_fieldid = list_str[0];
  1186. // str_particleid = list_str[1];
  1187. // str_stdtypeid = list_str[2];
  1188. // }
  1189. // ls_dparticle.CLRFieldID = Convert.ToInt32(str_fieldid);
  1190. // ls_dparticle.CLRTagID = Convert.ToInt32(str_particleid);
  1191. // ls_dparticle.STDTypeID = Convert.ToInt32(str_stdtypeid);
  1192. //}
  1193. ////显示xray能谱
  1194. //ShowXRay(ls_dparticle);
  1195. //Bitmap ls_bpex = new Bitmap(control_XRayTable1.Width, control_XRayTable1.Height);
  1196. //control_XRayTable1.DrawToBitmap(ls_bpex, new Rectangle(0, 0, control_XRayTable1.Width, control_XRayTable1.Height));
  1197. ////Bitmap ls_bpex = control_XRayTable1.ExportXRayImage();
  1198. //ls_bpex.Save("e:\\test222.jpg");
  1199. }
  1200. /// <summary>
  1201. /// 判断条件输入 前<后
  1202. /// </summary>
  1203. /// <param name="min"></param>
  1204. /// <param name="max"></param>
  1205. /// <returns></returns>
  1206. bool CompareInput(string min, string max)
  1207. {
  1208. int imax = 0;
  1209. int imin = 0;
  1210. double dmax = 0;
  1211. double dmin = 0;
  1212. if (int.TryParse(max, out imax))
  1213. {
  1214. dmax = (double)imax;
  1215. }
  1216. else
  1217. {
  1218. dmax = Convert.ToDouble(max);
  1219. }
  1220. if (int.TryParse(min, out imin))
  1221. {
  1222. dmin = (double)imin;
  1223. }
  1224. else
  1225. {
  1226. dmin = Convert.ToDouble(min);
  1227. }
  1228. if (dmin <= dmax)
  1229. {
  1230. return true;
  1231. }
  1232. else
  1233. {
  1234. return false;
  1235. }
  1236. }
  1237. private void btn_Sel_Click(object sender, EventArgs e)
  1238. {
  1239. condition = "";
  1240. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text))
  1241. {
  1242. double dnum = 0;
  1243. int inum = 0;
  1244. if (double.TryParse(tBx_AreaMin.Text, out dnum) && dnum >= 0)
  1245. {
  1246. condition += " and Area" + " > " + tBx_AreaMin.Text;
  1247. }
  1248. else if (int.TryParse(tBx_AreaMin.Text, out inum) && inum >= 0)
  1249. {
  1250. condition += " and Area" + " > " + tBx_AreaMin.Text;
  1251. }
  1252. else
  1253. {
  1254. MessageBox.Show(table["str10"].ToString());
  1255. return;
  1256. }
  1257. }
  1258. if (!string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  1259. {
  1260. double dnum = 0;
  1261. int inum = 0;
  1262. if (double.TryParse(Tbx_AreaMax.Text, out dnum) && dnum >= 0)
  1263. {
  1264. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  1265. }
  1266. else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
  1267. {
  1268. condition += " and Area" + "<" + Tbx_AreaMax.Text;
  1269. }
  1270. else
  1271. {
  1272. MessageBox.Show(table["str10"].ToString());
  1273. return;
  1274. }
  1275. }
  1276. if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text) && !string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
  1277. {
  1278. if (!CompareInput(tBx_AreaMin.Text, Tbx_AreaMax.Text))
  1279. {
  1280. MessageBox.Show(table["str11"].ToString());
  1281. return;
  1282. }
  1283. }
  1284. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text))
  1285. {
  1286. double dnum = 0;
  1287. int inum = 0;
  1288. if (double.TryParse(tbx_DmaxMin.Text, out dnum) && dnum >= 0)
  1289. {
  1290. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  1291. }
  1292. else if (int.TryParse(tbx_DmaxMin.Text, out inum) && inum >= 0)
  1293. {
  1294. condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
  1295. }
  1296. else
  1297. {
  1298. MessageBox.Show(table["str10"].ToString());
  1299. return;
  1300. }
  1301. }
  1302. if (!string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1303. {
  1304. double dnum = 0;
  1305. int inum = 0;
  1306. if (double.TryParse(tbx_DmaxMax.Text, out dnum) && dnum > 0)
  1307. {
  1308. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1309. }
  1310. else if (int.TryParse(tbx_DmaxMax.Text, out inum) && inum >= 0)
  1311. {
  1312. condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
  1313. }
  1314. else
  1315. {
  1316. MessageBox.Show(table["str10"].ToString());
  1317. return;
  1318. }
  1319. }
  1320. if (!string.IsNullOrWhiteSpace(tB_FieldId.Text))
  1321. {
  1322. int inum = 0;
  1323. if (int.TryParse(tB_FieldId.Text, out inum))
  1324. {
  1325. condition += " and FieldId =" + tB_FieldId.Text;
  1326. }
  1327. else
  1328. {
  1329. MessageBox.Show(table["str10"].ToString());
  1330. return;
  1331. }
  1332. }
  1333. if (!string.IsNullOrWhiteSpace(tB_ParticleId.Text))
  1334. {
  1335. int inum = 0;
  1336. if (int.TryParse(tB_ParticleId.Text, out inum))
  1337. {
  1338. condition += " and ParticleId =" + tB_ParticleId.Text;
  1339. }
  1340. else
  1341. {
  1342. MessageBox.Show(table["str10"].ToString());
  1343. return;
  1344. }
  1345. }
  1346. if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text) && !string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
  1347. {
  1348. if (!CompareInput(tbx_DmaxMin.Text, tbx_DmaxMax.Text))
  1349. {
  1350. MessageBox.Show(table["str11"].ToString());
  1351. return;
  1352. }
  1353. }
  1354. if (!string.IsNullOrWhiteSpace(tbx_Type.Text))
  1355. {
  1356. condition += " and TypeName Like \"%" + tbx_Type.Text + "%\" ";
  1357. }
  1358. if (m_frm_userprogress.IsDisposed)
  1359. {
  1360. ProgressStart();
  1361. }
  1362. UpdateTable();
  1363. lnkFirst_Click(null, null);
  1364. SetDataGridViewStyle();
  1365. }
  1366. void ProgressStart()
  1367. {
  1368. #region 加载显示进度条部份
  1369. this.Cursor = Cursors.WaitCursor;
  1370. m_frm_userprogress = new Frm_UserProgress();
  1371. //显示进度条,计算进度条应该显示的位置和宽度
  1372. Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
  1373. if (ls_main_form == null)
  1374. {
  1375. m_frm_userprogress.Visible = false;
  1376. }
  1377. else
  1378. {
  1379. m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
  1380. m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
  1381. m_frm_userprogress.Show();
  1382. m_frm_userprogress.SetProgressValueAndText(0, "Loading data of particles...");
  1383. }
  1384. #endregion
  1385. }
  1386. private void cbB_order_SelectedIndexChanged(object sender, EventArgs e)
  1387. {
  1388. //int ordernum = cbB_order.SelectedIndex;
  1389. //if (ordernum == 0)
  1390. //{
  1391. // OrderFunction = "fieldid,particleid";
  1392. //}
  1393. //else if (ordernum == 1)
  1394. //{
  1395. // OrderFunction = "TypeName";
  1396. //}
  1397. //else if (ordernum == 2)
  1398. //{
  1399. // OrderFunction = "DMAX";
  1400. //}
  1401. //else if (ordernum == 3)
  1402. //{
  1403. // OrderFunction = "DMAX desc";
  1404. //}
  1405. //else if (ordernum == 4)
  1406. //{
  1407. // OrderFunction = "Area";
  1408. //}
  1409. //else if (ordernum == 5)
  1410. //{
  1411. // OrderFunction = "Area desc";
  1412. //}
  1413. lnkFirst_Click(null, null);
  1414. SetDataGridViewStyle();
  1415. }
  1416. /// <summary>
  1417. /// 页面控件呈现
  1418. /// </summary>
  1419. private void DrawControl(bool callEvent)
  1420. {
  1421. BindDataGridView();
  1422. lblTotalCount.Text = RecordCount.ToString();
  1423. lblPageCount.Text = PageCount.ToString();
  1424. txtPageNum.Text = PageIndex.ToString();
  1425. SetFormCtrEnabled();
  1426. if (PageCount == 0 || PageCount == 1)//有且仅有一页
  1427. {
  1428. lnkFirst.Enabled = false;
  1429. lnkPrev.Enabled = false;
  1430. lnkNext.Enabled = false;
  1431. lnkLast.Enabled = false;
  1432. btnGo.Enabled = false;
  1433. }
  1434. else if (PageIndex == 1)//第一页
  1435. {
  1436. lnkFirst.Enabled = false;
  1437. lnkPrev.Enabled = false;
  1438. }
  1439. else if (PageIndex == PageCount)//最后一页
  1440. {
  1441. lnkNext.Enabled = false;
  1442. lnkLast.Enabled = false;
  1443. }
  1444. }
  1445. private void SetFormCtrEnabled()
  1446. {
  1447. lnkFirst.Enabled = true;
  1448. lnkPrev.Enabled = true;
  1449. lnkNext.Enabled = true;
  1450. lnkLast.Enabled = true;
  1451. btnGo.Enabled = true;
  1452. }
  1453. /// <summary>
  1454. /// 分页属性改变了。
  1455. /// </summary>
  1456. private void txtPageSize_TextChanged(object sender, EventArgs e)
  1457. {
  1458. int num = 0;
  1459. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1460. {
  1461. }
  1462. else { txtPageNum.Text = "1"; }
  1463. }
  1464. private void lnkFirst_Click(object sender, EventArgs e)
  1465. {
  1466. PageIndex = 1;
  1467. DrawControl(true);
  1468. }
  1469. private void lnkPrev_Click(object sender, EventArgs e)
  1470. {
  1471. PageIndex = Math.Max(1, PageIndex - 1);
  1472. DrawControl(true);
  1473. }
  1474. private void lnkNext_Click(object sender, EventArgs e)
  1475. {
  1476. PageIndex = Math.Min(PageCount, PageIndex + 1);
  1477. DrawControl(true);
  1478. }
  1479. private void lnkLast_Click(object sender, EventArgs e)
  1480. {
  1481. PageIndex = PageCount;
  1482. DrawControl(true);
  1483. }
  1484. /// <summary>
  1485. /// 跳转
  1486. /// </summary>
  1487. /// <param name="sender"></param>
  1488. /// <param name="e"></param>
  1489. private void btnGo_Click(object sender, EventArgs e)
  1490. {
  1491. int num = 0;
  1492. if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
  1493. {
  1494. if (num > PageCount)
  1495. {
  1496. num = PageCount;
  1497. txtPageNum.Text = PageCount.ToString();
  1498. }
  1499. PageIndex = num;
  1500. DrawControl(true);
  1501. }
  1502. }
  1503. private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
  1504. {
  1505. DisplayData();
  1506. }
  1507. /// <summary>
  1508. /// 在帧图上标记颗粒的位置矩形,并保存到FIELD_FILES_MARK文件夹中
  1509. /// </summary>
  1510. public void SaveMarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable, out List<string> vs, out DataTable dt_FIeld)
  1511. {
  1512. Init();
  1513. List<string> maxlength = new List<string>();
  1514. for (int i = 0; i < dataTable.Rows.Count; i++)
  1515. {
  1516. if (dataTable.Rows[i]["TypeName"].ToString() != "Not Identified")
  1517. {
  1518. if (maxlength.Count < 10)
  1519. {
  1520. maxlength.Add(dataTable.Rows[i]["Fieldid"].ToString());
  1521. }
  1522. else
  1523. {
  1524. break;
  1525. }
  1526. }
  1527. }
  1528. List<string> max_list = maxlength.Distinct().ToList();
  1529. string str_path_FIELD_FILES = str_resultPath + "\\FIELD_FILES\\";
  1530. string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
  1531. int intQuantity = 0;
  1532. //List<string> vs = new List<string>();
  1533. dt_FIeld = new DataTable();
  1534. vs = new List<string>();
  1535. ////判断是否已经有导出过的标记帧图文件夹,如果已经存在,则直接返回不输出,先不加
  1536. DirectoryInfo theFolder_FieldMark = new DirectoryInfo(str_path_FIELD_FILES_MARK);
  1537. if (!theFolder_FieldMark.Exists)
  1538. {
  1539. //创建
  1540. theFolder_FieldMark.Create();
  1541. }
  1542. else
  1543. {
  1544. theFolder_FieldMark.Delete(true);
  1545. //创建
  1546. theFolder_FieldMark.Create();
  1547. //已经存在的话,直接返回
  1548. //return;
  1549. }
  1550. //查找该field下对应所有的颗粒
  1551. DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
  1552. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
  1553. if (theFolder.Exists)
  1554. {
  1555. DataTable dt = new DataTable();
  1556. dt.Columns.Add("fieldid");
  1557. dt.Columns.Add("id");
  1558. dt.Columns.Add("fieldName");
  1559. dt.Columns.Add("cunt", typeof(int));
  1560. dt.Columns.Add("fieldFullName");
  1561. for (int i = 0; i < max_list.Count; i++)
  1562. {
  1563. foreach (FileInfo nextifile in theFolder.GetFiles())
  1564. {
  1565. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  1566. {
  1567. //确认对应的帧图名
  1568. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  1569. str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
  1570. bool bl = false;
  1571. if (str_fieldid == max_list[i].ToString())
  1572. {
  1573. bl = true;
  1574. }
  1575. if (bl)
  1576. {
  1577. DataRow dr = dt.NewRow();
  1578. dr["fieldid"] = " fieldid = " + str_fieldid;
  1579. dr["cunt"] = dataTable.Select(" fieldid = " + str_fieldid).Count();
  1580. dr["fieldName"] = nextifile.Name;
  1581. dr["fieldFullName"] = nextifile.FullName;
  1582. dr["id"] = str_fieldid;
  1583. dt.Rows.Add(dr);
  1584. }
  1585. }
  1586. }
  1587. }
  1588. //DataView dv = dt.DefaultView;
  1589. //dv.Sort = "cunt DESC";
  1590. dt_FIeld = dt.Copy();
  1591. for (int i = 0; i < dt_FIeld.Rows.Count; i++)
  1592. {
  1593. if (dataTable.Select(dt_FIeld.Rows[i]["fieldid"].ToString()).Count() > 0)
  1594. {
  1595. vs.Add(dt_FIeld.Rows[i]["id"].ToString());
  1596. Image img = Image.FromFile(dt_FIeld.Rows[i]["fieldFullName"].ToString());
  1597. //img.Save(@"D:\1.bmp");
  1598. Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  1599. using (Graphics g = Graphics.FromImage(ls_fieldbp))
  1600. {
  1601. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1602. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1603. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1604. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
  1605. }
  1606. //ls_fieldbp.Save(@"D:\1.bmp");
  1607. img.Dispose();
  1608. img = null;
  1609. //循环将颗粒,进行标记到bitmap图上
  1610. DataRow[] drlist = dt_AllParticle.Select(dt_FIeld.Rows[i]["fieldid"].ToString());
  1611. if (drlist.Count() > 0)
  1612. intQuantity = intQuantity + 1;
  1613. for (int i_row = 0; i_row < drlist.Count(); i_row++)
  1614. {
  1615. //string str_fieldid = drlist[i_row]["fieldid"].ToString();
  1616. string str_particleid = drlist[i_row]["particleid"].ToString();
  1617. string str_stdtypeid = drlist[i_row]["typeid"].ToString();
  1618. string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
  1619. string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
  1620. string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
  1621. string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
  1622. //确定需要标记颗粒的定位
  1623. Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
  1624. Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
  1625. //向帧图进行标记颗粒位置
  1626. Graphics g = Graphics.FromImage(ls_fieldbp);
  1627. g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
  1628. //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
  1629. int ls_offsetx = offset_rect.X + offset_rect.Width;
  1630. if (ls_offsetx > ls_fieldbp.Width - 10)
  1631. {
  1632. ls_offsetx = offset_rect.X - 10;
  1633. }
  1634. g.DrawString(dt_FIeld.Rows[i]["id"].ToString() + "" + str_particleid.ToString(),
  1635. new Font("黑体", 8), new SolidBrush(Color.Aqua), new PointF(ls_offsetx, offset_rect.Y));
  1636. //保存带有标记的帧图
  1637. ls_fieldbp.Save(str_path_FIELD_FILES_MARK + dt_FIeld.Rows[i]["id"].ToString() + ".bmp");
  1638. //ls_fieldbp.Dispose();
  1639. }
  1640. }
  1641. }
  1642. }
  1643. //
  1644. GC.Collect();
  1645. GC.WaitForPendingFinalizers();
  1646. }
  1647. private void testToolStripMenuItem1_Click(object sender, EventArgs e)
  1648. {
  1649. //SaveMarkParticleRectangleOnFieldFile();
  1650. MessageBox.Show("Export completed!");
  1651. }
  1652. private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
  1653. {
  1654. OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation sfd = new OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation();
  1655. if (sfd.ShowDialog() == DialogResult.OK)
  1656. {
  1657. //IWorkbook workbook = new HSSFWorkbook(); //用于创建.xls office2003开始以前的
  1658. IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(); //用于创建.xlsx office2007开始以后的
  1659. ISheet sheet;
  1660. //创建Excel文件
  1661. FileStream fs = File.Create(sfd.FileName);
  1662. fs.Close();
  1663. sheet = workbook.CreateSheet("Particles");//创建工作表
  1664. //创建表格边框样式风格
  1665. ICellStyle cellStyle = workbook.CreateCellStyle();
  1666. cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  1667. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  1668. //设置上4边
  1669. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1670. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1671. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1672. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1673. //设置字符大小和颜色
  1674. IFont font = workbook.CreateFont();
  1675. font.FontName = "黑体";
  1676. font.FontHeightInPoints = 10;
  1677. cellStyle.SetFont(font);
  1678. //设置颗粒名列宽
  1679. sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
  1680. sheet.SetColumnWidth(2, 7 * 256);//图像列宽
  1681. IRow row;
  1682. ICell cell;
  1683. //插入表头
  1684. row = sheet.CreateRow(1);//从第15行添加一行
  1685. row.Height = 30 * 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. cell.SetCellValue(dgV_ParticlesDevidePage.Columns[i_cell].Name);
  1691. }
  1692. //插入表内容
  1693. for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
  1694. {
  1695. row = sheet.CreateRow(2 + i_row);
  1696. row.Height = 45 * 20;
  1697. for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
  1698. {
  1699. cell = row.CreateCell(i_cell);
  1700. cell.CellStyle = cellStyle;
  1701. if (dgV_ParticlesDevidePage[i_cell, i_row].Value == null)
  1702. continue;
  1703. if (i_cell == 2)
  1704. {
  1705. //颗粒图像列
  1706. Bitmap bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
  1707. byte[] bytes = ImageConvertToBytes(bp);
  1708. //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
  1709. int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
  1710. //第三步,在sheet中创建画布
  1711. IDrawing patriarch = sheet.CreateDrawingPatriarch();
  1712. //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
  1713. IClientAnchor anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
  1714. //第五步,创建图片
  1715. IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
  1716. //图像效果不好,自己另外导出吧,这里对该列宽进行了设置0
  1717. }
  1718. else
  1719. {
  1720. //非图像列
  1721. double dbl = 0;
  1722. if (double.TryParse(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString(), out dbl))
  1723. {
  1724. cell.SetCellValue(dbl);
  1725. }
  1726. else
  1727. {
  1728. cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
  1729. }
  1730. }
  1731. }
  1732. }
  1733. ISheet sheet2;
  1734. sheet2 = workbook.CreateSheet("Peak spectrum Data");//创建工作表
  1735. //插入表头
  1736. row = sheet2.CreateRow(1);
  1737. row.Height = 30 * 20;
  1738. cell = row.CreateCell(0);
  1739. cell.CellStyle = cellStyle;
  1740. cell.SetCellValue("rowid");
  1741. for (int i_cell = 1; i_cell < 2001; i_cell++)
  1742. {
  1743. cell = row.CreateCell(i_cell);
  1744. cell.CellStyle = cellStyle;
  1745. if (i_cell == 1)
  1746. {
  1747. cell.SetCellValue("PeakSpectrumData");
  1748. }
  1749. }
  1750. sheet2.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 1, 1, 2000));
  1751. for (int j = 0; j < particles.Rows.Count; j++)
  1752. {
  1753. row = sheet2.CreateRow(2 + j);
  1754. cell = row.CreateCell(0);
  1755. cell.CellStyle = cellStyle;
  1756. cell.SetCellValue(j + 1);
  1757. var tmpPart = Particledata.GetParticleXrayDataByFidAndPid(particles.Rows[j]["fieldid"].ToString(), particles.Rows[j]["particleid"].ToString());
  1758. if (tmpPart != null)
  1759. {
  1760. if (tmpPart.XrayId > -1)
  1761. {
  1762. uint[] Analysis_xray = new uint[2000];
  1763. for (int i = 0; i < 2000; i++)
  1764. {
  1765. Analysis_xray[i] = BitConverter.ToUInt32(tmpPart.XRayData, i * 4);
  1766. cell = row.CreateCell(i + 1);
  1767. cell.CellStyle = cellStyle;
  1768. cell.SetCellValue(Analysis_xray[i]);
  1769. }
  1770. }
  1771. }
  1772. }
  1773. if (sfd.SpectrumConfirmation)
  1774. {
  1775. ISheet sheet3;
  1776. sheet3 = workbook.CreateSheet("Peak spectrum");
  1777. sheet3.SetColumnWidth(1, 200 * 256);//图像列宽
  1778. //插入表头
  1779. row = sheet3.CreateRow(1);
  1780. row.Height = 30 * 20;
  1781. cell = row.CreateCell(0);
  1782. cell.CellStyle = cellStyle;
  1783. cell.SetCellValue("rowid");
  1784. cell = row.CreateCell(1);
  1785. cell.CellStyle = cellStyle;
  1786. cell.SetCellValue("PeakSpectrum");
  1787. IDrawing drawing;
  1788. IClientAnchor anchor3;
  1789. for (int j = 0; j < particles.Rows.Count; j++)
  1790. {
  1791. row = sheet3.CreateRow(j + 2);
  1792. row.Height = 120 * 20;
  1793. cell = row.CreateCell(0);
  1794. cell.CellStyle = cellStyle;
  1795. cell.SetCellValue(j + 1);
  1796. cell = row.CreateCell(1);
  1797. cell = row.CreateCell(2);
  1798. cell = row.CreateCell(3);
  1799. drawing = sheet3.CreateDrawingPatriarch();
  1800. //锚点
  1801. 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开始
  1802. CreateChart(drawing, sheet2, anchor3, j + 2);
  1803. }
  1804. }
  1805. //完成后,对Excel进行保存
  1806. FileStream file = new FileStream(sfd.FileName, FileMode.Create);
  1807. workbook.Write(file);
  1808. file.Close();
  1809. MessageBox.Show("Export complete!");
  1810. //导出完成后,打开Excel文件
  1811. if (File.Exists(sfd.FileName))
  1812. {
  1813. //打开刚才导出的文件
  1814. System.Diagnostics.Process.Start(sfd.FileName);
  1815. }
  1816. }
  1817. }
  1818. void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, int rowid)
  1819. {
  1820. var chart = drawing.CreateChart(anchor) as XSSFChart;
  1821. //图表
  1822. var data = chart.ChartDataFactory.CreateLineChartData<double, double>(); //折线图
  1823. IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
  1824. IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
  1825. leftAxis.Crosses = AxisCrosses.AutoZero;
  1826. leftAxis.IsVisible = true;
  1827. bottomAxis.IsVisible = true;
  1828. //数据源
  1829. IChartDataSource<double> ys = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(rowid, rowid, 1, 2001));
  1830. Double[] doubles = new Double[2000];
  1831. for (int i = 0; i < 2000; i++)
  1832. {
  1833. doubles[i] = i;
  1834. }
  1835. IChartDataSource<double> xs = DataSources.FromArray(doubles);
  1836. //数据系列
  1837. var s1 = data.AddSeries(xs, ys);
  1838. // 开始绘制折线图
  1839. chart.Plot(data, bottomAxis, leftAxis);
  1840. }
  1841. /// <summary>
  1842. /// 将image转成bytes
  1843. /// </summary>
  1844. /// <param name="in_img"></param>
  1845. /// <returns></returns>
  1846. public byte[] ImageConvertToBytes(System.Drawing.Image in_img)
  1847. {
  1848. MemoryStream ms = new MemoryStream();
  1849. in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1850. return ms.ToArray();
  1851. }
  1852. public bool CheckParamExist<T>(T Param)
  1853. {
  1854. if (Param == null)
  1855. {
  1856. return false;
  1857. }
  1858. else
  1859. {
  1860. return true;
  1861. }
  1862. }
  1863. private void ToolStripMenuItem_Delete_Particle_Click(object sender, EventArgs e)
  1864. {
  1865. string path = result.FilePath;
  1866. ParticleData fielddata = new ParticleData(result.FilePath);
  1867. List<Particle> particles = fielddata.GetParticleAllList();
  1868. List<Particle> ls_list_cotsparticleclr = new List<Particle>();
  1869. for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
  1870. {
  1871. //从事先加载的Bitmap对象的Tag中取出List<string>
  1872. DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
  1873. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  1874. List<string> list_str = (List<string>)ls_bp.Tag;
  1875. if (list_str != null)
  1876. {
  1877. int i_ls_fieldid = Convert.ToInt32(list_str[0]);
  1878. int i_ls_particleid = Convert.ToInt32(list_str[1]);
  1879. foreach (Particle item in particles)
  1880. {
  1881. if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
  1882. {
  1883. if (DeleteParticlesFromLibrary(item.ParticleId, item.FieldId))
  1884. {
  1885. MessageBox.Show("Deleted successfully");
  1886. for (int i = 0; i < particlesAll.Rows.Count; i++)
  1887. {
  1888. if (particlesAll.Rows[i]["Fieldid"].ToString() == item.FieldId.ToString() && particlesAll.Rows[i]["Particleid"].ToString() == item.ParticleId.ToString())
  1889. {
  1890. particlesAll.Rows.RemoveAt(i);
  1891. }
  1892. }
  1893. DisplayData();
  1894. }
  1895. else
  1896. {
  1897. MessageBox.Show("Delete failed");
  1898. }
  1899. break;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. }
  1905. private bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
  1906. {
  1907. bool DoesItExist = false;
  1908. for (int i = 1; i < 201; i++)
  1909. {
  1910. if (System.IO.Directory.Exists(resultFile.FilePath + "\\FIELD_FILES\\Backups" + i.ToString()))
  1911. {
  1912. DoesItExist = true;
  1913. break;
  1914. }
  1915. }
  1916. if (!DoesItExist)
  1917. {
  1918. //备份数据库
  1919. BackupDatabase();
  1920. }
  1921. DoesItExist = false;
  1922. //防止为空校验判断
  1923. if (resultFile.List_OTSField == null)
  1924. return false;
  1925. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  1926. if (new ParticleData(resultFile.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
  1927. {
  1928. return true;
  1929. }
  1930. else
  1931. {
  1932. return false;
  1933. }
  1934. }
  1935. private bool BackupDatabase()
  1936. {
  1937. //创建备份数据库文件夹
  1938. string sourcePath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  1939. string sourceName = "Inclusion.db";//源文件名称
  1940. string folderPath = resultFile.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  1941. string Fields = "";
  1942. for (int i = 1; i < 201; i++)
  1943. {
  1944. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  1945. {
  1946. Fields = folderPath + i.ToString();
  1947. continue;
  1948. }
  1949. else
  1950. {
  1951. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  1952. Fields = folderPath + i.ToString();
  1953. break;
  1954. }
  1955. }
  1956. if (Fields == "")
  1957. {
  1958. return false;
  1959. }
  1960. //复制数据库文件
  1961. string targetPath = Path.Combine(Fields, sourceName);
  1962. FileInfo file = new FileInfo(sourcePath);
  1963. if (file.Exists)
  1964. {
  1965. file.CopyTo(targetPath, true);
  1966. }
  1967. return true;
  1968. }
  1969. private void DisplayData()
  1970. {
  1971. if (cbB_PageSize.SelectedItem.ToString() == "All")
  1972. {
  1973. pageSize = -1;
  1974. }
  1975. else
  1976. {
  1977. pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
  1978. }
  1979. lnkFirst_Click(null, null);
  1980. SetDataGridViewStyle();
  1981. }
  1982. private void btn_ReMeasure_Click(object sender, EventArgs e)
  1983. {
  1984. //二次测量参数页面
  1985. frmReMeasure frmReMeasure = new frmReMeasure(m_OTSIncAReportGridsFun, m_ReportApp.GetSelectedParticles(), resultFile);
  1986. frmReMeasure.TopMost = true;//设置置顶
  1987. frmReMeasure.ShowDialog();
  1988. }
  1989. string ChangeHardnessColor(string Hardness)
  1990. {
  1991. string str = System.Text.RegularExpressions.Regex.Replace(Hardness, @"[^\d.\d]", "");
  1992. double hd;
  1993. if (double.TryParse(str, out hd))
  1994. {
  1995. if (hd >= 1000)
  1996. {
  1997. return "#FF0000";
  1998. }
  1999. else return "";
  2000. }
  2001. else
  2002. return "";
  2003. }
  2004. /// <summary>
  2005. ///
  2006. /// </summary>
  2007. /// <param name="str_resultPath"></param>
  2008. /// <param name="dataTable"></param>
  2009. /// <param name="vs"></param>
  2010. /// <param name="dt_FIeld"></param>
  2011. public void Out_MarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable, out List<string> vs, out DataTable dt_FIeld)
  2012. {
  2013. Init();
  2014. List<string> maxlength = new List<string>();
  2015. for (int i = 0; i < dataTable.Rows.Count; i++)
  2016. {
  2017. if (dataTable.Rows[i]["TypeName"].ToString() != "Not Identified")
  2018. {
  2019. if (maxlength.Count < 10)
  2020. {
  2021. maxlength.Add(dataTable.Rows[i]["Fieldid"].ToString());
  2022. }
  2023. else
  2024. {
  2025. break;
  2026. }
  2027. }
  2028. }
  2029. List<string> max_list = maxlength.Distinct().ToList();
  2030. string str_path_FIELD_FILES = str_resultPath + "\\FIELD_FILES\\";
  2031. int intQuantity = 0;
  2032. dt_FIeld = new DataTable();
  2033. vs = new List<string>();
  2034. //查找该field下对应所有的颗粒
  2035. DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
  2036. DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
  2037. if (theFolder.Exists)
  2038. {
  2039. DataTable dt = new DataTable();
  2040. dt.Columns.Add("fieldid");
  2041. dt.Columns.Add("id");
  2042. dt.Columns.Add("fieldName");
  2043. dt.Columns.Add("cunt", typeof(int));
  2044. dt.Columns.Add("fieldFullName");
  2045. for (int i = 0; i < max_list.Count; i++)
  2046. {
  2047. foreach (FileInfo nextifile in theFolder.GetFiles())
  2048. {
  2049. if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
  2050. {
  2051. //确认对应的帧图名
  2052. string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
  2053. str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
  2054. bool bl = false;
  2055. if (str_fieldid == max_list[i].ToString())
  2056. {
  2057. bl = true;
  2058. }
  2059. if (bl)
  2060. {
  2061. DataRow dr = dt.NewRow();
  2062. dr["fieldid"] = " fieldid = " + str_fieldid;
  2063. dr["cunt"] = dataTable.Select(" fieldid = " + str_fieldid).Count();
  2064. dr["fieldName"] = nextifile.Name;
  2065. dr["fieldFullName"] = nextifile.FullName;
  2066. dr["id"] = str_fieldid;
  2067. dt.Rows.Add(dr);
  2068. }
  2069. }
  2070. }
  2071. }
  2072. dt_FIeld = dt.Copy();
  2073. dt_FIeld.Columns.Add("Field_pic", typeof(Bitmap));
  2074. for (int i = 0; i < dt_FIeld.Rows.Count; i++)
  2075. {
  2076. if (dataTable.Select(dt_FIeld.Rows[i]["fieldid"].ToString()).Count() > 0)
  2077. {
  2078. vs.Add(dt_FIeld.Rows[i]["id"].ToString());
  2079. Image img = Image.FromFile(dt_FIeld.Rows[i]["fieldFullName"].ToString());
  2080. //img.Save(@"D:\1.bmp");
  2081. Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  2082. using (Graphics g = Graphics.FromImage(ls_fieldbp))
  2083. {
  2084. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  2085. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  2086. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  2087. g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
  2088. }
  2089. //ls_fieldbp.Save(@"D:\1.bmp");
  2090. img.Dispose();
  2091. img = null;
  2092. //循环将颗粒,进行标记到bitmap图上
  2093. DataRow[] drlist = dt_AllParticle.Select(dt_FIeld.Rows[i]["fieldid"].ToString());
  2094. if (drlist.Count() > 0)
  2095. intQuantity = intQuantity + 1;
  2096. for (int i_row = 0; i_row < drlist.Count(); i_row++)
  2097. {
  2098. //string str_fieldid = drlist[i_row]["fieldid"].ToString();
  2099. string str_particleid = drlist[i_row]["particleid"].ToString();
  2100. string str_stdtypeid = drlist[i_row]["typeid"].ToString();
  2101. string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
  2102. string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
  2103. string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
  2104. string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
  2105. //确定需要标记颗粒的定位
  2106. Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
  2107. Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
  2108. //向帧图进行标记颗粒位置
  2109. Graphics g = Graphics.FromImage(ls_fieldbp);
  2110. g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
  2111. //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
  2112. int ls_offsetx = offset_rect.X + offset_rect.Width;
  2113. if (ls_offsetx > ls_fieldbp.Width - 10)
  2114. {
  2115. ls_offsetx = offset_rect.X - 10;
  2116. }
  2117. g.DrawString(dt_FIeld.Rows[i]["id"].ToString() + "" + str_particleid.ToString(),
  2118. new Font("黑体", 8), new SolidBrush(Color.Aqua), new PointF(ls_offsetx, offset_rect.Y));
  2119. dt_FIeld.Rows[i]["Field_pic"] = ls_fieldbp;
  2120. //保存带有标记的帧图
  2121. //ls_fieldbp.Save(str_path_FIELD_FILES_MARK + dt_FIeld.Rows[i]["id"].ToString() + ".bmp");
  2122. //ls_fieldbp.Dispose();
  2123. }
  2124. }
  2125. }
  2126. }
  2127. //
  2128. GC.Collect();
  2129. GC.WaitForPendingFinalizers();
  2130. }
  2131. private void ImportSTDDb_Click(object sender, EventArgs e)
  2132. {
  2133. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  2134. string STDName = ((Dictionary<string, object>)sampleMembers["MsrParams"])["STDName"].ToString();
  2135. string ResultDbPath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";
  2136. if (STDName.ToLower().Split('.')[0] == "nostddb")
  2137. {
  2138. OpenFileDialog openFileDialog = new OpenFileDialog();
  2139. openFileDialog.Filter = "(*.db)|*.db";
  2140. openFileDialog.RestoreDirectory = true;
  2141. openFileDialog.FilterIndex = 1;
  2142. openFileDialog.Title = "Please choose a STD to add the rule!";
  2143. if (openFileDialog.ShowDialog() == DialogResult.OK)
  2144. {
  2145. try
  2146. {
  2147. string arguments = openFileDialog.FileName;
  2148. var SelectRows= dgV_ParticlesDevidePage.SelectedRows;
  2149. DataGridViewRow dgvr = SelectRows[0];
  2150. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  2151. List<string> list_str = (List<string>)ls_bp.Tag;
  2152. arguments += " " + ResultDbPath + " " + list_str[0].ToString() + " " + list_str[1].ToString() + " " + list_str[3].ToString();
  2153. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  2154. p.WaitForExit();
  2155. }
  2156. catch (Exception ex)
  2157. {
  2158. log.Error("OTSPartA_STDEditor:" + ex.ToString());
  2159. }
  2160. }
  2161. }
  2162. else
  2163. {
  2164. string arguments = ".\\Config\\SysData\\" + STDName.Split('.')[0] + ".db";
  2165. var selectRow = dgV_ParticlesDevidePage.SelectedRows[0];
  2166. Bitmap ls_bp = (Bitmap)selectRow.Cells[2].Value;
  2167. List<string> list_str = (List<string>)ls_bp.Tag;
  2168. arguments += " " + ResultDbPath + " " + list_str[0].ToString() + " " + list_str[1].ToString() + " " + list_str[3].ToString();
  2169. System.Diagnostics.Process p = System.Diagnostics.Process.Start(".\\OTSPartA_STDEditor.exe", arguments);
  2170. p.WaitForExit();
  2171. }
  2172. }
  2173. private void dgV_ParticlesDevidePage_MouseDown(object sender, MouseEventArgs e)
  2174. {
  2175. var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
  2176. int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
  2177. {
  2178. if (sel != (int)SelItem.MergeParticles)
  2179. {
  2180. if (SelectRows != null && SelectRows.Count == 1)
  2181. {
  2182. DataGridViewRow dgvr = SelectRows[0];
  2183. Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
  2184. List<string> list_str = (List<string>)ls_bp.Tag;
  2185. contextMenuStrip1.Items[10].Visible = true;
  2186. }
  2187. else
  2188. {
  2189. contextMenuStrip1.Items[10].Visible = false;
  2190. }
  2191. }
  2192. else
  2193. {
  2194. contextMenuStrip1.Items[10].Visible = false;
  2195. }
  2196. }
  2197. }
  2198. }
  2199. }