Blame view

Excel/HH.Data.Excel/Services/MainService.cs 4.06 KB
-  
唐召明 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Hh.Mes.Common.Exel;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.WebEntity.equipment;
using HH.Data.Excel.SqlHelp;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using ComboBox = System.Windows.Forms.ComboBox;

namespace HH.Data.Excel.Services
{
    /// <summary>
    /// 
    /// </summary>
    public class MainService
    {
        private readonly DatabaseService _service;

        public MainService()
        {
            // 初始化 SqlDataService 实例
            _service = DatabaseService.Instance;
        }


        /// <summary>
        /// 加载项目列表到指定的 ComboBox 控件中
        /// </summary>
        public List<KeyValuePair<Guid, string>> InitProject(ComboBox comboBox)
        {
            return ExceptionsHelp.Instance.Execute(() =>
             {
-  
唐召明 authored
42
                 var projectList = _service.GetProjectList().Select(x => new KeyValuePair<Guid, string>(x.keys, x.projectName))
-  
唐召明 authored
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                                           .ToList();
                 comboBox.DisplayMember = "Value";
                 comboBox.ValueMember = "Key";
                 comboBox.DataSource = projectList;

                 return projectList;

             }, actionCatCh: (ex) =>
             {
                 Program.SysMsgShow("加载设备列表:" + ex.Message);
             });
        }

        /// <summary>
        /// 加载项目列表到指定的 ComboBox 控件中
        /// </summary>
        public List<KeyValuePair<string, string>> InitFactory(ComboBox comboBox, Guid selectValue)
        {
            return ExceptionsHelp.Instance.Execute(() =>
            {
                var projectList = _service.GetFactoryList(selectValue);
-  
唐召明 authored
64
65
66
67
                if (projectList.Count == 0)
                {
                    comboBox.Text = "无数据";
                }
-  
唐召明 authored
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
                var items = projectList.Select(item => new KeyValuePair<string, string>(item.factoryCode, item.factoryName))
                                        .ToList();
                comboBox.DisplayMember = "Value";
                comboBox.ValueMember = "Key";
                comboBox.DataSource = new BindingSource(items, null);

                return items;

            }, actionCatCh: (ex) =>
            {
                Program.SysMsgShow("加载厂房列表:" + ex.Message);
            });
        }

        /// <summary>
        /// 加载设备类型 CheckedListBox
        /// 默认隐藏
        /// </summary>
        public Dictionary<int, string> InitEqType(CheckedListBox chkList, Panel panel, bool isShow = true)
        {
            return ExceptionsHelp.Instance.Execute(() =>
            {
                // 根据 isShow 参数来设置 CheckedListBox 的可见性
                panel.Visible = !isShow;
                if (chkList.DataSource != null) return Program._mainWindow.EqTypeDataSource;

                // 获取设备类型数据
                var items = _service.GetEqTypeList().ToDictionary(item => item.Id, item => item.Name);

                // 5. 线程安全绑定
                if (chkList.InvokeRequired)
                {
                    chkList.Invoke(new Action(() =>
                    {
                        chkList.DataSource = new BindingSource(items, null);
                        chkList.DisplayMember = "Value";
                        chkList.ValueMember = "Key";
                    }));
                }
                else
                {
                    chkList.DataSource = new BindingSource(items, null);
                    chkList.DisplayMember = "Value";
                    chkList.ValueMember = "Key";
                }
                return items;
            }, actionCatCh: (ex) =>
            {
                Program.SysMsgShow("加载设备类型:" + ex.Message);
            });
        }
    }
}