schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using DataEntity;
using DataRWDAL.Base;
using SqlSugar;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using XImagingXhandler.XDAL;
using static System.Net.WebRequestMethods;
 
namespace DataRWDAL
{
    /// <summary>
    /// 台面板位库表操作类
    /// </summary>
    public class LatticeDB : BaseDB
    {
        #region 查询返回台面板位数据集 by 设备型号名
        /// <summary>
        /// 查询返回台面板位数据集 by 设备型号名
        /// </summary>
        /// <param name="deviceNumber">设备型号名</param>
        /// <returns>台面板位数据集</returns>
        public static List<Lattice> GetLatticeDataFromdb(string deviceNumber)
        {
            List<Lattice> lattices = new List<Lattice>();
            using (var db = GetInstance())
            {
                // 多表查询
                var query = db.Queryable<Lattice, SoftwareInformation>
                    (
                        (st, sc) =>
                        new JoinQueryInfos(JoinType.Left, st.software_information_id == sc.software_information_id)
                    )
                    .Where((st, sc) => sc.software_device_number == deviceNumber&&st.lattice_state.Equals(1));
 
                var result =query.ToList(); // 转换为List
 
                foreach (Lattice lattice in result)
                {
                    var filterQuery = db.Queryable<TabletopRelLattice>().Where(x => x.lattice_id.Equals(System.Convert.ToInt32(lattice.lattice_id)));
                    if (filterQuery != null && filterQuery.Count() > 0)
                    {
                    }
                    else
                    {
                        lattices.Add(lattice);
                    }
                }
 
                if (lattices != null && lattices.Count > 0)
                {
                    var a = lattices[lattices.Count - 1];
                    if (a.lattice_num.Equals("P0"))
                    {
                        lattices.RemoveAt(lattices.Count - 1);
                        lattices.Insert(0, a);
                    }
                }
 
                return lattices;//db.Queryable<Lattice, SoftwareInformation>((st, sc) => st.software_information_id == sc.software_information_id && sc.software_device_number == deviceNumber).ToList();
            }
        }
        #endregion
 
        #region 查询返回台面板位数据集 by 设备型号名、设备臂Id
        /// <summary>
        /// 查询返回台面板位数据集 by 设备型号名
        /// </summary>
        /// <param name="deviceNumber">设备型号名</param>
        /// <param name="device_arm_id">设备臂Id</param>
        /// <param name="isbaselattice">是否是构建台面用的板位:0: 不是;1:是</param>
        /// <returns>台面板位数据集</returns>
        public static List<Lattice> GetLatticeDataFromdb(string deviceNumber, int device_arm_id,int isbaselattice=1)
        {
            List<Lattice> lattices= new List<Lattice>();
            using (var db = GetInstance())
            {
                // 多表查询
                var query = db.Queryable<Lattice, SoftwareInformation>
                    (
                        (st, sc) =>
                        new JoinQueryInfos(JoinType.Left, st.software_information_id == sc.software_information_id)
                    )
                    .Where((st, sc) => sc.software_device_number == deviceNumber && st.device_arm_id == device_arm_id&&st.lattice_state.Equals(1));//.OrderBy(st=>st.lattice_num,OrderByType.Asc);
 
                var result =query.ToList();
 
                foreach (Lattice lattice in result)
                {
                    var filterQuery = db.Queryable<TabletopRelLattice>().Where(x => x.lattice_id.Equals(System.Convert.ToInt32(lattice.lattice_id)));
                    if (filterQuery != null && filterQuery.Count() > 0)
                    {
                        if(isbaselattice==0) //非出厂台面
                        {
                            lattices.Add(lattice); 
                        }
                        else if(isbaselattice==1)
                        {
                            lattices.Add(lattice);
                        }
                    }
                    else
                    {
                        lattices.Add(lattice); //出厂默认台面
                    }
                }
 
                if (lattices != null && lattices.Count > 0)
                {
                    var a = lattices[lattices.Count - 1];
                    if (a.lattice_num.Equals("P0"))//把P0移动到第一个
                    {
                        lattices.RemoveAt(lattices.Count - 1);
                        lattices.Insert(0, a);
                    }
                }
 
                Lattice lat = new Lattice();
                lat.lattice_id = "0";
                lat.lattice_num = "请选择";
                lattices.Insert(0,lat);
                return lattices;
            }
        }
        #endregion
 
