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

namespace AutoScanAndLabel
{
    public partial class SettingControl : UserControl
    {
        public SettingControl()
        {
            InitializeComponent();
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            //chbAutoRun.Enabled = false;
            chbAutoRun.Checked = Convert.ToBoolean(ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun));
            this.chbAutoRun.CheckedChanged += new System.EventHandler(this.chbAutoRun_CheckedChanged);
            //chbAutoRun.Enabled = true;           
        }     
        
        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (!state)
                return;
            cb_printerselect.Items.Clear();
            cb_labelselect.Items.Clear();
            foreach (string sPrint in System.Drawing.Printing.PrinterSettings.InstalledPrinters)//获取所有打印机名称
            {
                cb_printerselect.Items.Add(sPrint);
            }
            if (RobotManage.printerHelper != null)
            {
                foreach (string labelname in RobotManage.printerHelper.GetLabelList())
                {
                    cb_labelselect.Items.Add(labelname);
                }
            }
            string PrintName = ConfigHelper.Config.Get(Setting_Init.PrinterName);
            string labelName = ConfigHelper.Config.Get(Setting_Init.LabelName);
            cb_printerselect.Text = PrintName;
            cb_labelselect.Text = labelName;
        }


        private void SettingControl_Load(object sender, EventArgs e)
        {
            
            AlarmBuzzer.Enable = Config.Get("EnableBuzzer", true);
            cb_EnableBuzzer.Checked = AlarmBuzzer.Enable;
        }

        private void cb_printerselect_SelectedIndexChanged(object sender, EventArgs e)
        {
            Config.Set(Setting_Init.PrinterName, (sender as ComboBox).Text);
            RobotManage.LoadPrintSetting();
        }

        private void cb_labelselect_SelectedIndexChanged(object sender, EventArgs e)
        {
            Config.Set(Setting_Init.LabelName, (sender as ComboBox).Text);
            RobotManage.LoadPrintSetting();
        }

        private void btn_labeledit_Click(object sender, EventArgs e)
        {
            var keys = File.ReadAllLines(Application.StartupPath+ "\\NeoScan\\Config\\MacroKey.txt");

            //RobotManage.PrintBean.EditLabel();
            PrintLabel.FrmLabel frmLabel = new PrintLabel.FrmLabel();
            //crc.CurrLanguage = "";
            frmLabel.Text = crc.GetString("FrmLabel_Text", "标签编辑");
            crc.LanguageProcess(frmLabel, "FrmLabel");
            frmLabel.KeyWord.AddRange(keys);
            frmLabel.Show();
            RobotManage_LoadFinishEvent(true, "");
            RobotManage.LoadPrintSetting();
        }

        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)
            {
                ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 1);
                AutoRun(Application.ExecutablePath, true);
            }
            else
            {
                ConfigAppSettings.SaveValue(Setting_Init.App_AutoRun, 0);
                AutoRun(Application.ExecutablePath, false);
            }
        }

        private void btn_labelDebug_Click(object sender, EventArgs e)
        {
            LabelParam la = new LabelParam();
            Common.RenderedImage(la, new Point(500,500), new Point(1000,1000), 0);
            //UnifiedDataHandler.RecordPrintNg(false,true,out string[] s);
            //UnifiedDataHandler.RecordEmsData(false,"78945699999");
            //Dictionary<string, string> dic = new Dictionary<string, string>();
            //dic.Add("cid","NS01_1");
            //Bitmap bitmap = new Bitmap("C:\\Users\\Neotel\\Desktop\\lQLPKdvOHVK-69fNAdjNAsSwG8ONhvwwiG8Fi4NMZw68AQ_708_472.png");
            //_ = UnifiedDataHandler.PostSmfImageAsync(bitmap, dic, bitmap.Width, bitmap.Height);

            //Bitmap bitmap1 = new Bitmap("C:\\Users\\Neotel\\Desktop\\lQLPJyGyZ6lafJfNDkDNFUCwiSqya_VMap0Fi4NMZw68AA_5440_3648.png");
            //Dictionary<string, string> dic1 = new Dictionary<string, string>();
            //dic1.Add("cid", "NS01_2");
            //_ = UnifiedDataHandler.PostSmfImageAsync(bitmap1, dic1);
            //Bitmap bitmap = new Bitmap("16-51-26-94.bmp");
            //List<CodeInfo> tlci = EyemDecode2.Decoder(ref bitmap);
            //bitmap.Dispose();622-X:1928;Y:1231
            //4781-x: 1838; y: 2292
            //List<CodeInfo> tlci = new List<CodeInfo>();
            //tlci.Add(new CodeInfo("", 1928, 1231));
            ////tlci.Add(new CodeInfo("", 3110, 1654));
            //LabelParam labelParam = new LabelParam();
            //labelParam.codeInfos = tlci;
            //labelParam.PlateW = 15;
            //labelParam.bitmapfilename = "D:\\Desktop\\软件日志\\ns200苏州工厂\\12-29-贴标是歪的\\2023-12-29-16-12-27622.bmp";

            //LabelParam aaa = labelParam.clone();
            //Point Right_Batch_Point = new Point(RobotManage.Config.Right_Batch_X, RobotManage.Config.Right_Batch_Y);

            ////Point p = Common.CalcLabelPoint(labelParam, Right_Batch_Point, RobotManage.Config.Label_R_Offset, RobotManage.Config.Label_R_Angle_Diff, out int labelAngle);
            //Point p = Common.Customlabeling(labelParam, Right_Batch_Point, out int labelAngle);


            //            //计算贴标角度的脉冲值
            //            int labelAxisPos = RobotManage.Config.Label_R_360 / 360 * labelAngle;

            //            //计算像素点位与中心点的差
            //            Point p1 = new Point(p.X - Right_Batch_Point.X, p.Y - Right_Batch_Point.Y);
            //            //计算像素*脉冲像素比得到脉冲值+中心点基准脉冲
            //            p1.X = (int)(p1.X * RobotManage.Config.Cam_Pixel_X_Ratio) + RobotManage.Config.Label_X_Base;
            //            p1.Y = (int)(p1.Y * RobotManage.Config.Cam_Pixel_Y_Ratio) + RobotManage.Config.Label_Y_Base;

        }

        static bool IsPointInTriangle(Point p, Point[] triangle)
        {
            int s1 = (triangle[0].X * (triangle[1].Y - triangle[2].Y) + triangle[1].X * (triangle[2].Y - triangle[0].Y) + triangle[2].X * (triangle[0].Y - triangle[1].Y)) / 2;
            int s2 = (p.X * (triangle[1].Y - triangle[2].Y) + triangle[1].X * (triangle[2].Y - p.Y) + triangle[2].X * (p.Y - triangle[1].Y)) / 2;
            int s3 = (triangle[0].X * (p.Y - triangle[2].Y) + p.X * (triangle[2].Y - triangle[0].Y) + triangle[2].X * (triangle[0].Y - p.Y)) / 2;
            int s4 = (triangle[0].X * (triangle[1].Y - p.Y) + triangle[1].X * (p.Y - triangle[0].Y) + p.X * (triangle[0].Y - triangle[1].Y)) / 2;

            int totalArea = Math.Abs(s1 + s2 + s3 + s4);

            return totalArea == s1 + s2 + s3 + s4; // 如果点在三角形内,两者应该相等
        }

        private void listEdit_pn_DataRefresh(object sender, EventArgs e)
        {
            Common.LoadMatchList();
        }

        private void btn_codetest_Click(object sender, EventArgs e)
        {
            DeviceLibrary.LabelParam labelParam = new DeviceLibrary.LabelParam();
            labelParam.codeInfos = new List<CodeLibrary.CodeInfo>();
            labelParam.codeInfos.Add(new CodeLibrary.CodeInfo(txt_code.Text, 0, 0));
            Common.codeProcess(labelParam, out string debugstring);
            label_matchdebugstring.Text = debugstring;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RemoteDecodeHelper_mod.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper_mod.RemoteDecodeParam();
            var bmp = new Bitmap("D:\\Desktop\\001.jpg");
            var cc = RemoteDecodeHelper_mod.DecodeRequest(bmp, remoteDecodeParam);
        }

        private void cb_IgnoreGratingSignal_CheckedChanged(object sender, EventArgs e)
        {
            RobotManage.IgnoreGratingSignal((sender as CheckBox).Checked);
        }

        private void cb_IgnoreSafecheck_CheckedChanged(object sender, EventArgs e)
        {
            RobotManage.IgnoreSafecheck((sender as CheckBox).Checked);
        }

        private void cb_EnableBuzzer_CheckedChanged(object sender, EventArgs e)
        {
            Config.Set("EnableBuzzer", cb_EnableBuzzer.Checked);
            AlarmBuzzer.Enable = cb_EnableBuzzer.Checked;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            RobotManage.IgnoreSafecheck((sender as CheckBox).Checked);
        }
    }
}