MainWindow.cs 2.66 KB
using AutoMapper.Configuration.Conventions;
using Hh.Mes.POJO.Entity;
using HH.Data.Excel.Services;
using HH.Data.Excel.SqlHelp;
using System;
using System.Configuration;
using System.IO;

namespace HH.Data.Excel
{
    public partial class MainWindow : Form
    {
        #region 属性
        public readonly MainService _appService;
        public readonly DatabaseService _dataService;
        public Guid selectProjectKey;
        public string? selectFactoryCode;
        public readonly string _sysIpFileName = "IP地址表.xlsx";

        /// <summary>项目信息
        /// </summary>
        public List<KeyValuePair<Guid, string>>? ProjectKeyValueList { get; set; }
        /// <summary>
        /// 设备类型 数据源
        /// </summary>
        public Dictionary<int, string> EqTypeDataSource { get; set; }


        /// <summary> 事件注册 处理
        /// </summary>
        public MainEventHandlers _eventHandlers;


        #region 公共属性返回控件的值

        public TabControl _tabControl1 => tabControl1;
        public ComboBox _cb_project => cb_project;
        public ComboBox _cb_factory => cb_factory;

        public Panel _panel2 => panel2;
        /// <summary>设备复选框
        /// </summary>
        public CheckedListBox _ccb_type => ccb_type;

        public Button _btn_read => btn_read;
        public Button _btn_read_save => btn_read_save;

        public Button _btnDefaule => btnDefaule;

        #endregion

        #endregion

        public MainWindow()
        {
            InitializeComponent();
            _appService = new MainService();
            _eventHandlers = new MainEventHandlers(this);
            Init();
        }

        void Init()
        {
            this.Text = "IOT平台数据地址协议解析 " + GetAppVersion();
            this.MaximizeBox = false; // 禁止最大化
            this.FormBorderStyle = FormBorderStyle.FixedSingle; // 禁止调整大小
            ProjectKeyValueList = new List<KeyValuePair<Guid, string>>();
            InitControl();
        }

        /// <summary>初始化 项目、厂房、设备类型 控件
        /// </summary>
        void InitControl()
        {
            ProjectKeyValueList = _appService.InitProject(cb_project);
            _appService.InitFactory(cb_factory, ProjectKeyValueList[0].Key);
            EqTypeDataSource = _appService.InitEqType(ccb_type, panel2);
        }

        public string GetAppVersion()
        {
            // 读取版本号
            var version = ConfigurationManager.AppSettings["ver"];

            // 空值验证
            if (string.IsNullOrEmpty(version))
            {
                throw new ConfigurationErrorsException("未找到版本号配置");
            }
            return version;
        }
    }
}