        #region 只查询出板位的编号名,提供给该设备下的夹爪使用
        /// <summary>
        /// 只查询出板位的编号名,提供给该设备下的夹爪使用
        /// </summary>
        /// <param name="deviceNumber">设备型号</param>
        /// <param name="device_arm_id">夹爪臂Id</param>
        /// <param name="mainChannelArmId">主通道臂Id</param>
        /// <returns></returns>
        public static List<Lattice> GetGripperLatticeNumDataFromdb(string deviceNumber, int mainChannelArmId)
        {
            List<Lattice> lattices = new List<Lattice>();
            using (var db = GetInstance())
            {
                // 多表查询
                var query = db.Queryable<Lattice, SoftwareInformation>
                    (
                        (st, sc) =>
                        new JoinQueryInfos(JoinType.Left, st.software_information_id == sc.software_information_id)
                    )
                    .Where((st, sc) => sc.software_device_number == deviceNumber && st.device_arm_id == mainChannelArmId && st.lattice_state.Equals(1));
 
                var result = query.ToList();
 
                foreach (Lattice lattice in result)
                {
                    lattice.lattice_id = "";
                    var filterQuery = db.Queryable<TabletopRelLattice>().Where(x => x.lattice_id.Equals(System.Convert.ToInt32(lattice.lattice_id)));
                    if (filterQuery != null && filterQuery.Count() > 0)
                    {
                        lattices.Add(lattice); //非出厂台面
                    }
                    else
                    {
                        lattices.Add(lattice); //出厂默认台面
                    }
                }
 
                if (lattices != null && lattices.Count > 0)
                {
                    var a = lattices[lattices.Count - 1];
                    if (a.lattice_num.Equals("P0"))//把P0移动到第一个
                    {
                        lattices.RemoveAt(lattices.Count - 1);
                        lattices.Insert(0, a);
                    }
                }
 
                Lattice lat = new Lattice();
                lat.lattice_id = "0";
                lat.lattice_num = "请选择";
                lattices.Insert(0, lat);
                return lattices;
            }
 
            return lattices;
        }
        #endregion
 
        #region 查询返回台面板位数据集 by 设备型号名、设备臂Id
        /// <summary>
        /// 查询返回台面板位数据集 by 设备型号名
        /// </summary>
        /// <param name="tabletopid">台面模板Id</param>
        /// <returns>台面板位数据集</returns>
        public static List<Lattice> GetLatticeDataByTabletopTemplateFromdb(string tabletopid)
        {
            using (var db = GetInstance())
            {
                // 多表查询
                var query = db.Queryable<Lattice,TabletopRelLattice>
                    (
                        (st, sc) =>
                        new JoinQueryInfos(JoinType.Left, st.lattice_id == sc.lattice_id.ToString())
                    )
                    .Where((st, sc) => sc.tabletopid == tabletopid&&st.lattice_state.Equals(1));
 
                var result = query.OrderBy("lattice_id").ToList();
 
                if (result != null && result.Count > 0)
                {
                    var a = result[result.Count - 1];
                    if (a.lattice_num.Equals("P0"))//把P0移动到第一个
                    {
                        result.RemoveAt(result.Count - 1);
                        result.Insert(0, a);
                    }
                }
 
                Lattice lat = new Lattice();
                lat.lattice_id = "0";
                lat.lattice_num = "请选择";
                result.Insert(0, lat);
                return result;
            }
        }
        #endregion
 
        #region 查询返回台面板位数据 by 台面板位Id
        /// <summary>
        /// 查询返回台面板位数据 by 台面板位Id
        /// </summary>
        /// <param name="latticeId">台面板位Id</param>
        /// <returns>台面板位数据</returns>
        public static Lattice GetLatticeDataByIdFromdb(string latticeId)
        {
            using (var db = GetInstance())
            {
                return db.Queryable<Lattice>().Single(it => it.lattice_id.Equals(latticeId));
            }
        }
        #endregion
 
