123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using OTS.WinFormsUI.Docking;
- using System.IO;
- using System.Collections;
- using OTSDataType;
- using OTSModelSharp;
- namespace OTSMeasureApp
- {
- public partial class OTSMeasureResultWindow : DockContent
- {
-
- #region 全局变量
- OTSIncAMeasureAppForm m_MeasureAppForm;
- //进度条最大值
- int m_MaxValue = 100;
- //进度条最小值
- int m_MinValue = 0;
- //步长
- int m_Step = 1;
-
- //文件名称
- private string m_fileName = string.Empty;
- private bool m_resetText = true;
-
- //国际化
- OTSCommon.Language lan;
- Hashtable table;
- NLog.Logger log ;
- #endregion
- public OTSMeasureResultWindow(OTSIncAMeasureAppForm MeasureAppForm)
- {
- InitializeComponent();
- m_MeasureAppForm = MeasureAppForm;
- //国际化
- lan = new OTSCommon.Language(this);
- table = lan.GetNameTable(this.Name);
- }
- public string FileName
- {
- get { return m_fileName; }
- set
- {
- if (value != string.Empty)
- {
- Stream s = new FileStream(value, FileMode.Open);
- FileInfo efInfo = new FileInfo(value);
- string fext = efInfo.Extension.ToUpper();
- s.Close();
- }
- m_fileName = value;
- this.ToolTipText = value;
- }
- }
-
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- if (m_resetText)
- {
- m_resetText = false;
- FileName = FileName;
- }
- }
- protected override string GetPersistString()
- {
- String stName = GetType().ToString() + "," + FileName + "," + Text;
- return stName;
- }
- protected override void OnTextChanged(EventArgs e)
- {
- base.OnTextChanged(e);
- if (FileName == string.Empty)
- {
- //this.richTextBox1.Text = Text;
- return;
- }
- }
- private void OTSMeasureResultWindow_Load(object sender, EventArgs e)
- {
- this.dg_Info.AutoResizeColumns();
- //创建列
- this.dg_Info.AutoGenerateColumns = false;
- CheckForIllegalCrossThreadCalls = false;
- log = NLog.LogManager.GetCurrentClassLogger();
- for(int i=0;i< dg_Info.ColumnCount;i++)
- {
- dg_Info.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- }
- dg_Info.RowHeadersDefaultCellStyle.Padding = new Padding(dg_Info.RowHeadersWidth);
- }
- private void OTSMeasureResultWindow_SizeChanged(object sender, EventArgs e)
- {
- //获取屏幕的宽度与高度
- int width = this.Width;
- int height = this.Height;
- }
- /// <summary>
- /// 设置当前进度信息(当前帧图数量 总数)
- /// </summary>
- /// <param name="MeasureFieldCount"></param>
- /// <param name="CompleteFieldCount"></param>
- /// <returns></returns>
- public bool SetCurrentProgressInfo(int CompleteFieldCount, int MeasureFieldTotalCount, int ParticleCount)
- {
- //测量进度
- SetProgressInfo(CompleteFieldCount, MeasureFieldTotalCount, ParticleCount);
- return false;
- }
- /// <summary>
- /// 初始化 点击主窗体中新建按钮
- /// </summary>
- /// <returns></returns>
- public bool SetInit()
- {
- lblSampleName.Text = string.Empty;
- lblMeasureTime.Text = string.Empty;
- lblParticleCount.Text = string.Empty;
- lblBeginTime.Text = string.Empty;
- lblSingleCount.Text = string.Empty;
- lblProgressInfo.Text = "0%";
- PBState.Value = 0;
- dg_Info.DataSource = null;
- return true;
- }
- #region 显示操作
- /// <summary>
- /// 测量进度
- /// </summary>
- /// <param name="currentMeasureCount"></param>
- /// <param name="beginTime"></param>
- /// <param name="MeasureTime"></param>
- public void SetProgressInfo(int currentMeasureCount, int measureAllCount, int ParticleCount)
- {
- try
- {
- //设置进度条最大、最小、步长值
- PBState.Minimum = m_MinValue;
- PBState.Maximum = m_MaxValue;
- PBState.Step = m_Step;
- int currentProgress = m_MinValue;
- int currentMeasureCountAdd = currentMeasureCount;
- //设置当前帧图数
- lblSingleCount.Text = currentMeasureCount.ToString();
- if (currentMeasureCountAdd <= measureAllCount)
- {
- currentProgress = (currentMeasureCountAdd) * 100 / measureAllCount;
- }
- //设置当前进度值
- if (currentProgress < 100)
- {
- PBState.Value = currentProgress;
- lblProgressInfo.Text = currentProgress + "%";
- }
- else
- {
- lblProgressInfo.Text = currentProgress + "%";
- PBState.Value = 100;
- }
- //设置颗粒数量
- int pCount = ParticleCount;
- lblParticleCount.Text = (pCount).ToString();
- }
- catch (Exception ex)
- {
- log.Trace( ex.ToString());
- }
- }
- /// <summary>
- /// 设置样品名称
- /// </summary>
- /// <param name="sampleName"></param>
- public void SetSampleName(string sampleName)
- {
- //设置样品名称
- if (sampleName != null)
- {
- if (sampleName != "")
- {
- lblSampleName.Text = sampleName;
- }
- }
- }
- /// <summary>
- /// 设置开始时间
- /// </summary>
- /// <param name="startTime"></param>
- public void SetStartTime(string startTime)
- {
- if (startTime != null)
- {
- if (startTime != "")
- {
- try
- {
- //设置开始时间
- lblBeginTime.Text = startTime;
- }
- catch (Exception)
- {
- lblBeginTime.Text = "";
- }
- }
- }
- }
- /// <summary>
- /// 设置结束时间
- /// </summary>
- /// <param name="endTime"></param>
- public void CloseProgressWindow()
- {
- //this.Dispose();
- this.Close();
- }
- #endregion
- private void OTSMeasureResultWindow_FormClosing(object sender, FormClosingEventArgs e)
- {
- }
- #region 设置当前测量用时
- /// <summary>
- /// 设置当前测量用时
- /// </summary>
- /// <param name="ts">时间间隔对象</param>
- public void SetMeasureTime(TimeSpan ts)
- {
- //这样就能得到天数、小时、分差
- string str1 = string.Empty;
- if (ts.Days > 0)
- {
- string str = table["str1"].ToString();
- str1 += ts.Days + str;
- }
- if (ts.Hours > 0)
- {
- string str = table["str2"].ToString();
- str1 += ts.Hours + str;
- }
- if (ts.Minutes > 0)
- {
- string str = table["str3"].ToString();
- str1 += ts.Minutes + str;
- }
- if (ts.Seconds > 0)
- {
- string str = table["str4"].ToString();
- str1 += ts.Seconds + str;
- }
- //所有时间换去 总计天数、小时、分钟
- lblMeasureTime.Text = str1;
- }
- #endregion
- #region 设置当前测量列表
- /// <summary>
- /// 设置当前测量用时
- /// </summary>
- /// <param name="ts">时间间隔对象</param>
- public void SetMeasureListInfo(IList list)
- {
- try
- {
- //颗粒类型数量
- int IParticleTypeAmount = 0;
- //颗粒总数量
- int IParticleAmount = 0;
- //颗粒面积总数量
- double dAreaAmount = 0;
- COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
- //list 序列化 DataTable
- DataTable dt = ListConvertToDT(list);
-
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- IParticleTypeAmount = dt.Rows.Count;
- string stdName = string.Empty;
-
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- stdName = string.Empty;
- int STDID = Convert.ToInt32(dt.Rows[i]["TypeId"].ToString());
- IParticleAmount += Convert.ToInt32(dt.Rows[i]["Number"].ToString());
- dAreaAmount += Convert.ToDouble(dt.Rows[i]["Area"].ToString());
-
- }
- //添加统计行信息
- DataRow dr = dt.NewRow();
- dr["TypeId"] = "";
- dr["STDName"] = "";
- string str = table["str6"].ToString();
- dr["Number"] = str + IParticleAmount;
- str = table["str7"].ToString();
- dr["Area"] = str + dAreaAmount;
- dt.Rows.Add(dr);
- }
-
- dg_Info.DataSource = dt;
- }
- }
- catch (Exception ex)
- {
- string str = table["str8"].ToString();
- log.Trace(str + ex.ToString());
- }
- }
- #endregion
- #region List转换为DataTable
- /// <summary>
- /// 将集合类转换成DataTable
- /// </summary>
- /// <param name="list">集合</param>
- /// <returns></returns>
- public static DataTable ListConvertToDT(IList list)
- {
- DataTable result = new DataTable();
- result.Columns.Add("TypeId");
- result.Columns.Add("Number");
- result.Columns.Add("Area");
- result.Columns.Add("STDName");
- if (list == null)
- {
- return null;
- }
- if (list.Count > 0)
- {
- for (int i = 0; i < list.Count; i++)
- {
- CMsrResultItem cMsrResultItemClr = (CMsrResultItem)list[i];
- DataRow dr = result.NewRow();
- dr[0] = cMsrResultItemClr.GetTypeId();
- dr[1] = cMsrResultItemClr.GetNumber();
- dr[2] = Math.Round(Convert.ToDouble(cMsrResultItemClr.GetArea()),2);
- dr[3] = cMsrResultItemClr.GetName();
- result.Rows.Add(dr);
- }
- }
- return result;
- }
- #endregion
- public void GetResultFileInfoBySampleName(string sampleName)
- {
- //显示样品名称信息
- COTSSample sample = m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(sampleName);
- //设置当前样品名称
- SetSampleName(sampleName);
- //已完成的数量
- int CompleteFieldCount = sample.GetMsrStatus().GetCompletedFields();
- int MeasureFieldTotalCount = (int)sample.GetMsrStatus().GetCompletedFields();
- int ParticleCount = 0;
- if (CompleteFieldCount > 0)
- {
- //设置完成数量 颗粒数量
- SetCurrentProgressInfo(CompleteFieldCount, MeasureFieldTotalCount, ParticleCount);
- //设置开始、测量时间
- string startTime = sample.GetMsrStatus().GetStartTime().ToString();
- //开始时间
- SetStartTime(startTime);
- TimeSpan usedTimeTS = sample.GetMsrStatus().GetUsedTime();
- //获取测量时间
- SetMeasureTime(usedTimeTS);
- //获取结果文件 颗粒列表信息
- List<CMsrResultItem> cMsrResultItemClrList = sample.GetMsrResults().GetResultItems();
- //设置测量状态数据列表
- SetMeasureListInfo(cMsrResultItemClrList);
- }
- else
- {
- SetInit();
- }
- }
- private void PBState_SizeChanged(object sender, EventArgs e)
- {
- //每次在进度条尺寸更变的时候 将进度内容位置设置在进度条位置中心
- lblProgressInfo.Location = new Point(PBState.Location.X + (PBState.Width), lblProgressInfo.Location.Y);
- }
- }
- }
|