杨前锦
2025-06-11 e0d89637030791ce1e7dd46ca5fdec9979977960
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
using HH.WCS.Mobox3.HD.models;
using HH.WCS.Mobox3.HD.util;
using System;
using System.Collections.Generic;
using static HH.WCS.Mobox3.HD.util.ExpressionHelper;
using System.Linq.Expressions;
using System.Linq;
 
namespace HH.WCS.Mobox3.HD.wms
{
    internal class MouldHelper
    {
        
        internal static MouldCntr GetMouldCntr(MouldCntr mouldCntrTemplate)
        {
            var db = new SqlHelper<object>().GetInstance();
            var query = db.Queryable<MouldCntr>(); 
            if (mouldCntrTemplate.S_MOULD_NO != null) {
                query.Where(a => a.S_MOULD_NO == mouldCntrTemplate.S_MOULD_NO || a.S_ITEM_CODE == mouldCntrTemplate.S_MOULD_NO);
            }
            if (mouldCntrTemplate.S_CNTR_CODE != null)
            {
                query.Where(a => a.S_CNTR_CODE == mouldCntrTemplate.S_CNTR_CODE);
            }
            if (mouldCntrTemplate.S_LOC_CODE != null)
            {
                query.Where(a => a.S_LOC_CODE == mouldCntrTemplate.S_LOC_CODE);
            }
            if (mouldCntrTemplate.S_ABLE_FLAG != null)
            {
                query.Where(a => a.S_ABLE_FLAG == mouldCntrTemplate.S_ABLE_FLAG);
            }
 
            MouldCntr mouldCntr = query.First();
 
            if (mouldCntr != null)
            {
                // 加载相关的 MouldDetail 记录  
                List<MouldDetail> mouldDetails = db.Queryable<MouldDetail>().Where(a => a.S_MOULD_NO == mouldCntr.S_MOULD_NO).ToList();
                mouldCntr.mouldDetails = mouldDetails; 
            }
 
            return mouldCntr;
        }
 
        internal static List<MouldCntr> GetMouldCntrList(MouldCntr mouldCntrTemplate)
        {
            var db = new SqlHelper<object>().GetInstance();
            var query = db.Queryable<MouldCntr>();
            if (mouldCntrTemplate.S_MOULD_NO != null)
            {
                query.Where(a => (a.S_MOULD_NO == mouldCntrTemplate.S_MOULD_NO || a.S_ITEM_CODE == mouldCntrTemplate.S_MOULD_NO));
            }
            if (mouldCntrTemplate.S_CNTR_CODE != null)
            {
                query.Where(a => a.S_CNTR_CODE == mouldCntrTemplate.S_CNTR_CODE);
            }
            if (mouldCntrTemplate.S_LOC_CODE != null)
            {
                query.Where(a => a.S_LOC_CODE == mouldCntrTemplate.S_LOC_CODE);
            }
            var mouldCntrs = query.Where(a => a.S_STATUS == "Y" && a.S_ABLE_FLAG == "是").ToList();
            return mouldCntrs;
        }
 
        internal static MouldCntr GetMouldCntrByLoc(string locCode)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<MouldCntr>().Where(a => a.S_LOC_CODE == locCode).First(); 
        }
        internal static MouldCntr GetMouldCntrByCntr(string cntrNo)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<MouldCntr>().Where(a => a.S_CNTR_CODE == cntrNo).First();
        }
 
        internal static MouldCntr GetMouldCntr(string mouldNo)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<MouldCntr>().Where(a => a.S_MOULD_NO == mouldNo).First();
        }
 
        internal static List<MouldDetail> GetMouldDetails (string mouldNo )
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Queryable<MouldDetail>().Where(a => a.S_MOULD_NO == mouldNo).ToList();
        }
 
        internal static bool deleteMould(string mouldNo)
        {
            bool result = false;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                db.BeginTran();
                var mouldCntr = db.Queryable<MouldCntr>().Where(a => a.S_MOULD_NO == mouldNo).First();
                if (mouldCntr != null) {
                    int count = db.Deleteable<MouldCntr>().Where(a => a.S_MOULD_NO == mouldNo).ExecuteCommand();
                    if (count > 0)
                    {
                        result = db.Deleteable<MouldDetail>().Where(a => a.S_MOULD_NO == mouldNo).ExecuteCommand() > 0;
                        if (result)
                        {
                            var container = ContainerHelper.GetCntr(mouldCntr.S_CNTR_CODE);
                            container.N_DETAIL_COUNT = 0;
                            db.Updateable(container).ExecuteCommand();
                        }
                    }
                }
                db.CommitTran();
                return result;
            }
            catch (Exception ex) {
                db.RollbackTran();
                LogHelper.Info("删除模具异常-deleteMould,error:"+ex.Message, "mobox");
            }
            return result;
        }
 
        internal static bool deleteMouldByCntr(string cntrCode)
        {
            bool result = false;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                db.BeginTran();
                var mouldCntr = db.Queryable<MouldCntr>().Where(a => a.S_CNTR_CODE.Trim() == cntrCode).First();
                int count = db.Deleteable<MouldCntr>().Where(a => a.S_MOULD_NO == mouldCntr.S_MOULD_NO).ExecuteCommand();
                if (count > 0)
                {
                    result = db.Deleteable<MouldDetail>().Where(a => a.S_MOULD_NO == mouldCntr.S_MOULD_NO).ExecuteCommand() > 0;
                }
                db.CommitTran();
                return result;
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                LogHelper.Info("删除模具异常-deleteMould,error:" + ex.Message, "mobox");
            }
            return result;
        }
 
        /// <summary>
        /// 更新模具数量
        /// </summary>
        /// <param name="mouldDetails"></param>
        /// <returns></returns>    
        internal static bool updateMouldNum(List<MouldDetail> mouldDetails)
        {
            var db = new SqlHelper<object>().GetInstance();
            mouldDetails.ForEach(it =>
            {
                db.Updateable<MouldDetail>(it).UpdateColumns(a => a.N_QTY).ExecuteCommand();
            });
            return true;
        }
        /// <summary>
        /// 更新模具状态
        /// </summary>
        /// <param name="cntrCode"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        internal static bool updateMouldStatus(string cntrCode ,string status)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Updateable<MouldCntr>().SetColumns(a => a.S_STATUS == status).Where(a => a.S_CNTR_CODE == cntrCode).ExecuteCommand() > 0;
        }
 
        /// <summary>
        /// 更新模具状态
        /// </summary>
        /// <param name="mouldCntr"></param>
        /// <returns></returns>
        internal static bool updateMouldStatus(MouldCntr mouldCntr)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Updateable<MouldCntr>(mouldCntr).UpdateColumns(a => new { a.S_ABLE_FLAG  ,a.S_STATUS }).ExecuteCommand() > 0;
        }
 
        /// <summary>
        /// 添加模具
        /// </summary>
        /// <param name="mouldCntr"></param>
        /// <returns></returns>
        internal static bool addMould(MouldCntr mouldCntr)
        {
            var db = new SqlHelper<object>().GetInstance();
            return db.Insertable<MouldCntr>(mouldCntr).ExecuteCommand() > 0;
        }
 
        /// <summary>
        /// 添加子模具
        /// </summary>
        /// <param name="mouldDetails"></param>
        /// <returns></returns>
        internal static void batchAddChildMould(List<MouldDetail> mouldDetails)
        {
            var db = new SqlHelper<object>().GetInstance();
            foreach (MouldDetail item in mouldDetails)
            {
                db.Insertable<MouldDetail>(item).ExecuteCommand();
            }
        }
 
    }
}