123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325 |
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using OTSIncAReportApp;
- using OTSIncAReportApp.DataOperation.DataAccess;
- using OTSIncAReportApp.DataOperation.Model;
- using OTSIncAReportApp.SysMgrTools;
- using OTSIncAReportGraph.Class;
- using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
- using OTSIncAReportMailInterface;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Windows.Forms;
- namespace OTSIncAReportGrids
- {
- public partial class ParticlesGridDevidePage : UserControl
- {
- #region 枚举定义
- /// <summary>
- /// 样品台X轴方向
- /// </summary>
- enum OTS_X_AXIS_DIRECTION
- {
- LEFT_TOWARD = 0,
- RIGHT_TOWARD = 1
- }
- /// <summary>
- /// 样品台Y轴方向
- /// </summary>
- enum OTS_Y_AXIS_DIRECTION
- {
- UP_TOWARD = 0,
- DOWN_TOWARD = 1
- }
- #endregion
- //设置模拟数据表
- public DataTable m_dt = new DataTable();
- //底层操作类
- OTSIncAReportGridsFun 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;
- //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
- public List<int> m_list_oneresult_columncount;
- //国际化
- Language lan;
- Hashtable table;
- //测量结果
- ResultFile result = null;
- FieldData fieldData;
- private string m_filename = "";
- #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;
- #endregion
- public ParticlesGridDevidePage(frmReportApp ReportApp)
- {
- m_ReportApp = ReportApp;
- result = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult];
- InitializeComponent();
- m_frm_userprogress = new Frm_UserProgress();
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- fieldData = new FieldData(result.FilePath);
- }
- private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
- {
- ////显示进度条,计算进度条应该显示的位置和宽度
- //Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
- //if (ls_main_form == null)
- //{
- // m_frm_userprogress.Visible = false;
- //}
- //else
- //{
- // string str7 = table["str7"].ToString();
- // 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, str7);
- //}
- //string str2 = "加载颗粒列表,开始从底层加载数据....";
- //str2 = table["str2"].ToString();
- //m_frm_userprogress.SetProgressValueAndText(1, str2);
- if (Language.ReadDefaultLanguage() == "EN")
- {
- cbB_order.Items.Add("Default");
- cbB_order.Items.Add("ParticlesName");
- cbB_order.Items.Add("Dmax Ascend");
- cbB_order.Items.Add("Dmax Descend");
- cbB_order.Items.Add("Area Ascend");
- cbB_order.Items.Add("Area Descend");
- }
- else
- {
- cbB_order.Items.Add("默认");
- cbB_order.Items.Add("颗粒名称");
- cbB_order.Items.Add("最大直径 升序");
- cbB_order.Items.Add("最大直径 降序");
- cbB_order.Items.Add("面积 升序");
- cbB_order.Items.Add("面积 降序");
- }
- cbB_order.SelectedIndex = 0;
- 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.SelectedIndexChanged -= new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
- cbB_PageSize.SelectedIndex = 0;
- cbB_PageSize.SelectedIndexChanged += new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
- //string str8 = table["str8"].ToString();
- //m_frm_userprogress.SetProgressValueAndText(100, str8);
- ////加载完成,关闭进度条
- //m_frm_userprogress.Close();
- }
- #region 自定义方法
- /// <summary>
- /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
- /// </summary>
- /// <param name="in_cotsparticleclr"></param>
- /// <returns></returns>
- public Bitmap GetBitmapByParticle(string fieldImage, Rectangle offset_rect)
- {
- //然后将取出的数据,转换成Bitmap对象
- Bitmap ls_bt = DrawFuncation.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, PixelFormat.Format8bppIndexed);
- }
- else
- {
- new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
- }
- return new_ret_bp;
- }
- public Bitmap GetBitmapForBig(string sub, ParticleData fielddata, double xs)
- {
- string vs = "," + sub.Replace(':', '-') + ",";
- DataTable dataTable = fielddata.GetParticleAll(vs);
- if (dataTable.Rows.Count == 0)
- {
- return null;
- }
- string path = result.FilePath;
- //内接矩形
- double max_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs - Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
- double max_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs + Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
- double min_Y = max_Y;
- double min_X = max_X;
- //拼接field矩形
- double MAX_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
- double MAX_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
- double MIN_Y = MAX_Y;
- double MIN_X = MAX_X;
- foreach (DataRow item in dataTable.Rows)
- {
- //颗粒外接矩形
- double lefttopX = Convert.ToInt64(item["FieldPosX"]) * xs + Convert.ToInt64(item["RectLeft"]);
- if (lefttopX < min_X)
- {
- min_X = lefttopX;
- }
- if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
- {
- max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
- }
- double lrfttopY = Convert.ToInt64(item["FieldPosY"]) * xs - Convert.ToInt64(item["RectTop"]);
- if (max_Y < lrfttopY)
- {
- max_Y = lrfttopY;
- }
- if (min_Y > lrfttopY - Convert.ToInt64(item["RectHeight"]))
- {
- min_Y = lrfttopY - Convert.ToInt64(item["RectHeight"]);
- }
- //画布
- double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
- if (lefttopXH > MAX_X)
- {
- MAX_X = lefttopXH;
- }
- if (lefttopXH < MIN_X)
- {
- MIN_X = lefttopXH;
- }
- double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
- if (MAX_Y < lrfttopYH)
- {
- MAX_Y = lrfttopYH;
- }
- if (MIN_Y > lrfttopYH)
- {
- MIN_Y = lrfttopYH;
- }
- }
- int WIDTH = Convert.ToInt32(MAX_X - MIN_X) + 1024;
- int HEIGHT = Convert.ToInt32(MAX_Y - MIN_Y) + 768;
- //构造最终的图片白板
- Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
- Graphics graph = Graphics.FromImage(tableChartImage);
- //初始化这个大图
- graph.DrawImage(tableChartImage, 0, 0);
- int width = Convert.ToInt32(max_X - min_X);
- int height = Convert.ToInt32(max_Y - min_Y);
- int X = Convert.ToInt32(min_X - MIN_X);
- int Y = Convert.ToInt32(MAX_Y - max_Y);
- Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
- foreach (DataRow item in dataTable.Rows)
- {
- string filePath = path + "\\FIELD_FILES\\";
- string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
- //然后将取出的数据,转换成Bitmap对象
- Bitmap ls_bt = DrawFuncation.ReadImageFile(imagePath);
- int x = Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - MIN_X);
- int y = System.Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - MAX_Y));
- try
- {
- graph.DrawImage(ls_bt, x, y);
- }
- catch (Exception e)
- {
- throw;
- }
- }
- Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
- return bmap;
- }
- ///// <summary>
- ///// 绑定datagridview数据--
- ///// </summary>
- //private void BindDataGridView()
- //{
- // #region 加载显示进度条部份
- // //m_sec.SendCall("设置鼠标样式", "", "WaitCursor");
- // 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
- // {
- // string str7 = table["str7"].ToString();
- // 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, str7);
- // }
- // string str2 = "加载颗粒列表,开始从底层加载数据....";
- // str2 = table["str2"].ToString();
- // m_frm_userprogress.SetProgressValueAndText(1, str2);
- // #endregion
- // dgV_ParticlesDevidePage.Rows.Clear();
- // dgV_ParticlesDevidePage.Columns.Clear();
- // //列名
- // 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("Area", "Areaμm²");
- // keyValues.Add("DMAX", "DMAXμm");
- // keyValues.Add("DMIN", "DMINμm");
- // keyValues.Add("ASPECT_MAX", "ASPECT_MAX");
- // keyValues.Add("DFERET", "FERETμm");
- // keyValues.Add("DPERP", "DPERPμm");
- // keyValues.Add("PERIMETER", "PERIMETERμm");
- // keyValues.Add("DINSCR", "DINSCRμm");
- // keyValues.Add("DMEAN", "DMEANμm");
- // keyValues.Add("DELONG", "DELONGμm");
- // keyValues.Add("ASPECT_ELONG", "ASPECT_ELONG");
- // keyValues.Add("ORIENTATION", "ORIENTATION");
- // 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
- // {
- // int columndid = dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
- // }
- // }
- // }
- // ParticleData fielddata = new ParticleData(result.FilePath);
- // DataTable particles = fielddata.GetInfoForPartucleDevidePage(PageIndex, pageSize, OrderFunction, condition);
- // PageSize = particles.Rows.Count;
- // if (particles == null)
- // {
- // return;
- // }
- // List<string> ElementType = new List<string>();
- // for (int i = 0; i < particles.Rows.Count; i++)
- // {
- // string[] strcbo = particles.Rows[i]["Element"].ToString().Split(';');
- // for (int j = 0; j < strcbo.Length; j++)
- // {
- // string str = strcbo[j].Split('-')[0].ToString();
- // if (!ElementType.Contains(str))
- // {
- // ElementType.Add(str);
- // }
- // }
- // }
- // ElementType.Sort(delegate (string a, string b) { return ReturnsAtomicNumberByElementName(a).CompareTo(ReturnsAtomicNumberByElementName(b)); });
- // List<string> list_str = new List<string>(GetElementsColName().Distinct().ToList());//去重
- // List<string> ElementTypeSort = new List<string>(ElementType);
- // for (int i = 0; i < list_str.Count; i++)
- // {
- // for (int j = 0; j < ElementType.Count; j++)
- // {
- // if (list_str[i] == ElementType[j])
- // {
- // dgV_ParticlesDevidePage.Columns.Add(ElementType[j], ElementType[j]);
- // ElementTypeSort.Remove(ElementType[j]);
- // }
- // }
- // }
- // for (int i = 0; i < ElementTypeSort.Count; i++)
- // {
- // dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
- // }
- // RecordCount = fielddata.GetAllInfo(condition).Rows.Count;
- // string particleM = "";
- // double jd = 95f / (double)particles.Rows.Count;//计算进度刻度
- // //将datatable的数据,分别解析绑定到GridView上
- // KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
- // for (int i = 0; i < particles.Rows.Count; i++)
- // {
- // //更新进度,每100条记录加载完,更新一次进度
- // if (i % 100 == 0)
- // m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "Loding..");
- // 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 == "rowid")
- // {
- // //dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = i + 1;
- // }
- // if (enl.Current.Key == "ParticleImage")
- // {
- // string subt = particles.Rows[i]["SubParticles"].ToString();
- // if (subt != null && subt != "")
- // {
- // double ScanFieldSize = 1142;
- // //double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
- // string filePatht = result.FilePath + "\\FIELD_FILES\\";
- // string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
- // //然后将取出的数据,转换成Bitmap对象
- // Bitmap tempbit = fielddata.ReadImageFile(imagePatht);
- // int pixw = tempbit.Width;
- // double xs = pixw / ScanFieldSize;
- // particleM = particleM + "," + subt;
- // Bitmap bmap = fielddata.GetBitmapForBig(subt, xs, result.FilePath);
- // if (bmap != null)
- // {
- // bmap.Tag = new List<string>() { subt.Split(',')[0].Split(':')[0], subt.Split(',')[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() };
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
- // }
- // else
- // {
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Height = 150;
- // }
- // }
- // else
- // {
- // string filePath = result.FilePath + "\\FIELD_FILES\\";
- // 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(), fielddata.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 = fielddata.GetBitmapByParticle(FieldImage.Value, rectangle);
- // bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString() };
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
- // }
- // }
- // if (enl.Current.Key == "ASPECT_MAX")
- // {
- // 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 (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>(ElementType);
- // string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';');
- // for (int j = 0; j < strcbo.Length; j++)
- // {
- // string[] str = strcbo[j].Split('-');
- // 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
- // {
- // 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() == "7")
- // {
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = table["partcletype7"].ToString();
- // }
- // else if (particles.Rows[i]["TypeId"].ToString() == "8")
- // {
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = table["partcletype8"].ToString();
- // }
- // else if (particles.Rows[i]["TypeId"].ToString() == "9")
- // {
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = table["partcletype9"].ToString();
- // }
- // }
- // }
- // }
- // //每加载2000条数据后,进行一次内存回收
- // if (i % 2000 == 0)
- // {
- // GC.Collect();
- // GC.WaitForPendingFinalizers();
- // }
- // }
- // #region 加载进度条进度部份结束
- // //加载完成设置鼠标为默认
- // //m_sec.SendCall("设置鼠标样式", "", "Default");
- // this.Cursor = Cursors.Default;
- // string str8 = table["str8"].ToString();
- // m_frm_userprogress.SetProgressValueAndText(100, str8);
- // //加载完成,关闭进度条
- // m_frm_userprogress.Close();
- // #endregion
- //}
- private void BindDataGridView()
- {
- #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
- {
- string str7 = table["str7"].ToString();
- 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, str7);
- }
- string str2 = "加载颗粒列表,开始从底层加载数据....";
- str2 = table["str2"].ToString();
- m_frm_userprogress.SetProgressValueAndText(1, str2);
- #endregion
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- //从报告xml文件中加载,显示计算列,显示元素信息
- string str_DefaultComputedColName = "", str_ElementsColName = "";
- DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXmlData(Application.StartupPath + m_ReportApp.m_OTSReportMgrParamFile, "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("SEMPosX", "SEMPosX");
- keyValues.Add("SEMPosY", "SEMPosY");
- for (int i = 0; i < strs.Count(); i++)
- {
- 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());
- }
- }
- 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
- {
- int columndid = dgV_ParticlesDevidePage.Columns.Add(en.Current.Key, en.Current.Value);
- }
- }
- }
- ParticleData fielddata = new ParticleData(result.FilePath);
- DataTable particles = fielddata.GetInfoForPartucleDevidePage(PageIndex, pageSize, OrderFunction, condition);
- //PageSize = particles.Rows.Count;
- if (particles == null)
- {
- return;
- }
- //获取需要显示的元素名
- List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
- for (int i = 0; i < ElementTypeSort.Count; i++)
- {
- dgV_ParticlesDevidePage.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]);
- }
- ////禁止列排序
- //for (int i = 0; i < this.dgV_ParticlesDevidePage.Columns.Count; i++)
- //{
- // this.dgV_ParticlesDevidePage.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- //}
- RecordCount = fielddata.GetAllInfo(condition).Rows.Count;
- string particleM = "";
- //DataTable particlesNew = particles.Clone();
- 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++)
- {
- //更新进度,每100条记录加载完,更新一次进度
- if (i % 100 == 0)
- m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "Loding..");
- 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 == "rowid")
- {
- //dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = i + 1;
- }
- if (enl.Current.Key == "ParticleImage")
- {
- string subt = particles.Rows[i]["SubParticles"].ToString();
- if (subt != null && subt != "")
- {
- double ScanFieldSize = 1142;
- //double ScanFieldSize = Convert.ToDouble(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)result.ResultInfo["Sample"])["Members"])["SEMDataMsr"])["ScanFieldSize"]);
- string filePatht = result.FilePath + "\\FIELD_FILES\\";
- string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
- //然后将取出的数据,转换成Bitmap对象
- Bitmap tempbit = fielddata.ReadImageFile(imagePatht);
- int pixw = tempbit.Width;
- double xs = pixw / ScanFieldSize;
- particleM = particleM + "," + subt;
- Bitmap bmap = fielddata.GetBitmapForBig(subt, xs, result.FilePath);
- if (bmap != null)
- {
- bmap.Tag = new List<string>() { subt.Split(',')[0].Split(':')[0], subt.Split(',')[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;
- }
- 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(), fielddata.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 = fielddata.GetBitmapByParticle(FieldImage.Value, rectangle);
- bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString() };
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
- }
- }
- 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 (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++)
- {
- 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
- {
- 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() == "7")
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "SiC";
- }
- else if (particles.Rows[i]["TypeId"].ToString() == "8")
- {
- dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = "FeO";
- }
- else 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);
- }
- }
- }
- //每加载2000条数据后,进行一次内存回收
- if (i % 2000 == 0)
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- }
- #region 加载进度条进度部份结束
- //加载完成设置鼠标为默认
- this.Cursor = Cursors.Default;
- string str8 = table["str8"].ToString();
- m_frm_userprogress.SetProgressValueAndText(100, str8);
- //加载完成,关闭进度条
- m_frm_userprogress.Close();
- #endregion
- }
- /// <summary>
- /// 设置DataGridView样式
- /// </summary>
- private void SetDataGridViewStyle()
- {
- //用户不能调整标题的高度
- dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //用户不能调整 行高
- dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
- //改变行的高度;
- //Gview_gz.RowTemplate.Height = 20;
- //点击选择整行
- 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;
- ////用户不能调整标题的高度
- //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 = 200;
- //dgV_ParticlesDevidePage.AutoResizeColumn(dgV_ParticlesDevidePage.Columns.Count - 1);
- //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.AllowUserToAddRows = false;
- //dgV_ParticlesDevidePage.AllowUserToDeleteRows = false;
- //dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
- //dgV_ParticlesDevidePage.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
- //dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- //dgV_ParticlesDevidePage.ContextMenuStrip = this.contextMenuStrip1;
- //dgV_ParticlesDevidePage.BorderStyle = 0;
- //dgV_ParticlesDevidePage.Margin = new System.Windows.Forms.Padding(2);
- //dgV_ParticlesDevidePage.ReadOnly = true;
- //dgV_ParticlesDevidePage.RowHeadersVisible = false;
- //dgV_ParticlesDevidePage.RowHeadersWidth = 40;
- ////先设置一下头的高度,否则会太矮不好看
- //dgV_ParticlesDevidePage.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
- //dgV_ParticlesDevidePage.RowsDefaultCellStyle.BackColor = Color.Azure;
- }
- #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 (this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex1].Tag.ToString() == "统计行")
- {
- //ROW1>ROW2
- e.SortResult = 1;
- if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
- e.SortResult = -1;
- e.Handled = true;
- return;
- }
- if (this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag != null && this.dgV_ParticlesDevidePage.Rows[e.RowIndex2].Tag.ToString() == "统计行")
- {
- //ROW1<ROW2
- e.SortResult = -1;
- if (this.dgV_ParticlesDevidePage.SortOrder == SortOrder.Descending)
- e.SortResult = 1;
- e.Handled = true;
- return;
- }
- }
- /// <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 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 yCenter = (yStart + yEnd) / 2;
- // delte = SEM - OTSa
- long deltex = xCenter - 0;
- long deltey = yCenter - 0;
- int xdir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["xAxisDir"]);
- int ydir = Convert.ToInt32(((Dictionary<string, object>)result.ResultInfo["SEMStageData"])["yAxisDir"]);
- if (xdir == (int)OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
- {
- ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
- }
- else if (xdir == (int)OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
- {
- ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
- }
- if (ydir == (int)OTS_Y_AXIS_DIRECTION.UP_TOWARD)
- {
- ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
- }
- else if (ydir == (int)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(500);
- //第三步,断开电镜连接
- m_OTSIncAReportGridsFun.DisConnectSEM_ForParticlesGrid();
- Thread.Sleep(1000);
- 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);
- }
- /// <summary>
- /// 显示x-ray能谱图
- /// </summary>
- /// <param name="in_dparticle"></param>
- //private void ShowXRay(OTSIncAReportGraph.DParticle in_dparticle)
- //{
- // //显示xray相关信息
- // uint[] Search_xray = new uint[2000];
- // uint[] Analysis_xray = new uint[2000];
- // //
- // int i_xray_id = 0;
- // List<Element> list_celementchemistryclr = new List<Element>();
- // //获取Xray数据
- // m_OTSIncAReportGridsFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(in_dparticle.CLRTagID, in_dparticle.CLRFieldID, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr);
- // //get CElementChemistryClr list
- // 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;
- // list_showelementinfo.Add(ls_sei);
- // }
- // //获取使用标准库的名称
- // string str_stdname = "";
- // string str_IncALibName = "";
- // List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
- // List<string> NameList = new List<string>() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString() };
- // if (in_dparticle.STDTypeID < 1000)
- // {
- // int index = FLID.IndexOf(in_dparticle.STDTypeID);
- // if (index == -1)
- // {
- // index = 7;
- // }
- // string name = NameList[index];
- // //小于1000,使用系统默认分类
- // str_IncALibName = name;
- // str_stdname = "Default standard library";
- // }
- // else if (in_dparticle.STDTypeID > 10000)
- // {
- // //大于10000时,使用用户标准库来分析夹杂物名称
- // str_IncALibName = in_dparticle.TypeName;
- // if (str_stdname == "")
- // str_stdname = "System standard library";
- // }
- // //获取数据后,需要对xraytable设置
- // control_XRayTable1.Visible = false;
- // control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray);
- // //颗粒国标信息
- // control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
- // control_XRayTable1.GoodName = str_IncALibName;//杂夹物
- // control_XRayTable1.STDName = str_stdname;//标准库
- // control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- // control_XRayTable1.Visible = false;
- // this.Refresh();
- //}
- ///// <summary>
- ///// 输入颗粒的所在帧图id,颗粒id,颗粒类型id,获取对应的XRay能谱数据图
- ///// </summary>
- ///// <returns></returns>
- //public Bitmap ExportXRayBitmap(string in_fieldid, string in_particleid, int in_stdtypeid, string TypeName)
- //{
- // Bitmap ret_bp;
- // //显示xray相关信息
- // uint[] Search_xray = new uint[2000];
- // uint[] Analysis_xray = new uint[2000];
- // //
- // int i_xray_id = 0;
- // List<Element> list_celementchemistryclr = new List<Element>();
- // //获取Xray数据
- // list_celementchemistryclr = new List<Element>();
- // ParticleData particleData = new ParticleData(result.FilePath);
- // Particle list = particleData.GetParticleByFidAndPid(in_fieldid, in_particleid);
- // if (list == null)
- // {
- // return null;
- // }
- // Particle particle = list;
- // if (particle.XrayId > -1)
- // {
- // for (int i = 0; i < 2000; i++)
- // {
- // Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
- // }
- // Search_xray = Analysis_xray;
- // i_xray_id = particle.XrayId;
- // list_celementchemistryclr = particle.ElementList;
- // }
- // //get CElementChemistryClr list
- // 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;
- // list_showelementinfo.Add(ls_sei);
- // }
- // //获取使用标准库的名称
- // string str_stdname = "";
- // string str_IncALibName = "";
- // if (in_stdtypeid < 1000)
- // {
- // //小于1000,使用系统默认分类
- // str_IncALibName = TypeName;
- // str_stdname = "Default standard library";
- // }
- // else if (in_stdtypeid >= 1000 && in_stdtypeid < 10000)
- // {
- // //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析
- // str_IncALibName = TypeName;
- // str_stdname = "User defined standard library";
- // }
- // else if (in_stdtypeid > 10000)
- // {
- // //大于10000时,使用用户标准库来分析夹杂物名称
- // str_IncALibName = TypeName;
- // str_stdname = "System standard library";
- // }
- // //获取数据后,需要对xraytable设置
- // control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray);
- // //颗粒国标信息
- // //control_XRayTable1.GBInfoStr = in_dparticle.GBContent;
- // control_XRayTable1.GoodName = str_IncALibName;//杂夹物
- // control_XRayTable1.STDName = str_stdname;//标准库
- // control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- // control_XRayTable1.Visible = true;
- // control_XRayTable1.Invalidate();
- // control_XRayTable1.Refresh();
- // //this.Controls.Add(control_XRayTable1);
- // ret_bp = control_XRayTable1.ExportXRayImage();
- // return ret_bp;
- //}
- private void ToolStripMenuItem3_Click(object sender, EventArgs e)
- {
- //恢复至初始状态
- dgV_ParticlesDevidePage.Rows.Clear();
- dgV_ParticlesDevidePage.Columns.Clear();
- BindDataGridView();
- SetDataGridViewStyle();
- }
- 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));
- }
- //改为线程调用,先判断线程状态
- m_mythread.Start(new Point(particle.SEMPosX, particle.SEMPosY));
- }
- private void ToolStripMenuItem_selectparticle_Click(object sender, EventArgs e)
- {
- string path = result.FilePath;
- ParticleData fielddata = new ParticleData(result.FilePath);
- List<Particle> particles = fielddata.GetParticleAllList();
- List<Particle> ls_list_cotsparticleclr = new List<Particle>();
- 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)
- {
- ls_list_cotsparticleclr.Add(item);
- break;
- }
- }
- }
- }
- m_ReportApp.SelectedParticles = ls_list_cotsparticleclr;
- string str1 = table["str1"].ToString();
- //然后循环得出,list cotsparticleclr列表,返回给框架
- //m_sec.SendCall(str1, "", "", ls_list_cotsparticleclr);
- string str2 = table["str2"].ToString();
- string str3 = table["str3"].ToString();
- MessageBox.Show(str2 + ls_list_cotsparticleclr.Count.ToString() + str3);
- }
- 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(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_Type.Text))
- {
- condition += " and TypeName Like \"%" + tbx_Type.Text + "%\" ";
- }
- lnkFirst_Click(null, null);
- SetDataGridViewStyle();
- }
- private void cbB_order_SelectedIndexChanged(object sender, EventArgs e)
- {
- int ordernum = cbB_order.SelectedIndex;
- if (ordernum == 0)
- {
- OrderFunction = "fieldid,particleid";
- }
- else if (ordernum == 1)
- {
- OrderFunction = "TypeName";
- }
- else if (ordernum == 2)
- {
- OrderFunction = "DMAX";
- }
- else if (ordernum == 3)
- {
- OrderFunction = "DMAX desc";
- }
- else if (ordernum == 4)
- {
- OrderFunction = "Area";
- }
- else if (ordernum == 5)
- {
- OrderFunction = "Area desc";
- }
- 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;
- }
- bool isTextChanged = false;
- /// <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"; }
- }
- /// <summary>
- /// 光标离开分页属性
- private void txtPageSize_Leave(object sender, EventArgs e)
- {
- if (isTextChanged)
- {
- isTextChanged = false;
- lnkFirst_Click(null, null);
- }
- }
- private void txtPageSize_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (isTextChanged)
- {
- isTextChanged = false;
- lnkFirst_Click(null, null);
- }
- }
- 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);
- }
- }
- /// <summary>
- /// 跳转页数限制
- /// </summary>
- private void txtPageNum_TextChanged(object sender, EventArgs e)
- {
- int num = 0;
- if (int.TryParse(txtPageNum.Text.Trim(), out num) && num > 0)
- {
- }
- else { txtPageNum.Text = "1"; }
- }
- /// <summary>
- /// enter键功能
- /// </summary>
- private void txtPageNum_KeyPress(object sender, KeyPressEventArgs e)
- {
- btnGo_Click(null, null);
- }
- private void cbB_PageSize_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cbB_PageSize.SelectedItem.ToString() == "All")
- {
- pageSize = -1;
- }
- else
- {
- pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
- }
- lnkFirst_Click(null, null);
- }
- /// <summary>
- /// 在帧图上标记颗粒的位置矩形,并保存到FIELD_FILES_MARK文件夹中
- /// </summary>
- public void SaveMarkParticleRectangleOnFieldFile()
- {
- string str_path_FIELD_FILES = result.FilePath + "\\FIELD_FILES\\";
- string str_path_FIELD_FILES_MARK = result.FilePath + "\\FIELD_FILES_MARK\\";
- ////判断是否已经有导出过的标记帧图文件夹,如果已经存在,则直接返回不输出,先不加
- DirectoryInfo theFolder_FieldMark = new DirectoryInfo(str_path_FIELD_FILES_MARK);
- if (!theFolder_FieldMark.Exists)
- {
- //创建
- theFolder_FieldMark.Create();
- }
- else
- {
- //已经存在的话,直接返回
- //return;
- }
- //查找该field下对应所有的颗粒
- DataTable dt_AllParticle = fieldData.GetAllParticle_DataTable();
- DirectoryInfo theFolder = new DirectoryInfo(str_path_FIELD_FILES);
- if (theFolder.Exists)
- {
- //循环帧图,再循环各帧图中的颗粒,进行标记,保存
- foreach (FileInfo nextifile in theFolder.GetFiles())
- {
- //找出所有的用户库文件,在这个目录中
- if (nextifile.Name.Contains(".bmp") == true || nextifile.Name.Contains(".BMP") == true)
- {
- Image img = Image.FromFile(nextifile.FullName);
- 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, 0, 0);
- }
- img.Dispose();
- img = null;
- //确认对应的帧图名
- string str_fieldid = Path.GetFileNameWithoutExtension(nextifile.Name);
- str_fieldid = str_fieldid.Substring(5, str_fieldid.Length - 5);//减去field字符长度
- //循环将颗粒,进行标记到bitmap图上
- DataRow[] drlist = dt_AllParticle.Select(" fieldid = " + str_fieldid);
- 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(str_fieldid + "" + 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 + str_fieldid.ToString() + ".bmp");
- //ls_fieldbp.Dispose();
- }
- }
- }
- }
- //
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- private void testToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- SaveMarkParticleRectangleOnFieldFile();
- MessageBox.Show("导出完成!");
- }
- private void EXCELToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //将所有的数据导出到EXCEL中
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Excel文件(*.xls)|*.xls";
- //设置默认文件类型显示顺序
- sfd.FilterIndex = 1;
- //保存对话框是否记忆上次打开的目录
- sfd.RestoreDirectory = true;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- IWorkbook workbook = new HSSFWorkbook(); //用于创建.xls office2003开始以前的
- //IWorkbook workbook = new 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, 3 * 256);//图像列宽
- IRow row;
- ICell cell;
- //插入表头
- row = sheet.CreateRow(1);//从第15行添加一行
- 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].Name);
- }
- //插入表内容
- for (int i_row = 0; i_row < dgV_ParticlesDevidePage.Rows.Count; i_row++)
- {
- row = sheet.CreateRow(2 + i_row);
- 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)
- {
- //颗粒图像列
- Bitmap bp = (Bitmap)dgV_ParticlesDevidePage.Rows[i_row].Cells[2].Value;
- byte[] bytes = ImageConvertToBytes(bp);
- //第二步,将图片添加到workbook中,指定图片的格式,返回图片所在workbook->paicture数组中的索引的地址,从1开始
- int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
- //第三步,在sheet中创建画布
- IDrawing patriarch = sheet.CreateDrawingPatriarch();
- //第四步,设置锚点,(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格行数,列数,终止单元格行数,列数)
- IClientAnchor anchor = patriarch.CreateAnchor(1, 1, 2, 2, i_cell, i_row + 2, i_cell + 1, i_row + 3);//终止比开始位置大1,会自动缩放到一个单元格内的
- //第五步,创建图片
- IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
- //图像效果不好,自己另外导出吧,这里对该列宽进行了设置0
- }
- else
- {
- //非图像列
- cell.SetCellValue(dgV_ParticlesDevidePage[i_cell, i_row].Value.ToString());
- }
- }
- }
- //完成后,对Excel进行保存
- FileStream file = new FileStream(sfd.FileName, FileMode.Create);
- workbook.Write(file);
- file.Close();
- MessageBox.Show("导出完成!");
- //导出完成后,打开Excel文件
- if (File.Exists(sfd.FileName))
- {
- //打开刚才导出的文件
- System.Diagnostics.Process.Start(sfd.FileName);
- }
- }
- }
- /// <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();
- }
- /// <summary>
- /// 返回原子序数
- /// </summary>
- /// <param name="ElementName"></param>
- /// <returns></returns>
- int ReturnsAtomicNumberByElementName(string ElementName)
- {
- switch (ElementName)
- {
- case "H": return 1;
- case "He": return 2;
- case "Li": return 3;
- case "Be": return 4;
- case "B": return 5;
- case "C": return 6;
- case "N": return 7;
- case "O": return 8;
- case "F": return 9;
- case "Ne": return 10;
- case "Na": return 11;
- case "Mg": return 12;
- case "Al": return 13;
- case "Si": return 14;
- case "P": return 15;
- case "S": return 16;
- case "Cl": return 17;
- case "Ar": return 18;
- case "K": return 19;
- case "Ca": return 20;
- case "Sc": return 21;
- case "Ti": return 22;
- case "V": return 23;
- case "Cr": return 24;
- case "Mn": return 25;
- case "Fe": return 26;
- case "Co": return 27;
- case "Ni": return 28;
- case "Cu": return 29;
- case "Zn": return 30;
- case "Ga": return 31;
- case "Ge": return 32;
- case "As": return 33;
- case "Se": return 34;
- case "Br": return 35;
- case "Kr": return 36;
- case "Rb": return 37;
- case "Sr": return 38;
- case "Y": return 39;
- case "Zr": return 40;
- case "Nb": return 41;
- case "Mo": return 42;
- case "Tc": return 43;
- case "Ru": return 44;
- case "Rh": return 45;
- case "Pd": return 46;
- case "Ag": return 47;
- case "Cd": return 48;
- case "In": return 49;
- case "Sn": return 50;
- case "Sb": return 51;
- case "Te": return 52;
- case "I": return 53;
- case "Xe": return 54;
- case "Cs": return 55;
- case "Ba": return 56;
- case "La": return 57;
- case "Ce": return 58;
- case "Pr": return 59;
- case "Nd": return 60;
- case "Pm": return 61;
- case "Sm": return 62;
- case "Eu": return 63;
- case "Gd": return 64;
- case "Tb": return 65;
- case "Dy": return 66;
- case "Ho": return 67;
- case "Er": return 68;
- case "Tm": return 69;
- case "Yb": return 70;
- case "Lu": return 71;
- case "Hf": return 72;
- case "Ta": return 73;
- case "W": return 74;
- case "Re": return 75;
- case "Os": return 76;
- case "Ir": return 77;
- case "Pt": return 78;
- case "Au": return 79;
- case "Hq": return 80;
- case "TI": return 81;
- case "Pb": return 82;
- case "Bi": return 83;
- case "Po": return 84;
- case "At": return 85;
- case "Rn": return 86;
- case "Fr": return 87;
- case "Ra": return 88;
- case "Ac": return 89;
- case "Th": return 90;
- case "Pa": return 91;
- case "U": return 92;
- case "Np": return 93;
- case "Pu": return 94;
- case "Am": return 95;
- case "Cm": return 96;
- case "Bk": return 97;
- case "Cf": return 98;
- case "Es": return 99;
- case "Fm": return 100;
- case "Mc": return 101;
- case "No": return 102;
- case "Lr": return 103;
- case "Rf": return 104;
- case "Db": return 105;
- case "Sg": return 106;
- case "Bh": return 107;
- case "Hs": return 108;
- case "Mt": return 109;
- case "Ds": return 110;
- case "Rg": return 111;
- case "Unb": return 112;
- default: return 1000;
- }
- }
- public List<string> GetElementsColName()
- {
- List<string> list_str = new List<string>();
- // m_COTSReportProjFileMgrClr.GetPropertyParams().get
- //CRptParamFileMgrClr crptparam = new CRptParamFileMgrClr();
- //if (!crptparam.Load(0))
- //{
- // log.Error("(OTSDataMgrFun.CheckParamFile) m_pRptParamFileMgr.Load((int)OTS_SOFT_PACKAGE_ID.OTSIncA)");
- //}
- //string ls_str = crptparam.GetRptParamFile().GetElementsColName();
- string ls_str = "Ar,Al,Si,B,P,C,S,N,Cl,O,F,Ne,He,Lr,Lu,Rn,Xe,Kr,Md,Tm,Po,Te,Se,Es,Ho,Pb,Sn,Ge,Np,Pm,Os,Ru,Fe,Bk,Tb,Hg,Cd,Zn,Pa,Pr,W,Mo,Cr,No,Yb,At,I,Br,Fm,Er,Bi,Sb,As,Hf,Zr,Ti,Am,Eu,Pt,Pd,Ni,U,Nd,Re,Tc,Mn,Cf,Dy,Tl,In,Ga,Ra,Ba,Sr,Ca,Cm,Gd,Au,Ag,Cu,Th,Ce,Ta,Pu,Nb,Sm,V,Ir,Rh,Co,Ac,La,Y,Sc,Fr,Cs,Rb,K,Na,Mg,Be,Li,H";
- string[] strs = ls_str.Split(',');
- for (int i = 0; i < strs.Count(); i++)
- {
- list_str.Add(strs[i]);
- }
- return list_str;
- }
- }
- }
|