wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Linq;
using System.Text;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.BllCheckEntity;
using WMS.Entity.BllSoEntity;
using WMS.Entity.Context;
using WMS.Entity.LogEntity;
using WMS.Entity.SysEntity;
 
namespace WMS.DAL
{
    public class Common
    {
        //public static readonly DataContext Db = new DataContext();
 
 
        /// <summary>
        /// 获取深度为1的储位号(根据深度为2的储位号)
        /// </summary>
        /// <param name="houseNo">仓库号</param>
        /// <param name="locateNo">储位号</param>
        /// <returns></returns>
        public SysStorageLocat GetLocateNoDepth1(string houseNo, string locateNo)
        {
            try
            {
                var Db = DataContext.Db;
                var ceshi = Db.Queryable<SysStorageLocat>()
                    .Where(m => m.IsDel == "0" && m.WareHouseNo == houseNo && m.LocatNo == locateNo).ToList();
 
                //获取储位信息
                var sql = $@"select * from SysStorageLocat where  WareHouseNo = '{houseNo}' and LocatNo = '{locateNo}'; ";
                var locate = Db.Ado.SqlQuery<SysStorageLocat>(sql).First();
                if (locate == null)
                {
                    throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的信息");
                }
                //获取深度为2的储位信息
                var sql2 = $@"select * from SysStorageLocat where  WareHouseNo = '{houseNo}' and row = {locate.Row} and [Column] = {locate.Column} and Layer = {locate.Layer} and Depth = '01'; ";
                var data = Db.Ado.SqlQuery<SysStorageLocat>(sql2).First();
                if (data == null)
                {
                    throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的里面储位信息");
                }
 
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 获取深度为2的储位号(根据深度为1的储位号)
        /// </summary>
        /// <param name="houseNo">仓库号</param>
        /// <param name="locateNo">储位号</param>
        /// <returns></returns>
        public SysStorageLocat GetLocateNoDepth2(string houseNo, string locateNo)
        {
            try
            {
                var Db = DataContext.Db;
                //获取储位信息
                var sql = $@"select * from SysStorageLocat where  WareHouseNo = '{houseNo}' and LocatNo = '{locateNo}'; ";
                var locate = Db.Ado.SqlQuery<SysStorageLocat>(sql).First();
                if (locate == null)
                {
                    throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的信息");
                }
                //获取深度为2的储位信息
                var sql2 = $@"select * from SysStorageLocat where  WareHouseNo = '{houseNo}' and row = {locate.Row} and [Column] = {locate.Column} and Layer = {locate.Layer} and Depth = '02'; ";
                var data = Db.Ado.SqlQuery<SysStorageLocat>(sql2).First();
                if (data == null)
                {
                    throw new Exception($"未查询到仓库号为{houseNo}、储位号为{locateNo}的里面储位信息");
                }
                return data;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 根据前缀获取最大单据号
        /// </summary>
        /// <param name="codeFlag">单据前缀</param>
        /// <returns></returns>
        public string GetMaxNo(string codeFlag)
        {
            try
            {
                var maxNo = "";
                //获取异常号
                maxNo = SelectMaxNo(codeFlag);
                if (!string.IsNullOrEmpty(maxNo))
                {
                    maxNo = maxNo.Substring(codeFlag.Length);
                }
                //获取数据库时间八位
                string date = DateTime.Now.ToString("yyyyMMdd").Trim();
                string no = "";
                if (string.IsNullOrEmpty(maxNo))
                {
                    no = codeFlag + date + "00001";
                }
                else
                {
                    if (maxNo.Substring(0, 8) == date)
                    {
                        int lastNo = Convert.ToInt32(maxNo.Substring(8, 5)) + 1;
                        no = codeFlag + date + (lastNo.ToString().PadLeft(5, '0'));
                    }
                    else
                    {
                        no = codeFlag + date + "00001";
                    }
                }
                return no;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        /// <summary>
        /// 根据前缀判断出当前最大单据号
        /// </summary>
        /// <param name="codeFlag">单据前缀</param>
        /// <returns></returns>
        public string SelectMaxNo(string codeFlag)
        {
            try
            {
                string orderNo = "";
                if (codeFlag == InOutFlag.SO.ToString())//出库
                {
                    var list = DataContext.Db.Queryable<BllExportNotice>().Where(m => m.SONo.StartsWith("SO")).ToList();
                    orderNo = list.Max(a => a.SONo);
                }
                if (codeFlag == InOutFlag.WSO.ToString())//波次出库
                { 
                }
                else if (codeFlag == InOutFlag.ASN.ToString())//入库
                {
                    var list = DataContext.Db.Queryable<BllArrivalNotice>().Where(m => m.ASNNo.StartsWith("ASN")).ToList();
                    orderNo = list.Select(a => a.ASNNo).Max();
                }
                else if (codeFlag == InOutFlag.PM.ToString())//移库
                { 
                }
                else if (codeFlag == InOutFlag.CR.ToString())//盘点
                {
                    var list = DataContext.Db.Queryable<BllStockCheck>().Where(m => m.CRNo.StartsWith("CR")).ToList();
                    orderNo = list.Select(a => a.CRNo).Max();
                }
                else if (codeFlag == InOutFlag.TK.ToString())//任务
                {
                    var list = DataContext.Db.Queryable<LogTask>().Where(m => m.TaskNo.StartsWith("TK")).ToList();
                    orderNo = list.Max(m=>m.TaskNo);
                }
                else if (codeFlag == InOutFlag.EX.ToString())//异常
                {
                    var list = DataContext.Db.Queryable<SysException>().Where(m => m.ExceptionNo.StartsWith("EX")).ToList();
                    orderNo = list.Max(a => a.ExceptionNo);
                }
 
                return orderNo;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 
        /// <summary>
        /// 执行sql语句获取行数
        /// </summary>
        /// <param name="sqlString">查询语句</param>
        /// <returns>行数</returns>
        public int GetRowCount(string sqlString) 
        {
            try
            {
                var db = DataContext.Db;
                var rowCount = db.Ado.GetInt(sqlString);
 
                return rowCount;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 
        /// <summary>
        /// 判断托盘是否在入库中
        /// </summary>
        /// <param name="palletNo">托盘号</param>
        /// <returns></returns>
        public LogTask GetImTask(string palletNo)
        {
            try
            {
                var db = DataContext.Db;
                //查询托盘是否有正在入库的任务
                var imTask = db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "1");
                 
                return imTask;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 
    }
    public enum InOutFlag
    {
        /// <summary>
        /// 入库单
        /// </summary>
        [Description("入库单")]
        ASN,
        /// <summary>
        /// 出库单
        /// </summary>
        [Description("出库单")]
        SO,
        /// <summary>
        /// 波次出库单
        /// </summary>
        [Description("波次出库单")]
        WSO,
        /// <summary>
        /// 出库单
        /// </summary>
        [Description("盘点单")]
        CR,
        /// <summary>
        /// 移库单
        /// </summary>
        [Description("移库单")]
        PM,
        
        /// <summary>
        /// 任务
        /// </summary>
        [Description("任务")]
        TK,
        /// <summary>
        /// 异常号 
        /// </summary>
        [Description("异常")]
        EX
    }
}