FrmConfig.cs 3.4 KB

using SmartShelf.Common;
using SmartShelf.DeviceLibrary;
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;

namespace SmartShelf
{
    internal partial class FrmConfig :Form
    { 
        internal FrmConfig( )
        { 
            InitializeComponent();
        }
        private List<string> ColorList = new List<string>();
        private void FrmPwd_Load(object sender, EventArgs e)
        {
            txtIP.Text = LEDManager.DefaultIP;
            txtStaDmxId.Text = ConfigAppSettings.GetValue(Setting_Init.StatusLedDmx);
            ColorList = new List<string>(){
            "RGB=红绿蓝",
            "RBG=红蓝绿",
            "GRB=绿红蓝",
            "GBR=绿蓝红",
            "BRG=蓝红绿",
            "BGR=蓝绿红"};
          
            comBoxColor.Items.Clear();
            int index = 0;
            int i = 0;
            foreach (string s in ColorList)
            {
                comBoxColor.Items.Add(s);
                if (s.Contains(LEDManager.ColorRule))
                {
                    index = i;
                }
                i++;
            }
            comBoxColor.SelectedIndex = 0;
            if (LEDManager.ConnectionMode.Equals(0))
            {
                cmbConMode.SelectedIndex = 0;
            }
            else
            {
                cmbConMode.SelectedIndex = 1;
            }
          
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            string ip = txtIP.Text; 
            ConfigAppSettings.SaveValue(Setting_Init.DefaultDeviceIP, ip);
            LEDManager.DefaultIP = ip;


            string dmxIds = txtStaDmxId.Text.Trim();
            ConfigAppSettings.SaveValue(Setting_Init.StatusLedDmx, dmxIds);
            LEDManager.LoadStatusDMX();

            string colorText = comBoxColor.Text;
            if (colorText.Length >= 7)
            {
                string result = colorText.Substring(0, 3);
                ConfigAppSettings.SaveValue(Setting_Init.ColorRuleConfig, result);
                LEDManager.ColorRule = result;
                LogUtil.info("保存灯条颜色配置:" + Setting_Init.ColorRuleConfig +"="+ result);
            }


            int modeIndex = cmbConMode.SelectedIndex;
            ConfigAppSettings.SaveValue(Setting_Init.ConnectionMode, modeIndex);
            LogUtil.info("保存控制器连接方式:" + modeIndex);

            MessageBox.Show("保存成功,重启软件后生效");
            this.Close();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
           
            this.Close();
        }

        private void FrmPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Enter))
            {
                btnNext_Click(null, null);
            }
        }

        private void txtPwd_KeyDown(object sender, KeyEventArgs e)
        { 
            if (e.KeyCode.Equals(Keys.Enter))
            {
                btnNext_Click(null, null);
            }else if (e.KeyCode.Equals(Keys.Escape))
            {
                btnBack_Click(null, null);
            }
        }

        private void FrmPwd_Shown(object sender, EventArgs e)
        {
            txtIP.Focus();

        }
    }
}