SettingControl.cs 6.6 KB
using CodeLibrary;
using ConfigHelper;
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
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)
        {

        }

        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("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.ShowDialog();
            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)
        {
            //Bitmap bitmap = new Bitmap("16-51-26-94.bmp");
            //List<CodeInfo> tlci = EyemDecode2.Decoder(ref bitmap);
            //bitmap.Dispose();
            List<CodeInfo> tlci = new List<CodeInfo>();
            tlci.Add(new CodeInfo("", 413, 1809));
            LabelParam labelParam = new LabelParam();
            labelParam.codeInfos = tlci;
            labelParam.bitmapfilename = @"D:\logs\827\15-02-40-402.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);

            //计算贴标角度的脉冲值
            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;

        }

        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:\\17-09-05-154.bmp");
            var cc = RemoteDecodeHelper_mod.DecodeRequest(bmp, remoteDecodeParam);
        }
    }
}