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
using DataEntity;
using DataRWDAL;
using DataRWDAL.Base;
using HxEnum;
using MySql.Data.MySqlClient;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XCommon.Log;
using XCommon.MySql;
 
namespace XImagingXhandler.XDAL
{
    /// <summary>
    /// 台面模板内板位关联操作类
    /// </summary>
    public class TabletopRelLatticeDB:BaseDB
    {
        #region 删除某台面模板内的所有板位数据
        /// <summary>
        /// 删除某台面模板内的所有板位数据
        /// </summary>
        /// <param name="tabletopid">台面模板Id</param>
        /// <returns>1:成功;0:失败;</returns>
        public static int DeleteTabletopRelLatticeIntodb(string tabletopid)
        {
            using (var db = GetInstance())
            {
                int sum = 0;//执行的总数
                var query = db.Queryable<TabletopRelLattice>().Where(it => it.tabletopid.Equals(tabletopid)).ToList();
                if(query!=null&&query.Count()>0)
                {
                    foreach(var item in query) 
                    {
                        Lattice lattice = LatticeDB.GetLatticeDataByIdFromdb(item.lattice_id.ToString());
                        lattice.lattice_state = 0;
                        int ret=DeleteLatticeFromdb(lattice);
                        if (ret == 1)
                        {
                            sum++;
                        }
                    }
 
                    if (sum == query.Count)
                    {
                        return 1;
                    }
                }
 
                return 0;
            }
        }
        #endregion
 
        #region 删除指定的台面模板内的板位数据
        /// <summary>
        /// 删除指定的台面模板内的板位数据
        /// </summary>
        /// <param name="lattice">板位</param>
        /// <returns>1:成功;0:失败;</returns>
        public static int DeleteLatticeFromdb(Lattice lattice)
        {
            using (var db = GetInstance())
            {
                return db.Updateable<Lattice>(lattice).ExecuteCommand();
            }
        }
        #endregion
 
        #region 更新指定的台面模板内的板位数据
        /// <summary>
        /// 更新指定的台面模板内的板位数据
        /// </summary>
        /// <param name="lattice">板位</param>
        /// <returns>1:成功;0:失败;</returns>
        public static int UpdateLatticeFromdb(Lattice lattice)
        {
            using (var db = GetInstance())
            {
                return db.Updateable<Lattice>(lattice).ExecuteCommand();
            }
        }
        #endregion
 
        #region 更新指定的台面模板与板位关系数据
        /// <summary>
        /// 更新指定的台面模板与板位关系数据
        /// </summary>
        /// <param name="tabletopRelLattice">台面与板位关系对象</param>
        /// <returns>1:成功;0:失败;</returns>
        public static int UpdateTabletopRelLatticeFromdb(TabletopRelLattice tabletopRelLattice)
        {
            using (var db = GetInstance())
            {
                return db.Updateable<TabletopRelLattice>(tabletopRelLattice).Where(it=>it.tabletopid.Equals(tabletopRelLattice.tabletopid)
                                                                               &&it.lattice_id.Equals(tabletopRelLattice.lattice_id)).ExecuteCommand();
            }
        }
        #endregion
 
        #region 获取当前最大的台面板位Id
        /// <summary>
        /// 获取当前最大的台面板位Id
        /// </summary>
        /// <returns>最大板位Id</returns>
        public static int GetMaxLattceId()
        {
            using (var db = GetInstance())
            {
                return db.Queryable<Lattice>().ToList().Count;
            }
        }
        #endregion
 
        #region 获取台面板位关系数据 通过台面Id和板位Id
        /// <summary>
        /// 获取台面板位关系数据 通过台面Id和板位Id
        /// </summary>
        /// <param name="latticeId">板位Id</param>
        /// <param name="tabletopId">台面Id</param>
        /// <returns>台面板位关系数据</returns>
        public static TabletopRelLattice GetTabletopRelLatticeByTabletopIdAndLatticeId(string tabletopId,int latticeId)
        {
            using (var db = GetInstance())
            {
                return db.Queryable<TabletopRelLattice>().Single(it => it.tabletopid.Equals(tabletopId) && it.lattice_id.Equals(latticeId));
            }
        }
        #endregion
 
        #region 批量添加板位数据
        /// <summary>
        /// 批量添加板位数据
        /// </summary>
        /// <param name="lattice">板位对象</param>
        /// <param name="startLatticeid">开始板位Id</param>
        /// <param name="tabletopId">台面模板Id</param>
        /// <returns></returns>
        public static int AddLatticeIntodb(Lattice lattice,int startLatticeid,string tabletopId)
        {
            using (var db = GetInstance())
            {
                int sum = 0;//执行的总数
                //for (int i = 0; i < lattices.Count; i++)
                //{
 
                    lattice.lattice_id = (startLatticeid).ToString();
                    db.Insertable<Lattice>(lattice).ExecuteCommand();
 
                    int ret=db.Insertable<TabletopRelLattice>(new TabletopRelLattice() { lattice_id = (startLatticeid), tabletopid = tabletopId, 
                        lattice_pixel_x = lattice.lattice_pixel_x,
                        lattice_pixel_y = lattice.lattice_pixel_y,
                        labware_id= lattice.labware_id,
                        isbaselattice = 1
                    }).ExecuteCommand();
                    sum++;
                //}
 
                //if(sum==lattices.Count)
                //{
                if(ret>0)
                {
                    return ret;
                }
                //}
                
                return 0;
            }
        }
        #endregion
    }
}