using SlMesDbIterface;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using DC_A95;
using ExternalDataSync;
using MainLineRepair;
using NPOITest;

namespace MesWork
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Temp { }
    /// <summary>
    /// 事件处理
    /// </summary>
    public partial class MesWorkForm
    {
        /// <summary>
        /// 打开监控界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label_Monitor_PLC_Click(object sender, EventArgs e)
        {
            new OpcForm(IsDemoMesServer).Show(this);
        }
        /// <summary>
        /// 关闭按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label_ExitSys_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("是否确认退出程序？", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                timer_OnLine_Show.Enabled = false;
                timer_ShowStation.Enabled = false;
               
                CloseDeviceConn();
                //StopServer();
                LogRecord.LogRecord.Insert_Log(Type_Log.Login, "", "退出MES系统！！！！");
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
        }
      
        private void label_PlanManage_Click(object sender, System.EventArgs e)
        {
            var planquery = new PlanExecute_Query.PlanExecute();
            planquery.ShowDialog();
        }

        /// <summary>
        /// 鼠标移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void C_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (allowDrag & isMouseDown)
            {
                var control = (Control)sender;
                int left = control.Left + e.X - mouseOffset.X;
                int top = control.Top + e.Y - mouseOffset.Y;
                control.Location = new Point(left, top);
            }
        }
        /// <summary>
        /// 打开调试界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label_Test_RW_Click(object sender, EventArgs e)
        {
            new F_TestPage().Show(this);
        }
        
        /// <summary>
        /// 打开监控画面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Panel_Click(object sender, EventArgs e)
        {
            if (MesWorkForm.allowDrag)
            {
                return;
            }
            var panel = (Panel)sender;
            var stationName = panel.Tag.ToString();
            if (!MesWorkForm.list_OpenForm.Contains(stationName))
            {
                var stationShow = new TagDataEngineStatusShowDialog(stationName);
                stationShow.Show(this);
                MesWorkForm.list_OpenForm.Add(stationName);
            }

        }

        /// <summary>
        /// 查看消息提示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Panel_MouseHover(object sender, EventArgs e)
        {
            var panel = (Panel)sender;
            new ToolTip().SetToolTip(panel, panel.Tag.ToString());
        }
        /// <summary>
        /// 打开日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_QueryLog_Click(object sender, EventArgs e)
        {
            new LogRecord.LogRecord(this.Width, this.Height).Show(this);
        }
        /// <summary>
        /// 保存布局
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_SaveLyout_Click(object sender, EventArgs e)
        {
            FuncOperation.SaveLyout();
        }
        /// <summary>
        /// 打开参数配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label_ParamConfig_Click(object sender, EventArgs e)
        {
            new ParamConfigPage().ShowDialog();
        }
        /// <summary>
        /// 按下鼠标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void C_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOffset.X = e.X;
                mouseOffset.Y = e.Y;
                isMouseDown = true;
            }
        }
        /// <summary>
        /// 抬起鼠标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void C_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }

        /// <summary>
        /// 工位管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label_StationManage_Click(object sender, System.EventArgs e)
        {
            var dlg = new F_StationManage();
            dlg.ShowDialog();
        }



    }
}
