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;
|
}
|
}
|
}
|
}
|