12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885 |
- using NPOI.SS.UserModel;
- using NPOI.SS.UserModel.Charts;
- using NPOI.SS.Util;
- using NPOI.XSSF.UserModel;
- using OTSCLRINTERFACE;
- using OTSCommon.DBOperate.Model;
- using OTSIncAReportApp;
- using OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage;
- using OTSIncAReportApp.DataOperation.DataAccess;
- using OTSIncAReportApp.OTSRstMgrFunction;
- using OTSIncAReportApp.SysMgrTools;
- using OTSIncAReportGraph.Class;
- using OTSIncAReportGraph.Controls;
- using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
- using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
- using OTSIncAReportMailInterface;
- using OTSPeriodicTable;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Threading;
- using System.Windows.Forms;
- using static OTSDataType.otsdataconst;
- namespace OTSIncAReportGrids
- {
- public partial class ParticlesGridDevidePage : UserControl
- {
- ParticlesGridDevidePageShowConfig m_particlesGridDevidePageShowConfig=null;
- //设置模拟数据表
- public DataTable m_dt = new DataTable();
- //底层操作类
- OTSReportGridsFun m_OTSIncAReportGridsFun = null;
- //进度条窗体
- public Frm_UserProgress m_frm_userprogress;
- //移动SEM到指定位置发生线程
- private Thread m_mythread;
- //记录线程是否已经运行完成的状态
- private bool m_mythread_state = false;
- //导出图像文件的路径
- private string m_imagefilepath = "";
- //显示元素列表
- public List<string> m_list_elementscolname = null;
- //单个数据源所拥有的列数,这里保存下来,供导出模块使用
- public int m_oneresult_columncount = 0;
- OTSImageDisHelp m_ReportFun = null;
- private OTSImageDisHelp ReportFun { get => m_ReportFun; set => m_ReportFun = value; }
- /// <summary>
- /// 选择颗粒缓存表
- /// </summary>
- List<Particle> Particleslist_selecttodisplay = new List<Particle>();
- //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
- public List<int> m_list_oneresult_columncount;
- //国际化
- Language lan;
- Hashtable table;
- //测量结果
- ResultFile result = null;
- frmReportConditionChoose m_condition;
- FieldData fieldData;
- DataTable particlesAll;
- DataTable particles;
- ParticleData Particledata;
- UserLibraryData userLibrary;
- DataTable userLibraryData;
- NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
- enum SelItem
- {
- analyticalParticle = 0,
- otherParticles = 1,
- MergeParticles = 2,
- allParticles=3
- }
- #region 分页器相关
- #region 分页字段和属性
- string condition = "";
- public string FileName = null;
- private int pageIndex = 1;
- /// <summary>
- /// 当前页面
- /// </summary>
- public virtual int PageIndex
- {
- get { return pageIndex; }
- set { pageIndex = value; }
- }
- private int pageSize = 20;
- /// <summary>
- /// 每页记录数
- /// </summary>
- public virtual int PageSize
- {
- get { return pageSize; }
- set { pageSize = value; }
- }
- //string OrderFunction = "fieldid,particleid";
- private int recordCount = 0;
- /// <summary>
- /// 总记录数
- /// </summary>
- public virtual int RecordCount
- {
- get { return recordCount; }
- set { recordCount = value; }
- }
- private int pageCount = 0;
- /// <summary>
- /// 总页数
- /// </summary>
- public int PageCount
- {
- get
- {
- pageCount = GetPageCount();
- return pageCount;
- }
- }
- /// <summary>
- /// 计算总页数
- /// </summary>
- /// <returns></returns>
- private int GetPageCount()
- {
- if (PageSize == 0)
- {
- return 0;
- }
- int pageCount = RecordCount / PageSize;
- if (RecordCount % PageSize == 0)
- {
- pageCount = RecordCount / PageSize;
- }
- else
- {
- pageCount = RecordCount / PageSize + 1;
- }
- return pageCount;
- }
- #endregion
- frmReportApp m_ReportApp;
- //ResultFile resultFile = null;
- #endregion
- public ParticlesGridDevidePage(frmReportApp ReportApp)
- {
- m_ReportApp = ReportApp;
- m_condition = ReportApp.m_conditionChoose;
- string sou = m_condition.m_CurrentConditions[OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
- if (sou.Contains("+"))
- {
- MessageBox.Show("This function does not support multiple samples!");
- result = m_ReportApp.m_rstDataMgr.ResultFilesList[0];
- }
- else
- {
- result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE)];
- }
- ReportFun = new OTSImageDisHelp(result);
- //设置窗体的双缓冲,以保证大数据时拖动不卡
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
- this.UpdateStyles();
- InitializeComponent();
- //利用反射设置DataGridView的双缓冲
- Type dgvType = this.dgV_ParticlesDevidePage.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.dgV_ParticlesDevidePage, true, null);
- this.control_XRayTable1 = new Control_XRayTable(null);
- this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
- this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.control_XRayTable1.GBInfoStr = "";
- this.control_XRayTable1.GoodChineseName = "";
- this.control_XRayTable1.MaterialName = "";
- //this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAReportGraph.Controls.ShowElementInfo>)(Resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
- this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
- this.control_XRayTable1.Name = "control_XRayTable1";
- this.control_XRayTable1.ShowAnalysisXray = true;
- this.control_XRayTable1.ShowSearchXray = false;
- this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
- this.control_XRayTable1.STDName = "";
- this.control_XRayTable1.Visible = false;
- this.control_XRayTable1.label_close.Visible = true;
- this.Controls.Add(this.control_XRayTable1);
- }
- bool Init()
- {
- if(result==null)
- {
- return false;
- }
- try
- {
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- m_mythread_state = false;
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- fieldData = new FieldData(result.FilePath);
- Particledata = new ParticleData(result.FilePath);
- var systype = m_ReportApp.m_RptConfigFile.Systype;
- if (systype == OTS_SysType_ID.TCCleannessA || systype == OTS_SysType_ID.BatteryCleannessA)
- {
- string str_libraryName = result.GetSTDName();
- userLibrary = new UserLibraryData(str_libraryName,result.FilePath+"\\");
- if (userLibrary.GetSqlHelper() != null)
- {
- userLibraryData = userLibrary.GetSubAttributeFromDatabase();
- }
- else
- {
- userLibraryData = null;
- }
- }
- //初始化底层操作类
- m_OTSIncAReportGridsFun = new OTSReportGridsFun(m_ReportApp, this);
- return true;
- }
- catch (Exception ex)
- {
- log.Error(ex.ToString());
- return false;
- }
- }
- private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
- {
- if (!Init())
- {
- return;
- }
- ProgressStart();//进度条关闭通过cbB_PageSize.SelectedIndex事件
- if (!UpdateTable())
- {
- return;
- }
- cbB_PageSize.Items.Add("20");
- cbB_PageSize.Items.Add("100");
- cbB_PageSize.Items.Add("500");
- cbB_PageSize.Items.Add("1000");
- cbB_PageSize.Items.Add("5000");
- cbB_PageSize.Items.Add("All");
- cbB_PageSize.SelectedIndex = 0;
- DataTable table = Particledata.GetClassificationOfAllParticles();
- if (table != null)
- {
- if (table.Rows.Count > 0)
- {
- foreach(DataRow row in table.Rows)
- {
- tbx_Type.Text += row["TypeName"].ToString() + '$';
- }
- }
- if(tbx_Type.Text!="")
- {
- tbx_Type.Text = tbx_Type.Text.Remove(tbx_Type.Text.Length - 1);
- }
- }
- dgV_ParticlesDevidePage.Focus();
- }
- #region 自定义方法
- bool UpdateTable()
- {
- int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
- particlesAll = new DataTable();
- if (sel == (int)SelItem.analyticalParticle)
- {
-
- particlesAll = Particledata.GetInfoForPartucleDevidePage_analyticalParticle(condition);
- DataTable mergeParticles = Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
- if (mergeParticles != null && mergeParticles.Rows.Count > 0)
- {
- RemoveMergeParticles(ref particlesAll, mergeParticles);
- }
- }
- if (sel == (int)SelItem.otherParticles)
- {
- particlesAll = Particledata.GetInfoForPartucleDevidePage_otherParticle(condition);
- DataTable mergeParticles = Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
- if (mergeParticles != null && mergeParticles.Rows.Count > 0)
- {
- RemoveMergeParticles(ref particlesAll, mergeParticles);
- }
- }
- if (sel == (int)SelItem.MergeParticles)
- {
- particlesAll = Particledata.GetInfoForPartucleDevidePage_mergeParticles(condition);
- }
- if (sel == (int)SelItem.allParticles)
- {
- particlesAll = Particledata.GetInfoForPartucleDevidePage_allParticles(condition);
- }
- particlesAll.Columns.Add("Hardness");
- particlesAll.Columns.Add("Density");
- particlesAll.Columns.Add("Electrical_conductivity");
- if (userLibraryData != null)
- {
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- DataRow[] dr = userLibraryData.Select("STDId=" + particlesAll.Rows[i]["TypeId"].ToString());
- if (dr.Length > 0)
- {
- particlesAll.Rows[i]["Hardness"] = dr[0]["Hardness"].ToString();
- particlesAll.Rows[i]["Density"] = dr[0]["Density"].ToString();
- particlesAll.Rows[i]["Electrical_conductivity"] = dr[0]["Electrical_conductivity"].ToString();
- }
- else
- {
- particlesAll.Rows[i]["Hardness"] = "";
- particlesAll.Rows[i]["Density"] = "";
- particlesAll.Rows[i]["Electrical_conductivity"] = "";
- }
- }
- }
- else
- {
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- particlesAll.Rows[i]["Hardness"] = "";
- particlesAll.Rows[i]["Density"] = "";
- particlesAll.Rows[i]["Electrical_conductivity"] = "";
- }
- }
- btn_Sel.Enabled = true;
- if (particlesAll == null)
- {
- log.Error("There is an exception in the data of the database!");
- #region 加载进度条进度部份结束
- //加载完成设置鼠标为默认
- this.Cursor = Cursors.Default;
- //加载完成,关闭进度条
- m_frm_userprogress.Close();
- #endregion
- return false;
- }
- DataTable elementchemistry = Particledata.GetElementChemistry();
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
- DataRow[] drs = elementchemistry.Select(str);
- string ConcatenatedString = "";
- for (int j = 0; j < drs.Length; j++)
- {
- ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';';
- }
- particlesAll.Rows[i]["Element"] = ConcatenatedString;
- }
- if (sel!=(int)SelItem.MergeParticles)
- {
- DataTable XRayData = Particledata.GetXRayData();
- particlesAll.Columns.Add("XRayDataCount");
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- if (int.Parse(particlesAll.Rows[i]["particleId"].ToString()) > -1)
- {
- particlesAll.Rows[i]["XRayDataCount"] = 0;
- string str = " XrayIndex= " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString();
- DataRow[] drs = XRayData.Select(str);
- uint xraycount = 0;
- if (drs != null)
- {
- if (drs.Length > 0)
- {
- uint[] Analysis_xray = new uint[2000];
- for (int j = 0; j < 2000; j++)
- {
- Analysis_xray[j] = BitConverter.ToUInt32((byte[])drs[0][2], j * 4);
- }
- for (int j = 0; j < 2000; j++)
- {
- xraycount += Analysis_xray[j];
- }
- particlesAll.Rows[i]["XRayDataCount"] = xraycount;
- }
- }
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
- /// </summary>
- /// <param name="in_cotsparticleclr"></param>
- /// <returns></returns>
- public Bitmap GetBitmapByParticle(string fieldImage, Rectangle offset_rect)
- {
- Bitmap ls_bt = DrawFunction.ReadImageFile(fieldImage);
- offset_rect.X = offset_rect.X - 5;
- offset_rect.Y = offset_rect.Y - 5;
- offset_rect.Width = offset_rect.Width + 10;
- offset_rect.Height = offset_rect.Height + 10;
- //防止计算偏差后,有坐标溢出现象
- if (offset_rect.X < 0)
- offset_rect.X = 0;
- if (offset_rect.Y < 0)
- offset_rect.Y = 0;
- if (offset_rect.X + offset_rect.Width > ls_bt.Width)
- {
- offset_rect.Width = ls_bt.Width - offset_rect.X;
- }
- if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
- {
- offset_rect.Height = ls_bt.Height - offset_rect.Y;
- }
- //
- Bitmap new_ret_bp;
- //防止为0后面计算出错
- if (offset_rect.Width > 0 && offset_rect.Height > 0)
- {
- //最后通过list_showsegment组建成新的图片,进行返回
- new_ret_bp = ls_bt.Clone(offset_rect, ls_bt.PixelFormat);
- }
- else
- {
- new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
- }
- return new_ret_bp;
- }
-
- private void BindDataGridView()
- {
- dgV_ParticlesDevidePage.Visible = false;
- if (m_frm_userprogress.IsDisposed)
- {
- ProgressStart();
- }
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- var startFun = m_ReportApp.m_RptConfigFile.Systype;
-
- string str_DefaultComputedColName = "", str_ElementsColName = "";
- DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData");
- DataTable dt = ds.Tables["Member"];
- foreach (DataRow element in dt.Rows)
- {
- string RegName = element["RegName"].ToString();
- if (RegName == "DefaultComputedColName")
- {
- str_DefaultComputedColName = element["strValue"].ToString();
- }
- if (RegName == "ElementsColName")
- {
- str_ElementsColName = element["strValue"].ToString();
- }
- }
- string[] strs = str_DefaultComputedColName.Split(',');
- Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
- keyValues.Add("rowid", table["str4"].ToString());
- keyValues.Add("TypeName", table["str6"].ToString());
- keyValues.Add("ParticleImage", table["str5"].ToString());
- keyValues.Add("FieldId", "FieldId");
- keyValues.Add("ParticleId", "ParticleId");
- keyValues.Add("SEMPosX", "SEMPosX");
- keyValues.Add("SEMPosY", "SEMPosY");
- for (int i = 0; i < strs.Count(); i++)
- {
- if (strs[i] == "ParticleCoordinate")
- {
- keyValues.Add("AbPosX", "PosX");
- keyValues.Add("AbPosY", "PosY");
- }
- if (strs[i] == "Area")
- {
- keyValues.Add("Area", table["str21"].ToString());
- }
- if (strs[i] == "EquivalentCircleDiameter")
- {
- keyValues.Add("Equivalent", table["str22"].ToString());
- }
- if (strs[i] == "MaxDiameter")
- {
- keyValues.Add("DMAX", table["str23"].ToString());
- }
- if (strs[i] == "MinDiameter")
- {
- keyValues.Add("DMIN", table["str24"].ToString());
- }
- if (strs[i] == "DiameterRatio")
- {
- keyValues.Add("DiameterRatio", table["str25"].ToString());
- }
- if (strs[i] == "FerretDiameter")
- {
- keyValues.Add("DFERET", table["str26"].ToString());
- }
- if (strs[i] == "PERP")
- {
- keyValues.Add("DPERP", table["str27"].ToString());
- }
- if (strs[i] == "PERI")
- {
- keyValues.Add("PERIMETER", table["str28"].ToString());
- }
- if (strs[i] == "INSCR")
- {
- keyValues.Add("DINSCR", table["str29"].ToString());
- }
- if (strs[i] == "MEAN")
- {
- keyValues.Add("DMEAN", table["str30"].ToString());
- }
- if (strs[i] == "ELONG")
- {
- keyValues.Add("DELONG", table["str31"].ToString());
- }
- if (strs[i] == "ASPECT_ELONG")
- {
- keyValues.Add("ASPECT_ELONG", table["str32"].ToString());
- }
- if (strs[i] == "Orientation")
- {
- keyValues.Add("ORIENTATION", table["str33"].ToString());
- }
- if (strs[i] == "XRayDataCount")
- {
- keyValues.Add("XRayDataCount", "XRay计数");
- }
- if (startFun == OTS_SysType_ID.TCCleannessA|| startFun == OTS_SysType_ID.BatteryCleannessA)
- {
- if (strs[i] == "Hardness")
- {
- keyValues.Add("Hardness", table["str34"].ToString());
- }
- if (strs[i] == "Density")
- {
- keyValues.Add("Density", table["str35"].ToString());
- }
- if (strs[i] == "Electrical_conductivity")
- {
- keyValues.Add("Electrical_conductivity", table["str36"].ToString());
- }
- }
- }
- keyValues.Add("Element", "Element");
- Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
- for (int irow = 0; irow < keyValues.Count; irow++)
- {
- if (en.MoveNext())
- {
- if (en.Current.Key == "ParticleImage")
- {
- DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
- iconColumn.Name = en.Current.Key;
- iconColumn.HeaderText = en.Current.Value;
- dgV_ParticlesDevidePage.Columns.Add(iconColumn);
- }
- else if (en.Current.Key == "Element")
- {
- }
- else
- {
- dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
- 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")
- {
- int id = dgV_ParticlesDevidePage.Columns.Count;
- dgV_ParticlesDevidePage.Columns[id - 1].Tag = "NumericType";
- }
- }
- }
- }
- if (PageSize == -1)
- {
- PageSize = particlesAll.Rows.Count;
- }
- if (particlesAll == null)
- {
- return;
- }
- RecordCount = particlesAll.Rows.Count;
- particles = particlesAll.Clone();
- for (int fi = (PageIndex - 1) * pageSize; fi < PageIndex * pageSize; fi++)
- {
- if (fi > RecordCount - 1)
- {
- break;
- }
- particles.ImportRow(particlesAll.Rows[fi]);
- }
- string particleM = "";
- List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
- for (int i = 0; i < ElementTypeSort.Count; i++)
- {
- if(ElementTypeSort[0]=="")
- {
- ElementTypeSort.RemoveAt(0);
- break;
- }
- dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
- int id = dgV_ParticlesDevidePage.Columns.Count;
- dgV_ParticlesDevidePage.Columns[id - 1].Tag = "NumericType";
- }
- double jd = 95f / (double)particles.Rows.Count;
- string filePath = result.FilePath + "\\FIELD_FILES\\";
- KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
- for (int i = 0; i < particles.Rows.Count; i++)
- {
- if (i % 10 == 0)
- m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "loading..");
- Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
- int add_rowindex = dgV_ParticlesDevidePage.Rows.Add();
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[0].Value = (pageSize * (PageIndex - 1) + add_rowindex + 1).ToString();
- for (int k = 0; k < keyValues.Count; k++)
- {
- if (enl.MoveNext())
- {
- if (enl.Current.Key == "ParticleImage")
- {
- if (particles.Columns.Contains("SubParticles"))
- {
- string subt = particles.Rows[i]["SubParticles"].ToString();
- if (subt != null && subt != "")
- {
- //double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
- double ScanFieldSize = result.GetScanFieldSizeX();
- string filePatht = result.FilePath + "\\FIELD_FILES\\";
- string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
- //然后将取出的数据,转换成Bitmap对象
- Bitmap tempbit = Particledata.ReadImageFile(imagePatht);
- int pixw = tempbit.Width;
- double xs = pixw / ScanFieldSize;
- particleM = particleM + "," + subt;
- Bitmap bmap = Particledata.GetBitmapForBig(subt, xs, result.FilePath, tempbit.Height, tempbit.Width);
- if (bmap != null)
- {
- string[] str = subt.Split(',');
- bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
- dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
- dgV_ParticlesDevidePage.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate;
- }
- else
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure;
- }
- }
- }
- else
- {
- if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
- {
- string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
- FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), Particledata.ReadImageFile(imagePath));
- }
- 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"]) };
- Bitmap bmap = Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
- 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() };
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
- dgV_ParticlesDevidePage.Rows[add_rowindex].Height = bmap.Height + 20;
- }
- }
- if (enl.Current.Key == "DiameterRatio")
- {
- double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]);
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
- }
- if (en.Current.Key == "Element")
- {
- }
- if (enl.Current.Key == "ASPECT_ELONG")
- {
- double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]);
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2);
- }
- if (particles.Columns.Contains(enl.Current.Key))
- {
- double num = 0;
- if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num))
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);
- }
- else if (enl.Current.Key == "Element")
- {
- List<string> elementtemp = new List<string>(ElementTypeSort);
- string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
- for (int j = 0; j < strcbo.Length; j++)
- {
- if(ElementTypeSort.Count==0)
- {
- break;
- }
- string[] str = strcbo[j].Split('-');
- if (ElementTypeSort.Contains(str[0]))
- { dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); }
- elementtemp.Remove(str[0].ToString());
- }
- foreach (var ele in elementtemp)
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[ele].Value = "0";
- }
- }
- else
- {
- double val = 0;
- if(double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]),out val))
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = val;
- }
- else
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key];
- }
-
- }
- }
- if (enl.Current.Key == "TypeName")
- {
- if (particles.Rows[i]["TypeId"].ToString() == "9")
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "Not Identified";
- }
- }
- if (enl.Current.Key == "Equivalent")
- {
- double dSize = Convert.ToDouble(particles.Rows[i]["Area"]);
- double Diameter = Math.Sqrt(dSize / Math.PI) * 2;
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2);
- }
- if (enl.Current.Key == "Hardness")
- {
- string str = ChangeHardnessColor(particles.Rows[i]["Hardness"].ToString());
- {
- if (str == "#FF0000")
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Style.ForeColor = Color.Red;
- }
- }
- }
- if (enl.Current.Key == "AbPosX")
- {
- 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"])));
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells["AbPosX"].Value = point.X;
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y;
- }
- }
- }
- }
- #region 加载进度条进度部份结束
- //加载完成设置鼠标为默认
- this.Cursor = Cursors.Default;
- string str8 = table["str8"].ToString();
- m_frm_userprogress.SetProgressValueAndText(100, str8);
- //加载完成,关闭进度条
- m_frm_userprogress.Close();
- #endregion
- dgV_ParticlesDevidePage.Visible = true;
- }
- /// <summary>
- /// 设置DataGridView样式
- /// </summary>
- private void SetDataGridViewStyle()
- {
- //用户不能调整标题的高度
- dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //用户不能调整 行高
- dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
- //点击选择整行
- dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- //居中显示
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dgV_ParticlesDevidePage.DefaultCellStyle = dataGridViewCellStyle1;
- dgV_ParticlesDevidePage.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- //再次重覆禁用拖动表头高度,居然有效果了
- dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //设置grid可以复制
- dgV_ParticlesDevidePage.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
- //设置每列的宽度
- dgV_ParticlesDevidePage.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
- dgV_ParticlesDevidePage.Columns[1].Width = 150;
- //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].Width = 450;
- //dgV_ParticlesDevidePage.Columns[dgV_ParticlesDevidePage.Columns.Count - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
- //设置序号列不排序
- dgV_ParticlesDevidePage.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- //设置序号列不可以设置宽度
- dgV_ParticlesDevidePage.Columns[0].Resizable = DataGridViewTriState.False;
- dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
- }
- /// <summary>
- /// 计算颗粒中心的电镜坐标
- /// </summary>
- /// <param name="resultFile"></param>
- /// <param name="SEMPos"></param>
- /// <param name="ParticlePos"></param>
- /// <returns></returns>
- public static Point CalculateParticleCenterPosition(ResultFile resultFile, Point SEMPos, Point ParticlePos)
- {
- Point point = new Point();
- float ScanFieldSizeX = resultFile.GetScanFieldSizeX();
- string leftOrRight = resultFile.GetXAxisDir();
- string downOrUp = resultFile.GetYAxisDir();
- float ScanFieldSizeY = resultFile.GetScanFieldSizeY();
- float m_pixelSize = resultFile.GetPixelSize();
- if (leftOrRight == "RIGHT_TOWARD")
- {
- point.X = (int)(SEMPos.X - ScanFieldSizeX / 2 + ParticlePos.X * m_pixelSize);
- }
- else
- {
- point.X = (int)(SEMPos.X + ScanFieldSizeX / 2 - ParticlePos.X * m_pixelSize);
- }
- if (downOrUp == "UP_TOWARD")
- {
- point.Y = (int)(SEMPos.Y + ScanFieldSizeY / 2 - ParticlePos.Y * m_pixelSize);
- }
- else
- {
- point.Y = (int)(SEMPos.Y - ScanFieldSizeY / 2 + ParticlePos.Y * m_pixelSize);
- }
- return point;
- }
- #endregion
- #region 相关事件
- private void ToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- //复制整个表
- CopyAll();
- }
- private void ToolStripMenuItem2_Click(object sender, EventArgs e)
- {
- //复制选择区域
- CopySelected();
- }
- /// <summary>
- /// 复制选择区域
- /// </summary>
- public void CopySelected()
- {
- //复制选择区域
- object oo = dgV_ParticlesDevidePage.GetClipboardContent();
- if (oo != null)
- Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
- }
- /// <summary>
- /// 复制所有
- /// </summary>
- public void CopyAll()
- {
- dgV_ParticlesDevidePage.SelectAll();
- Clipboard.SetDataObject(dgV_ParticlesDevidePage.GetClipboardContent());
- }
- /// <summary>
- /// 以图像的方式将GridView进行截图
- /// </summary>
- public void CopyImage()
- {
- int height, width;
- width = dgV_ParticlesDevidePage.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + 2;
- height = this.Height;
- Bitmap image = new Bitmap(width, height);
- dgV_ParticlesDevidePage.DrawToBitmap(image, new Rectangle(0, 0, width, height));
- Clipboard.SetImage(image);
- }
- private void toolStripMenuItem4_Click(object sender, EventArgs e)
- {
- //对gridview进行截图
- CopyImage();
- }
- private void dgV_ParticlesDevidePage_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
- {
- //排序中
- if (e.Column.Tag != null && e.Column.Tag.ToString() == "NumericType")
- {
- e.SortResult = double.Parse(e.CellValue1.ToString()).CompareTo(double.Parse(e.CellValue2.ToString()));
- e.Handled = true;
- }
- }
- /// <summary>
- /// 将OTS坐标转换为Sem 坐标
- /// </summary>
- /// <param name="POTSCoord"></param>
- /// <returns></returns>
- public Point ChangeOTSToSemCoord(Point POTSCoord)
- {
- //first if m_semstagedata is null to get stage inforation
- //Convert.ToDouble(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["scanFieldSize"]);
- //after obtaining stage info,calc stage point data
- Point ret_SEM_point = new Point();
- // get center point, um
- //long xStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["start"]);
- //long xEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["XAxis"])["end"]);
- long xStart = result.GetXAxisStart();
- long xEnd = result.GetXAxisEnd();
- long xCenter = (xStart + xEnd) / 2;
- //long yStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["start"]);
- //long yEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["Members"])["YAxis"])["end"]);
- long yStart = result.GetYAxisStart();
- long yEnd = result.GetYAxisEnd();
- long yCenter = (yStart + yEnd) / 2;
- // delte = SEM - OTSa
- long deltex = xCenter - 0;
- long deltey = yCenter - 0;
- OTS_X_AXIS_DIRECTION xdir = result.GetXAxisDirEnum();
- OTS_Y_AXIS_DIRECTION ydir = result.GetYAxisDirEnum();
- if (xdir == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
- {
- ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
- }
- else if (xdir == OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
- {
- ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
- }
- if (ydir == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
- {
- ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
- }
- else if (ydir == OTS_Y_AXIS_DIRECTION.DOWN_TOWARD)
- {
- ret_SEM_point.Y = -1 * (POTSCoord.Y - Convert.ToInt32(deltey));
- }
- return ret_SEM_point;
- }
- #endregion
- #region 获取向导出模块提供的DataTable和GridView对象
- /// <summary>
- /// 获取到该模块输出后形成的DataTable,和GridView
- /// </summary>
- /// <param name="out_dt"></param>
- /// <param name="out_dg"></param>
- public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
- {
- out_dt = m_dt;
- out_dg = this.dgV_ParticlesDevidePage;//同样通过 dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[2].Value 来获取bitmap对象
- }
- #endregion
- #region 连接电镜相关
- /// <summary>
- /// 移动SEM到指定位置线程函数
- /// </summary>
- private void Thread_GO(object in_obj)
- {
- if (m_mythread_state == false)
- {
- m_mythread_state = true;
- Point sem_point = (Point)in_obj;
- //第一步,连接电镜
- m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
- Thread.Sleep(500);
- //第二步,移动到指定位置,先读取再设置
- if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
- {
- m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y);
- }
- Thread.Sleep(1500);
- //第三步,断开电镜连接
- //m_OTSIncAReportGridsFun.DisConnectSEM_ForParticlesGrid();
- //Thread.Sleep(500);
- m_mythread_state = false;
- }
- }
- #endregion
- private void ToolStripMenuItem_exportzoomimagefile_Click(object sender, EventArgs e)
- {
- //导出放大图像
- FolderBrowserDialog fbd = new FolderBrowserDialog();
- if (fbd.ShowDialog() == DialogResult.OK)
- {
- m_imagefilepath = fbd.SelectedPath;
- for (int i = 0; i < m_dt.Rows.Count; i++)
- {
- Bitmap ls_bp = new Bitmap(1, 1);
- ls_bp = (Bitmap)m_dt.Rows[i][1];
- string strPath = m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg";
- string strPath2 = m_imagefilepath + "\\" + (i + 1).ToString() + "s.jpg";
- ls_bp.Save(strPath);
- //m_COTSReportProjFileMgrClr.ReZoom(strPath, strPath2);
- System.IO.File.Delete(strPath);//再将文件删除
- }
- string str1 = table["str9"].ToString();
- MessageBox.Show(str1 + m_dt.Rows.Count.ToString());
- }
- }
- /// <summary>
- /// 导出二次放大图像
- /// </summary>
- /// <param name="str_srcPathName"></param>
- /// <param name="str_outPathName"></param>
- public void ParticleReZoom(string str_srcPathName, string str_outPathName)
- {
- //m_COTSReportProjFileMgrClr.ReZoom(str_srcPathName, str_outPathName);
- }
- private void ToolStripMenuItem3_Click(object sender, EventArgs e)
- {
- //如果没有选中颗粒退出
- if (dgV_ParticlesDevidePage.SelectedRows.Count==0)
- {
- return;
- }
- string CategoryName = "";
- //循环选中颗粒
- for (int i=0;i< dgV_ParticlesDevidePage.SelectedRows.Count;i++)
- {
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
- CategoryName = dgvr.Cells[1].Value.ToString();
- }
- string TypeId = "";
- string TypeName = "";
- string TypeColor = "";
- string GroupName = "";
- DataTable da = Particledata.GetParticleListForParticlSize("area", "");
- ModifyCategoryForm modifyCategoryForm = new ModifyCategoryForm(da, CategoryName);
- DialogResult result = modifyCategoryForm.ShowDialog();
- if(modifyCategoryForm.DoYouWantToModifyIt)
- {
- TypeId = modifyCategoryForm.OutTypeAndName[0];
- TypeName = modifyCategoryForm.OutTypeAndName[1];
- TypeColor = modifyCategoryForm.OutTypeAndName[2];
- GroupName = modifyCategoryForm.OutTypeAndName[3];
- List<string> strings = new List<string>();
- strings.Add(TypeId);
- strings.Add(TypeName);
- strings.Add(TypeColor);
- strings.Add(GroupName);
- List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
- for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
- {
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
- dgvr.Cells[1].Value = TypeName;
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- int i_ls_fieldid = Convert.ToInt32(list_str[0]);
- int i_ls_particleid = Convert.ToInt32(list_str[1]);
- List<int> ints = new List<int>();
- ints.Add(i_ls_fieldid);
- ints.Add(i_ls_particleid);
- var cmd= Particledata.GetUpdataAIncACmd(ints, strings);
- cmdlist.Add(cmd);
- }
- Particledata.ExecuteNonQueryBatch(cmdlist);
- }
- }
- private void ToolStripMenuItem5_Click(object sender, EventArgs e)
- {
- /*注意:多数据源情况下,只获取第一个数据源的选择了多行的情况下,只获取最后一个选择行的,没有办法,这是为了符合李阳博士提出的要求*/
- //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID
- string i_ls_fieldid = "";
- string i_ls_particleid = "";
- int cou = dgV_ParticlesDevidePage.SelectedRows.Count;
- if (cou > 0)
- {
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[cou - 1];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- if (list_str != null)
- {
- i_ls_fieldid = list_str[0];
- i_ls_particleid = list_str[1];
- }
- }
- ParticleData particleData = new ParticleData(result.FilePath);
- Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid);
- ////然后遍历所有的Field
- //Point ls_ots_point = new Point() { X = particle.PosX, Y = particle.PosY };
- ////将该坐标转成SEM坐标
- //Point ls_sem_point = ChangeOTSToSemCoord(ls_ots_point);
- //取得Field的Position,然后执行线程移动SEM到当前Field的位置
- if (m_mythread == null)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin)
- {
- return;
- }
- if (m_mythread.ThreadState == ThreadState.Stopped)
- {
- m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
- }
- Point point = CalculateParticleCenterPosition(result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY));
- //改为线程调用,先判断线程状态
- m_mythread.Start(point);
- }
- private void ToolStripMenuItem_exportimagefile_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog fbd = new FolderBrowserDialog();
- if (fbd.ShowDialog() == DialogResult.OK)
- {
- m_imagefilepath = fbd.SelectedPath;
- for (int i = 0; i < dgV_ParticlesDevidePage.Rows.Count; i++)
- {
- Bitmap ls_bp = new Bitmap(1, 1);
- ls_bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i].Cells[2].Value;
- ls_bp.Save(m_imagefilepath + "\\" + (i + 1).ToString() + ".jpg");
- }
- string str9 = table["str9"].ToString();
- MessageBox.Show(str9 + dgV_ParticlesDevidePage.Rows.Count.ToString());
- }
- }
- private void testToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ////测试导出指定颗粒的能谱图,测试相关代码
- //OTSIncAReportGraph.DParticle ls_dparticle = new OTSIncAReportGraph.DParticle();
- //for (int i = 0; i < dgV_ParticlesDevidePage.SelectedRows.Count; i++)
- //{
- // //获取选择行颗粒的fieldid,和particleid
- // string str_fieldid = "";
- // string str_particleid = "";
- // string str_stdtypeid = "";
- // DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[i];
- // Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- // List<string> list_str = (List<string>)ls_bp.Tag;
- // if (list_str != null)
- // {
- // str_fieldid = list_str[0];
- // str_particleid = list_str[1];
- // str_stdtypeid = list_str[2];
- // }
- // ls_dparticle.CLRFieldID = Convert.ToInt32(str_fieldid);
- // ls_dparticle.CLRTagID = Convert.ToInt32(str_particleid);
- // ls_dparticle.STDTypeID = Convert.ToInt32(str_stdtypeid);
- //}
- ////显示xray能谱
- //ShowXRay(ls_dparticle);
- //Bitmap ls_bpex = new Bitmap(control_XRayTable1.Width, control_XRayTable1.Height);
- //control_XRayTable1.DrawToBitmap(ls_bpex, new Rectangle(0, 0, control_XRayTable1.Width, control_XRayTable1.Height));
- ////Bitmap ls_bpex = control_XRayTable1.ExportXRayImage();
- //ls_bpex.Save("e:\\test222.jpg");
- }
- /// <summary>
- /// 判断条件输入 前<后
- /// </summary>
- /// <param name="min"></param>
- /// <param name="max"></param>
- /// <returns></returns>
- bool CompareInput(string min, string max)
- {
- int imax = 0;
- int imin = 0;
- double dmax = 0;
- double dmin = 0;
- if (int.TryParse(max, out imax))
- {
- dmax = (double)imax;
- }
- else
- {
- dmax = Convert.ToDouble(max);
- }
- if (int.TryParse(min, out imin))
- {
- dmin = (double)imin;
- }
- else
- {
- dmin = Convert.ToDouble(min);
- }
- if (dmin <= dmax)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private void btn_Sel_Click(object sender, EventArgs e)
- {
- condition = "";
- if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(tBx_AreaMin.Text, out dnum) && dnum >= 0)
- {
- condition += " and Area" + " > " + tBx_AreaMin.Text;
- }
- else if (int.TryParse(tBx_AreaMin.Text, out inum) && inum >= 0)
- {
- condition += " and Area" + " > " + tBx_AreaMin.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(Tbx_AreaMax.Text, out dnum) && dnum >= 0)
- {
- condition += " and Area" + "<" + Tbx_AreaMax.Text;
- }
- else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
- {
- condition += " and Area" + "<" + Tbx_AreaMax.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tBx_AreaMin.Text) && !string.IsNullOrWhiteSpace(Tbx_AreaMax.Text))
- {
- if (!CompareInput(tBx_AreaMin.Text, Tbx_AreaMax.Text))
- {
- MessageBox.Show(table["str11"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(tbx_DmaxMin.Text, out dnum) && dnum >= 0)
- {
- condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
- }
- else if (int.TryParse(tbx_DmaxMin.Text, out inum) && inum >= 0)
- {
- condition += " and DMAX" + " > " + tbx_DmaxMin.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(tbx_DmaxMax.Text, out dnum) && dnum > 0)
- {
- condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
- }
- else if (int.TryParse(tbx_DmaxMax.Text, out inum) && inum >= 0)
- {
- condition += " and DMAX" + "<" + tbx_DmaxMax.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tB_FieldId.Text))
- {
- int inum = 0;
- if (int.TryParse(tB_FieldId.Text, out inum))
- {
- condition += " and FieldId =" + tB_FieldId.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tB_ParticleId.Text))
- {
- int inum = 0;
- if (int.TryParse(tB_ParticleId.Text, out inum))
- {
- condition += " and ParticleId =" + tB_ParticleId.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_DmaxMin.Text) && !string.IsNullOrWhiteSpace(tbx_DmaxMax.Text))
- {
- if (!CompareInput(tbx_DmaxMin.Text, tbx_DmaxMax.Text))
- {
- MessageBox.Show(table["str11"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_DferretMin.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(tbx_DferretMin.Text, out dnum) && dnum >= 0)
- {
- condition += " and PERIMETER" + ">" + tbx_DferretMin.Text;
- }
- else if (int.TryParse(Tbx_AreaMax.Text, out inum) && inum >= 0)
- {
- condition += " and PERIMETER" + ">" + tbx_DferretMin.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_DferretMax.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(tbx_DferretMax.Text, out dnum) && dnum >= 0)
- {
- condition += " and PERIMETER" + "<" + tbx_DferretMax.Text;
- }
- else if (int.TryParse(tbx_DferretMax.Text, out inum) && inum >= 0)
- {
- condition += " and PERIMETER" + "<" + tbx_DferretMax.Text;
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_DferretMin.Text) && !string.IsNullOrWhiteSpace(tbx_DferretMax.Text))
- {
- if (!CompareInput(tbx_DferretMin.Text, tbx_DferretMax.Text))
- {
- MessageBox.Show(table["str11"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_ECDMin.Text))
- {
- double dnum = 0;
- int inum = 0;
- if (double.TryParse(tbx_ECDMin.Text, out dnum) && dnum >= 0)
- {
- double area = Math.PI * dnum/2 * dnum/2;
- condition += " and Area" + ">" + area.ToString();
- }
- else if (int.TryParse(tbx_ECDMin.Text, out inum) && inum >= 0)
- {
- double area = Math.PI * dnum/2 * dnum/2;
- condition += " and Area" + ">" + area.ToString();
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_ECDMax.Text))
- {
- double dnum = 0;int inum = 0;
- if (double.TryParse(tbx_ECDMax.Text, out dnum) && dnum >= 0)
- {
- double area = Math.PI * dnum/2 * dnum/2;
- condition += " and Area" + "<" + area.ToString();
- }
- else if (int.TryParse(tbx_ECDMax.Text, out inum) && inum >= 0)
- {
- double area = Math.PI * dnum/2 * dnum/2;
- condition += " and Area" + "<" + area.ToString();
- }
- else
- {
- MessageBox.Show(table["str10"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_ECDMin.Text) && !string.IsNullOrWhiteSpace(tbx_ECDMax.Text))
- {
- if (!CompareInput(tbx_ECDMin.Text, tbx_ECDMax.Text))
- {
- MessageBox.Show(table["str11"].ToString());
- return;
- }
- }
- if (!string.IsNullOrWhiteSpace(tbx_Type.Text))
- {
- string[] tr = tbx_Type.Text.Split('$');
- condition += " and (";
- for (int i = 0; i < tr.Length; i++)
- {
- if (i == 0)
- {
- condition += " TypeName = '" + tr[i] + "'";
- }
- else
- {
- condition += " or TypeName = '" + tr[i] + "'";
- }
- }
- condition += ")";
- }
- if (m_frm_userprogress.IsDisposed)
- {
- ProgressStart();
- }
- UpdateTable();
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- void ProgressStart()
- {
- #region 加载显示进度条部份
- this.Cursor = Cursors.WaitCursor;
- m_frm_userprogress = new Frm_UserProgress();
- //显示进度条,计算进度条应该显示的位置和宽度
- Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
- if (ls_main_form == null)
- {
- m_frm_userprogress.Visible = false;
- }
- else
- {
- m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
- m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
- m_frm_userprogress.Show();
- m_frm_userprogress.SetProgressValueAndText(0, "Loading data of particles...");
- }
- #endregion
- }
- private void cbB_order_SelectedIndexChanged(object sender, EventArgs e)
- {
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- /// <summary>
- /// 页面控件呈现
- /// </summary>
- private void DrawControl(bool callEvent)
- {
- BindDataGridView();
- lblTotalCount.Text = RecordCount.ToString();
- lblPageCount.Text = PageCount.ToString();
- txtPageNum.Text = PageIndex.ToString();
- SetFormCtrEnabled();
- if (PageCount == 0 || PageCount == 1)//有且仅有一页
- {
- lnkFirst.Enabled = false;
- lnkPrev.Enabled = false;
- lnkNext.Enabled = false;
- lnkLast.Enabled = false;
- btnGo.Enabled = false;
- }
- else if (PageIndex == 1)//第一页
- {
- lnkFirst.Enabled = false;
- lnkPrev.Enabled = false;
- }
- else if (PageIndex == PageCount)//最后一页
- {
- lnkNext.Enabled = false;
- lnkLast.Enabled = false;
- }
- }
- private void SetFormCtrEnabled()
- {
- lnkFirst.Enabled = true;
- lnkPrev.Enabled = true;
- lnkNext.Enabled = true;
- lnkLast.Enabled = true;
- btnGo.Enabled = true;
- }
- /// <summary>
- /// 分页属性改变了。
- /// </summary>
- private void txtPageSize_TextChanged(object sender, EventArgs e)
- {
- int num = 0;
- if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
- {
- }
- else { txtPageNum.Text = "1"; }
- }
- private void lnkFirst_Click(object sender, EventArgs e)
- {
- PageIndex = 1;
- DrawControl(true);
- }
- private void lnkPrev_Click(object sender, EventArgs e)
- {
- PageIndex = Math.Max(1, PageIndex - 1);
- DrawControl(true);
- }
- private void lnkNext_Click(object sender, EventArgs e)
- {
- PageIndex = Math.Min(PageCount, PageIndex + 1);
- DrawControl(true);
- }
- private void lnkLast_Click(object sender, EventArgs e)
- {
- PageIndex = PageCount;
- DrawControl(true);
- }
- /// <summary>
- /// 跳转
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnGo_Click(object sender, EventArgs e)
- {
- int num = 0;
- if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
- {
- if (num > PageCount)
- {
- num = PageCount;
- txtPageNum.Text = PageCount.ToString();
- }
- PageIndex = num;
- DrawControl(true);
- }
- }
- private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
- {
- DisplayData();
- }
- /// <summary>
- /// 在帧图上标记颗粒的位置矩形,并保存到FIELD_FILES_MARK文件夹中
- /// </summary>
- public void SaveMarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable, out List<string> vs, out DataTable dt_FIeld)
- {
- if(!Init())
- {
- vs = null;
- dt_FIeld = null;
- return;
- }
- List<string> maxlength = new List<string>();
- for (int i = 0; i < dataTable.Rows.Count; i++)
- {
- if (dataTable.Rows[i]["TypeName"].ToString() != "Not Identified")
- {
- if (maxlength.Count < 10)
- {
- maxlength.Add(dataTable.Rows[i]["Fieldid"].ToString());
- }
- else
- {
- break;
- }
- }
- }
- List<string> max_list = maxlength.Distinct().ToList();
- string str_path_FIELD_FILES = str_resultPath + "\\FIELD_FILES\\";
- string str_path_FIELD_FILES_MARK = str_resultPath + "\\FIELD_FILES_MARK\\";
- int intQuantity = 0;
- dt_FIeld = new DataTable();
- vs = new List<string>();
- ////判断是否已经有导出过的标记帧图文件夹,如果已经存在,则直接返回不输出,先不加
- DirectoryInfo theFolder_FieldMark = new DirectoryInfo(str_path_FIELD_FILES_MARK);
- if (!theFolder_FieldMark.Exists)
- {
- //创建
- theFolder_FieldMark.Create();
- }
- else
- {
- theFolder_FieldMark.Delete(true);
- //创建
- theFolder_FieldMark.Create();
- //已经存在的话,直接返回
- //return;
- }
- //查找该field下对应所有的颗粒
- DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
- DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
- if (theFolder.Exists)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("fieldid");
- dt.Columns.Add("id");
- dt.Columns.Add("fieldName");
- dt.Columns.Add("cunt", typeof(int));
- dt.Columns.Add("fieldFullName");
- for (int i = 0; i < max_list.Count; i++)
- {
- foreach (FileInfo nextifile in theFolder.GetFiles())
- {
- if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
- {
- //确认对应的帧图名
- string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
- str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
- bool bl = false;
- if (str_fieldid == max_list[i].ToString())
- {
- bl = true;
- }
- if (bl)
- {
- DataRow dr = dt.NewRow();
- dr["fieldid"] = " fieldid = " + str_fieldid;
- dr["cunt"] = dataTable.Select(" fieldid = " + str_fieldid).Count();
- dr["fieldName"] = nextifile.Name;
- dr["fieldFullName"] = nextifile.FullName;
- dr["id"] = str_fieldid;
- dt.Rows.Add(dr);
- }
- }
- }
- }
- //DataView dv = dt.DefaultView;
- //dv.Sort = "cunt DESC";
- dt_FIeld = dt.Copy();
- for (int i = 0; i < dt_FIeld.Rows.Count; i++)
- {
- if (dataTable.Select(dt_FIeld.Rows[i]["fieldid"].ToString()).Count() > 0)
- {
- vs.Add(dt_FIeld.Rows[i]["id"].ToString());
- Image img = Image.FromFile(dt_FIeld.Rows[i]["fieldFullName"].ToString());
- //img.Save(@"D:\1.bmp");
- Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- using (Graphics g = Graphics.FromImage(ls_fieldbp))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
- }
- //ls_fieldbp.Save(@"D:\1.bmp");
- img.Dispose();
- img = null;
- //循环将颗粒,进行标记到bitmap图上
- DataRow[] drlist = dt_AllParticle.Select(dt_FIeld.Rows[i]["fieldid"].ToString());
- if (drlist.Count() > 0)
- intQuantity = intQuantity + 1;
- for (int i_row = 0; i_row < drlist.Count(); i_row++)
- {
- //string str_fieldid = drlist[i_row]["fieldid"].ToString();
- string str_particleid = drlist[i_row]["particleid"].ToString();
- string str_stdtypeid = drlist[i_row]["typeid"].ToString();
- string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
- string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
- string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
- string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
- //确定需要标记颗粒的定位
- Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
- Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
- //向帧图进行标记颗粒位置
- Graphics g = Graphics.FromImage(ls_fieldbp);
- g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
- //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
- int ls_offsetx = offset_rect.X + offset_rect.Width;
- if (ls_offsetx > ls_fieldbp.Width - 10)
- {
- ls_offsetx = offset_rect.X - 10;
- }
- 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));
- //保存带有标记的帧图
- ls_fieldbp.Save(str_path_FIELD_FILES_MARK + dt_FIeld.Rows[i]["id"].ToString() + ".bmp");
- //ls_fieldbp.Dispose();
- }
- }
- }
- }
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- private void testToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- //SaveMarkParticleRectangleOnFieldFile();
- MessageBox.Show("Export completed!");
- }
- private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation sfd = new OTSIncAReportApp._1_UI.Control_Grids.SpectrumExportConfirmation();
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- Cursor = Cursors.WaitCursor;
- //var progr = new Frm_UserProgress();
- if (m_frm_userprogress.IsDisposed)
- {
- ProgressStart();
- }
- //IWorkbook workbook = new HSSFWorkbook(); //用于创建.xls office2003开始以前的
- IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(); //用于创建.xlsx office2007开始以后的
- ISheet sheet;
- //创建Excel文件
- FileStream fs = File.Create(sfd.FileName);
- fs.Close();
- sheet = workbook.CreateSheet("Particles");//创建工作表
- //创建表格边框样式风格
- ICellStyle cellStyle = workbook.CreateCellStyle();
- cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
- cellStyle.VerticalAlignment = VerticalAlignment.Center;
- //设置上4边
- cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
- cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
- cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
- cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
- //设置字符大小和颜色
- IFont font = workbook.CreateFont();
- font.FontName = "黑体";
- font.FontHeightInPoints = 10;
- cellStyle.SetFont(font);
- //设置颗粒名列宽
- sheet.SetColumnWidth(1, 30 * 256);//夹杂物名列宽
- sheet.SetColumnWidth(2, 7 * 256);//图像列宽
- IRow row;
- ICell cell;
- //插入表头
- row = sheet.CreateRow(1);//从第15行添加一行
- IDrawing patriarch;
- patriarch = sheet.CreateDrawingPatriarch();
- row.Height = 30 * 20;
- for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
- {
- cell = row.CreateCell(i_cell);
- cell.CellStyle = cellStyle;
- cell.SetCellValue(dgV_ParticlesDevidePage.Columns[i_cell].HeaderText);
- }
- m_frm_userprogress.SetProgressValueAndText(0, "export:"+"0"+"/total:"+ dgV_ParticlesDevidePage.Rows.Count);
- IClientAnchor anchor;
- int pictureIdx;
- Bitmap bp;
- byte[] bytes;
- IPicture pict;
- //插入表内容
- for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
- {
- if (dgV_ParticlesDevidePage.Rows.Count > 100)
- {
- if (i_row%(dgV_ParticlesDevidePage.Rows.Count / 100) == 0)
- m_frm_userprogress.SetProgressValueAndText(i_row * 100/ dgV_ParticlesDevidePage.Rows.Count, "export:" + i_row + "/total:" + dgV_ParticlesDevidePage.Rows.Count);
- }
- row = sheet.CreateRow(2 + i_row);
- row.Height = 45 * 20;
- for (int i_cell = 0; i_cell < dgV_ParticlesDevidePage.Columns.Count; i_cell++)
- {
- cell = row.CreateCell(i_cell);
- cell.CellStyle = cellStyle;
- if (dgV_ParticlesDevidePage[i_cell, i_row].Value == null)
- continue;
- if (i_cell == 2)
- {
- if (sfd.IfExportPicture)
- {
- //颗粒图像列
- bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
- bytes = ImageConvertToBytes(bp);
- //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
- pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
- //第三步,在sheet中创建画布
-
- //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
- anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
- //第五步,创建图片
- pict = patriarch.CreatePicture(anchor, pictureIdx);
- }
- }
- else
- {
- //非图像列
-
- cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
- }
- }
- }
- if (sfd.IfExportSpectrumData)
- {
- ISheet sheet2;
- sheet2 = workbook.CreateSheet("Peak spectrum Data");//创建工作表
- //插入表头
- row = sheet2.CreateRow(1);
- row.Height = 30 * 20;
- cell = row.CreateCell(0);
- cell.CellStyle = cellStyle;
- cell.SetCellValue("rowid");
- for (int i_cell = 1; i_cell < 2001; i_cell++)
- {
- cell = row.CreateCell(i_cell);
- cell.CellStyle = cellStyle;
- if (i_cell == 1)
- {
- cell.SetCellValue("PeakSpectrumData");
- }
- }
- sheet2.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 1, 1, 2000));
- for (int j = 0; j < particles.Rows.Count; j++)
- {
- row = sheet2.CreateRow(2 + j);
- cell = row.CreateCell(0);
- cell.CellStyle = cellStyle;
- cell.SetCellValue(j + 1);
- var tmpPart = Particledata.GetParticleXrayDataByFidAndPid(particles.Rows[j]["fieldid"].ToString(), particles.Rows[j]["particleid"].ToString());
- if (tmpPart != null)
- {
- if (tmpPart.XrayId > -1)
- {
- uint[] Analysis_xray = new uint[2000];
- for (int i = 0; i < 2000; i++)
- {
- Analysis_xray[i] = BitConverter.ToUInt32(tmpPart.XRayData, i * 4);
- cell = row.CreateCell(i + 1);
- cell.CellStyle = cellStyle;
- cell.SetCellValue(Analysis_xray[i]);
- }
- }
- }
- }
- }
- if (sfd.IfExportSpectrumConfirmation)
- {
- ISheet sheet3;
- sheet3 = workbook.CreateSheet("Peak spectrum");
- sheet3.SetColumnWidth(1, 200 * 256);//图像列宽
- //插入表头
- row = sheet3.CreateRow(1);
- row.Height = 30 * 20;
- cell = row.CreateCell(0);
- cell.CellStyle = cellStyle;
- cell.SetCellValue("rowid");
- cell = row.CreateCell(1);
- cell.CellStyle = cellStyle;
- cell.SetCellValue("PeakSpectrum");
- IDrawing drawing;
- IClientAnchor anchor3;
- for (int j = 0; j < particles.Rows.Count; j++)
- {
- row = sheet3.CreateRow(j + 2);
- row.Height = 120 * 20;
- cell = row.CreateCell(0);
- cell.CellStyle = cellStyle;
- cell.SetCellValue(j + 1);
- cell = row.CreateCell(1);
- cell = row.CreateCell(2);
- cell = row.CreateCell(3);
- drawing = sheet3.CreateDrawingPatriarch();
- //锚点
- 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开始
- CreateChart(drawing, sheet3, anchor3, j + 2);
- }
- }
- //完成后,对Excel进行保存
- FileStream file = new FileStream(sfd.FileName, FileMode.Create);
- workbook.Write(file);
- file.Close();
- //MessageBox.Show("Export complete!");
- m_frm_userprogress.SetProgressValueAndText(100, "export:" + dgV_ParticlesDevidePage.Rows.Count + "/total:" + dgV_ParticlesDevidePage.Rows.Count);
- //加载完成,关闭进度条
- m_frm_userprogress.Close();
- Cursor = Cursors.Default;
- //导出完成后,打开Excel文件
- if (File.Exists(sfd.FileName))
- {
- //打开刚才导出的文件
- System.Diagnostics.Process.Start(sfd.FileName);
- }
- }
- }
- void CreateChart(IDrawing drawing, ISheet sheet, IClientAnchor anchor, int rowid)
- {
- var chart = drawing.CreateChart(anchor) as XSSFChart;
- //图表
- var data = chart.ChartDataFactory.CreateLineChartData<double, double>(); //折线图
- IChartAxis bottomAxis = chart.ChartAxisFactory.CreateCategoryAxis(AxisPosition.Bottom);
- IValueAxis leftAxis = chart.ChartAxisFactory.CreateValueAxis(AxisPosition.Left);
- leftAxis.Crosses = AxisCrosses.AutoZero;
- leftAxis.IsVisible = true;
- bottomAxis.IsVisible = true;
- //数据源
- IChartDataSource<double> ys = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(rowid, rowid, 1, 2001));
- Double[] doubles = new Double[2000];
- for (int i = 0; i < 2000; i++)
- {
- doubles[i] = i;
- }
- IChartDataSource<double> xs = DataSources.FromArray(doubles);
- //数据系列
- var s1 = data.AddSeries(xs, ys);
- }
- /// <summary>
- /// 将image转成bytes
- /// </summary>
- /// <param name="in_img"></param>
- /// <returns></returns>
- public byte[] ImageConvertToBytes(System.Drawing.Image in_img)
- {
- MemoryStream ms = new MemoryStream();
- in_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
- return ms.ToArray();
- }
- public bool CheckParamExist<T>(T Param)
- {
- if (Param == null)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- private void ToolStripMenuItem_Delete_Particle_Click(object sender, EventArgs e)
- {
- string path = result.FilePath;
- ParticleData fielddata = new ParticleData(result.FilePath);
- List<Particle> particles = fielddata.GetParticleAllList();
- DialogResult dr = MessageBox.Show("Remove all these particles permanently?", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (dr == DialogResult.OK)
- {
- List<Particle> list_Part = new List<Particle>();
- for (int ii = 0; ii < dgV_ParticlesDevidePage.SelectedRows.Count; ii++)
- {
-
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[ii];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- if (list_str != null)
- {
- int i_ls_fieldid = Convert.ToInt32(list_str[0]);
- int i_ls_particleid = Convert.ToInt32(list_str[1]);
- foreach (Particle item in particles)
- {
- if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
- {
- if (DeleteParticlesFromLibrary(item.ParticleId, item.FieldId))
- {
- for (int i = 0; i < particlesAll.Rows.Count; i++)
- {
- if (particlesAll.Rows[i]["Fieldid"].ToString() == item.FieldId.ToString() && particlesAll.Rows[i]["Particleid"].ToString() == item.ParticleId.ToString())
- {
- particlesAll.Rows.RemoveAt(i);
- list_Part.Add(item);
- }
- }
- }
- else
- {
- MessageBox.Show("Delete failed");
- }
- break;
- }
- }
- }
- }
- RecordCount = recordCount - dgV_ParticlesDevidePage.SelectedRows.Count;
- lblTotalCount.Text = RecordCount.ToString();
- foreach (DataGridViewRow Row in dgV_ParticlesDevidePage.SelectedRows)
- {
- dgV_ParticlesDevidePage.Rows.Remove(Row);
- }
- if(dgV_ParticlesDevidePage.Rows.Count==0)
- {
- DisplayData();
- }
- for(int j=0;j< dgV_ParticlesDevidePage.Rows.Count;j++)
- {
- dgV_ParticlesDevidePage.Rows[j].Cells[0].Value = (pageSize * (PageIndex - 1) + j + 1).ToString();
- }
- if (m_ReportApp.im_Control_DrawDistrbutionImageAndBSE != null)
- {
- m_ReportApp.im_Control_DrawDistrbutionImageAndBSE.DeletesParticlesSynchronously(list_Part);
- }
- else
- {
- var _Control_DrawDistrbutionImageAndBSE = new OTSIncAReportGraph.Controls.Control_DrawDistrbutionImageAndBSE(m_ReportApp);
- foreach (var p in list_Part)
- {
- _Control_DrawDistrbutionImageAndBSE.DeleteParticlesFromLibrary(p.ParticleId, p.FieldId);
- }
- }
- }
- }
- private bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
- {
- bool DoesItExist = false;
- for (int i = 1; i < 201; i++)
- {
- if (System.IO.Directory.Exists(result.FilePath + "\\FIELD_FILES\\Backups" + i.ToString()))
- {
- DoesItExist = true;
- break;
- }
- }
- if (!DoesItExist)
- {
- //备份数据库
- BackupDatabase();
- }
- DoesItExist = false;
- //防止为空校验判断
- if (result.List_OTSField == null)
- return false;
- Particle particle = result.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
- if (new ParticleData(result.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private bool BackupDatabase()
- {
- //创建备份数据库文件夹
- string sourcePath = result.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
- string sourceName = "Inclusion.db";//源文件名称
- string folderPath = result.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
- string Fields = "";
- for (int i = 1; i < 201; i++)
- {
- if (System.IO.Directory.Exists(folderPath + i.ToString()))
- {
- Fields = folderPath + i.ToString();
- continue;
- }
- else
- {
- System.IO.Directory.CreateDirectory(folderPath + i.ToString());
- Fields = folderPath + i.ToString();
- break;
- }
- }
- if (Fields == "")
- {
- return false;
- }
- //复制数据库文件
- string targetPath = Path.Combine(Fields, sourceName);
- FileInfo file = new FileInfo(sourcePath);
- if (file.Exists)
- {
- file.CopyTo(targetPath, true);
- }
- return true;
- }
- private void DisplayData()
- {
- if (cbB_PageSize.SelectedItem.ToString() == "All")
- {
- pageSize = -1;
- }
- else
- {
- pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
- }
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- string ChangeHardnessColor(string Hardness)
- {
- string str = System.Text.RegularExpressions.Regex.Replace(Hardness, @"[^\d.\d]", "");
- double hd;
- if (double.TryParse(str, out hd))
- {
- if (hd >= 1000)
- {
- return "#FF0000";
- }
- else return "";
- }
- else
- return "";
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="str_resultPath"></param>
- /// <param name="dataTable"></param>
- /// <param name="vs"></param>
- /// <param name="dt_FIeld"></param>
- public void Out_MarkParticleRectangleOnFieldFile(string str_resultPath, DataTable dataTable, out List<string> vs, out DataTable dt_FIeld)
- {
- Init();
- List<string> maxlength = new List<string>();
- for (int i = 0; i < dataTable.Rows.Count; i++)
- {
- if (Convert.ToInt32(dataTable.Rows[i]["TypeId"])>9)
- {
- if (maxlength.Count < 10)
- {
- maxlength.Add(dataTable.Rows[i]["Fieldid"].ToString());
- }
- else
- {
- break;
- }
- }
- }
- List<string> max_list = maxlength.Distinct().ToList();
- string str_path_FIELD_FILES = str_resultPath + "\\FIELD_FILES\\";
- int intQuantity = 0;
- dt_FIeld = new DataTable();
- vs = new List<string>();
- ResultFile resfile = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
- float PixelSize = resfile.GetPixelSize();
- float ScanFieldSizeX = resfile.GetScanFieldSizeX();
- int gauge = RulerSelection(ScanFieldSizeX);
- float RulerPixels = gauge / PixelSize;
- DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
- DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
- if (theFolder.Exists)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("fieldid");
- dt.Columns.Add("id");
- dt.Columns.Add("fieldName");
- dt.Columns.Add("cunt", typeof(int));
- dt.Columns.Add("fieldFullName");
- for (int i = 0; i < max_list.Count; i++)
- {
- foreach (FileInfo nextifile in theFolder.GetFiles())
- {
- if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
- {
- string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
- str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
- bool bl = false;
- if (str_fieldid == max_list[i].ToString())
- {
- bl = true;
- }
- if (bl)
- {
- DataRow dr = dt.NewRow();
- dr["fieldid"] = " fieldid = " + str_fieldid;
- int drcunt = 0;
- for (int ia=0;ia< dataTable.Rows.Count;ia++)
- {
- if (dataTable.Rows[ia]["fieldid"].ToString()== str_fieldid.ToString())
- {
- drcunt++;
- }
- }
- dr["cunt"] = drcunt;
- dr["fieldName"] = nextifile.Name;
- dr["fieldFullName"] = nextifile.FullName;
- dr["id"] = str_fieldid;
- dt.Rows.Add(dr);
- }
- }
- }
- }
- dt_FIeld = dt.Copy();
- dt_FIeld.Columns.Add("Field_pic", typeof(Bitmap));
- for (int i = 0; i < dt_FIeld.Rows.Count; i++)
- {
- int drCount = 0;
- for (int ia = 0; ia < dataTable.Rows.Count; ia++)
- if (Convert.ToInt32(dt_FIeld.Rows[i]["id"]) == Convert.ToInt32(dataTable.Rows[ia]["fieldid"]))
- drCount++;
- if (drCount > 0)
- {
- vs.Add(dt_FIeld.Rows[i]["id"].ToString());
- Image img = Image.FromFile(dt_FIeld.Rows[i]["fieldFullName"].ToString());
-
- Bitmap ls_fieldbp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- using (Graphics g = Graphics.FromImage(ls_fieldbp))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
- g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
- }
-
- img.Dispose();
- img = null;
- //循环将颗粒,进行标记到bitmap图上
- DataRow[] drlist = dt_AllParticle.Select(dt_FIeld.Rows[i]["fieldid"].ToString());
- if (drlist.Count() > 0)
- intQuantity = intQuantity + 1;
- for (int i_row = 0; i_row < drlist.Count(); i_row++)
- {
-
- string str_particleid = drlist[i_row]["particleid"].ToString();
- string str_stdtypeid = drlist[i_row]["typeid"].ToString();
- string str_offset_rect_X = drlist[i_row]["RectLeft"].ToString();
- string str_offset_rect_Y = drlist[i_row]["RectTop"].ToString();
- string str_offset_rect_Width = drlist[i_row]["RectWidth"].ToString();
- string str_offset_rect_Height = drlist[i_row]["RectHeight"].ToString();
- //确定需要标记颗粒的定位
- Rectangle offset_rect = new Rectangle(Convert.ToInt32(str_offset_rect_X), Convert.ToInt32(str_offset_rect_Y),
- Convert.ToInt32(str_offset_rect_Width), Convert.ToInt32(str_offset_rect_Height));
- //向帧图进行标记颗粒位置
- Graphics g = Graphics.FromImage(ls_fieldbp);
- g.DrawRectangle(new Pen(Color.Aquamarine), offset_rect);
- //判断是否超出了图像外面,是的话,让文字在左侧显示,默认在右侧显示
- int ls_offsetx = offset_rect.X + offset_rect.Width;
- if (ls_offsetx > ls_fieldbp.Width - 10)
- {
- ls_offsetx = offset_rect.X - 10;
- }
- 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));
-
-
- var bitmap = DrawRuler(ls_fieldbp, (int)(RulerPixels/2), 2, (gauge/2).ToString()+ "μm");
- dt_FIeld.Rows[i]["Field_pic"] = bitmap;
- }
- }
- }
- }
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- /// <summary>
- /// 在图片上绘制标尺
- /// </summary>
- /// <param name="bitmap">图片</param>
- /// <param name="LineLength">线长(像素)</param>
- /// <param name="LineWidth">线宽(像素)</param>
- /// <returns></returns>
- private Bitmap DrawRuler(Bitmap bitmap, int LineLength, int LineWidth,string a_str)
- {
- if (bitmap == null)
- throw new ArgumentNullException(nameof(bitmap));
- // 创建一个新的Bitmap,并设置其大小与原图相同
- Bitmap rgbBitmap = new Bitmap(bitmap.Width, bitmap.Height);
- using (Graphics graphics = Graphics.FromImage(rgbBitmap))
- {
- // 将原图转换为RGB格式,并绘制到新的Bitmap上
- graphics.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
- Color color = FromHex("#00FF00");
- //Color color = FromHex("#00FF00");
- // 设置线条颜色和宽度
- Pen pen = new Pen(color, LineWidth);
- Font font = new Font("Arial", 20, GraphicsUnit.Pixel);
- Brush brush = new SolidBrush(color);
- StringFormat stringFormat = new StringFormat();
- stringFormat.Alignment = StringAlignment.Center; // 居中对齐
- stringFormat.LineAlignment = StringAlignment.Center; // 居中对齐行
- // 绘制文字
- SizeF textSize = Graphics.FromImage(bitmap).MeasureString(a_str, font);
- PointF point = new PointF();
- // 计算文本应该开始的位置,使其居中
- point.X = (bitmap.Width - LineLength - 20) + ((LineLength - textSize.Width) / 2);
- point.Y = bitmap.Height - 80;
- graphics.DrawString(a_str, font, new SolidBrush(color), point);
- graphics.DrawLine(pen, bitmap.Width - LineLength - 20, bitmap.Height - 40, bitmap.Width - 20, bitmap.Height - 40);
- graphics.DrawLine(pen, bitmap.Width - LineLength - 20, bitmap.Height - 40, bitmap.Width - LineLength - 20, bitmap.Height - 50);
- graphics.DrawLine(pen, bitmap.Width - 20, bitmap.Height - 40, bitmap.Width - 20, bitmap.Height - 50);
- }
- return rgbBitmap;
- }
- private static Color FromHex(string hex)
- {
- hex = hex.Replace("#", ""); // 移除 # 前缀
- byte a = 255; // 默认Alpha值为255(不透明)
- byte r = Convert.ToByte(hex.Substring(0, 2), 16);
- byte g = Convert.ToByte(hex.Substring(2, 2), 16);
- byte b = Convert.ToByte(hex.Substring(4, 2), 16);
- return Color.FromArgb(a, r, g, b);
- }
- /// <summary>
- /// 判断当前图片应该使用多大标尺
- /// </summary>
- /// <param name="a_value"> </param>
- /// <returns></returns>
- private int RulerSelection(float a_value)
- {
- int value = 0;
- a_value = a_value / 2;
- for (int i = 10; i < 5000; i += 5)
- {
- if (a_value < i)
- {
- value = i - 5;
- break;
- }
- }
- if (value == 0)
- {
- value = 5000;
- }
- return value;
- }
- private void dgV_ParticlesDevidePage_MouseDown(object sender, MouseEventArgs e)
- {
- var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
- int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
- {
- if (sel != (int)SelItem.MergeParticles)
- {
- if (SelectRows != null && SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- }
- ToolStripMenuItemDelete_Particle.Visible = true;
- }
- else
- {
- ToolStripMenuItemDelete_Particle.Visible = false;
- }
- }
- }
- /// <summary>
- /// 去除拼接颗粒组成颗粒
- /// </summary>
- /// <param name="dataTable_Particle"></param>
- /// <param name="dataTable_MergeParticles"></param>
- void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
- {
- foreach (DataRow row in dataTable_Particle.Rows)
- {
- foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
- {
- string subt = MergeParticlesRow["SubParticles"].ToString();
- string[] sub = subt.Split(',');
- if (row.RowState == DataRowState.Deleted)
- {
- break;
- }
- if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
- {
- row.Delete();
- break;
- }
- if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
- {
- row.Delete();
- break; ;
- }
- }
- }
- dataTable_Particle.AcceptChanges();
- }
- private void btn_showconfig_Click(object sender, EventArgs e)
- {
- //if (m_particlesGridDevidePageShowConfig == null|| m_particlesGridDevidePageShowConfig.IsDisposed)
- //{
- var p = particles; List<string> ele = new List<string>();
- string elementsstr = "";
- foreach (DataRow row in particles.Rows)
- {
- string[] strcbo = row["Element"].ToString().Split(';');
- for (int j = 0; j < strcbo.Length; j++)
- {
- string[] str = strcbo[j].Split('-');
-
- if (!ele.Contains(str[0]) && str[0] != "")
- {
- if (str[1] != ""&&double.Parse(str[1]) != 0) //咨询demo后,元素含量返回值为零时一般去除此元素
- {ele.Add(str[0]);}
- }
- }
- }
- foreach(var el in ele)
- {
- elementsstr += el.ToString() + ',';
- }
- if(elementsstr!="")
- {
- elementsstr=elementsstr.Remove(elementsstr.Length - 1, 1);
- }
- m_particlesGridDevidePageShowConfig = new ParticlesGridDevidePageShowConfig(m_ReportApp.m_RptConfigFile.Systype, elementsstr);
- m_particlesGridDevidePageShowConfig.ShowDialog();
- if (m_particlesGridDevidePageShowConfig.DialogResult == DialogResult.OK)
- {
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- BindDataGridView();
- SetDataGridViewStyle();
- }
- }
- private void SaveParticleslist_select()
- {
- ParticleData fielddata = new ParticleData(result.FilePath);
- List<Particle> particles = fielddata.GetParticleAllList();
- Particleslist_selecttodisplay.Clear();
- for (int l = 0; l < dgV_ParticlesDevidePage.SelectedRows.Count; l++)
- {
- //从事先加载的Bitmap对象的Tag中取出List<string>
- DataGridViewRow dgvr = dgV_ParticlesDevidePage.SelectedRows[l];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- if (list_str != null)
- {
- int i_ls_fieldid = Convert.ToInt32(list_str[0]);
- int i_ls_particleid = Convert.ToInt32(list_str[1]);
- foreach (Particle item in particles)
- {
- if (i_ls_fieldid == item.FieldId && i_ls_particleid == item.ParticleId)
- {
- Particleslist_selecttodisplay.Add(item);
- break;
- }
- }
- }
- }
- }
- public List<Particle> GetParticleslist_select()
- {
- return Particleslist_selecttodisplay;
- }
- private void dgV_ParticlesDevidePage_MouseUp(object sender, MouseEventArgs e)
- {
- int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.PARTICE_LIST);
- if (sel == (int)SelItem.MergeParticles)
- {
- return;
- }
- var SelectRows = dgV_ParticlesDevidePage.SelectedRows;
- if (SelectRows.Count != 0)
- {
- if (SelectRows.Count == 1)
- {
- DataGridViewRow dgvr = SelectRows[0];
- Bitmap ls_bp = (Bitmap)dgvr.Cells[2].Value;
- List<string> list_str = (List<string>)ls_bp.Tag;
- uint[] Search_xray = new uint[2000];
- uint[] Analysis_xray = new uint[2000];
- int i_xray_id = 0;
- List<Element> list_celementchemistryclr = new List<Element>();
- 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);
- List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
- for (int i = 0; i < list_celementchemistryclr.Count; i++)
- {
- ShowElementInfo ls_sei = new ShowElementInfo();
- ls_sei.ElementName = list_celementchemistryclr[i].Name;
- ls_sei.Percentage = list_celementchemistryclr[i].Percentage;
- ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
- double de_sx2 = 0;
- if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
- {
- de_sx2 = 0;
- }
- else
- {
- de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
- }
- ls_sei.dLF = de_sx2;
- list_showelementinfo.Add(ls_sei);
- }
- list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage));
- string str_IncAName = "";
- str_IncAName = Convert.ToString(dgvr.Cells[1].Value);
- 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));
- if (particle == null)
- {
- return;
- }
- 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));
- control_XRayTable1.Visible = true;
- control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo);
- //颗粒国标信息
- control_XRayTable1.GBInfoStr = "";
- control_XRayTable1.MaterialName = str_IncAName;//杂夹物
- control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString();
- DataRow[] drs = particles.Select(str);
- if (drs.Length > 0)
- {
- Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) };
- Bitmap dpImage = new Bitmap(result.GetImageWidth(), result.GetImageHeight());
- using (Graphics graphics = Graphics.FromImage(dpImage))
- {
- graphics.Clear(Color.White); // 清除位图背景为白色
- }
- string filePath = result.FilePath + "\\FIELD_FILES\\";
- string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp";
- Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath);
-
- foreach (Segment seg in particle.SegmentList)
- {
- int f_length = seg.Length;
- for (int m = 0; m < f_length; m++)
- {
- int lsjs_x = seg.Start + m;
- int lsjs_y = seg.Height;
- var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y);
- dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
- }
- }
- Bitmap bmap = Particledata.GetBitmapByParticle(dpImage, rectangle);
- Bitmap bmap1 = Particledata.GetBitmapByParticle(m_originalImage, rectangle);
- control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap);
- Invalidate();
- }
- else
- {
- control_XRayTable1.Visible = false;
- }
- }
- SaveParticleslist_select();
- }
- }
- private void dgV_ParticlesDevidePage_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Delete)
- {
- ToolStripMenuItem_Delete_Particle_Click(null, null);
- }
- //if (e.Control && e.KeyCode == Keys.A)
- //{
-
- //}
- }
- private void dgV_ParticlesDevidePage_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyData == Keys.Down)
- {
- dgV_ParticlesDevidePage_MouseUp(null, null);
- }
- if (e.KeyData == Keys.Up)
- {
- dgV_ParticlesDevidePage_MouseUp(null, null);
- }
- }
- private void tbx_Type_Click(object sender, EventArgs e)
- {
- ParticleClassificationSelect particleClassificationSelect = new ParticleClassificationSelect(Particledata, tbx_Type.Text);
- DialogResult result = particleClassificationSelect.ShowDialog();
- if (result == DialogResult.OK)
- {
- condition = "";
- tbx_Type.Text = particleClassificationSelect.ParticleClassificationSelected;
- string[] tr = tbx_Type.Text.Split(',');
- condition += " and (";
- for (int i = 0; i < tr.Length; i++)
- {
- if (i == 0)
- {
- condition += " TypeName = '" + tr[i] + "'";
- }
- else
- {
- condition += " or TypeName = '" + tr[i] + "'";
- }
- }
- condition += ")";
- if (m_frm_userprogress.IsDisposed)
- {
- ProgressStart();
- }
- UpdateTable();
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- }
- private void btn_particletypesel_Click(object sender, EventArgs e)
- {
- ParticleClassificationSelect particleClassificationSelect = new ParticleClassificationSelect(Particledata, tbx_Type.Text);
- DialogResult result = particleClassificationSelect.ShowDialog();
- if (result == DialogResult.OK)
- {
- condition = "";
- tbx_Type.Text = "";
- if (particleClassificationSelect.ParticleClassificationSelected != "")
- {
- tbx_Type.Text = particleClassificationSelect.ParticleClassificationSelected;
- btn_Sel_Click(null, null);
- }
- }
- }
- private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1)
- {
- if (posXray == null) return 0;
- if (posXray1 == null) return 0;
- if (posXray.GetChannelsNum() != posXray1.GetChannelsNum())
- {
- return 0;
- }
- var pXrayData = posXray.GetXrayData();
- var pXrayData1 = posXray1.GetXrayData();
- // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2))
- double dotProduct = 0;
- double d1 = 0;
- double d2 = 0;
- for (int i = 0; i < posXray.GetChannelsNum(); i++)
- {
- double r1 = pXrayData[i];
- double r2 = pXrayData1[i];
- r1 *= r2;
- dotProduct = dotProduct + r1;
- }
- d1 = posXray.GetXrayDataVectorNorm();
- d2 = posXray1.GetXrayDataVectorNorm();
- return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2);
- }
- }
- }
|