FrmLabelEdit.cs 4.3 KB
using CodeLibrary;
using DeviceLibrary;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using JsonHelper = OnlineStore.Common.JsonHelper;

namespace PrintLabel
{
    public partial class FrmLabelEdit : Form
    {
        public FrmLabelEdit()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
            loadCames();
        }
        void loadCames()
        {          
            comboBox1.Items.AddRange(CodeManager.cameraNameList.ToArray());
            if (comboBox1.Items.Count > 0)
                comboBox1.SelectedIndex = 0;
        }
        string filename = "";
        List<CodeInfo> codeinfo = null;
        Dictionary<string, string> keyword;
        bool[] amatch = null;
        Dictionary<string, int> newpointanlge;
        private void btnAcquire_Click(object sender, EventArgs e)
        {
            Task.Factory.StartNew(delegate
            {
                (codeinfo, keyword, filename, newpointanlge) = CodeManager.CameraScan(new List<string>() { comboBox1.SelectedItem.ToString() },7);
                if (string.IsNullOrEmpty(filename)) return;
                pictureBox1.Image = new Bitmap(filename);
            });
        }

        LabelParam labelparam = new LabelParam();
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(filename)) return;
            //labelparam.BitmapFilename = filename;
            //labelparam.LabelContent = new LabelContent();
            //labelparam.LabelContent.codeInfos = codeinfo;
            //labelparam.LabelContent.PN = textBox2.Text;
            //labelparam.TrayCenterInImg_X = int.Parse(txtX.Text);
            //labelparam.TrayCenterInImg_Y = int.Parse(txtY.Text);
            //labelparam.LabelInImgAngle = int.Parse(txtLabel_R_Angle_Diff.Text);
            //labelparam.RelativeAngle = int.Parse(txtRelativeAngle.Text);
            //(string resFile, int codeAngle, int labelAngle, int needRound) res = LabelManager.CalcLabelAngle(labelparam, true);
            //lblCodePos.Text = $"二维码角度:{res.codeAngle}°";
            //lblAngle.Text = $"旋转角度:{res.needRound}°";
            //lblLabelAngle.Text = $"标签角度:{res.labelAngle}°";
            //pictureBox2.Image = new Bitmap(res.resFile);
            //textBox1.Text = JsonHelper.SerializeObject(codeinfo);
        }

        private void load(int side = 0)
        {
            if (side == 0)
            {
                //txtX.Text = ConfigAppSettings.GetValue(Setting_Init.TrayCenterInImg_X_CamA,"2600");
                //txtY.Text = ConfigAppSettings.GetValue(Setting_Init.TrayCenterInImg_Y_CamA,"1700");
                //txtLabel_R_Angle_Diff.Text = ConfigAppSettings.GetValue(Setting_Init.LabelInImgAngle_CamA,"190");
                //txtRelativeAngle.Text = ConfigAppSettings.GetValue(Setting_Init.RelativeAngle_CamA,"150");
            }
        }
        private void save(int side = 0)
        {
            //if (side == 0)
            //{
            //    ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_X_CamA, txtX.Text);
            //    ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_Y_CamA, txtY.Text);
            //    ConfigAppSettings.SaveValue(Setting_Init.LabelInImgAngle_CamA, txtLabel_R_Angle_Diff.Text);
            //    ConfigAppSettings.SaveValue(Setting_Init.RelativeAngle_CamA, txtRelativeAngle.Text);
            //}
            //else if (side == 1)
            //{
            //    ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_X_CamB, txtX.Text);
            //    ConfigAppSettings.SaveValue(Setting_Init.TrayCenterInImg_Y_CamB, txtY.Text);
            //    ConfigAppSettings.SaveValue(Setting_Init.LabelInImgAngle_CamB, txtLabel_R_Angle_Diff.Text);
            //    ConfigAppSettings.SaveValue(Setting_Init.RelativeAngle_CamB, txtRelativeAngle.Text);
            //}
            //else
            //    return;
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            load(comboBox1.SelectedIndex);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            save(comboBox1.SelectedIndex); 
        }
    }
}