FrmChangeWidth.cs 5.5 KB
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;

namespace TSA_V
{
    public partial class FrmChangeWidth : FrmBase
    {

        private int defaultWidth = 100;
        public FrmChangeWidth()
        {
            InitializeComponent();
        }
        private void FrmPutCom_Load(object sender, EventArgs e)
        {
            LanguageProcess();
            SetScreen();
            LoadData();

        }
        private List<int> widthList = new List<int>();
        private void LoadData()
        {
            numChangeValue.Value = ConfigAppSettings.GetIntValue(Setting_Init.Line_ChangeValue);
            numHomeWidth.Value = ConfigAppSettings.GetIntValue(Setting_Init.Line_HomeWidth);
            numSlv.Value = ConfigAppSettings.GetIntValue(Setting_Init.Line_NodeAddr);
            numTarget.Value = defaultWidth;
            txtTargetPosition.Text = (defaultWidth - ((int)numHomeWidth.Value)) * ((int)numChangeValue.Value) + "";
            LoadList();

        }
        private void LoadList()
        {
            widthList = new List<int>();
            lbWidthMap.Items.Clear();
            foreach (int key in LWidthManager.WPositionMap.Keys)
            {
                int value = LWidthManager.WPositionMap[key];
                lbWidthMap.Items.Add(" " + key + "mm  = " + value);

                if (txtW.Text.Equals(""))
                {
                    txtW.Text = key.ToString();
                    txtWP.Text = value.ToString();
                }
                widthList.Add(key);
            }
        }
        private void btnChWidth_Click(object sender, EventArgs e)
        {
            numTarget_ValueChanged(null, null);
            int w = (int)numTarget.Value;
            int p = FormUtil.GetIntValue(txtTargetPosition);
            LogUtil.info("点击 轨道调宽:【" + w + "】【" + p + "】");
            if (!LWidthManager.CanStartChWidth())
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChangeWFail, "启动调宽失败"));
                return;
            }
            Task.Factory.StartNew(delegate
            {
                string result = LWidthManager.StartChangeWidth(w, p);
                LogUtil.info("调宽" + w + "=" + p + "结束:" + result);
                if (String.IsNullOrEmpty(result))
                {
                    MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChangeWOk, "调宽{0}={1}完成", w, p));
                }
                else
                {
                    MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChangeWEnd, "调宽{0}={1}结束:{2}", w, p, result));
                }
            });
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            int slvAddr = (int)numSlv.Value;
            int homeWidth = (int)numHomeWidth.Value;
            int numChange = (int)numChangeValue.Value;
         
            ConfigAppSettings.SaveValue(Setting_Init.Line_NodeAddr, slvAddr);
            ConfigAppSettings.SaveValue(Setting_Init.Line_ChangeValue, numChange);
            ConfigAppSettings.SaveValue(Setting_Init.Line_HomeWidth, homeWidth);

            LWidthManager.Line_NodeAddr = (uint)slvAddr;
            LWidthManager.Line_HomeWidth = homeWidth;
            LWidthManager.Line_ChangeValue = numChange; 
            MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk, "保存成功!"));
        }



        private void FrmPutCom_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {


        }


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

        private void btnDSave_Click(object sender, EventArgs e)
        {
            int width = FormUtil.GetIntValue(txtW);
            int position = FormUtil.GetIntValue(txtWP);
            if (width <= 0 || width > 1000)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteLength, "请输入宽度"));
                txtW.Focus();
            }
            LWidthManager.UpdateWPosition(width, position);
            MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk, "保存成功!"));
            LoadList();
        }

        private void listDetitalP2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbWidthMap.SelectedIndex < 0)
            {
                return;
            }
            int index = lbWidthMap.SelectedIndex;
            if (index >= widthList.Count)
            {
                return;
            }
            int width = widthList[index];
            txtW.Text = width.ToString();
            txtWP.Text = LWidthManager.GetWidthPosition(width).ToString();
        }

        private void numTarget_ValueChanged(object sender, EventArgs e)
        {
            int value = (int)numTarget.Value;
            int p = LWidthManager.GetWidthPosition(value);
            txtTargetPosition.Text = p.ToString();

        }

        private void btnHomeM_Click(object sender, EventArgs e)
        {
            LogUtil.info(Name+ "点击 原点返回");
            PUSICANControl.HomeMove(LWidthManager.Line_NodeAddr, true);
        }
    }
}