123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963 |
- using FileManager;
- using MeasureData;
- using MeasureThread;
- using SenseShield;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- //using SenseShield;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static MeasureThread.ThreadStatusEventArgs;
- namespace HOZProject
- {
- public partial class FormHOZMain : Form
- {
- #region 控制窗体可以调整大小用
- const int HTLEFT = 10;
- const int HTRIGHT = 11;
- const int HTTOP = 12;
- const int HTTOPLEFT = 13;
- const int HTTOPRIGHT = 14;
- const int HTBOTTOM = 15;
- const int HTBOTTOMLEFT = 0x10;
- const int HTBOTTOMRIGHT = 17;
- protected override void WndProc(ref Message m)
- {
- switch (m.Msg)
- {
- case 0x0084:
- base.WndProc(ref m);
- Point vPoint = new Point((int)m.LParam & 0xFFFF,
- (int)m.LParam >> 16 & 0xFFFF);
- vPoint = PointToClient(vPoint);
- if (vPoint.X <= 5)
- if (vPoint.Y <= 5)
- m.Result = (IntPtr)HTTOPLEFT;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)HTBOTTOMLEFT;
- else m.Result = (IntPtr)HTLEFT;
- else if (vPoint.X >= ClientSize.Width - 5)
- if (vPoint.Y <= 5)
- m.Result = (IntPtr)HTTOPRIGHT;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)HTBOTTOMRIGHT;
- else m.Result = (IntPtr)HTRIGHT;
- else if (vPoint.Y <= 5)
- m.Result = (IntPtr)HTTOP;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)HTBOTTOM;
- break;
- case 0x0201://鼠标左键按下的消息
- m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
- m.LParam = IntPtr.Zero;//默认值
- m.WParam = new IntPtr(2);//鼠标放在标题栏内
- base.WndProc(ref m);
- break;
- default:
- base.WndProc(ref m);
- break;
- }
- }
- #endregion
- #region 成员变量
- private NLog.Logger log;
- /// <summary>
- /// 控制闪烁
- /// </summary>
- public static bool ControlFlicker;//控制流程闪烁
- public BackgroundWorker m_BackgroundWorker;// 申明后台对象
- /// <summary>
- /// 测量文件
- /// </summary>
- public MeasureFile m_MeasureFile;
- /// 测量线程
- public Measure m_Ms;
- /// <summary>
- /// 显示日志窗体
- /// </summary>
- Form m_FormLog = null;
- /// <summary>
- /// 显示实例化窗体
- /// </summary>
- FormMove m_FormInit = null;
-
- /// <summary>
- /// 是否已保存
- /// </summary>
- public bool IsSave = false;
- /// <summary>
- /// 初始化用户控件
- /// </summary>
- UControl_Init uControl_Init = null;
-
- /// <summary>
- /// 日志用户控件
- /// </summary>
- UControl_Log ucLog = null;
- //流程控制
- public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
- //是否关闭窗体标识
- public bool IsClose = false;
- OTSMeasureOutputNlog logwin;
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- #endregion
- #region 构造函数
- public FormHOZMain()
- {
- InitializeComponent();
- //在线程操作过程中,可以设置控件属性
- Control.CheckForIllegalCrossThreadCalls = false;
- m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
- m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
- m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
- m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
- m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
- m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
- uControl_Init = new UControl_Init(this);
-
- }
- #endregion
- #region 测量线程
- void DoWork(object sender, DoWorkEventArgs e)
- {
- try
- {
-
- m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
- ConfigurationManager.AppSettings["WebServerPort"].ToString(),
- ConfigurationManager.AppSettings["WebServerUrl"].ToString(),m_MeasureFile);
-
-
- m_Ms.InitMeasure();
- //注册事件
- m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage);
- //注册事件
- m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage);
-
- //自动测量的全过程
- m_Ms.DoMeasure();
- }
- catch (Exception ex)
- {
- log.Error(ex.ToString(),false);
- }
- }
- public void displayMessage(object sender, ThreadStatusEventArgs e)
- {
- //主界面显示内容
- this.BeginInvoke((Action)delegate
- {
- this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
- //显示流程中对应编号的内容
- MeasureMsgManage.ShowMsgContent(this, e);
- AddLogListInfo(e);
- });
- }
- public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
- {
- //主界面显示内容
- this.BeginInvoke((Action)delegate
- {
- //修改切孔状态
- ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
- });
- }
- void UpdateProgress(object sender, ProgressChangedEventArgs e)
- {
- }
- void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
- {
- ControlFlicker = false;
- //设置控件操作
- MessageBox.Show("测量已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetWinControlMeasureState(true);
- pbStop.Visible = false;
- pbStart.Visible = true;
- //UControl_ParaInfo uControl_ParaInfo=new UControl_ParaInfo()
- UControl_ParaInfo uControl_ParaInfo = new UControl_ParaInfo(this);
- uControl_ParaInfo.pbMeasure.Value = 100;
- uControl_ParaInfo.lblCompletedAmount.Text = "100%";
- }
- #endregion
- #region 窗体加载
- private void FormHOZMain_Load(object sender, EventArgs e)
- {
- try
- {
- DogDecrypting.decrypting(100);//参数为许可号
- //加载控件的点击事件
- this.Click += new EventHandler(FormHOZMain_Click);
- plFill.Click += new EventHandler(FormHOZMain_Click);
- plTop.Click += new EventHandler(FormHOZMain_Click);
- plLeft.Click += new EventHandler(FormHOZMain_Click);
- plLeftContent.Click += new EventHandler(FormHOZMain_Click);
- pbImage.Click += new EventHandler(FormHOZMain_Click);
- //加载窗口移动事件
- this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
- this.plTop.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
- //新建
- m_MeasureFile = new MeasureFile();
- m_MeasureFile.MParam.GetMeasureParamFromConfigration() ;//读到参数对象中
-
- uControl_Init.DisplayInitialParam();//显示到界面上
-
-
- logwin = new OTSMeasureOutputNlog();
- logwin.Show();
- logwin.Height = this.Height;
- logwin.Left = this.Left - logwin.Width;
- logwin.Top = this.Top;
- NLog.Config.LoggingRule lr = NLog.LogManager.Configuration.LoggingRules.FirstOrDefault(
- r => r.Targets.Any(
- t => "control" == t.Name
- )
- );
-
- log = NLog.LogManager.GetCurrentClassLogger();
-
- this.Left = this.Location.X + logwin.Width / 2;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
- this.Close();
- }
- }
- #endregion
- #region 创建切孔列表信息
- /// <summary>
- /// 创建切孔列表信息
- /// </summary>
- /// <param name="ListCutHole"></param>
- public void CreateCutHoleList(List<CutHole> ListCutHole)
- {
- //清空左侧Panel中的切孔控件
- ClearPanelControls();
- for (int i = ListCutHole.Count - 1; i >= 0; i--)
- {
- UControl_CutHole ucCutHole = new UControl_CutHole(this);
- ucCutHole.Dock = DockStyle.Top;
- ucCutHole.CutHoleName = ListCutHole[i].HoleName;
- //显示切孔参数信息
- if (ucCutHole.UControl_ParaInfo == null)
- {
- ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
- }
- plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
- plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
- //设置当前样品的参数信息
- string CutHoleName = ListCutHole[i].HoleName;
- ucCutHole.UControl_ParaInfo.Name = CutHoleName;
- ucCutHole.UControl_ParaInfo.CutHoleName = CutHoleName;
- ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
- ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
- ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
- int state = (int)ListCutHole[i].STATE;
- ucCutHole.UControl_ParaInfo.State = state;
- ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
- ucCutHole.UControl_ParaInfo.ShowParaInfo();
- this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
- plLeftContent.Controls.Add(ucCutHole);
- ChangeCutHoleState(CutHoleName, state);
- }
- plPrarInfo.Visible = false;
- }
- #endregion
- #region 隐藏处理层
- //隐藏处理层
- private void FormHOZMain_Click(object sender, EventArgs e)
- {
- if (plPrarInfo.Visible)
- {
- plPrarInfo.Visible = false;
- }
- }
- #endregion
- #region 设置控件在线程过程中的编辑状态
- /// <summary>
- /// 设置控件在线程过程中的编辑状态
- /// </summary>
- /// <param name="cState"></param>
- public void SetWinControlMeasureState(bool cState)
- {
- pbNew.Enabled = cState;
- pbOpen.Enabled = cState;
- pbSave.Enabled = cState;
- // pbInit.Enabled = cState;
- pbImportTemplateFile.Enabled = cState;
- //pbLog.Enabled = cState;
- pbStart.Enabled = cState;
- pbStop.Enabled = !cState;
- //设置切孔是否执行
- foreach (Control item in plPrarInfo.Controls)
- {
- if (item is UserControl)
- {
- UControl_ParaInfo ucParaInfo = (UControl_ParaInfo)item;
- ucParaInfo.CkIsSwitch.Enabled = cState;
- }
- }
- }
- #endregion
-
- #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
- private void pbMin_MouseEnter(object sender, EventArgs e)
- {
- this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
- }
- private void pbMin_MouseLeave(object sender, EventArgs e)
- {
- this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
- }
- private void pbMax_MouseEnter(object sender, EventArgs e)
- {
- this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
- }
- private void pbMax_MouseLeave(object sender, EventArgs e)
- {
- this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
- }
- private void pbClose_MouseEnter(object sender, EventArgs e)
- {
- this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
- }
- private void pbClose_MouseLeave(object sender, EventArgs e)
- {
- this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
- }
- private void pbStart_MouseEnter(object sender, EventArgs e)
- {
- //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.StartMove;
- }
- private void pbStart_MouseLeave(object sender, EventArgs e)
- {
- //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_3_;
- }
- private void pbStop_MouseEnter(object sender, EventArgs e)
- {
- //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.StopMove;
- }
- private void pbStop_MouseLeave(object sender, EventArgs e)
- {
- //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
- }
- private void pbClose_Click(object sender, EventArgs e)
- {
- try
- {
- if (m_Ms != null)
- {
- if (m_BackgroundWorker.IsBusy)
- {
- if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- //线程停止变量
- m_Ms.key_stop = true;
- IsClose = true;
- lblStateMessage.Text = "正在关闭窗体...请等待";
- pbClose.Enabled = false;
- ControlFlicker = false;
- }
- return;
- }
- }
- if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
-
-
-
- //m_MeasureFile.Save();
- this.Close();
- }
- }
- catch (Exception ex)
- {
- log.Error(ex.Message);
- }
- }
- private void pbMin_Click(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Minimized;
- }
- private void pbMax_Click(object sender, EventArgs e)
- {
- if (this.WindowState == FormWindowState.Maximized)
- {
- this.WindowState = FormWindowState.Normal;
- }
- else
- {
- this.WindowState = FormWindowState.Maximized;
- }
- //窗体据中
- this.StartPosition = FormStartPosition.CenterScreen;
-
-
- }
- #endregion
- #region 新建、保存、打开、初始化、导入配置、查看日志
- private void pbNew_Click(object sender, EventArgs e)
- {
-
- m_MeasureFile.MParam.GetMeasureParamFromConfigration();
- }
-
- private void pbSave_Click(object sender, EventArgs e)
- {
- Saveclick();
-
- }
- public void Saveclick()
- {
-
-
-
-
- }
- private void pbOpen_Click(object sender, EventArgs e)
- {
- try
- {
- //打开默认路径
- OpenFileDialog openFileDialog = new OpenFileDialog();
- //设置筛选文件格式
- openFileDialog.Filter = "测量文件(*.msf)|*.msf";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- //读取文件
- string measureFileNamePath = openFileDialog.FileName;
- m_MeasureFile.FileName = measureFileNamePath;
- m_MeasureFile.Open();
- List<CutHole> ListCutHole = m_MeasureFile.ListCutHole;
- //文件路径
- string CutHoleFilePath = m_MeasureFile.CutHoleFilePath;
- CreateCutHoleList(ListCutHole);
- ////保存测量文件
- //m_MeasureFile.Save();
- //设置已保存状态
- IsSave = true;
- }
- }
- catch (Exception ex)
- {
- log.Error(ex.Message);
- }
- }
- private void pbInit_Click(object sender, EventArgs e)
- {
- if (uControl_Init == null)
- {
- uControl_Init = new UControl_Init(this);
- //uControl_Init.ReloadConfig();
- }
- if (m_FormInit == null)
- {
- m_FormInit = new FormMove();
- }
- m_FormInit.StartPosition = FormStartPosition.CenterScreen;
- m_FormInit.FormBorderStyle = FormBorderStyle.None;
- m_FormInit.Width = uControl_Init.Width + 8;
- m_FormInit.Height = uControl_Init.Height + 8;
- if (m_FormInit.Controls.Count == 0)
- {
- uControl_Init.Location = new Point(4,4);
- m_FormInit.Controls.Add(uControl_Init);
-
- }
- m_FormInit.ShowDialog();
- //ConfigurationParameter();
- m_FormInit.Left = this.Left;
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
-
- }
- private void pbImportTemplateFile_Click(object sender, EventArgs e)
- {
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
- //判断保存的路径是否存在
- if (!Directory.Exists(m_TemplateFilePath))
- {
- ////创建路径
- //Directory.CreateDirectory(m_TemplateFilePath);
- FolderBrowserDialog dialog = new FolderBrowserDialog();
- dialog.Description = "请选择文件路径";
- //dialog.RootFolder = Environment.SpecialFolder.Programs;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- m_TemplateFilePath = dialog.SelectedPath;
- config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
- }
- }
- //打开默认路径
- OpenFileDialog openFileDialog = new OpenFileDialog();
- //设置默认打开路径(绝对路径)
- openFileDialog.InitialDirectory = m_TemplateFilePath;
- openFileDialog.Filter = "样品参数文件|*.cfg";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- if (uControl_Init == null)
- {
- uControl_Init = new UControl_Init(this);
- }
- //设置选择的模板文件
- uControl_Init.ReadConfigPath = openFileDialog.FileName;
- //获取文件
- uControl_Init.ReadConfigInfo();
- }
- }
- private void pbLog_Click(object sender, EventArgs e)
- {
-
- }
- //显示日志
- private void AddLogListInfo(ThreadStatusEventArgs e)
- {
- if (m_FormLog != null)
- {
- foreach (Control item in m_FormLog.Controls)
- {
- if (item is UserControl)
- {
- if (item.Name == "UControl_Log")
- {
- ucLog = (UControl_Log)item;
- //获取日志信息
- if (listmsg.Items.Count > 0)
- {
- string[] strLog = new string[listmsg.Items.Count];
- for (int i = 0; i < listmsg.Items.Count; i++)
- {
- //赋值给数组
- strLog[i] = listmsg.Items[i].ToString();
- }
- ucLog.ShowProcessLogInfo(strLog);
- }
- }
- }
- }
- }
- }
- #endregion
- #region 修改切孔状态
- /// <summary>
- /// 修改切孔状态
- /// </summary>
- /// <param name="cutHoleCode"></param>
- /// <param name="States"></param>
- public void ChangeCutHoleState(string CutHoleName, int States)
- {
- foreach (Control item in plLeftContent.Controls)
- {
- if (item is UserControl)
- {
- UControl_CutHole cutHole = (UControl_CutHole)item;
- if (cutHole.CutHoleName == CutHoleName)
- {
- Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
- switch (States)
- {
- //运行中
- case (int)MeasureThread.ThreadState.InProcess:
- //btnCutHole.BackColor = Color.Yellow;
- btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
- btnCutHole.BackgroundImageLayout = ImageLayout.Center;
- ChangeCutHoleMeasureState(CutHoleName, States);
- ControlFlicker = true;
- break;
- //等待
- case (int)MeasureThread.ThreadState.Waiting:
- //btnCutHole.BackColor = Color.Yellow;
- btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
- btnCutHole.BackgroundImageLayout = ImageLayout.Center;
- ChangeCutHoleMeasureState(CutHoleName, States);
- break;
- //准备
- case (int)MeasureThread.ThreadState.Ready:
- //btnCutHole.BackColor = Color.White;
- btnCutHole.BackgroundImage = Properties.Resources.CutHole_Gray_2_;
- btnCutHole.BackgroundImageLayout = ImageLayout.Center;
- ChangeCutHoleMeasureState(CutHoleName, States);
- break;
- //失败
- case (int)MeasureThread.ThreadState.Failed:
- //btnCutHole.BackColor = Color.Red;
- btnCutHole.BackgroundImage = Properties.Resources.CutHole_Red_2_;
- btnCutHole.BackgroundImageLayout = ImageLayout.Center;
- ChangeCutHoleMeasureState(CutHoleName, States);
- ControlFlicker = false;
- break;
- //完成
- case (int)MeasureThread.ThreadState.Success:
- //btnCutHole.BackColor = Color.GreenYellow;
- btnCutHole.BackgroundImage = Properties.Resources.CutHole_Green_2_;
- btnCutHole.BackgroundImageLayout = ImageLayout.Center;
- //修改切孔状态
- ChangeCutHoleMeasureState(CutHoleName, States);
- ControlFlicker = false;
- break;
- }
- break;
- }
- }
- }
- }
- #endregion
- #region 修改切孔状态
- public void ChangeCutHoleMeasureState(string CutHoleName, int States)
- {
- if (plPrarInfo.Controls.Count > 0)
- {
- foreach (Control item in plPrarInfo.Controls)
- {
- if (item is UserControl)
- {
- if (item.Name == CutHoleName)
- {
- UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
- //获取切孔列表
- List<CutHole> aCutHole = m_MeasureFile.ListCutHole;
- foreach (CutHole cutHoleItem in aCutHole)
- {
- if (cutHoleItem.HoleName == CutHoleName)
- {
- //设置开始时间与结束时间
- uControl_ParaInfo.StartTime = cutHoleItem.START.ToString();
- uControl_ParaInfo.EndTime = cutHoleItem.END.ToString();
- uControl_ParaInfo.ShowTime();
- break;
- }
- }
- switch (States)
- {
- //准备
- case (int)MeasureThread.ThreadState.Ready:
- //修改切孔状态
- uControl_ParaInfo.lblShowState.Text = "准备";
- break;
- //等待
- case (int)MeasureThread.ThreadState.Waiting:
- //修改切孔状态
- uControl_ParaInfo.lblShowState.Text = "等待";
- break;
- //进行中
- case (int)MeasureThread.ThreadState.InProcess:
- //修改切孔状态
- uControl_ParaInfo.lblShowState.Text = "进行中";
- break;
- //完成
- case (int)MeasureThread.ThreadState.Success:
- //修改切孔状态
- uControl_ParaInfo.lblShowState.Text = "完成";
- break;
- //失败
- case (int)MeasureThread.ThreadState.Failed:
- uControl_ParaInfo.lblShowState.Text = "失败";
- uControl_ParaInfo.pbMeasure.Value = 100;
- uControl_ParaInfo.lblCompletedAmount.Text = "100%";
- break;
- }
- break;
- }
- }
- }
- }
- }
- #endregion
- #region 拖动无窗体的控件
- [DllImport("user32.dll")]//拖动无窗体的控件
- public static extern bool ReleaseCapture();
- [DllImport("user32.dll")]
- public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
- public const int WM_SYSCOMMAND = 0x0112;
- public const int SC_MOVE = 0xF010;
- public const int HTCAPTION = 0x0002;
- private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
- {
- if (this.WindowState == FormWindowState.Normal)
- {
- //拖动窗体
- ReleaseCapture();
- SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
- }
- }
- #endregion
- #region 开始、结束线程事件
- private void pbStart_Click(object sender, EventArgs e)
- {
- if (plLeftContent.Controls.Count==0)
- {
- MessageBox.Show("请添加切孔信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (IsSave)
- {
- if (m_BackgroundWorker.IsBusy)
- {
- MessageBox.Show("线程已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- else
- {
- log.Info("开始", true);
- m_BackgroundWorker.RunWorkerAsync(this);
- //设置控件操作
- SetWinControlMeasureState(false);
- pbStop.Visible = true;
- pbStart.Visible = false;
- }
- }
- else
- {
- MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- private void pbStop_Click(object sender, EventArgs e)
- {
- if (m_Ms != null)
- {
- if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
- {
- ControlFlicker = false;
- //线程停止变量
- m_Ms.key_stop = true;
- }
- }
- }
- #endregion
- #region 清空内容容器中的控件
- /// <summary>
- /// 清空内容容器中的控件
- /// </summary>
- private void ClearPanelControls()
- {
- //清空内容容器中的控件
- plLeftContent.Controls.Clear();
- plPrarInfo.Controls.Clear();
- }
- /// <summary>
- /// 清空日志控件内容
- /// </summary>
- private void ClearContrlsContent()
- {
- try
- {
- if (ucLog != null)
- {
- if (ucLog.dgvLog != null)
- {
- if (ucLog.dgvLog.Rows.Count > 0)
- {
- ucLog.dgvLog.Rows.Clear();
- }
- }
- }
- if (listmsg != null)
- {
- if (listmsg.Items.Count > 0)
- {
- listmsg.Items.Clear();
- }
- }
- }
- catch (Exception ex)
- {
- log.Error(ex.Message);
- }
- }
- #endregion
- #region 测试修改切孔中流程状态
- private void button1_Click(object sender, EventArgs e)
- {
- if (plPrarInfo.Controls.Count > 0)
- {
- string name = textBox1.Text;
- string code = textBox2.Text;
- bool state = Convert.ToBoolean(comboBox1.Text);
- foreach (Control item in plPrarInfo.Controls)
- {
- if (item is UserControl)
- {
- if (item.Name == name)
- {
- UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
- TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
- foreach (TimeLineItem tlItem in ParaItem)
- {
- if (tlItem.Code == code)
- {
- tlItem.State = Convert.ToInt32(state);
- break;
- }
- }
- uControl_ParaInfo.TimeLineInvalidate();
- break;
- }
- }
- }
- }
- }
- #endregion
- private void FormHOZMain_Resize(object sender, EventArgs e)
- {
- plMain.Left = 2;
- plMain.Top = 2;
- plMain.Width = this.Width - 4;
- plMain.Height = this.Height - 4;
- plFill.Width = plMain.Width - plLeft.Width - 4;
- plFill.Height = plMain.Height - plTop.Height - 4;
- plFill.Left = plLeft.Width + 4;
- plFill.Top = plTop.Height + 4;
- if(this.WindowState!= FormWindowState.Maximized)
- {
-
- plPrarInfo.Height = 505;
- foreach (Control item in plPrarInfo.Controls)
- {
- if (item is UserControl)
- {
- if(item.Height>505)
- {
- item.Height = 505;
- }
- }
- }
- }
- }
-
- private void FormHOZMain_Paint(object sender, PaintEventArgs e)
- {
-
- }
-
-
- private void FormHOZMain_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (m_Ms != null)
- {
- if (m_Ms.iExtender != null)
- {
- m_Ms.iExtender.CloseExtender();
- }
- }
- }
- private void FormHOZMain_LocationChanged(object sender, EventArgs e)
- {
- if (logwin != null)
- {
- logwin.Left = this.Left-logwin.Width;
- logwin.Top = this.Top;
- }
- }
- private void pbPause_Click(object sender, EventArgs e)
- {
- if (File.Exists(m_MeasureFile.m_SavePath))
- {
- string position = System.Environment.CurrentDirectory;
- //Process pro = Process.Start(@"C:\Users\admin\Desktop\Report\Report\ExportReport.exe", @"C:\Users\admin\Downloads\3\3\3.msf");//打开程序B
- Process pro = Process.Start(position + "\\Report\\ExportReport.exe", m_MeasureFile.m_SavePath);//打开程序B
- pro.WaitForExit();
- int Result = pro.ExitCode;//程序B退出回传值
- if (Result == 1)//接收到程序B退出代码"1"
- {
- MessageBox.Show("退出程序B");
- }
- }
- else
- {
- MessageBox.Show("尚未保存文件");
- }
- }
- }
- }
|