bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
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
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Common;
using System.Collections;
using System.Net;
 
namespace BLL
{
    public class DALTray
    {
        /// <summary>
        /// 查询托盘信息
        /// </summary>
        /// <param name="trayModel">托盘实体类</param>
        /// <param name="pageInfo">分页信息</param>
        /// <returns>托盘信息,实体</returns>
        public IList<Tray> GetList(TrayList trayModel, ref PageInfo pageInfo) 
        {
            try
            {
                IList<Tray> list = new List<Tray>();
                StringBuilder strSql = new StringBuilder();
 
                strSql.Append("Select * from View_Log_Store_Palno where 1 = 1 ");
                if (trayModel.Addre != null && trayModel.Addre != "") 
                {
                    strSql.Append(" and Addre like '%" + trayModel.Addre + "%'");
                }
                if (trayModel.Palno != null && trayModel.Palno != "")
                { 
                    strSql.Append(" and Palno like '%" + trayModel.Palno + "%'");
                }
                if (trayModel.ALock != null && trayModel.ALock != "")
                {
                    strSql.Append(" and ALockNo = '" + trayModel.ALock + "'");
                }
                if (trayModel.BeCreateTime != null && trayModel.BeCreateTime != DateTime.MinValue)
                {
                    strSql.Append(" and CreateTime >= '"+trayModel.BeCreateTime+"'");
                }
                if (trayModel.EnCreateTime != null && trayModel.EnCreateTime != DateTime.MinValue)
                {
                    strSql.Append(" and CreateTime <= '" + trayModel.EnCreateTime + "'");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), null, "CreateTime", "DESC", ref pageInfo);
 
                return  ModelConvertHelper<Tray>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取单行托盘信息
        /// </summary>
        /// <param name="Palno">托盘码</param>
        /// <returns>dataRow</returns>
        public Tray GetTrayModel(string Palno) 
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select * from View_Log_Store_Palno where palno = '" + Palno + "';");
                IDataReader dr = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
 
                return ModelConvertHelper<Tray>.ReaderToModel(dr);
            }
            catch (Exception)
            {
                return null;
            }
        }
 
        /// <summary>
        /// 新增编辑托盘
        /// </summary>
        /// <param name="trayModel">托盘信息集合</param>
        /// <returns>true:保存成功 false:保存失败</returns>
        public bool AddEdit(Tray trayModel) 
        {
            bool bl = false;
            try
            {
                int rowCount = 0;
                if (trayModel.Palno == "")
                {
                    // add托盘
                    string palnoNext = this.GetPalnoCode();
                    Hashtable ht = new Hashtable();
                    ht["Addre"] = "'" + trayModel.Addre + "'";
                    ht["Palno"] = "'" + palnoNext + "'";
                    ht["ALock"] = "'" + trayModel.ALock + "'";
                    ht["CreateTime"] = "convert(varchar(20),getdate(),120)";
                    ht["Demo"] = "'" + trayModel.Demo + "'";
                    ht["guid"] = "NEWID()";
 
                    rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("log_Store_Palno", ht);
                }
                else 
                {
                    // Edit托盘
                    Hashtable ht = new Hashtable();
                    ht["Addre"] = "'" + trayModel.Addre + "'";
                    ht["CreateTime"] = "'" + trayModel.CreateTime + "'";
                    ht["Demo"] = "'" + trayModel.Demo + "'";
                    rowCount = DataFactory.SqlDataBase().UpdateByHashtable("log_Store_Palno", "Palno", trayModel.Palno, ht);
                }
 
                if (rowCount == 1)
                {
                    bl = true;
                }
            }
            catch (Exception)
            {
                bl = false;
            }
 
            return bl;
        }
 
        /// <summary>
        /// 删除托盘
        /// </summary>
        /// <param name="Palnolist">须删除项主键集合</param>
        /// <returns>true:删除成功 false:删除失败</returns>
        public bool Delete(string[] Palno) 
        {
            bool bl = false;
            try
            {
                // 后期可根据库存明细,来限制托盘的删除。
                int rowCount = DataFactory.SqlDataBase().BatchDeleteData("log_Store_Palno", "Palno", Palno);
                if (rowCount >= Palno.Length) 
                {
                    bl = true;
                }
 
                return bl;
            }
            catch (Exception)
            {
                return bl;
            }
        }
 
        /// <summary>
        /// 获取货位信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetGoodsPosPrint(string StorageNo) 
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                if (StorageNo != "")
                {
                    strSql.Append("select Addre from GoodsPos where StorageAraeNo = '" + StorageNo + "'; ");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
 
                return dt;
            }
            catch (Exception)
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取单个货位信息
        /// </summary>
        /// <param name="Addre"></param>
        /// <returns></returns>
        public DataTable GetGoodsPos(string Addre) 
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                if (Addre != "")
                {
                    strSql.Append("select tb1.Addre,tb2.StorageName from GoodsPos as tb1 ");
                    strSql.Append("left join StorageArea as tb2 on tb1.StorageAraeNo = tb2.StorageNo ");
                    strSql.Append("where tb1.Addre = '"+ Addre + "';");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
 
                return dt;
            }
            catch (Exception)
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 打印托盘信息
        /// </summary>
        /// <param name="Addre"></param>
        /// <param name="TrayNo"></param>
        /// <returns></returns>
        public DataTable GetTrayPrint(string Addre,string TrayNo) 
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select tb1.Addre,tb2.StorageName,tb3.Palno from GoodsPos as tb1 ");
                strSql.Append("left join StorageArea as tb2 on tb1.StorageAraeNo = tb2.StorageNo ");
                strSql.Append("left join log_Store_Palno as tb3 on tb1.Addre = tb3.Addre ");
 
                if (Addre != "")
                {
                    strSql.Append("where tb1.Addre = '" + Addre + "';");
                }
                else if (TrayNo != "") 
                {
                    strSql.Append("where tb3.Palno = '" + TrayNo + "';");
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
 
                return dt;
            }
            catch (Exception)
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取最大托盘码
        /// </summary>
        /// <returns></returns>
        private string GetPalnoCode() 
        {
            StringBuilder sbstr = new StringBuilder();
            try
            {
                string palno = "00000001";
                sbstr.Append("select isnull(max(palno)+1,'0') as palno from log_Store_Palno;");
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sbstr);
 
                if (dt.Rows[0][0].ToString() != "0") 
                {
                    palno = dt.Rows[0][0].ToString().PadLeft(8,'0');
                }
 
                return palno;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}