SettingControl.cs 8.2 KB
using CodeLibrary;
using ConfigHelper;
using DeviceLibrary;
using Newtonsoft.Json;
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.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class SettingControl : UserControl
    {
        public SettingControl()
        {
            InitializeComponent();
            crc.LanguageProcess(this);
            crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            //chbAutoRun.Enabled = false;
            chbAutoRun.Checked =Setting_Init.App_AutoRun;
            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 Crc_LanguageChangeEvent(object sender, EventArgs e)
        {
            crc.LanguageProcess(this);
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (!state)
                return;

            uC_LedConfig1.Config = RobotManage.Config;
        }


        private void SettingControl_Load(object sender, EventArgs e)
        {
            //Config.PropertyBind(Setting_Init.Device_DauxiKS107_Port.Key, cb_tempsensorport, "SelectedItem", "SelectedIndexChanged");
            Config.PropertyBind(Setting_Init.Printer_Labelname.Key, cb_labelselect, "SelectedItem", "SelectedValueChanged");
            loadlabellist();
        }


        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)
        {
            Setting_Init.App_AutoRun = chbAutoRun.Checked;
            AutoRun(Application.ExecutablePath, Setting_Init.App_AutoRun);
        }

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


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

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!Visible)
                return;

            //lbl_hmdstate.Text = crc.GetString("Res0022","当前状态:");
            //if (!HumitureController.IsRun)
            //{
            //    lbl_hmdstate.Text += crc.GetString("Res0023", "未成功连接");
            //}
            //else
            //{
            //    var t = HumitureController.LastData;
            //    lbl_hmdstate.Text += $"{"温度"}:{t.Temperate}℃, {"湿度"}:{t.Humidity}%";
            //}
            if (RobotManage.dauxiKS107.Distance>0)
                lbl_Liquidstatus.Text = crc.GetString("Res0178.bade191d","当前液位距离:") + RobotManage.dauxiKS107.Distance + "mm ," + crc.GetString("Res0179.562122a5","最小液位距离:") + Setting_Init.Device_Liquid_level_distance + "mm";
            else
                lbl_Liquidstatus.Text = crc.GetString("Res0023", "未成功连接");
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
           
        }

        private void btn_printertest_Click(object sender, EventArgs e)
        {
            ReelParam reelParam = new ReelParam();
            reelParam.ReeID = "Demo ReelID";
            reelParam.PN = "Demo PN";
            reelParam.QTY = 999;
            var t = RobotManage.printerHelper.PrintLabel(reelParam, Setting_Init.Printer_Labelname);
            t.Wait();
            if (!t.Result.Item1)
            {
                MessageBox.Show(t.Result.Item2);
            }
            else
                MessageBox.Show(crc.GetString("Res0024","打印成功"));
        }

        private void btn_labeledit_Click(object sender, EventArgs e)
        {
            PrintLabel.FrmLabel frmLabel = new PrintLabel.FrmLabel();
            crc.LanguageProcess(frmLabel, "FrmLabel");
            frmLabel.ShowDialog();
            loadlabellist();
        }
        void loadlabellist()
        {
            cb_labelselect.Items.Clear();
            cb_labelselect.Items.AddRange(RobotManage.printerHelper.GetLabelList());
            cb_labelselect.SelectedItem = Setting_Init.Printer_Labelname.Val;
        }

        private void tabPage_set_Click(object sender, EventArgs e)
        {

        }

        private void btn_testlabeling_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning || RobotManage.mainMachine.runStatus != RunStatus.Running) {
                MessageBox.Show("Please start the device first and complete the home reset");
                return;
            }
            if (RobotManage.mainMachine.LabelingMoveInfo.MoveStep!= MoveStep.Wait)
            {
                MessageBox.Show("Please wait for the labeling action to end");
                return;
            }
            RobotManage.mainMachine.LabelingMoveInfo.NewMove(MoveStep.Labeling01);
            RobotManage.mainMachine.LabelingMoveInfo.log("开始一次贴标测试");
        }

        private void cb_labelingtestmoce_CheckedChanged(object sender, EventArgs e)
        {
            RobotManage.mainMachine.LabelingTestMode=cb_labelingtestmoce.Checked;
            btn_testlabeling.Enabled = cb_labelingtestmoce.Checked;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning || RobotManage.mainMachine.runStatus != RunStatus.Running)
            {
                MessageBox.Show("请先启动设备并完成回原");
            }
            //Setting_Init.Device_step_by_step_mode = true;

            RobotManage.mainMachine.newDrawer = false;
            RobotManage.mainMachine.NGInfoList = new List<ReelParam>();
            Setting_Init.Runtime_NGINFOLIST = JsonConvert.SerializeObject(RobotManage.mainMachine.NGInfoList);
            RobotManage.mainMachine.StoreMoveInfo.NewMove(MoveStep.StoreIn01);
            RobotManage.mainMachine.StoreMoveInfo.log("手动开始取料");


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning || RobotManage.mainMachine.runStatus != RunStatus.Running)
            {
                MessageBox.Show("请先启动设备并完成回原");
            }
            Setting_Init.Runtime_NGINFOLIST = JsonConvert.SerializeObject(RobotManage.mainMachine.NGInfoList);
            RobotManage.mainMachine.LabelingMoveInfo.NewMove(MoveStep.Labeling01); ;
            RobotManage.mainMachine.LabelingMoveInfo.log("手动扫码");
        }
    }
}