using BLL.IDAL;
|
using Common;
|
using Model;
|
using NLog;
|
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 DAL_Pub
|
{
|
private Logger logger = LogManager.GetCurrentClassLogger();
|
public int SplitPosCode(string strSplit, ref int pai, ref int lie, ref int ceng)
|
{
|
pai = 0;
|
lie = 0;
|
ceng = 0;
|
try
|
{
|
pai = int.Parse(strSplit.Substring(strSplit.Length - 9, 3));
|
lie = int.Parse(strSplit.Substring(strSplit.Length - 6, 3));
|
ceng = int.Parse(strSplit.Substring(strSplit.Length - 3, 3));
|
}
|
catch
|
{
|
return -1;
|
}
|
|
return 0;
|
}
|
/// <summary>
|
/// 移库获取移动目标货位,返回1表示分配的是里边库位,且该库位被外边货物挡住,需要先移库,返回0,表示该库位没被挡住
|
/// </summary>
|
/// <param name="newPos"></param>
|
/// <param name="oriPos"></param>
|
/// <returns></returns>
|
public int GetEmptyPos(ref string newPos, int height, string oriPos = null)
|
{
|
int iret = 0;
|
newPos = null;
|
string newP = null;
|
try
|
{
|
if (oriPos == null)//普通入库,优先最底层,第一列,...
|
{
|
//按顺序获取外边第一个空库位
|
DepotsLocation dl = new DepotsLocation();
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("select top(1) * from View_GetEmptyPos where ( LRow = 2 or LRow = 3 ) and Height >= ");
|
strSql.Append(height);
|
strSql.Append(" order by Height, LLayer, LRow, LColumn");
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
|
if (dt != null)
|
{
|
dl = ModelConvertHelper<DepotsLocation>.ReaderToModel(dt);
|
int LColumn = dl.LColumn;
|
int LLayer = dl.LLayer;
|
newP = dl.LocationCode;
|
//检测对应里边库位是否为空
|
StringBuilder sqlFindIn = new StringBuilder();
|
if (dl.LRow == 2)
|
{
|
sqlFindIn.Append("select * from View_GetEmptyPos where LRow = 1 and LColumn = @LColumn and LLayer = @LLayer");
|
}
|
else
|
{
|
sqlFindIn.Append("select * from View_GetEmptyPos where LRow = 4 and LColumn = @LColumn and LLayer = @LLayer");
|
}
|
SqlParam[] para = new SqlParam[]
|
{
|
new SqlParam("@LColumn", LColumn),
|
new SqlParam("@LLayer", LLayer)
|
};
|
IDataReader dt1 = DataFactory.SqlDataBase().GetDataReaderBySQL(sqlFindIn, para);
|
dl = ModelConvertHelper<DepotsLocation>.ReaderToModel(dt1);
|
if (dl != null)
|
{
|
newP = dl.LocationCode;
|
}
|
newPos = newP;
|
}
|
else
|
{
|
//找里边空库位,该库位对应外边库位肯定是占用状态,被外库位挡着,需要移库
|
DepotsLocation dl2 = new DepotsLocation();
|
StringBuilder strSql2 = new StringBuilder();
|
strSql2.Append("select top(1) * from View_GetEmptyPos where ( LRow = 1 or LRow = 4 ) and Height >= ");
|
strSql2.Append(height);
|
strSql2.Append(" order by Height, LLayer, LRow, LColumn");
|
|
IDataReader dt2 = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql2);
|
|
dl2 = ModelConvertHelper<DepotsLocation>.ReaderToModel(dt2);
|
|
if (dl2 != null)
|
{
|
newP = dl2.LocationCode;
|
return 1;
|
}
|
else
|
{
|
return -2;
|
}
|
}
|
}
|
else
|
{
|
//移库,优先将外边移到对应里边库位,若里边不为空,找外边最近库位,然后再优先移到该最近库位对应里边库位
|
int row = 0, column = 0, layer = 0;
|
//解析库位坐标
|
SplitPosCode(oriPos, ref row, ref column, ref layer);
|
//
|
List<DepotsLocation> lst3 = new List<DepotsLocation>();
|
StringBuilder strSQLInner = new StringBuilder();
|
StringBuilder strSql3 = new StringBuilder();
|
//原始库位为外边库位,则判断对应里边库位是否为空,为空则分配出去
|
if (row == 2)
|
{
|
strSQLInner.Append("select * from View_GetEmptyPos where LRow = 1 and LColumn = ");
|
strSQLInner.Append(column);
|
strSQLInner.Append(" and LLayer = ");
|
strSQLInner.Append(layer);
|
|
IDataReader dr = DataFactory.SqlDataBase().GetDataReaderBySQL(strSQLInner);
|
if (dr != null && dr.IsEmpty())
|
{
|
DepotsLocation dl = new DepotsLocation();
|
dl = ModelConvertHelper<DepotsLocation>.ReaderToModel(dr);
|
newPos = dl.LocationCode;
|
return 0;
|
}
|
}
|
if (row == 3)
|
{
|
strSQLInner.Append("select * from View_GetEmptyPos where LRow = 4 and LColumn = ");
|
strSQLInner.Append(column);
|
strSQLInner.Append(" and LLayer = ");
|
strSQLInner.Append(layer);
|
|
IDataReader dr = DataFactory.SqlDataBase().GetDataReaderBySQL(strSQLInner);
|
if (dr != null && dr.IsEmpty())
|
{
|
DepotsLocation dl = new DepotsLocation();
|
dl = ModelConvertHelper<DepotsLocation>.ReaderToModel(dr);
|
newPos = dl.LocationCode;
|
return 0;
|
}
|
}
|
//获取2/3排是空库位货位
|
strSql3.Append("select * from View_GetEmptyPos where (LRow = 2 or LRow = 3) and Height >= ");
|
strSql3.Append(height + " and LocationCode != '" + oriPos + "' ");
|
strSql3.Append(" order by Height, LLayer, LColumn, LRow");
|
|
IDataReader dt3 = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql3);
|
if (dt3 == null)
|
{
|
return 0;
|
}
|
lst3 = (List<DepotsLocation>)ModelConvertHelper<DepotsLocation>.DataReaderToModel(dt3);
|
int sum = 100000;
|
DepotsLocation depotsLocation = new DepotsLocation();
|
//获取最近外层库位
|
for (int j = 0; j < lst3.Count; j++)
|
{
|
|
DepotsLocation dl = lst3[j];
|
|
// liudl注释 神逻辑看不懂
|
//if ((dl != null) && (dl.Height > height))
|
//{
|
// break;//后边库位高度与实际不符,不在对比,除非depotsLocation为空
|
//}
|
|
int vAbs = (Math.Abs(dl.LRow - row) + Math.Abs(dl.LLayer - layer));
|
if (sum > vAbs)
|
{
|
sum = vAbs;
|
depotsLocation = dl;
|
}
|
}
|
StringBuilder strSqlIn = new StringBuilder();
|
//判断该外层库位对应里边库位是否为空
|
if (depotsLocation.LRow == 2)
|
{
|
strSqlIn.Append("select * from View_GetEmptyPos where LRow = 1 and LColumn = @LColumn and LLayer = @LLayer");
|
}
|
else
|
{
|
strSqlIn.Append("select * from View_GetEmptyPos where LRow = 4 and LColumn = @LColumn and LLayer = @LLayer");
|
}
|
SqlParam[] param = new SqlParam[]
|
{
|
new SqlParam("@LLayer", depotsLocation.LLayer),
|
new SqlParam("@LColumn", depotsLocation.LColumn)
|
};
|
List<DepotsLocation> lstIn = new List<DepotsLocation>();
|
IDataReader dtIn = DataFactory.SqlDataBase().GetDataReaderBySQL(strSqlIn, param);
|
//不为空,则将里边库位分配出去
|
if (dtIn != null)
|
{
|
lstIn = (List<DepotsLocation>)ModelConvertHelper<DepotsLocation>.DataReaderToModel(dtIn);
|
if ((lstIn.Count > 0) && (lstIn[0].LocationCode != oriPos))
|
{
|
depotsLocation = lstIn[0];
|
}
|
}
|
newPos = depotsLocation.LocationCode;
|
}
|
}
|
catch (Exception ex)
|
{
|
iret = -1;
|
}
|
return iret;
|
}
|
//检查出库单是否所有托盘出库完成更改出库单状态,并更新该条指令状态
|
public int Erp_to(string taskID, string palno, string oldAddre)
|
{
|
int r = -1;
|
try
|
{
|
StringBuilder SQL = new StringBuilder();
|
SQL.Append("select * from Erp_Out where Ordno= '" + taskID + "' ");
|
DataTable dd = DataFactory.SqlDataBase().GetDataTableBySQL(SQL);
|
if (dd.Rows.Count > 0)
|
{
|
StringBuilder hql = new StringBuilder();
|
hql.Append("update WH_CMD set IsDel =1 where TaskID = '" + taskID + "' and OldAddre ='" + oldAddre + "' and Palno ='" + palno + "' and CMDType='to'");
|
DataFactory.SqlDataBase().ExecuteBySql(hql);
|
StringBuilder aql = new StringBuilder();
|
aql.Append("update DepotsLocation set TurnoverDemand ='02' where LocationCode = '" + oldAddre + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(aql);
|
//查询该指令下单号所有是否都出库,是则更改出库单状态
|
StringBuilder sql = new StringBuilder();
|
sql.Append("select * from WH_CMD where TaskID = '" + taskID + "' and IsDel=0");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (dt.Rows.Count <= 0)
|
{
|
StringBuilder eql = new StringBuilder();
|
eql.Append("update Erp_Out set Statu ='ER03' where Ordno = '" + taskID + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(eql);
|
}
|
|
}
|
return r = 0;
|
}
|
catch (Exception)
|
{
|
|
return r;
|
}
|
}
|
|
/// <summary>
|
/// 移库更改库存明细表托盘位置和指令表托盘位置
|
/// </summary>
|
/// <param name="taskID"></param>
|
/// <param name="palno"></param>
|
/// <param name="oldAddre"></param>
|
/// <param name="nowAddre"></param>
|
/// <returns></returns>
|
public int UpdatemoveStore(string taskID, string palno, string oldAddre, string nowAddre)
|
{
|
int r = -1;
|
try
|
{
|
if (taskID == "" || taskID == null)
|
{
|
StringBuilder sql = new StringBuilder();
|
sql.Append("update log_Store set Addre='" + nowAddre + "' where Addre = '" + oldAddre + "' and Palno='" + palno + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(sql);
|
this.UpdateDeopotsLocation(nowAddre, "02");
|
this.UpdateDeopotsLocation(oldAddre, "01");
|
|
//更改未生成指令的出库单,对应的出库明细表中的托盘的库位地址
|
sql.Clear();
|
sql.Append("Update ErpOutDetail set addre = '" + nowAddre + "' ");
|
sql.Append("where Palno = '" + palno + "' and OrdNo in ");
|
sql.Append("(select OrdNo from Erp_Out where Statu = 'ER01' and Erp_Out.IsDel = 0);");
|
DataFactory.SqlDataBase().ExecuteBySql(sql);
|
|
//查询指令表中是不是有移走的托盘指令,有则更改该托盘新货位
|
StringBuilder hql = new StringBuilder();
|
hql.Append("select * from WH_CMD where OldAddre = '" + oldAddre + "' and Palno='" + palno + "' and CMDType !='move' and IsDel=0");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(hql);
|
if (dt.Rows.Count > 0)
|
{
|
StringBuilder eql = new StringBuilder();
|
eql.Append("update WH_CMD set OldAddre='" + nowAddre + "' where OldAddre = '" + oldAddre + "' and Palno='" + palno + "' and CMDType !='move' and IsDel=0 ");
|
DataFactory.SqlDataBase().ExecuteBySql(eql);
|
}
|
//更改指令表该条指令状态
|
StringBuilder ql = new StringBuilder();
|
ql.Append("update WH_CMD set IsDel=1 where OldAddre = '" + oldAddre + "' and Palno='" + palno + "' and NowAddre='" + nowAddre + "' and CMDType ='move' and IsDel=0 ");
|
DataFactory.SqlDataBase().ExecuteBySql(ql);
|
}
|
|
return r = 0;
|
}
|
catch (Exception)
|
{
|
return r;
|
}
|
}
|
|
/// <summary>
|
/// 更改指令状态,查看是否出完所有托盘是则改出库单状态
|
/// </summary>
|
/// <param name="taskID"></param>
|
/// <param name="palno"></param>
|
/// <param name="oldAddre"></param>
|
/// <returns></returns>
|
public int UpdateOut(string taskID, string palno, string oldAddre)
|
{
|
int r = -1;
|
try
|
{
|
//StringBuilder hql = new StringBuilder();
|
//hql.Append("update WH_CMD set IsDel =1 where TaskID = '" + taskID + "' and OldAddre ='" + oldAddre + "' and Palno ='" + palno + "' and CMDType='out'");
|
//DataFactory.SqlDataBase().ExecuteBySql(hql);
|
////查询该指令下单号所有是否都出库和回库表中该订单是否需要回库,没有指令和回库则更改出库单状态
|
//StringBuilder sql = new StringBuilder();
|
//sql.Append("select * from WH_CMD where TaskID = '" + taskID + "' and IsDel=0");
|
//DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
//查询回库表中是否有该订单需要回库
|
//StringBuilder ql = new StringBuilder();
|
//ql.Append("select * from Picking where OrdNo = '" + taskID + "' and IsDel=0");
|
//DataTable tt = DataFactory.SqlDataBase().GetDataTableBySQL(ql);
|
//if (tt.Rows.Count <= 0)
|
//{
|
// eql.Append($"update Erp_Out set Statu ='03',CompletionTime=GETDATE() where Ordno = '" + taskID + "'");
|
//}
|
//else
|
//{
|
// eql.Append($"update Erp_Out set Statu ='04',CompletionTime=GETDATE() where Ordno = '" + taskID + "'");
|
//}
|
//eql.Append($"select 1 from View_ErpOutDetail where OrdNo='{taskID}'");
|
//DataTable tt = DataFactory.SqlDataBase().GetDataTableBySQL(eql);
|
//if (tt != null && tt.Rows.Count <= 0)
|
//{
|
StringBuilder eql = new StringBuilder();
|
eql.Clear();
|
eql.Append($"update Erp_Out set Statu ='03',CompletionTime=GETDATE() where Ordno = '" + taskID + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(eql);
|
//}
|
|
return r = 0;
|
}
|
catch (Exception)
|
{
|
|
return r;
|
}
|
}
|
|
/// <summary>
|
/// 查询出库托盘下是否有物料,有则回库,没有则更改货位状态为空货位
|
/// </summary>
|
/// <param name="taskID"></param>
|
/// <param name="palno"></param>
|
/// <param name="oldAddre"></param>
|
/// <returns></returns>
|
public int InsertPicking(string taskID, string palno, string oldAddre)
|
{
|
int r = -1;
|
try
|
{
|
//出库指令更新完库存后判断托盘是否还有物料,有则回库表插入数据,没有则更改货位状态为空货位
|
StringBuilder sql = new StringBuilder();
|
sql.Append("select 1 from log_Store where log_Store.Palno='" + palno + "' and IsDel=0");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (dt.Rows.Count > 0)
|
{
|
Hashtable ht = new Hashtable();
|
ht["OrdNo"] = "'" + taskID + "'";
|
ht["Palno"] = "'" + palno + "'";
|
ht["Addre"] = "'" + oldAddre + "'";
|
ht["IsDel"] = 0;
|
|
StringBuilder ql = new StringBuilder();
|
ql.Append("select * from Picking where OrdNo='" + taskID + "' and Palno='" + palno + "' AND IsDel=0 ");
|
DataTable tt = DataFactory.SqlDataBase().GetDataTableBySQL(ql);
|
if (tt != null && tt.Rows.Count <= 0)
|
{
|
DataFactory.SqlDataBase().InsertByHashtableNullParam("Picking", ht);
|
}
|
StringBuilder hql = new StringBuilder();
|
hql.Append("update DepotsLocation set TurnoverDemand ='03' where LocationCode = '" + oldAddre + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(hql);
|
}
|
else
|
{
|
StringBuilder hql = new StringBuilder();
|
hql.Append("update DepotsLocation set TurnoverDemand ='01' where LocationCode = '" + oldAddre + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(hql);
|
// 删除回库表数据
|
hql.Clear();
|
hql.Append($"UPDATE dbo.Picking SET IsDel=1 WHERE Palno='{palno}' AND Addre='{oldAddre}' AND IsDel=0");
|
DataFactory.SqlDataBase().ExecuteBySql(hql);
|
}
|
|
return r = 0;
|
}
|
catch (Exception)
|
{
|
|
return r;
|
}
|
|
}
|
|
/// <summary>
|
/// 查询单号该out指令是不是出库单的
|
/// </summary>
|
/// <param name="taskID"></param>
|
/// <returns></returns>
|
public int UpdateStore(string taskID, string palno, string OldAddre)
|
{
|
int r = 0;
|
try
|
{
|
StringBuilder SQL = new StringBuilder();
|
SQL.Append("select * from View_ErpOutDetail where OrdNo= '" + taskID + "' and Palno='" + palno + "'and LocationCode = '" + OldAddre + "' and Statu='02'");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(SQL);
|
//如果该指令任务号是出库单单号匹配则更改库存表
|
if (dt.Rows.Count > 0)
|
{
|
for (int i = 0; i < dt.Rows.Count; i++)
|
{
|
// 空托盘出库 物料编码为null
|
if (dt.Rows[i]["MatNo"].ToString() == "")
|
{
|
StringBuilder sql = new StringBuilder();
|
sql.Append("select quant from log_Store where LocationCode= '" + dt.Rows[i]["LocationCode"].ToString());
|
sql.Append("' and log_Store.Palno='" + dt.Rows[i]["Palno"].ToString() + "' and isnull(matno,'') = '' and IsDel=0");
|
DataTable ddd = DataFactory.SqlDataBase().GetDataTableBySQL(sql);
|
if (ddd.Rows.Count > 0)
|
{
|
int subtract = ddd.Rows[0]["Quant"].ToInt() - dt.Rows[i]["CurQuant"].ToInt();
|
if (subtract <= 0)
|
{
|
StringBuilder ht = new StringBuilder();
|
ht.Append("delete from log_Store where LocationCode= '" + dt.Rows[i]["LocationCode"].ToString() + "' and Palno='" + dt.Rows[i]["Palno"].ToString() + "' and isnull(MatNo,'')=''");
|
DataFactory.SqlDataBase().ExecuteBySql(ht);
|
|
}
|
else
|
{
|
StringBuilder ht = new StringBuilder();
|
ht.Append("update log_Store set Quant='" + subtract + "' where LocationCode= '" + dt.Rows[i]["LocationCode"].ToString() + "' and Palno='" + dt.Rows[i]["Palno"].ToString() + "' and isnull(MatNo,'')=''");
|
DataFactory.SqlDataBase().ExecuteBySql(ht);
|
}
|
}
|
|
}
|
else // 物料出库
|
{
|
//查询出库存明细表数量减去出库单数量并更新库存表 //lijiangang修改:增加合格证Certificate条件图号条件
|
StringBuilder hql = new StringBuilder();
|
hql.Append("select log_Store.Guid,log_Store.Quant,Log_Stroe_Mat.Quant as MatQuant from log_Store left join Log_Stroe_Mat on log_Store.MatNo = Log_Stroe_Mat.MatNo" +
|
" where log_Store.LocationCode= '" + dt.Rows[i]["LocationCode"].ToString() + "' and log_Store.Palno='" + dt.Rows[i]["Palno"].ToString() + "' " +
|
" and log_Store.MatNo='" + dt.Rows[i]["MatNo"].ToString() + "' " +
|
"and isnull(log_Store.TuNo,'') = '" + dt.Rows[i]["TuNo"].ToString() + "' and log_Store.lingno = '" + dt.Rows[i]["lingno"].ToString() + "'");
|
DataTable dd = DataFactory.SqlDataBase().GetDataTableBySQL(hql);
|
if (dd.Rows.Count > 0)
|
{
|
//更新库存明细表
|
int subtract = dd.Rows[0]["Quant"].ToInt() - dt.Rows[i]["CurQuant"].ToInt();
|
if (subtract <= 0)
|
{
|
StringBuilder ht = new StringBuilder();
|
//ht.Append("delete from log_Store where log_Store.Guid='" + dd.Rows[0]["Guid"].ToString() + "'");
|
ht.Append("update log_Store set isdel = '1' where log_Store.Guid='" + dd.Rows[0]["Guid"].ToString() + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(ht);
|
|
}
|
else
|
{
|
StringBuilder ht = new StringBuilder();
|
ht.Append("update log_Store set Quant='" + subtract + "' where log_Store.Guid='" + dd.Rows[0]["Guid"].ToString() + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(ht);
|
}
|
//更新库存总表
|
int subtractnum = dd.Rows[0]["MatQuant"].ToInt() - dt.Rows[i]["CurQuant"].ToInt();
|
StringBuilder qt = new StringBuilder();
|
qt.Append("update Log_Stroe_Mat set Quant='" + subtractnum + "' where Log_Stroe_Mat.MatNo='" + dt.Rows[i]["MatNo"].ToString() + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(qt);
|
}
|
}
|
}
|
|
r = 1;
|
}
|
else // 库内托盘出库重新组盘
|
{
|
if (string.IsNullOrWhiteSpace(taskID))
|
{
|
StringBuilder hql = new StringBuilder();
|
hql.Append("update DepotsLocation set TurnoverDemand ='03' where LocationCode = '" + OldAddre + "'");
|
DataFactory.SqlDataBase().ExecuteBySql(hql);
|
}
|
|
}
|
return r;
|
}
|
catch (Exception)
|
{
|
r = -1;
|
return r;
|
}
|
|
}
|
|
//生成入库指令
|
public int GenPalletInOrder(Order order)
|
{
|
try
|
{
|
Hashtable ht = new Hashtable();
|
DateTime t = DateTime.Now;
|
ht["TaskID"] = order.TaskID;
|
ht["Palno"] = order.Palno;
|
ht["CMDType"] = order.CMDType;
|
ht["OldAddre"] = order.OldAddre;
|
ht["NowAddre"] = order.NowAddre;
|
ht["CMDStatu"] = order.CMDStatu;
|
ht["CreateUser"] = order.CreateUser;
|
ht["CreateTime"] = t;
|
ht["IsDel"] = 0;
|
|
int r = DataFactory.SqlDataBase().InsertByHashtable("WH_CMD", ht);
|
if (r > 0)
|
{
|
return 0;
|
}
|
else
|
{
|
return -1;
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 改变库位状态
|
/// </summary>
|
/// <param name="Location">库位地址</param>
|
/// <param name="statu">库位状态</param>
|
/// <returns></returns>
|
public bool UpdateLocationState(string Location, string statu)
|
{
|
try
|
{
|
bool bl = false;
|
StringBuilder sbStr = new StringBuilder();
|
sbStr.Append("Update DepotsLocation set TurnoverDemand = '" + statu + "' ");
|
sbStr.Append("where LocationCode = '" + Location + "';");
|
|
int rowCount = DataFactory.SqlDataBase().ExecuteBySql(sbStr);
|
if (rowCount > 0)
|
{
|
bl = true;
|
}
|
|
return bl;
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
//从CMD表获取第一条命令
|
public int GetErpInCmd(ref IList<ErpInCmd> lst)
|
{
|
int ir = 0;
|
lst.Clear();
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("select top(1)* from WH_CMD where (CMDStatu = 1 or CMDStatu = 0 or CMDStatu = -1) and IsDel = 0 Order by CreateTime");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
lst = ModelConvertHelper<ErpInCmd>.DataTableToModel(dt);
|
}
|
}
|
catch (Exception ex)
|
{
|
ir = -1;
|
}
|
return ir;
|
}
|
//通过托盘码从组盘表获得订单号
|
public int GetOrdByPalletNo(string PalletNo, string CMDID, ref string OrdNo)
|
{
|
int ir = 0;
|
bool bl = false;
|
OrdNo = "";
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
// 判断组盘表里是否存在此托盘码
|
strSQL.Append("select * from IPalletBind where PalletNo = '");
|
strSQL.Append(PalletNo);
|
// 过滤已删除数据
|
strSQL.Append("' and Statu = '1' and IsDel = '0';");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
OrdNo = dt.Rows[0]["OrdNo"].ToString();
|
bl = true;
|
}
|
}
|
|
// 判断空托盘表里是否存在此托盘码
|
strSQL.Clear();
|
strSQL.Append("select id from IPalletEmptyIn where PalletNo = '" + PalletNo + "'");
|
strSQL.Append(" and Statu = '1' and isDel = '0';");
|
DataTable dtt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dtt.Rows.Count > 0)
|
{
|
bl = true;
|
}
|
|
if (!bl)
|
{
|
// 此托盘无单据关联,将该指令的statu状态置为 -5(非法托盘)
|
strSQL.Clear();
|
strSQL.Append("Update WH_CMD set CMDStatu = '-5' where CMDID='" + CMDID + "';");
|
DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
ir = -1;
|
}
|
}
|
catch
|
{
|
ir = -1;
|
}
|
|
return ir;
|
}
|
//更新cmd命令表
|
public int UpdateCmd(string PalletNo, int status, string OrdNo, string OriPos, string NewPos = "")
|
{
|
int ir = 0;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
strSQL.Append("update WH_CMD set OldAddre = @OldAddre, NowAddre = @NowAddre, TaskID = @OrdNo, CMDStatu = @CMDStatu ");
|
if (status == 3)
|
{
|
strSQL.Append(" ,IsDel=1");
|
}
|
strSQL.Append(" where Palno = @Palno and IsDel = 0");
|
SqlParam[] param = new SqlParam[]
|
{
|
new SqlParam("@OldAddre", OriPos),
|
new SqlParam("@NowAddre", NewPos),
|
new SqlParam("@OrdNo", OrdNo),
|
new SqlParam("@CMDStatu", status),
|
new SqlParam("@Palno", PalletNo)
|
|
};
|
ir = DataFactory.SqlDataBase().ExecuteBySql(strSQL, param);
|
}
|
catch (Exception ex)
|
{
|
ir = -1;
|
}
|
return ir;
|
}
|
//更新Log_store库存明细表
|
public int UpdateLogStore(string Pos, IList<PalletBind> lst)
|
{
|
int r = -1;
|
try
|
{
|
foreach (PalletBind pb in lst)
|
{
|
int has = 0;
|
StringBuilder strSQL = new StringBuilder();
|
StringBuilder strSQL2 = new StringBuilder();
|
|
strSQL.Append("select Quant,LocationCode from log_Store where MatNo = '");
|
strSQL.Append(pb.MatNo);
|
strSQL.Append("' and LingNo = '");
|
strSQL.Append(pb.LingNo);
|
strSQL.Append("' and Palno = '");
|
strSQL.Append(pb.PalletNo);
|
strSQL.Append("'");
|
strSQL.Append(" and isnull(Certificate,'') = '" + pb.HeGeZheng + "'");
|
strSQL.Append(" and isnull(tuno,'') = '" + pb.TuNo + "'");
|
strSQL.Append(" and isnull(BatchNo,'') = '" + pb.BatchNo + "'");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
has = int.Parse(dt.Rows[0]["Quant"].ToString());
|
has += int.Parse(pb.MatCount);
|
if (has > 0)
|
{
|
strSQL2.Append("update log_Store set Quant = '");
|
strSQL2.Append(has.ToString());
|
strSQL2.Append("' where ");
|
strSQL2.Append("MatNo = '");
|
strSQL2.Append(pb.MatNo);
|
strSQL2.Append("' and LingNo = '");
|
strSQL2.Append(pb.LingNo);
|
strSQL2.Append("' and Palno = '" + pb.PalletNo);
|
strSQL2.Append("' and isnull(Certificate,'') = '" + pb.HeGeZheng);
|
strSQL2.Append("' and isnull(tuno,'') = '" + pb.TuNo + "'");
|
strSQL2.Append("' and isnull(BatchNo,'') = '" + pb.BatchNo + "'");
|
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL2);
|
}
|
}
|
else
|
{
|
DateTime t = DateTime.Now;
|
Hashtable ht = new Hashtable();
|
ht["LocationCode"] = Pos;
|
ht["Palno"] = pb.PalletNo;
|
ht["MatNo"] = pb.MatNo;
|
ht["LingNo"] = pb.LingNo;
|
ht["TuNo"] = pb.TuNo;
|
ht["PageNo"] = pb.PageNo;
|
ht["Quant"] = pb.MatCount;
|
ht["CQuant"] = 0;
|
ht["Certificate"] = pb.HeGeZheng;
|
ht["DepartGuid"] = pb.DepartGuid;
|
ht["MatGuid"] = pb.MatGuid;
|
ht["BatchNo"] = pb.BatchNo;
|
ht["BatchName"] = pb.BatchDemo;
|
|
// ht["CreateTime"] = t.ToString("yyyy-MM-dd HH:mm:ss");
|
//ht["Demo"] = pb.Demo;
|
//ht["CheckTime"] = t.ToString("yyyy-MM-dd HH:mm:ss");
|
|
r = DataFactory.SqlDataBase().InsertByHashtable("log_Store", ht);
|
}
|
}
|
|
//入库完成后往入库单物料位置表ErpInPosition插入货位和托盘信息,方便查看入库单物料存放位置
|
StringBuilder strSQL1 = new StringBuilder();
|
strSQL1.Append("select Quant,LocationCode from log_Store where MatNo = '");
|
strSQL1.Append(pb.MatNo);
|
strSQL1.Append("' and LingNo = '");
|
strSQL1.Append(pb.LingNo);
|
strSQL1.Append("' and Palno = '");
|
strSQL1.Append(pb.PalletNo);
|
strSQL1.Append("'");
|
strSQL1.Append(" and isnull(Certificate,'') = '" + pb.HeGeZheng + "'");
|
strSQL1.Append(" and isnull(tuno,'') = '" + pb.TuNo + "'");
|
strSQL1.Append(" and isnull(BatchNo,'') = '" + pb.BatchNo + "'");
|
|
DataTable dt1 = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL1);
|
Hashtable ErpInPosition = new Hashtable();
|
ErpInPosition["OrdNo"] = pb.OrdNo;
|
ErpInPosition["MatNo"] = pb.MatNo;
|
ErpInPosition["PalletNo"] = pb.PalletNo;
|
ErpInPosition["AddreNo"] = dt1.Rows[0]["LocationCode"].ToString();
|
ErpInPosition["MatCount"] = pb.MatCount.ToInt();
|
int q = DataFactory.SqlDataBase().InsertByHashtable("ErpInPosition", ErpInPosition);
|
}
|
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//空托盘更新库存总表
|
public int UpdateLogStoreMat(string Pos, string PalletNo, int count)
|
{
|
int r = -1;
|
try
|
{
|
DateTime t = DateTime.Now;
|
Hashtable ht = new Hashtable();
|
ht["MatNo"] = PalletNo;
|
ht["Quant"] = count;
|
ht["CreateUser"] = "SuperUser";
|
ht["CreateTime"] = t.ToString("yyyy-MM-dd HH:mm:ss");
|
ht["IsDel"] = 0;
|
|
r = DataFactory.SqlDataBase().InsertByHashtable("log_Stroe_Mat", ht);
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
|
|
|
return r;
|
}
|
//空托盘更新库存明细表
|
public int UpdatePalletLogStore(string Pos, string PalletNo, int count)
|
{
|
int r = -1;
|
try
|
{
|
|
int has = 0;
|
StringBuilder strSQL = new StringBuilder();
|
StringBuilder strSQL2 = new StringBuilder();
|
|
strSQL.Append("select Quant,Palno from log_Store where LocationCode = '" + Pos + "' and Palno='" + PalletNo + "'");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
has = int.Parse(dt.Rows[0]["Quant"].ToString());
|
has += count;
|
if (has > 0)
|
{
|
strSQL2.Append("update log_Store set Quant = '");
|
strSQL2.Append(has.ToString());
|
strSQL2.Append("' where ");
|
strSQL2.Append(" LocationCode = '");
|
strSQL2.Append(Pos);
|
strSQL2.Append("' and Palno = '");
|
strSQL2.Append(PalletNo);
|
strSQL2.Append("'");
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL2);
|
}
|
}
|
else
|
{
|
DateTime t = DateTime.Now;
|
Hashtable ht = new Hashtable();
|
ht["LocationCode"] = Pos;
|
ht["Palno"] = PalletNo;
|
ht["Quant"] = count.ToString();
|
|
r = DataFactory.SqlDataBase().InsertByHashtable("log_Store", ht);
|
}
|
}
|
|
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//更新Log_store_mat物料明细表
|
public int UpdateLogStoreMat(string Pos, IList<PalletBind> lst)
|
{
|
int r = -1;
|
try
|
{
|
foreach (PalletBind em in lst)
|
{
|
int has = 0;
|
StringBuilder strSQL = new StringBuilder();
|
StringBuilder strSQL2 = new StringBuilder();
|
|
strSQL.Append("select Quant from Log_Stroe_Mat where MatNo = '");
|
strSQL.Append(em.MatNo);
|
strSQL.Append("'");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
has = int.Parse(dt.Rows[0]["Quant"].ToString());
|
has += int.Parse(em.MatCount);
|
if (has > 0)
|
{
|
strSQL2.Append("update log_Stroe_Mat set Quant = '");
|
strSQL2.Append(has.ToString());
|
strSQL2.Append("' where ");
|
strSQL2.Append("MatNo = '");
|
strSQL2.Append(em.MatNo);
|
strSQL2.Append("'");
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL2);
|
}
|
}
|
else
|
{
|
DateTime t = DateTime.Now;
|
Hashtable ht = new Hashtable();
|
ht["MatNo"] = em.MatNo;
|
ht["Quant"] = em.MatCount;
|
ht["CreateUser"] = "SuperUser";
|
ht["CreateTime"] = t.ToString("yyyy-MM-dd HH:mm:ss");
|
ht["IsDel"] = 0;
|
|
r = DataFactory.SqlDataBase().InsertByHashtable("log_Stroe_Mat", ht);
|
}
|
}
|
|
|
|
}
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//更新DeopotsLocation库位表
|
public int UpdateDeopotsLocation(string Pos, string statu)//1空;2合格;3待入;4待出;
|
{
|
int r = -1;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("update DepotsLocation set TurnoverDemand = @statu where LocationCode = @Pos");
|
|
SqlParam[] param = new SqlParam[]
|
{
|
new SqlParam("@statu", statu),
|
new SqlParam("@Pos", Pos)
|
};
|
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL, param);
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
|
return r;
|
}
|
//ErpIn逻辑状态判断
|
public int UpdateErp(string PalletNo)
|
{
|
int r = 0;
|
try
|
{
|
//获取该托盘上所有物料信息
|
StringBuilder strSQL = new StringBuilder();
|
strSQL.Append("select OrdNo from IPalletBind where PalNo = '");
|
strSQL.Append(PalletNo);
|
strSQL.Append("' and IsDel = 0 Group By OrdNo");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
//遍历所有入库单是否需要关单
|
for (int i = 0; i < dt.Rows.Count; i++)
|
{
|
bool bErpInClose = true;
|
string OrdNo = dt.Rows[i]["OrdNo"].ToString();
|
//该订单下所有物料
|
StringBuilder strSQLErpIn = new StringBuilder();
|
strSQLErpIn.Append("select * from ErpInDetail where OrdNo = '");
|
strSQLErpIn.Append(OrdNo);
|
strSQLErpIn.Append("'");
|
|
DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(strSQLErpIn);
|
if (dt2 != null)
|
{
|
//该入库单下所有物料是否已经入库
|
for (int j = 0; j < dt2.Rows.Count; j++)
|
{
|
//某一种物料
|
int ErpInCount = int.Parse(dt2.Rows[j]["CurQuant"].ToString());
|
string MatNo = dt2.Rows[j]["MatNo"].ToString();
|
//该入库单下该物料已经入库数量
|
StringBuilder strGetAllMatCount = new StringBuilder();
|
strGetAllMatCount.Append("select * from IPalletBind where OrdNo = '");
|
strGetAllMatCount.Append(OrdNo);
|
strGetAllMatCount.Append("' and MatGuid = '");
|
strGetAllMatCount.Append(MatNo);
|
strGetAllMatCount.Append("' and Statu = '03'");
|
|
DataTable dtAll = DataFactory.SqlDataBase().GetDataTableBySQL(strGetAllMatCount);
|
if (dtAll != null)
|
{
|
int sum = 0;
|
for (int m = 0; m < dtAll.Rows.Count; m++)
|
{
|
sum += int.Parse(dtAll.Rows[m]["MatCount"].ToString());
|
}
|
if (sum < ErpInCount)
|
{
|
bErpInClose = false;
|
}
|
}
|
|
}
|
}
|
if (bErpInClose)
|
{
|
//入库单执行完成,
|
UpdateErpInStatus(OrdNo, "03");
|
DelPalletBind(OrdNo);
|
}
|
}
|
}
|
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//更新Erpin入库单表
|
public int UpdateErpInStatus(string OrdNo, string status)
|
{
|
int r = 0;
|
try
|
{
|
StringBuilder strUpdateErpIn = new StringBuilder();
|
strUpdateErpIn.Append($"update Erp_in set Statu = '{status}',CompletionTime=GETDATE() where OrdNo = '{OrdNo}'");
|
r = DataFactory.SqlDataBase().ExecuteBySql(strUpdateErpIn);
|
}
|
catch
|
{
|
r = -1;
|
}
|
return r;
|
}
|
|
public bool UpdateErpInStatu(string PalletNo, string status)
|
{
|
bool bl = false;
|
try
|
{
|
// 根据托盘码获取关联入库单号
|
StringBuilder sbstr = new StringBuilder();
|
sbstr.Append("select distinct OrdNo from IPalletBind where Palno = '" + PalletNo + "' and Statu = '02' and IsDel = '0'");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(sbstr);
|
if (dt != null)
|
{
|
sbstr.Clear();
|
// 更改所有入库单,单据状态
|
foreach (DataRow row in dt.Rows)
|
{
|
sbstr.Append("Update Erp_in set Statu = '" + status);
|
sbstr.Append("' where OrdNo = '" + row["OrdNo"].ToString() + "';");
|
}
|
|
int rowCout = DataFactory.SqlDataBase().ExecuteBySql(sbstr);
|
if (rowCout > 0)
|
{
|
bl = true;
|
}
|
}
|
}
|
catch
|
{
|
bl = false;
|
}
|
|
return bl;
|
}
|
|
//删除托盘绑定
|
public int DelPalletBind(string OrdNo)
|
{
|
int r = 0;
|
try
|
{
|
//获取该订单下所有托盘
|
StringBuilder strAllPallet = new StringBuilder();
|
strAllPallet.Append("select * from IPalletBind where OrdNo = '");
|
strAllPallet.Append(OrdNo);
|
strAllPallet.Append("' and Statu = '03' and IsDel=0 ");
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strAllPallet);
|
if (dt != null)
|
{
|
//该订单下的所有托盘
|
for (int i = 0; i < dt.Rows.Count; i++)
|
{
|
bool delFlag = true;
|
string PalletNo = dt.Rows[i]["PalNo"].ToString();
|
StringBuilder strAllOrd = new StringBuilder();
|
strAllOrd.Append("select * from IPalletBind where PalNo = '");
|
strAllOrd.Append(PalletNo);
|
strAllOrd.Append("' and Statu = '03' and IsDel=0");
|
DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(strAllOrd);
|
if (dt2 != null)
|
{
|
//该托盘下的所有订单
|
for (int j = 0; j < dt2.Rows.Count; j++)
|
{
|
string erpOrdNo = dt2.Rows[j]["OrdNo"].ToString();
|
StringBuilder strOrdStatu = new StringBuilder();
|
strOrdStatu.Append("select * from Erp_in where OrdNo = '");
|
strOrdStatu.Append(erpOrdNo);
|
strOrdStatu.Append("'");
|
//所有订单完成,才能删除
|
DataTable dt3 = DataFactory.SqlDataBase().GetDataTableBySQL(strOrdStatu);
|
if (dt3 != null)
|
{
|
//订单状态,有一个订单没完成,就不能删除该托盘
|
for (int k = 0; k < dt3.Rows.Count; k++)
|
{
|
string Statu = dt3.Rows[k]["Statu"].ToString();
|
if (Statu != "03")
|
{
|
delFlag = false;
|
}
|
}
|
}
|
if (delFlag)
|
{
|
//改托盘上所有订单都关闭,则关闭
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("update IPalletBind set IsDel = 1 where OrdNo = '");
|
strSQL.Append(erpOrdNo);
|
strSQL.Append("'and PalNo = '");
|
strSQL.Append(PalletNo);
|
strSQL.Append("' and IsDel=0");
|
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
}
|
}
|
}
|
|
}
|
}
|
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//根据物料删除托盘绑定
|
public int DelPalletBind(string OrdNo, string MatNo)
|
{
|
int r = 0;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("update IPalletBind set IsDel = 1 where OrdNo = '");
|
strSQL.Append(OrdNo);
|
strSQL.Append("' and MatNo = '");
|
strSQL.Append(MatNo);
|
strSQL.Append("'");
|
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//根据入库单更新托盘绑定状态
|
public int UpdatePalletBindStatus(string PalletNo, string taskId, string status)
|
{
|
int r = 0;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("update IPalletBind set Statu = '");
|
strSQL.Append(status);
|
strSQL.Append("' where Palno = '");
|
strSQL.Append(PalletNo);
|
strSQL.Append("' and IsDel = '0' and Statu = '02' ;");
|
// liudl 注释 存在一个托盘多个入库单情况
|
//strSQL.Append("' and OrdNo = '")
|
//strSQL.Append(taskId);
|
//strSQL.Append("'");
|
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
//更新PallletBind托盘绑定表状态
|
public int UpdatePalletBind(string PalletNo, int status)
|
{
|
int r = -1;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append($"update IPalletBind set Statu = '0{status}' where Palno = '{PalletNo}' and Statu='01' and IsDel = 0");
|
r = DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
|
return r;
|
}
|
|
public int GetPalletNoAndOutPosByInPos(string InPos, ref string OutPos, ref string PalletNo)
|
{
|
int pai = 0, lie = 0, ceng = 0;
|
SplitPosCode(InPos, ref pai, ref lie, ref ceng);
|
|
StringBuilder strSQL = new StringBuilder();
|
if (pai == 1)
|
{
|
strSQL.Append("select top(1) * from View_GetEmptyPos where LRow = 2 and LColumn = ");
|
strSQL.Append(lie);
|
strSQL.Append(" and LLayer = ");
|
strSQL.Append(ceng);
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
DepotsLocation dl = new DepotsLocation();
|
dl = (DepotsLocation)ModelConvertHelper<DepotsLocation>.DataTableToModel(dt);
|
OutPos = dl.LocationCode;
|
}
|
}
|
}
|
if (pai == 4)
|
{
|
strSQL.Append("select top(1) * from View_GetEmptyPos where LRow = 3 and LColumn = ");
|
strSQL.Append(lie);
|
strSQL.Append(" and LLayer = ");
|
strSQL.Append(ceng);
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
DepotsLocation dl = new DepotsLocation();
|
dl = (DepotsLocation)ModelConvertHelper<DepotsLocation>.DataTableToModel(dt);
|
OutPos = dl.LocationCode;
|
}
|
}
|
}
|
StringBuilder strSQLPalletNo = new StringBuilder();
|
strSQLPalletNo.Append("select top(1) * from Log_Store where Addre = '");
|
strSQLPalletNo.Append(OutPos);
|
strSQLPalletNo.Append("'");
|
DataTable dt2 = DataFactory.SqlDataBase().GetDataTableBySQL(strSQLPalletNo);
|
if (dt2 != null)
|
{
|
if (dt2.Rows.Count > 0)
|
PalletNo = dt2.Rows[0]["Palno"].ToString();
|
}
|
|
return 0;
|
}
|
|
public int DelPalletEmptyIn(string PalletNo)
|
{
|
int ir = 0;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("Update IPalletEmptyIn set IsDel = 1 where IsDel = 0 and PalNo = '");
|
strSQL.Append(PalletNo);
|
strSQL.Append("'");
|
|
ir = DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
}
|
catch (Exception ex)
|
{
|
ir = -1;
|
}
|
return ir;
|
}
|
|
public int UpdatePalletEmptyInStatus(string PalletNo, string status)
|
{
|
int ir = 0;
|
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("Update IPalletEmptyIn set Statu = '");
|
strSQL.Append(status);
|
strSQL.Append("' where IsDel = 0 and PalNo = '");
|
strSQL.Append(PalletNo);
|
strSQL.Append("'");
|
|
ir = DataFactory.SqlDataBase().ExecuteBySql(strSQL);
|
}
|
catch (Exception ex)
|
{
|
ir = -1;
|
}
|
return ir;
|
}
|
|
public int GetPalletEmptyCount(string PalletNo, ref int count)
|
{
|
int r = -1;
|
count = 0;
|
try
|
{
|
StringBuilder strSQL = new StringBuilder();
|
|
strSQL.Append("select * from IPalletEmptyIn where PalNo = '");
|
strSQL.Append(PalletNo);
|
strSQL.Append("' and Statu = '02'");
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
|
if (dt != null)
|
{
|
if (dt.Rows.Count > 0)
|
{
|
count = int.Parse(dt.Rows[0]["PalCount"].ToString());
|
r = 0;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
return r;
|
}
|
|
public int GetOutPosParamByInnerPos(string Pos, ref DepotsLocation dl)
|
{
|
int r = -1;
|
try
|
{
|
int pai = 0, lie = 0, ceng = 0;
|
r = SplitPosCode(Pos, ref pai, ref lie, ref ceng);
|
StringBuilder strSQL = new StringBuilder();
|
strSQL.Append("select tb1.*,tb2.Palno from DepotsLocation as tb1 ");
|
strSQL.Append("left join log_Store as tb2 on tb1.LocationCode = tb2.Addre ");
|
strSQL.Append("where LRow = ");
|
if (pai == 1)
|
strSQL.Append(2);
|
else
|
strSQL.Append(3);
|
strSQL.Append(" and LColumn = ");
|
strSQL.Append(lie);
|
strSQL.Append(" and LLayer = ");
|
strSQL.Append(ceng);
|
|
DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSQL);
|
if (dt != null)
|
{
|
IList ls = new List<DepotsLocation>();
|
ls = (IList)ModelConvertHelper<DepotsLocation>.DataTableToModel(dt);
|
dl = (DepotsLocation)ls[0];
|
r = 0;
|
}
|
}
|
catch (Exception ex)
|
{
|
r = -1;
|
}
|
|
return r;
|
}
|
|
public int InsertIPalletReturn(string PalletNo, string Address)
|
{
|
int r = -1;
|
if (string.IsNullOrEmpty(PalletNo) || string.IsNullOrEmpty(Address))
|
{
|
return -1;
|
}
|
try
|
{
|
string[] para = new string[] { PalletNo };
|
int ie = DataFactory.SqlDataBase().IsExist("IPalletReturn", "PalletNo", para);
|
if (ie > 0)
|
{
|
Hashtable ht = new Hashtable();
|
ht["Address"] = Address;
|
ie = DataFactory.SqlDataBase().UpdateByHashtable("IPalletReturn", "PalletNo", PalletNo, ht);
|
}
|
else
|
{
|
Hashtable ht = new Hashtable();
|
ht["PalletNo"] = PalletNo;
|
ht["Address"] = Address;
|
ie = DataFactory.SqlDataBase().InsertByHashtable("IPalletReturn", ht);
|
}
|
if (ie > 0)
|
r = 0;
|
}
|
catch (Exception)
|
{
|
r = -1;
|
}
|
|
return r;
|
}
|
|
#region 空取异常处理
|
/// <summary>
|
/// 出库单空取异常处理
|
/// </summary>
|
/// <param name="cmd"></param>
|
/// <returns></returns>
|
public bool SetErpOut(ErpInCmd cmd)
|
{
|
bool bl = false;
|
try
|
{
|
// 将该出库单明细表中该托盘码对应的物料备注改空取
|
StringBuilder sqlString = new StringBuilder();
|
sqlString.Append("update ErpOutDetail set Demo = '托盘空取异常' ");
|
sqlString.Append("where OrdNo = '" + cmd.TaskID + "' and Palno = '" + cmd.Palno + "'");
|
sqlString.Append(" and Addre = '" + cmd.OldAddre + "';");
|
int rowCount = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
if (rowCount <= 0)
|
{
|
// 盘库异常在这里返回 不执行。
|
bl = false;
|
return bl;
|
}
|
// 将该出库单备注改为: 空取异常请进行盘库操作 (空托出库 = 2 出库单出库 = 1)
|
sqlString.Clear();
|
sqlString.Append("update Erp_Out SET Demo = '空取异常请进行盘库操作' where IsDel = '0' and Ordno = '" + cmd.TaskID + "'; ");
|
rowCount = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
if (rowCount <= 0)
|
{
|
bl = false;
|
return bl;
|
}
|
// 处理出库单状态并删除该指令
|
this.UpdateOut(cmd.TaskID, cmd.Palno, cmd.OldAddre);
|
|
// 库位状态应改位空托盘
|
sqlString.Clear();
|
sqlString.Append("update DepotsLocation set TurnoverDemand = '01' where LocationCode = '" + cmd.OldAddre + "';");
|
rowCount = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
if (rowCount <= 0)
|
{
|
bl = false;
|
return bl;
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
logger.ErrorException("出库单空取异常处理:", ex);
|
return bl;
|
}
|
}
|
|
/// <summary>
|
/// 移库空取异常处理
|
/// </summary>
|
/// <param name="cmd"></param>
|
/// <param name="statu"></param>
|
/// <returns></returns>
|
public bool SetMove(ErpInCmd cmd)
|
{
|
bool bl = false;
|
try
|
{
|
// 将原库位和目标库位置为空货位,库位信息备注置为空取异常 删除指令
|
StringBuilder sqlString = new StringBuilder();
|
sqlString.Append("update DepotsLocation set TurnoverDemand = '01',Demo= '移库空取异常,请进行盘库。'");
|
sqlString.Append("where LocationCode = '" + cmd.OldAddre + "';");
|
int rowCount = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
if (rowCount <= 0)
|
{
|
bl = false;
|
return bl;
|
}
|
|
sqlString.Clear();
|
sqlString.Append("update DepotsLocation set TurnoverDemand = '01' ");
|
sqlString.Append("where LocationCode = '" + cmd.NowAddre + "';");
|
rowCount = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
if (rowCount <= 0)
|
{
|
bl = false;
|
return bl;
|
}
|
|
// 删除指令保证后续指令继续进行
|
sqlString.Clear();
|
sqlString.Append("Update WH_CMD set isdel = '1' where CMDid = '" + cmd.CMDID.ToString() + "';");
|
rowCount = DataFactory.SqlDataBase().ExecuteBySql(sqlString);
|
if (rowCount <= 0)
|
{
|
bl = false;
|
return bl;
|
}
|
|
return true;
|
}
|
catch (Exception ex)
|
{
|
logger.ErrorException("移库空取异常处理:", ex);
|
return bl;
|
}
|
}
|
#endregion
|
}
|
|
public class Order
|
{
|
public string TaskID;
|
public string NumberNo;
|
public string Palno;
|
public string CMDType;
|
public string OldAddre;
|
public string NowAddre;
|
public int CMDStatu;
|
public string CreateUser;
|
public DateTime CreateTime;
|
public string Demo;
|
public int IsDel;
|
public string guid;
|
}
|
}
|