tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace TProduct.BLL
{
    public partial class WorkBenchMonitorPoint
    {
        private readonly DAL.WorkBenchMonitorPoint _dal = new DAL.WorkBenchMonitorPoint();
        static List<Model.WorkBenchMonitorPoint> _allWorkBenchMonitorPoint = null;
        internal static void ClearChache()
        {
            _allWorkBenchMonitorPoint = null;
        }
 
        #region Query
 
        /// <summary>
        /// 获取所有
        /// </summary>
        public List<Model.WorkBenchMonitorPoint> GetAll()
        {
            if (_allWorkBenchMonitorPoint != null)
                return _allWorkBenchMonitorPoint;
            var all = _dal.GetAll()?.OrderBy(x => x.SortCode)?.ToList();
            _allWorkBenchMonitorPoint = Entity2Models(all);
            if (_allWorkBenchMonitorPoint == null)
                _allWorkBenchMonitorPoint = new List<Model.WorkBenchMonitorPoint>();
            return _allWorkBenchMonitorPoint;
        }
 
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public Model.WorkBenchMonitorPoint GetByID(long ID)
        {
            if (ID < 1)
                return default;
            return GetAll().Find(x => x.ID == ID);
        }
 
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public List<Model.WorkBenchMonitorPoint> GetByBenchID(long BenchID)
        {
            if (BenchID < 1)
                return default;
            return GetAll().Where(x => x.BenchID == BenchID).ToList();
        }
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public List<Model.WorkBenchMonitorPoint> Get模拟量ByBenchID(long BenchID)
        {
            if (BenchID < 1)
                return default;
            return GetAll().Where(x => x.BenchID == BenchID && x.SourceType == Model.eMonitorPointSourceType.模拟量).ToList();
        }
 
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public List<Model.WorkBenchMonitorPoint> Get数字量ByBenchID(long BenchID)
        {
            if (BenchID < 1)
                return default;
            return GetAll().Where(x => x.BenchID == BenchID && x.SourceType == Model.eMonitorPointSourceType.数字量).ToList();
        }
 
        /// <summary>
        /// 通过 ID 获取
        /// </summary>
        public List<Model.WorkBenchMonitorPoint> GetByIds(List<long> Ids)
        {
            if (Ids == null || Ids.Count() < 1)
                return default;
            return GetAll().Where(x => Ids.Contains(x.ID)).ToList();
        }
 
        /// <summary>
        /// 获取最大排序码
        /// </summary>
        public int GetMaxSortCode(long BenchID)
        {
            if (BenchID < 1)
                return default;
            var items = GetAll().Where(x => x.BenchID == BenchID);
            if (items == null || items.Count() == 0)
                return 1;
            return items.Select(x => x.SortCode).Max();
        }
 
        #endregion
 
        #region Insert
 
        /// <summary>
        /// 添加一条
        /// </summary>
        public long Insert(Model.WorkBenchMonitorPoint model)
        {
            _allWorkBenchMonitorPoint = null;
            if (model == null)
                return default;
            model.CreateTime = DateTime.Now;
            model.UpdateTime = DateTime.Now;
            if (string.IsNullOrEmpty(model.Code))
                model.Code = CreateNO();
            var entity = Model2Entity(model);
            var id = _dal.Insert(entity);
            return id;
        }
 
        /// <summary>
        /// 批量插入
        /// </summary>
        public bool Inserts(List<Model.WorkBenchMonitorPoint> list)
        {
            _allWorkBenchMonitorPoint = null;
            if (list == null || list.Count() < 1)
                return default;
            var codes = new BLL.WorkBenchMonitorPoint().CreateNO(list.Count());
            for (int i = 0; i < list.Count; i++)
            {
                var item = list[i];
                item.CreateTime = DateTime.Now;
                item.UpdateTime = DateTime.Now;
                if (string.IsNullOrEmpty(item.Code))
                    item.Code = codes[i];
            }
            var entity_list = Model2Entities(list);
            var ids = _dal.InsertsR(entity_list);
            if (ids != null && ids.Count > 0)
                return true;
            return false;
        }
 
        /// <summary>
        /// 批量插入并返回标记
        /// </summary>
        public List<long> InsertsR(List<Model.WorkBenchMonitorPoint> list)
        {
            _allWorkBenchMonitorPoint = null;
            if (list == null || list.Count() < 1)
                return default;
            foreach (var item in list)
            {
                item.CreateTime = DateTime.Now;
                item.UpdateTime = DateTime.Now;
                if (string.IsNullOrEmpty(item.Code))
                    item.Code = CreateNO();
            }
            var entity_list = Model2Entities(list);
            return _dal.InsertsR(entity_list);
        }
 
        #endregion
 
        #region Update
 
        /// <summary>
        /// 更新一条
        /// </summary>
        public bool Update(Model.WorkBenchMonitorPoint model)
        {
            _allWorkBenchMonitorPoint = null;
            if (model == null)
                return default;
            model.UpdateTime = DateTime.Now;
            var entity = Model2Entity(model);
            var bol = _dal.Update(entity);
            return bol;
        }
 
        /// <summary>
        /// 批量更新
        /// </summary>
        public bool Updates(List<Model.WorkBenchMonitorPoint> list)
        {
            _allWorkBenchMonitorPoint = null;
            if (list == null || list.Count() < 1)
                return default;
            foreach (var item in list)
            {
                item.UpdateTime = DateTime.Now;
            }
            var entity_list = Model2Entities(list);
            var bol = _dal.Updates(entity_list);
            return bol;
        }
 
        #endregion
 
        #region Delete
        /// <summary>
        /// 通过 ID 删除
        /// </summary>
        public bool DeleteByID(long ID)
        {
            _allWorkBenchMonitorPoint = null;
            return _dal.DeleteByID(ID);
        }
        public bool DeleteByWorkBenchID(long WorkBenchID)
        {
            _allWorkBenchMonitorPoint = null;
            return _dal.DeleteByWorkBenchID(WorkBenchID);
        }
        /// <summary>
        /// 通过 Ids 批量删除
        /// </summary>
        public bool DeleteByIds(List<long> Ids)
        {
            _allWorkBenchMonitorPoint = null;
            return _dal.DeleteByIds(Ids);
        }
        #endregion
 
        #region Exist
        /// <summary>
        ///是否存在Code
        /// </summary>
        public bool IsExistCode(string Code)
        {
            if (string.IsNullOrEmpty(Code))
                return false;
            var find = GetAll().Find(x => x.Code.ToLower() == Code.ToLower());
            if (find == null)
                return false;
            else
                return true;
        }
 
        /// <summary>
        ///是否存在Name
        /// </summary>
        public bool IsExistName(long BenchID, string Name)
        {
            if (string.IsNullOrEmpty(Name) || BenchID <= 0)
                return false;
            var find = GetAll().Find(x => x.BenchID == BenchID && x.Name.ToLower() == Name.ToLower());
            if (find == null)
                return false;
            else
                return true;
        }
        #endregion
    }
}