ParticlesGridDevidePage.cs 104 KB

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