SettingControl.cs 5.0 KB
using CodeLibrary;
using ConfigHelper;
using DeviceLibrary;
using OnlineStore;
using OnlineStore.ACSingleStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class SettingControl : UserControl
    {
        public SettingControl()
        {
            InitializeComponent();
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            //chbAutoRun.Enabled = false;
            chbAutoRun.Checked = Convert.ToBoolean(Setting_Init.App_AutoRun == 1);
            this.chbAutoRun.CheckedChanged += new System.EventHandler(this.chbAutoRun_CheckedChanged);
            //chbAutoRun.Enabled = true;
            for (int i = 0; i < 20; i++)
            {
                cb_tempsensorport.Items.Add("COM" + i);
            }

            this.cb_tempsensorport.SelectedIndexChanged += new System.EventHandler(this.cb_tempsensorport_SelectedIndexChanged);
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (!state)
                return;
            uC_LedConfig1.Config = RobotManage.Config;
            if (!RobotManage.haveFixpos)
                cb_usefixpos.Visible = false;
        }


        private void SettingControl_Load(object sender, EventArgs e)
        {


            Config.PropertyBind("Device_Humiture_Port", cb_tempsensorport, "SelectedItem", "SelectedIndexChanged");
            Config.PropertyBind("Device_Use_Fixpos", cb_usefixpos, "Checked", "CheckedChanged");
        }


        public static void AutoRun(string strName, bool value)
        {
            try
            {
                //创建启动对象 
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                //设置运行文件
                startInfo.FileName = System.Windows.Forms.Application.StartupPath + "\\AuToRunManager.exe";
                //设置启动参数 
                startInfo.Arguments = String.Join(" ", new string[2] { strName, value.ToString() });
                //设置启动动作,确保以管理员身份运行
                startInfo.Verb = "runas";
                //如果不是管理员,则启动UAC 
                System.Diagnostics.Process.Start(startInfo);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void chbAutoRun_CheckedChanged(object sender, EventArgs e)
        {
            if (chbAutoRun.Checked)
            {
                Setting_Init.App_AutoRun = 1;
                AutoRun(Application.ExecutablePath, true);
            }
            else
            {
                Setting_Init.App_AutoRun = 0;
                AutoRun(Application.ExecutablePath, false);
            }
        }

        private void button_positiontool_Click(object sender, EventArgs e)
        {
            if (RobotManage.isRunning)
            {
                MessageBox.Show(crc.GetString(L.before_FrmPositionTool_stopmuchine, "运行库位校准程序前,需要先停止料仓的运行"));
            }
            else
            {
                FrmPositionTool frmPositionTool = new FrmPositionTool(RobotManage.mainMachine.UpDown_Axis, IO_Type.TrayCheck_Fixture);
                frmPositionTool.ShowDialog();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RobotManage.mainMachine.ScanCode();
        }

        private void cb_tempsensorport_SelectedIndexChanged(object sender, EventArgs e)
        {
            HumitureController.Init(Setting_Init.App_Humiture_Port);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!Visible)
                return;
            //label1.Text = ServerCommunication.ServerCommStr;
            lbl_hmdstate.Text = crc.GetString(L.current_status, "当前状态:");
            if (!HumitureController.IsRun)
            {
                lbl_hmdstate.Text += crc.GetString(L.connect_fail, "未成功连接");
                return;
            }
            var t = HumitureController.LastData;
            lbl_hmdstate.Text += $"{crc.GetString(L.temp, "温度")}:{t.Temperate}℃, {crc.GetString(L.humidity, "湿度")}:{t.Humidity}%";
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Task.Run(() => CodeManager.TestHasReel(CodeManager.hikNameList[0], out _, out _));
        }

        //private void button2_Click(object sender, EventArgs e)
        //{
        //    DeviceLibrary.IPCameraHelper.StartRecord("manual");
        //}

        //private void button3_Click(object sender, EventArgs e)
        //{
        //    DeviceLibrary.IPCameraHelper.StopRecord();
        //}
    }
}