You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

617 lines
22 KiB
C#

10 months ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.MvcShipping.Models.WMSDeliver;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Models.MsStevedores;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.Models.WMSNew;
//Please add references
namespace DSWeb.MvcShipping.DAL.WMSDeliver
{
/// <summary>
/// 数据访问类:WMSDeliver
/// </summary>
public partial class WMSEIPSDeliverDAL
{
public WMSEIPSDeliverDAL()
{ }
#region BasicMethod
//static Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
static public List<EIP_Deliver> GetDataList(string strCondition, int start, int limit, string userid, string username, string companyid, out int total, string sort = null)
{
/*
var rangstr = GetRangDAStr("index", userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
*/
var strSql = new StringBuilder();
strSql.Append(@"SELECT BSNO,DeliverNo,CustomerName,convert(char(10),DeliverDate,20) AS DeliverDate,
convert(char(10),EnterDate,20) AS EnterDate,Factory,BuyContract,TruckNo,Driver,EnterOperater,GoodsNameTT,
CASE BSStatus WHEN '0' THEN '' WHEN '1' THEN '' WHEN '2' THEN '' ELSE '' END AS BSStatus,CORPID,REMARK
FROM EIP_Deliver where 1=1 and BSStatus <> '0' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
if (!string.IsNullOrEmpty(sort))
{
var so = JsonConvert.Deserialize<List<SortObjectDeliver>>(sort);
string orderbyStr = " order by ";
foreach (var s in so)
{
orderbyStr += s.property + " " + s.direction + ",";
}
orderbyStr = orderbyStr.Substring(0, orderbyStr.Length - 1);
strSql.Append(orderbyStr);
}
else
{
strSql.Append(" order by DeliverNo DESC ");
}
int totalCount = 0;
StringBuilder sb = PagerHelperEIP.PageSQL(strSql.ToString(), start, limit, out totalCount);
total = totalCount;
return SetData(sb);
}
/// <summary>
/// 执行sql
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
private static List<EIP_Deliver> SetData(StringBuilder strSql)
{
#region 公共代码
var headList = new List<EIP_Deliver>();
Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 120000; //要加这一句
using (IDataReader row = dbEIP.ExecuteReader(cmd))
{
while (row.Read())
{
EIP_Deliver model = new EIP_Deliver();
#region 动软
if (row["BSNO"] != null)
{
model.BSNO = row["BSNO"].ToString();
}
if (row["BSSTATUS"] != null)
{
model.BSSTATUS = row["BSSTATUS"].ToString();
}
if (row["DELIVERNO"] != null)
{
model.DELIVERNO = row["DELIVERNO"].ToString();
}
if (row["CUSTOMERNAME"] != null)
{
model.CUSTOMERNAME = row["CUSTOMERNAME"].ToString();
}
if (row["FACTORY"] != null)
{
model.FACTORY = row["FACTORY"].ToString();
}
if (row["BUYCONTRACT"] != null)
{
model.BUYCONTRACT = row["BUYCONTRACT"].ToString();
}
if (row["GOODSNAMETT"] != null)
{
model.GOODSNAMETT = row["GOODSNAMETT"].ToString();
}
if (row["DELIVERDATE"] != null && row["DELIVERDATE"].ToString() != "")
{
model.DELIVERDATE = row["DELIVERDATE"].ToString();
}
if (row["DRIVER"] != null)
{
model.DRIVER = row["DRIVER"].ToString();
}
if (row["TRUCKNO"] != null)
{
model.TRUCKNO = row["TRUCKNO"].ToString();
}
if (row["ENTEROPERATER"] != null)
{
model.ENTEROPERATER = row["ENTEROPERATER"].ToString();
}
if (row["ENTERDATE"] != null && row["ENTERDATE"].ToString() != "")
{
model.ENTERDATE = row["ENTERDATE"].ToString();
}
if (row["CORPID"] != null && row["CORPID"].ToString() != "")
{
model.CORPID = row["CORPID"].ToString();
}
if (row["REMARK"] != null && row["REMARK"].ToString() != "")
{
model.REMARK = row["REMARK"].ToString();
}
#endregion
headList.Add(model);
}
row.Close();
}
return headList;
#endregion
}
static public List<EIP_Tray> GetTrayList(string strBSNO)
{
/*
var rangstr = GetRangDAStr("index", userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
*/
var strSql = new StringBuilder();
strSql.Append("select GID,BSNO,STOCKNO,TRAYNO,GOODSNAMETT,TTPKGS,TTWEIGHT,WMSNO,WMSOUTNO,ISSTOCKUP, ");
strSql.Append("CNTRNO,SEALNO,REMARK,CORPID ");
strSql.Append(" FROM EIP_Tray ");
if (strBSNO.Trim() != "")
{
strSql.Append(" where BSNO='" + strBSNO + "'");
}
return SetTrayData(strSql);
}
/// <summary>
/// 执行sql
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
private static List<EIP_Tray> SetTrayData(StringBuilder strSql)
{
#region 公共代码
var headList = new List<EIP_Tray>();
Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 120000; //要加这一句
using (IDataReader row = dbEIP.ExecuteReader(cmd))
{
while (row.Read())
{
EIP_Tray model = new EIP_Tray();
#region 动软
if (row != null)
{
if (row["GID"] != null)
{
model.GID = row["GID"].ToString();
}
if (row["BSNO"] != null)
{
model.BSNO = row["BSNO"].ToString();
}
if (row["STOCKNO"] != null)
{
model.STOCKNO = row["STOCKNO"].ToString();
}
if (row["TRAYNO"] != null)
{
model.TRAYNO = row["TRAYNO"].ToString();
}
if (row["GOODSNAMETT"] != null)
{
model.GOODSNAMETT = row["GOODSNAMETT"].ToString();
}
if (row["TTPKGS"] != null && row["TTPKGS"].ToString() != "")
{
model.TTPKGS = (row["TTPKGS"].ToString());
}
if (row["TTWEIGHT"] != null && row["TTWEIGHT"].ToString() != "")
{
model.TTWEIGHT = (row["TTWEIGHT"].ToString());
}
if (row["WMSNO"] != null)
{
model.WMSNO = row["WMSNO"].ToString();
}
if (row["WMSOUTNO"] != null)
{
model.WMSOUTNO = row["WMSOUTNO"].ToString();
}
if (row["ISSTOCKUP"] != null)
{
model.ISSTOCKUP = row["ISSTOCKUP"].ToString();
}
if (row["CNTRNO"] != null)
{
model.CNTRNO = row["CNTRNO"].ToString();
}
if (row["SEALNO"] != null)
{
model.SEALNO = row["SEALNO"].ToString();
}
if (row["REMARK"] != null)
{
model.REMARK = row["REMARK"].ToString();
}
if (row["CORPID"] != null)
{
model.REMARK = row["CORPID"].ToString();
}
}
#endregion
headList.Add(model);
}
row.Close();
}
return headList;
#endregion
}
public static bool UpdateByDeliverNo(string bsno, string state,bool flag)
{
StringBuilder strSql = new StringBuilder();
if (flag)
{
strSql.Append("update EIP_Deliver set BSSTATUS='" + state + "' where BSNO IN (" + bsno + ")");
}
else
{
strSql.Append("update EIP_Deliver set BSSTATUS='" + state + "' where BSNO='" + bsno + "'");
}
Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
int rst = dbEIP.ExecuteNonQuery(CommandType.Text, strSql.ToString());
if (rst > 0)
{
return true;
}
else
{
return false;
}
}
public static bool UpdateTrayNo(string gid, string trayNo, string storageName)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update EIP_Tray set TRAYNO='" + trayNo + "',STORAGENAME='" + storageName + "' where GID='" + gid + "'");
Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
int rst = dbEIP.ExecuteNonQuery(CommandType.Text, strSql.ToString());
if (rst > 0)
{
return true;
}
else
{
return false;
}
}
static public List<EIP_Goods> GetGoodsList(string strTRGID)
{
/*
var rangstr = GetRangDAStr("index", userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
*/
var strSql = new StringBuilder();
strSql.Append("select GID,BSNO,TRGID,SPECS,GOODSNAME,PKGS,UNIT,WEIGHT,REMARK,REMNANT,CONTRACTNUM,TRAYNO ");
strSql.Append(" FROM EIP_Goods ");
if (strTRGID.Trim() != "")
{
strSql.Append(" where TRGID='" + strTRGID + "'");
}
return SetGoodsData(strSql);
}
/// <summary>
/// 执行sql
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
private static List<EIP_Goods> SetGoodsData(StringBuilder strSql)
{
#region 公共代码
var headList = new List<EIP_Goods>();
Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strSql.ToString();
cmd.CommandTimeout = 120000; //要加这一句
using (IDataReader row = dbEIP.ExecuteReader(cmd))
{
while (row.Read())
{
EIP_Goods model = new EIP_Goods();
#region 动软
if (row != null)
{
if (row["GID"] != null)
{
model.GID = row["GID"].ToString();
}
if (row["BSNO"] != null)
{
model.BSNO = row["BSNO"].ToString();
}
if (row["TRGID"] != null)
{
model.TRGID = row["TRGID"].ToString();
}
if (row["SPECS"] != null)
{
model.SPECS = row["SPECS"].ToString();
}
if (row["GOODSNAME"] != null)
{
model.GOODSNAME = row["GOODSNAME"].ToString();
}
if (row["PKGS"] != null && row["PKGS"].ToString() != "")
{
model.PKGS = int.Parse(row["PKGS"].ToString());
}
if (row["UNIT"] != null)
{
model.UNIT = row["UNIT"].ToString();
}
if (row["WEIGHT"] != null && row["WEIGHT"].ToString() != "")
{
model.WEIGHT = decimal.Parse(row["WEIGHT"].ToString());
}
if (row["REMARK"] != null)
{
model.REMARK = row["REMARK"].ToString();
}
if (row["REMNANT"] != null && row["REMNANT"].ToString() != "")
{
model.REMNANT = int.Parse(row["REMNANT"].ToString());
}
if (row["CONTRACTNUM"] != null && row["CONTRACTNUM"].ToString() != "")
{
model.CONTRACTNUM = decimal.Parse(row["CONTRACTNUM"].ToString());
}
if (row["TRAYNO"] != null)
{
model.TRAYNO = row["TRAYNO"].ToString();
}
}
#endregion
headList.Add(model);
}
row.Close();
}
return headList;
#endregion
}
static public bool DeliverToWMS(string data,string userid)
{
var deliverList = JsonConvert.Deserialize<List<EIP_Deliver>>(data);
bool flag = false;
string msg = "";
foreach (var item in deliverList)
{
try
{
WMSNew wms = new WMSNew();
wms.GID = item.BSNO;
wms.WMSNO = item.DELIVERNO;
wms.CUSTOMERNAME = item.CUSTOMERNAME;
wms.FACTORY = item.FACTORY;
wms.CONTRACTNO = item.BUYCONTRACT;
wms.GOODSNAME = item.GOODSNAMETT;
wms.WMSDATE = item.DELIVERDATE;
wms.CREATEUSER = item.ENTEROPERATER;
wms.CREATETIME = item.ENTERDATE;
wms.CHARGEUNIT = "托";
wms.STARTBILLINGDATE = item.DELIVERDATE;
wms.ARCLIENT = item.CUSTOMERNAME;
wms.CORPID = item.CORPID;
wms.GOODSNAMEID = item.GOODSNAMETT;
wms.STORAGENAME = BasicDataRefDAL.GetHTStorageName();
wms.GOODSPACKSTOCK = "0";
wms.GOODSSTOCK = "0";
wms.GOODSPACK = "0";
wms.GOODSRKSL = "0";
wms.GOODSPACKACTUAL = "0";
wms.GOODSRKSLACTUAL = "0";
wms.MARKETVALUE = "0";
wms.BANKVALUE = "0";
wms.GOODSKGS = "0";
wms.ISCHANGE = "0";
wms.REMARK = item.REMARK;
wms.ISLOCK = "0";
wms.TiDanJianShu = "0";
wms.DbOperationType = DbOperationType.DbotIns;
wms.ModelUIStatus = "I";
List<EIP_Tray> trayList = WMSEIPSDeliverDAL.GetTrayList(item.BSNO);
List<WMSNewIN> wmsInList = new List<WMSNewIN>();
WMSNewIN wmsIn = new WMSNewIN();
int tmpPack = 0;
decimal tmpKgs = 0;
foreach (var itemTray in trayList)
{
wmsIn.GID = itemTray.GID;
wmsIn.ASSOCIATEDNO = item.BSNO;
wmsIn.TRAYNO = itemTray.TRAYNO;
wmsIn.GOODSNAME = itemTray.GOODSNAMETT;
wmsIn.JIANSHU1 = itemTray.TTPKGS;
wmsIn.GOODSPACK = itemTray.TTPKGS;
wmsIn.GOODSPACKSTOCK = itemTray.TTPKGS;
tmpPack += Convert.ToInt32(itemTray.TTPKGS);
//wmsIn.GOODSKGS = itemTray.TTWEIGHT;
//wmsIn.GOODSSTOCK = itemTray.TTWEIGHT;
wmsIn.GOODSKGS = "1";
wmsIn.GOODSSTOCK = "1";
tmpKgs += 1;
wmsIn.GOODSRKSL = "1";
wmsIn.CHARGEUNIT = "托";
wmsIn.REMARK = itemTray.REMARK;
wmsIn.GOODSNAMEID = itemTray.GOODSNAMETT;
wmsIn.STORAGENAME = wms.STORAGENAME;
wmsIn.CONTRACTNO = wms.CONTRACTNO;
WMSDeliverDAL.AddWMSIN(wmsIn);
List<EIP_Goods> goodsList = WMSEIPSDeliverDAL.GetGoodsList(itemTray.GID);
foreach (var itemGoods in goodsList)
{
WMSDeliverDAL.AddGoods(itemGoods);
}
}
wms.GOODSPACK = Convert.ToString(tmpPack);
wms.GOODSKGS = Convert.ToString(tmpKgs);
wms.GOODSSTOCK = Convert.ToString(tmpKgs);
wms.GOODSPACKSTOCK = Convert.ToString(tmpPack);
WMSDeliverDAL.Add(wms);
//更新EIP中送货单状态
flag = WMSEIPSDeliverDAL.UpdateByDeliverNo(item.BSNO, "2",false);
}
catch (Exception ee)
{
msg = ee.Message;
}
}
return flag;
}
#endregion BasicMethod
#region ExtensionMethod
public static DataSet GetTrayAndGoodsListWithDeliver(string deliverNO)
{
StringBuilder strSql = new StringBuilder();
strSql.AppendLine("SELECT DELIVERNO,GOODSNAMETT,BSNO,CUSTOMERNAME,BUYCONTRACT,");
strSql.AppendLine("convert(char(10),DeliverDate,20) AS DeliverDate,");
strSql.AppendLine("convert(char(10),EnterDate,20) AS EnterDate,");
strSql.AppendLine("Factory,BuyContract,TruckNo,Driver,EnterOperater,BSStatus,CORPID,");
strSql.AppendLine("CASE BSStatus WHEN '0' THEN '新建' WHEN '1' THEN '入库请求' WHEN '2' THEN '接受入库请求' ELSE '已入库' END AS BSStatusName,");
strSql.AppendLine("C.SHOWNAME CompanyName,C.COMNAME CompanyFullName");
strSql.AppendLine("FROM EIP_Deliver D");
strSql.AppendLine("JOIN [USER] C ON D.CORPID=C.COMNAME");
strSql.AppendLine($"WHERE DELIVERNO='{deliverNO}';");
strSql.AppendLine("SELECT T.GID,T.TRAYNO,T.GOODSNAMETT,T.TTPKGS,T.TTWEIGHT,D.BSNO");
strSql.AppendLine("from EIP_Tray T");
strSql.AppendLine("JOIN EIP_DeliverTray DT ON T.GID=DT.TRGID");
strSql.AppendLine("JOIN EIP_Deliver D ON DT.BSNO=D.BSNO");
strSql.AppendLine($"WHERE D.DELIVERNO='{deliverNO}';");
strSql.AppendLine("SELECT G.* from EIP_Tray T");
strSql.AppendLine("JOIN EIP_DeliverTray DT ON T.GID=DT.TRGID");
strSql.AppendLine("JOIN EIP_Deliver D ON DT.BSNO=D.BSNO");
strSql.AppendLine("JOIN EIP_Goods G ON G.TRGID=T.GID");
strSql.AppendLine($"WHERE D.DELIVERNO='{deliverNO}';");
Database dbEIP = DatabaseFactory.CreateDatabase("EIP");
return dbEIP.ExecuteDataSet(CommandType.Text, strSql.ToString());
}
#endregion ExtensionMethod
}
}