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
using Commom.Utility;
using Common;
using Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
 
namespace BLL.DAL
{
    public class DALDepotsLocation
    {
        public DataTable GetDictionaryItems() 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from Dictionary where IsDel = 0 and topCode is not null ");
                stringBuilder.Append("order by Ord ;");
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
                return dt;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public IList<DepotsLocation> GetDepotsLocationItems(QueryDLocation dLocation, ref PageInfo page) 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from View_RepotsLocation_DepotsArea where IsDel = 0 ");
                // 库区
                if (dLocation.DepotsAreaID != null && dLocation.DepotsAreaID != "")  
                {
                    stringBuilder.Append(" and DepotsAreaID = " + dLocation.DepotsAreaID.AddQuotes());
                }
                // 排、列、层
                if (dLocation.LRow != 0) 
                {
                    stringBuilder.Append(" and LRow = " + dLocation.LRow);
                }
                if (dLocation.LColumn != 0)
                {
                    stringBuilder.Append(" and LColumn = " + dLocation.LColumn);
                }
                if (dLocation.LLayer != 0)
                {
                    stringBuilder.Append(" and LLayer = " + dLocation.LLayer);
                }
                // 编码及库位各属性
                if (dLocation.LocationCode != null && dLocation.LocationCode != "")  
                {
                    stringBuilder.Append(" and LocationCode like '%" + dLocation.LocationCode+ "%'");
                }
                if (dLocation.PropertyID != null && dLocation.PropertyID != "")
                {
                    stringBuilder.Append(" and PropertyID = " + dLocation.PropertyID.AddQuotes());
                }
                if (dLocation.TurnoverDemandID != null && dLocation.TurnoverDemandID != "")
                {
                    stringBuilder.Append(" and TurnoverDemandID = " + dLocation.TurnoverDemandID.AddQuotes());
                }
                if (dLocation.TypeID != null && dLocation.TypeID != "")
                {
                    stringBuilder.Append(" and TypeID = " + dLocation.TypeID.AddQuotes());
                }
 
                SqlParam[] para = new SqlParam[]
                {
                };
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(stringBuilder.ToString(), para, "LocationCode", "DESC", ref page);
                IList<DepotsLocation> list = ModelConvertHelper<DepotsLocation>.DataTableToModel(dt);
 
                return list;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        public IList<DepotsLocation> GetDepotsLocationItems(string guid) 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from View_RepotsLocation_DepotsArea where IsDel = 0  ");
                if (guid != null && guid != "")
                {
                    stringBuilder.Append(" and Guid = " + guid.AddQuotes());
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
                return ModelConvertHelper<DepotsLocation>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public bool SetDLocations(DepotsLocation DLocation, string loginUser)
        {
            try
            {
                bool bl = false;
                int rowCount = 0;
 
                Hashtable ht = new Hashtable();
                ht["Type"] = DLocation.Type.AddQuotes();
                ht["Property"] = DLocation.Property.AddQuotes();
                ht["TurnoverDemand"] = DLocation.TurnoverDemand.AddQuotes();        // 库位状态
 
                ht["Long"] = DLocation.Long;
                ht["Width"] = DLocation.Width;
                ht["Height"] = DLocation.Height;
                ht["IsProduct"] = DLocation.IsProduct;
                ht["IsBatch"] = DLocation.IsBatch;
                ht["Weight"] = DLocation.Weight;
                ht["Volume"] = DLocation.Volume;
                ht["Demo"] = DLocation.Demo.AddQuotes();
                ht["UpdateTime"] = "convert(varchar(20),getdate(),120)";
                ht["UpdateUser"] = loginUser.AddQuotes();
 
                rowCount = DataFactory.SqlDataBase().UpdateByHashtable("DepotsLocation",
                    "Guid", DLocation.Guid.AddQuotes(), ht);
                
 
                if (rowCount > 0)
                {
                    bl = true;
                }
 
                return bl;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public DataTable GetChartItmes(string pai) 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
 
                stringBuilder.Append(@"select (LColumn-1) as LColumn,(LLayer-1) as LLayer,
case cast(TurnoverDemand as int) when 2 then 
    case (select top 1 isnull(MatNo,'') from log_Store where LocationCode = tb1.LocationCode) when '' then 5 else cast(TurnoverDemand as int) end 
else cast(TurnoverDemand as int) end as TurnoverDemand
from DepotsLocation as tb1
where LRow = '"+pai+"' and Property in ('02','03');");
 
                // liudl 增加空托盘展示
                //stringBuilder.Append("select (LColumn-1) as LColumn,(LLayer-1) as LLayer, " +
                //    "cast(TurnoverDemand as int) as TurnoverDemand from DepotsLocation where LRow = '" + pai +"' ");
                //stringBuilder.Append("and Property in ('02','03');");
 
                return DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        /// <summary>
        /// 获取立体库货位状态
        /// </summary>
        /// <returns></returns>
        public DataTable GetCharts() 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select cast(TurnoverDemand as int) as TurnoverDemand,COUNT(*) as rowNum " +
                    "from DepotsLocation group by cast(TurnoverDemand as int); ");
 
                return DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 删除区域(逻辑删除)
        /// </summary>
        /// <param name="regionCodes"></param>
        /// <param name="loginUser"></param>
        /// <returns>true:成功 false:失败</returns>
        public bool DelLocations(string[] DepotsAreaGuids, string loginUser)
        {
            try
            {
                bool bl = false;
                int rowCount = 0;
                Hashtable ht = new Hashtable();
                foreach (string DepotsAreaGuid in DepotsAreaGuids)
                {
                    ht["IsDel"] = 1;
                    rowCount += DataFactory.SqlDataBase().UpdateByHashtable("DepotsLocation",
                            "Guid", DepotsAreaGuid.AddQuotes(), ht);
                }
 
                if (rowCount > 0)
                {
                    bl = true;
                }
 
                return bl;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 验证库位是否操作员所属部门占用  
        /// </summary>
        /// <param name="Guid"></param>
        /// <param name="DepartGuid"></param>
        /// <returns>true:是本部门 False:不是本部门</returns>
        public bool CheckDepartment(string Guid,string DepartGuid) 
        {
            try
            {
                bool bl = false;
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append($"select count(*) from log_Store where IsDel = '0' and DepartGuid = '"+ DepartGuid + "' " +
                    $"and LocationCode in (select LocationCode from DepotsLocation where guid = '"+ Guid + "') ");
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
 
                if (dt.Rows[0][0].ToString() == "0")
                {
                    bl = true;
                }
 
                return bl;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
    }
}