        #region 查询返回台面板位数据 by 台面板位号、设备臂Id、设备型号
        /// <summary>
        /// 查询返回台面板位数据 by 台面板位号、设备臂Id、设备型号
        /// </summary>
        /// <param name="latticeNum">台面板位号</param>
        /// <param name="armId">设备臂Id</param>
        /// <param name="deviceNumber">设备型号</param>
        /// <param name="tabletopid">台面模板Id</param>
        /// <returns>台面板位数据</returns>
        public static Lattice GetLatticeDataByIdFromdb(string latticeNum, int armId, string deviceNumber)
        {
            using (var db = GetInstance())
            {
                // 多表查询
                var query = db.Queryable<Lattice, SoftwareInformation>
                    (
                        (st, sc) =>
                        new JoinQueryInfos(JoinType.Left, st.software_information_id == sc.software_information_id)
                    )
                    .Where((st, sc) => sc.software_device_number == deviceNumber && st.device_arm_id == armId&&st.lattice_num.Equals(latticeNum)&&st.lattice_state.Equals(1)).ToList();
                foreach(Lattice lattice in query)
                {
                    var filterQuery = db.Queryable<TabletopRelLattice>().Where(x => x.lattice_id.Equals(System.Convert.ToInt32(lattice.lattice_id)));
                    if(filterQuery!=null&&filterQuery.Count()>0)
                    {
                    }
                    else
                    {
                        return lattice;
                    }
                }
 
                return null;
            }
        }
        #endregion
 
        #region 查询返回台面板位数据集 by 设备臂Id、设备型号
        /// <summary>
        /// 查询返回台面板位数据集 by 设备臂Id、设备型号
        /// </summary>
        /// <param name="armId">设备臂Id</param>
        /// <param name="deviceNumber">设备型号</param>
        /// <returns>台面板位数据</returns>
        public static List<Lattice> GetTrashLatticeDataByIdFromdb(string armId, string deviceNumber)
        {
            int mid = System.Convert.ToInt32(armId);
 
            using (var db = GetInstance())
            {
                // 多表查询
                var query = db.Queryable<Lattice, SoftwareInformation>
                    (
                        (st, sc) =>
                        new JoinQueryInfos(JoinType.Left, st.software_information_id == sc.software_information_id)
                    )
                    .Where((st, sc) => sc.software_device_number == deviceNumber && st.device_arm_id == mid && st.is_trash == 1);
 
                return query.ToList();
            }
        }
        #endregion
 
        #region 修改台面板位数据 by 台面板位对象
        /// <summary>
        /// 修改台面板位数据 by 台面板位对象
        /// </summary>
        /// <param name="lattice">台面板位对象</param>
        /// <returns>1:成功;0:失败</returns>
        public static int UpdateLatticeIntodb(Lattice lattice)
        {
            using (var db = GetInstance())
            {
                return db.Updateable<Lattice>(lattice).ExecuteCommand();
            }
        }
        #endregion
 
        #region 查询返回台面板位数据 by 台面板位号、设备臂Id、设备型号、台面模板Id
        /// <summary>
        /// 查询返回台面板位数据 by 台面板位号、设备臂Id、设备型号、台面模板Id
        /// </summary>
        /// <param name="latticeNum">台面板位号</param>
        /// <param name="armId">设备臂Id</param>
        /// <param name="deviceNumber">设备型号</param>
        /// <param name="tabletopid">台面模板id</param>
        /// <returns>台面板位数据</returns>
        public static Lattice GetLatticeDataByLatticeNumAndTempIdFromdb(string latticeNum, int armId, string deviceNumber,string tabletopid)
        {
            using (var db = GetInstance())
            {
                // 多表查询
                //var query = db.Queryable<Lattice, SoftwareInformation>
                //    (
                //        (st, sc) =>
                //        new JoinQueryInfos(JoinType.Left, st.software_information_id == sc.software_information_id)
                //    )
                //    .Where((st, sc) => sc.software_device_number == deviceNumber && st.device_arm_id == armId && st.lattice_num.Equals(latticeNum)).Single();
 
                var query = db.Queryable("lattice", "t").AddJoinInfo("softwareinformation", "l", "t.software_information_id=l.software_information_id and l.software_device_number='"
                    + deviceNumber + "'"
                    + " and t.device_arm_id=" + armId.ToString() + ""
                    + " and t.lattice_num='" + latticeNum + "'"
                    + " and t.lattice_state=1", JoinType.Inner)
                    .AddJoinInfo("tabletoprellattice","tl", "t.lattice_id=tl.lattice_id and tl.tabletopid='" + tabletopid+"'", JoinType.Inner)
                    .Select("t.*");
 
                if (query != null)
                {
                    var a = query.ToList();
                    Lattice lattice = new Lattice();
                    foreach (ExpandoObject epo in a)
                    {
                        lattice = epo.ToEntity<Lattice>();
                        lattice.lattice_id= epo.ToArray().FirstOrDefault(x => x.Key.Equals("lattice_id")).Value.ToString();
                    }
                    var result = lattice;
                    return result;
                }
 
                return null;
            }
        }
        #endregion
    }
}