ParticlesGridDevidePage.cs 116 KB

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