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
using Common;
using Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace BLL.DAL
{
   public class DALPicking
    {
        public IList<Picking> GetList(AjaxErpOutList Json, ref PageInfo page)
        {
            try
            {
                IList<Picking> list = new List<Picking>();
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
                strSql.Append("Select * from Picking where 1 = 1");
                if (!string.IsNullOrEmpty(Json.OrdNo))
                {
                    strSql.Append(" and OrdNo like '%' + @OrdNo + '%'");
                    para.Add(new SqlParam("@OrdNo",Json.OrdNo));
                }
                if (!string.IsNullOrEmpty(Json.Statu))
                {
                    strSql.Append(" and IsDel = @Statu");
                    para.Add(new SqlParam("@Statu",Json.Statu));
                }
                else
                {
                    strSql.Append(" and IsDel = 0");
                }
                //if (Json.BeginTime != DateTime.MinValue && Json.BeginTime != null && Json.BeginTime != DateTime.MaxValue)
                //{
                //    strSql.Append(" and ");
                //    strSql.Append("CreateTime >= @CreateTime1 ");
                //    para.Add(new SqlParam("@CreateTime1", Convert.ToDateTime(Json.BeginTime)));
                //}
 
                //if (Json.EndTime != DateTime.MinValue && Json.EndTime != null && Json.EndTime != DateTime.MaxValue)
                //{
                //    strSql.Append(" and ");
                //    strSql.Append("CreateTime <= @CreateTime2 ");
                //    para.Add(new SqlParam("@CreateTime2", Convert.ToDateTime(Json.EndTime)));
                //}
 
                SqlParam[] param = null;
                if (para != null)
                    param = para.ToArray();
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "ID", "asc", ref page);
                list = ModelConvertHelper<Picking>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
 
        }
        /// <summary>
        /// 回库逻辑判断下发指令
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public bool Out(string[] json, string CreateUser)
        {
            bool result = false;
            try
            {
                StringBuilder strSql = new StringBuilder();
                //获取单号下货位
                strSql.Append("Select OrdNo,Addre,Palno from Picking where ID ='" + json[0] + "' and IsDel=0 ");
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
 
                for (int i = 0; i < dt.Rows.Count; i++)
                {
 
                    //判断货位是里层还是外层
                    if (dt.Rows[i]["Addre"].ToString().IndexOf("-001") >= 0 || dt.Rows[i]["Addre"].ToString().IndexOf("-004") >= 0)
                    {
                        string pai1 = "";
                        string pai2 = "";
                        //是里层判断外层是否是空货位,不是则先移库
                        if (dt.Rows[i]["Addre"].ToString().IndexOf("-001") >= 0)
                        {
                            pai1 = "-001";
                            pai2 = "-002";
                        }
                        else
                        {
                            pai1 = "-004";
                            pai2 = "-003";
                        }
                        StringBuilder seladdre = new StringBuilder();
                        seladdre.Append("Select Addre,Palno,DepotsLocation.Height from log_Store ");
                        seladdre.Append("left join DepotsLocation on log_Store.Addre = DepotsLocation.LocationCode ");
                        seladdre.Append("where Addre = '" + dt.Rows[i]["Addre"].ToString().Replace(pai1, pai2) + "' and DepotsLocation.TurnoverDemand in ('02') ");
                        seladdre.Append("group by Addre,Palno,DepotsLocation.Height;");
 
                        //seladdre.Append("Select Addre,Palno from log_Store where Addre ='" + dt.Rows[i]["Addre"].ToString().Replace(pai1, pai2) + "'");
                        DataTable dd = DataFactory.SqlDataBase().GetDataTableBySQL(seladdre);
                        if (dd.Rows.Count > 0)
                        {
                            if (dd.Rows.Count > 1) 
                            {
                                return false;
                            }
 
                            string moveaddre = "";
                            string oriPos = dt.Rows[0]["Addre"].ToString().Replace(pai1, pai2);
                            int height = int.Parse(dt.Rows[0]["Height"].ToString());
                            DAL_Pub pub = new DAL_Pub();
                            int move = pub.GetEmptyPos(ref moveaddre, height, oriPos);
                            //外层有托盘则先移库再回库
                            if (moveaddre.IndexOf("-001") >= 0 || moveaddre.IndexOf("-004") >= 0)
                            {
                                string ad1 = "";
                                string ad2 = "";
                                if (moveaddre.IndexOf("-001") >= 0)
                                {
                                    ad1 = "-001";
                                    ad2 = "-002";
                                }
                                else
                                {
                                    ad1 = "-004";
                                    ad2 = "-003";
                                }
                                //判断空货位外层是否是空位,是直接移库,不是外层托盘移向里层再移库
                                StringBuilder sql = new StringBuilder();
                                sql.Append("Select LocationCode,log_Store.Palno from DepotsLocation Select LocationCode,log_Store.Palno from DepotsLocation  left join log_Store on DepotsLocation.LocationCode = log_Store.Addre where LocationCode ='" + moveaddre.Replace(ad1, ad2) + "' and TurnoveDemand='01' ");
 
                                DataTable ad = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
                                if (ad.Rows.Count > 0)
                                {
                                    Hashtable ht = new Hashtable();
                                    ht["CMDType"] = "'move'";
                                    ht["Palno"] = "'" + ad.Rows[0]["Palno"].ToString() + "'";
                                    ht["OldAddre"] = "'" + ad.Rows[0]["Addre"].ToString() + "'";
                                    ht["NowAddre"] = "'"+moveaddre+"'";
                                    ht["CMDStatu"] = "0";
                                    ht["CreateUser"] = "'" + CreateUser + "'";
                                    int moveadd = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", ht);
 
                                    Hashtable ht1 = new Hashtable();
                                    ht1["CMDType"] = "'move'";
                                    ht1["Palno"] = "'" + dd.Rows[0]["Palno"].ToString() + "'";
                                    ht1["OldAddre"] = "'" + dd.Rows[0]["Addre"].ToString() + "'";
                                    ht1["NowAddre"] = "'" + ad.Rows[0]["LocationCode"].ToString() + "'";
                                    ht1["CMDStatu"] = "0";
                                    ht1["CreateUser"] = "'" + CreateUser + "'";
                                    int moveadd1 = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", ht1);
                                }
                                else
                                {
                                    Hashtable ht = new Hashtable();
                                    ht["CMDType"] = "'move'";
                                    ht["Palno"] = "'" + dd.Rows[0]["Palno"].ToString() + "'";
                                    ht["OldAddre"] = "'" + dd.Rows[0]["Addre"].ToString() + "'";
                                    ht["NowAddre"] = "'"+moveaddre+"'";
                                    ht["CMDStatu"] = "0";
                                    ht["CreateUser"] = "'" + CreateUser + "'";
                                    int moveadd = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", ht);
                                }
                            }
                            else
                            {
                                Hashtable ht = new Hashtable();
                                ht["CMDType"] = "'move'";
                                ht["Palno"] = "'" + dt.Rows[i]["Palno"].ToString() + "'";
                                ht["OldAddre"] = "'" + dt.Rows[i]["Addre"].ToString() + "'";
                                ht["NowAddre"] = "'"+moveaddre+"'";
                                ht["CMDStatu"] = "0";
                                ht["CreateUser"] = "'" + CreateUser + "'";
                                int moveadd = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", ht);
                            }
                            Hashtable hy = new Hashtable();
                            hy["TaskID"] = "'"+dt.Rows[i]["OrdNo"].ToString()+"'";
                            hy["CMDType"] = "'to'";
                            hy["Palno"] = "'" + dt.Rows[i]["Palno"].ToString() + "'";
                            hy["CMDStatu"] = "0";
                            hy["CreateUser"] = "'" + CreateUser + "'";
                            int outadd = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", hy);
 
                        }
                        else
                        {
                            //外层没有托盘直接回库
                            Hashtable ht = new Hashtable();
                            ht["TaskID"] = "'" + dt.Rows[i]["OrdNo"].ToString() + "'";
                            ht["CMDType"] = "'to'";
                            ht["Palno"] = "'" + dt.Rows[i]["Palno"].ToString() + "'";
                            ht["OldAddre"] = "'" + dt.Rows[i]["Addre"].ToString() + "'";
                            ht["CMDStatu"] = "0";
                            ht["CreateUser"] = "'" + CreateUser + "'";
                            int outadd = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", ht);
 
                        }
 
                    }//是外层则直接出库下发指令
                    else
                    {
                        Hashtable ht = new Hashtable();
                        ht["TaskID"] = "'" + dt.Rows[i]["OrdNo"].ToString() + "'";
                        ht["CMDType"] = "'to'";
                        ht["Palno"] = "'" + dt.Rows[i]["Palno"].ToString() + "'";
                        ht["OldAddre"] = "'" + dt.Rows[i]["Addre"].ToString() + "'";
                        ht["CMDStatu"] = "0";
                        ht["CreateUser"] = "'"+CreateUser+"'";
                        int dd = DataFactory.SqlDataBase().InsertByHashtableNullParam("WH_CMD", ht);
                    }
 
                    //下发完指令更改单号状态为正在执行
                    Hashtable htup = new Hashtable();
                    htup["IsDel"] = 1;
 
                    string ID = "'" + json[0] + "'";
 
                    int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Picking", nameof(ID), ID, htup);
                }
                return true;
            }
            catch
            {
                return result;
            }
        }
    }
}