using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MeasureData; using FileManager; using System.Xml; namespace HOZProject { public partial class UControl_ParaInfo : UserControl { #region 成员变量 /// /// 开始时间 /// private string startTime; /// /// 结束时间 /// private string endTime; /// /// 状态 /// private int state; /// /// 位置 /// private SemPosition position; private bool isSwitch; private string cutHoleName; private FormHOZMain formHOZMain; private TimeLineItem[] tlItem = null; private UCTimeLine uctrlTimeLine = null; public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; } public string StartTime { get => startTime; set => startTime = value; } public string EndTime { get => endTime; set => endTime = value; } public int State { get => state; set => state = value; } public SemPosition Position { get => position; set => position = value; } public string CutHoleName { get => cutHoleName; set => cutHoleName = value; } public bool IsSwitch { get => isSwitch; set => isSwitch = value; } public TimeLineItem[] TlItem { get => tlItem; set => tlItem = value; } #endregion public UControl_ParaInfo(FormHOZMain formHOZ) { InitializeComponent(); FormHOZMainObject = formHOZ; //显示测量流程 ShowMeasureFlow(); //设置Style支持透明背景色 this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); //this.BackColor = Color.FromArgb(0, 255, 255, 255); //this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192))); } public UCTimeLine GetUctrTimeLine() { return uctrlTimeLine; } #region 显示开始与结束时间 public void ShowTime() { if (StartTime == "0001/1/1 0:00:00") { lblShowStartTime.Text = ""; } else { lblShowStartTime.Text = StartTime; } if (EndTime == "0001/1/1 0:00:00") { lblShowEndTime.Text = ""; } else { lblShowEndTime.Text = EndTime; } } #endregion #region 当前进度 public void UpdateCurrentMeasureSchedule() { if (TlItem != null) { //完成状态数量 int finishCount = 0; //未完成状态数量 int unFinishedCount = 0; foreach (TimeLineItem item in TlItem) { if (item.State>0) { finishCount++; } switch (FormHOZMainObject.m_MeasureType) { case (int)MeasureMsgManage.measureType.Photo: if (item.Type.ToUpper() == "PT" || item.Type.ToUpper() == "FIB") { continue; } else { unFinishedCount++; } break; case (int)MeasureMsgManage.measureType.FIB: if (item.Type.ToUpper() == "PT") { continue; } else { unFinishedCount++; } break; case (int)MeasureMsgManage.measureType.PT: unFinishedCount = TlItem.Length; break; } } try { if (lblShowState.Text == "失败") { pbMeasure.Value = 100; lblCompletedAmount.Text = "100%"; } else { int pbValue = (int)((float)finishCount / (float)unFinishedCount * 100); pbMeasure.Value = pbValue; lblCompletedAmount.Text = pbValue + "%"; } } catch (Exception) { pbMeasure.Value = 0; } } } #endregion #region 隐藏属性层 private void btnClose_Click(object sender, EventArgs e) { FormHOZMainObject.plPrarInfo.Visible = false; } #endregion #region 重绘时间轴 /// /// 重绘时间轴 /// public void TimeLineInvalidate() { plTimeLine.Invalidate(); uctrlTimeLine.Invalidate(); } #endregion #region 显示切孔参数信息 /// /// 显示切孔参数信息 /// public void ShowParaInfo() { int multiple = 1000; //设置Position参数 lblX.Text = (Position.X * multiple).ToString("f2"); lblY.Text = (Position.Y * multiple).ToString("f2"); lblZ.Text = (Position.Z * multiple).ToString("f2"); lblR.Text = Position.R.ToString(); lblT.Text = Position.T.ToString(); lblM.Text = (Position.M * multiple).ToString(); try { DateTime dtst = Convert.ToDateTime(StartTime); if (dtst.Year != System.DateTime.Now.Year) { lblShowStartTime.Text = ""; } else { lblShowStartTime.Text = StartTime; } } catch { lblShowStartTime.Text = ""; } try { DateTime dtet = Convert.ToDateTime(EndTime); if (dtet.Year != System.DateTime.Now.Year) { lblShowEndTime.Text = ""; } else { lblShowEndTime.Text = EndTime; } } catch { lblShowEndTime.Text = ""; } //设置切孔状态 switch (State) { //准备 case (int)MeasureThread.ThreadState.Ready: //修改切孔状态 lblShowState.Text = "准备"; break; //等待 case (int)MeasureThread.ThreadState.Waiting: //修改切孔状态 lblShowState.Text = "等待"; break; //进行中 case (int)MeasureThread.ThreadState.InProcess: //修改切孔状态 lblShowState.Text = "进行中"; break; //完成 case (int)MeasureThread.ThreadState.Success: //修改切孔状态 lblShowState.Text = "完成"; break; //失败 case (int)MeasureThread.ThreadState.Failed: lblShowState.Text = "失败"; break; } lblCutHoleName.Text = CutHoleName; CkIsSwitch.Checked = IsSwitch; } #endregion #region 绑定流程信息 /// /// 绑定流程信息 /// /// private void ShowMeasureFlow() { if (TlItem == null) { TlItem = GetMeasureFlowStructInfo(); } if (TlItem != null) { ShowUCTimeLine(TlItem); } } public void ShowUCTimeLine(TimeLineItem[] tlItem) { if (plTimeLine.Controls.Count == 0) { uctrlTimeLine = new UCTimeLine(tlItem, FormHOZMainObject.m_MeasureType); uctrlTimeLine.Dock = DockStyle.Fill; plTimeLine.Controls.Add(uctrlTimeLine); } } private TimeLineItem[] GetMeasureFlowStructInfo() { string xmlfullname = Application.StartupPath + @"\MeasureXML\MeasureStructXml.xml"; XmlNodeList nodeList = XmlManager.GetXmlMeasureFlowNodeInfo(xmlfullname); if (nodeList != null) { return XmlConvertTimeListItem(nodeList); } return null; } private TimeLineItem[] XmlConvertTimeListItem(XmlNodeList nodeList) { List timeLineList = new List(); for (int i = 0; i < nodeList.Count; i++) { if (Convert.ToBoolean(nodeList[i].Attributes["IsShow"].Value)) { TimeLineItem tlItem = new TimeLineItem(); tlItem.Details = nodeList[i].Attributes["Details"].Value; tlItem.Code = nodeList[i].Attributes["Code"].Value; tlItem.State = -1; tlItem.Title = nodeList[i].Attributes["Title"].Value; tlItem.IsData = Convert.ToBoolean(nodeList[i].Attributes["IsData"].Value); tlItem.Type = nodeList[i].Attributes["Type"].Value; tlItem.IsShow = Convert.ToBoolean(nodeList[i].Attributes["IsShow"].Value); tlItem.Index = Convert.ToInt32(nodeList[i].Attributes["Index"].Value); timeLineList.Add(tlItem); } } TimeLineItem[] timeLineItem = new TimeLineItem[timeLineList.Count]; //按照Index进行升序 timeLineItem = timeLineList.OrderBy(i => i.Index).ToArray(); //清空时间轴列表 timeLineList.Clear(); return timeLineItem; } #endregion #region 关闭按钮 鼠标操作事件 private void pbClose_MouseEnter(object sender, EventArgs e) { pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_; } private void pbClose_MouseLeave(object sender, EventArgs e) { pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_; } #endregion #region 设置切孔是否检测 private void CkIsSwitch_CheckedChanged(object sender, EventArgs e) { //设置切孔是否检测 List cutHoles = formHOZMain.m_MeasureFile.ListCutHole; foreach (CutHole item in cutHoles) { if (item.HoleName == CutHoleName) { item.SWITCH = CkIsSwitch.Checked; //是否已保存 if (formHOZMain.IsSave) { //保存测量文件 formHOZMain.m_MeasureFile.Save(); } break; } } } #endregion private void timerTwinkle_Tick(object sender, EventArgs e) { if (FormHOZMain.ControlFlicker) { uctrlTimeLine.Invalidate(); } } private void panel3_MouseMove(object sender, MouseEventArgs e) { if (formHOZMain.WindowState== FormWindowState.Maximized) { if (e.Button == MouseButtons.Left) { //plMeasureFlow.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y -80; //this.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y+78 ; //formHOZMain.plPrarInfo.Height = this.Height; int h = plMeasureFlow.Height + e.Y + panel1.Height + panel2.Height; if (h < 300 || h > formHOZMain.pbImage.Height) { return; } plMeasureFlow.Height = plMeasureFlow.Height + e.Y; this.Height = plMeasureFlow.Height + panel1.Height + panel2.Height; formHOZMain.plPrarInfo.Height = this.Height; } } else { if (e.Button == MouseButtons.Left) { //this.Height = 588; //plMeasureFlow.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y - 210; //formHOZMain.plPrarInfo.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y-53; int h = plMeasureFlow.Height + e.Y + panel1.Height + panel2.Height; if (h < 300 || h > formHOZMain.pbImage.Height) { return; } plMeasureFlow.Height = plMeasureFlow.Height + e.Y; this.Height = plMeasureFlow.Height + panel1.Height + panel2.Height; formHOZMain.plPrarInfo.Height = this.Height; } } } private void panel3_Paint(object sender, PaintEventArgs e) { } private void UControl_ParaInfo_Resize(object sender, EventArgs e) { this.plMeasureFlow.Top = panel1.Height + panel2.Height; this.plMeasureFlow.Height = this.Height - this.plMeasureFlow.Top; } } }