ParticlesGridDevidePage.cs 111 KB

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