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.
DS7/DSWeb/Areas/TruckMng/DAL/MsRptPcHeadEdit/MsRptPcHeadEditDAL.cs

1359 lines
70 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsWlBs;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using System.Web;
using System.Data.Common;
using DSWeb.TruckMng.Comm.Cookie;
using WebSqlHelper;
using HcUtility.Core;
using DSWeb.EntityDA;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.Areas.CommMng.DAL;
using System.Linq;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using DSWeb.Common.DB;
using System.Data.Entity.Migrations;
2 years ago
namespace DSWeb.Areas.TruckMng.DAL.MsRptPcHeadEdit
{
public partial class MsRptPcHeadEditDAL
{
#region 派车计划列表
2 years ago
static public List<MsWlPcHead_ADLEdit> GetDataList ( string strCondition, string userid, string usercode, string username, string companyid, string sort )
2 years ago
{ //合同信息/商品信息
2 years ago
var rangstr = GetRangDAStr("index", userid, usercode, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
2 years ago
var strSql = new StringBuilder();
strSql.Append(" select GId,case when TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,dbo.trimdate(expdate) GroupDate ");
2 years ago
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate,CustomerName,(select description from info_client where shortname=t.CustomerName) CustomerNameFull ");
2 years ago
strSql.Append(" ,F_CustomerName,DstArea,DetiNation ");
strSql.Append(" ,ContainerType,ContainerTypeSe,(SELECT CtnName FROM VMSTRUCKCTN WHERE CTNCODE=ContainerType) AS ContainerType_Ref ");
strSql.Append(" ,isnull(ContainerQty,0) ContainerQty,TruckNo,MblNo,dbo.trimdate(EndPortDate) EndPortDate,DrvCode,DrvName ");
strSql.Append(" ,Mobile,YardCode,YARDNAME AS YardCode_Ref ");
strSql.Append(" ,RtnYardCode,RtnYardName AS RtnYardCode_Ref ");
strSql.Append(" ,VoyVeg,OrgCode,DDCode,LoadPlace,TruckSpec,FactoryAddr,Remark ");
2 years ago
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99033 and EnumValueID=(select Property from tmswltruck where truckno=t.truckno)) PropertyRef ");
2 years ago
strSql.Append(" ,RefBillNo,DGTYPE,DGTYPECODE,SECOND_DRV,dbo.trimdate(ArriveDate) ArriveDate,ArriveTime,RefBillNoSe");
2 years ago
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
2 years ago
strSql.Append(",GOODSCOUNT,CBM,ISHW,Ton,GoodsName,CreateTime,PGId,ContainerNo,SealNo,ContainerNoSe,SealNoSe ");
2 years ago
strSql.Append(" from tMsWlPcHead t ");
2 years ago
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition.Replace("~",""));//str.Replace("b","**");
}
//strSql.Append(" order by Expdate desc ");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by Expdate desc," + sortstring);
}
else
{
strSql.Append(" order by Expdate desc ");
}
return SetData(strSql);
}
//static public MsWlPcHead_ADLEdit GetData ( string condition )
//{
// var _t = "";
// var list = GetDataList(condition, _t);
// if (list.Count > 0)
// return list[0];
// return new MsWlPcHead_ADLEdit();
//}
static public List<MsWlPcHead_ADLEdit> AddTail(List<MsWlPcHead_ADLEdit> tmpList)
{
double ton = 0.000;
foreach (var item in tmpList)
{
ton += Convert.ToDouble(item.Ton);
}
MsWlPcHead_ADLEdit data = new MsWlPcHead_ADLEdit();
data.GId ="0000000000000";
data.RowNumber = "合计";
data.PCSTATUSREF = "";
data.BillNo = "";
data.ExpDate = "";
data.GroupDate = "";
data.CustomerName = "";
data.CustomerNameFull = "";
data.F_CustomerName = "";
data.DstArea = "";
data.DetiNation = "";
data.FactoryAddr = "";
data.ContainerType = "";
data.ContainerType_Ref = "";
data.ContainerQty = "";
data.TruckNo = "";
data.TruckSpec = "";
data.MblNo = "";
data.EndPortDate = "";
data.DrvCode = "";
data.DrvName = "";
data.Mobile = "";
data.YardCode = "";
data.YardCode_Ref = "";
data.RtnYardCode = "";
data.RtnYardCode_Ref = "";
data.VoyVeg = "";
data.OrgCode = "";
data.DDCode = "";
data.PropertyRef = "";
data.LoadPlace = "";
data.RefBillNo = "";
data.RefBillNoSe = "";
data.DGTYPE = "";
data.DGTYPECODE = "";
data.SECOND_DRV = "";
data.ArriveDate = "";
data.ArriveTime = "";
data.DRFEESTATUS = "";
data.CRFEESTATUS = "";
data.GOODSCOUNT = "";
data.CBM = "";
data.ISHW = 0;
data.Remark = "";
data.GoodsName = "";
data.Ton = Convert.ToString(ton);
data.CreateTime = "";
tmpList.Add(data);
return tmpList;
}
private static List<MsWlPcHead_ADLEdit> SetData ( StringBuilder strSql )
{
var headList = new List<MsWlPcHead_ADLEdit>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlPcHead_ADLEdit data = new MsWlPcHead_ADLEdit();
#region Set DB data to Object
data.GId = Convert.ToString(reader["GId"]);
data.RowNumber = Convert.ToString(reader["RowNumber"]);
data.PCSTATUSREF = Convert.ToString(reader["PCSTATUSREF"]);
data.BillNo = Convert.ToString(reader["BillNo"]);
data.ExpDate = Convert.ToString(reader["ExpDate"]);
data.GroupDate = Convert.ToString(reader["GroupDate"]);
data.CustomerName = Convert.ToString(reader["CustomerName"]);
data.CustomerNameFull = Convert.ToString(reader["CustomerNameFull"]);
data.F_CustomerName = Convert.ToString(reader["F_CustomerName"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.FactoryAddr = Convert.ToString(reader["FactoryAddr"]);
data.ContainerType = Convert.ToString(reader["ContainerType"]);
data.ContainerType_Ref = Convert.ToString(reader["ContainerType_Ref"]);
data.ContainerQty = Convert.ToString(reader["ContainerQty"]);
data.ContainerTypeSe = Convert.ToString(reader["ContainerTypeSe"]);
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.TruckSpec = Convert.ToString(reader["TruckSpec"]);
data.MblNo = Convert.ToString(reader["MblNo"]);
data.EndPortDate = Convert.ToString(reader["EndPortDate"]);
data.DrvCode = Convert.ToString(reader["DrvCode"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
data.Mobile = Convert.ToString(reader["Mobile"]);
data.YardCode = Convert.ToString(reader["YardCode"]);
data.YardCode_Ref = Convert.ToString(reader["YardCode_Ref"]);
data.RtnYardCode = Convert.ToString(reader["RtnYardCode"]);
data.RtnYardCode_Ref = Convert.ToString(reader["RtnYardCode_Ref"]);
data.VoyVeg = Convert.ToString(reader["VoyVeg"]);
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.DDCode = Convert.ToString(reader["DDCode"]);
data.PropertyRef = Convert.ToString(reader["PropertyRef"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.RefBillNo = Convert.ToString(reader["RefBillNo"]);
data.RefBillNoSe = Convert.ToString(reader["RefBillNoSe"]);
data.DGTYPE = Convert.ToString(reader["DGTYPE"]);
data.DGTYPECODE = Convert.ToString(reader["DGTYPECODE"]);
data.SECOND_DRV = Convert.ToString(reader["SECOND_DRV"]);
data.ArriveDate = Convert.ToString(reader["ArriveDate"]);
data.ArriveTime = Convert.ToString(reader["ArriveTime"]);
data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"]));
data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"]));
data.GOODSCOUNT = Convert.ToString(reader["GOODSCOUNT"]);
data.CBM = Convert.ToString(reader["CBM"]);
data.ISHW = Convert.ToDecimal(reader["ISHW"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.GoodsName = Convert.ToString(reader["GoodsName"]);
data.Ton = Convert.ToString(reader["Ton"]);
data.CreateTime = reader["CreateTime"] == DBNull.Value ? "" : reader["CreateTime"].ToString();
data.PGId = Convert.ToString(reader["PGId"]);
data.ContainerNo = Convert.ToString(reader["ContainerNo"]);
data.SealNo = Convert.ToString(reader["SealNo"]);
data.ContainerNoSe = Convert.ToString(reader["ContainerNoSe"]);
data.SealNoSe = Convert.ToString(reader["SealNoSe"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static string getfeestatus ( string feestatusint )
{
var result = "";
if (feestatusint == "0:")
{
return "审核通过";
}
else if (feestatusint == "1:")
{
return "录入状态";
}
else if (feestatusint == "2:")
{
return "提交审核";
}
else if (feestatusint == "8:")
{
return "部分结算";
}
else if (feestatusint == "9:")
{
return "结算完毕";
}
else if (feestatusint == "")
{
return "未录入";
}
else if (feestatusint == "3:")
{
return "申请修改";
}
else if (feestatusint == "4:")
{
return "申请删除";
}
else if (feestatusint == "6:")
{
return "驳回提交";
}
else if (feestatusint == "7:")
{
return "驳回申请";
}
else if (feestatusint.IndexOf("9:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("0:") > -1)
{
return "部分审核";
}
else if (feestatusint.IndexOf("2:") > -1)
{
return "部分提交";
}
else if (feestatusint.IndexOf("6:") > -1)
{
return "驳回提交";
}
else if (feestatusint.IndexOf("7:") > -1)
{
return "驳回申请";
}
return result;
}
#endregion
/// <summary>
/// 获取目的地列表
/// </summary>
/// <param name="strCondition"></param>
/// <param name="sort"></param>
/// <returns></returns>
static public List<MsWlMudidi> GetMuDiDi ( string strCondition, string sort )
{
string sql = "select DISTINCT dstarea from tMsWlPcHead where dstarea <> ''";
var list = new List<MsWlMudidi>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
MsWlMudidi mdd = new MsWlMudidi();
mdd.mudidi = reader["dstarea"].ToString();
list.Add(mdd);
}
}
return list;
}
/// <summary>
/// 获取始发地列表
/// </summary>
/// <param name="strCondition"></param>
/// <param name="sort"></param>
/// <returns></returns>
static public List<MsWlShiFaDi> GetShiFaDi ( string strCondition, string sort )
{
string sql = "select DISTINCT LoadPlace from tMsWlPcHead where dstarea <> ''";
var list = new List<MsWlShiFaDi>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
MsWlShiFaDi sfd = new MsWlShiFaDi();
sfd.shifadi = reader["LoadPlace"].ToString();
list.Add(sfd);
}
}
return list;
}
#region 编码生成
public static String getCodeRule ( string strRULENAME, string strfield, string strETD, string strACCDATE, string strUserID, string strCompanyID )
{
//调用编码规则
if (strETD.Trim().IndexOf("0001") > -1)
{
strETD = "";
}
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
//
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=6");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (strETD.Trim() == "")
{
return "";
}
DateTime dETD = System.Convert.ToDateTime(strETD.Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("会计期间"))
{
if (strACCDATE.Trim() == "")
{
return "";
}
DateTime dACCDATE = System.Convert.ToDateTime(strACCDATE.Trim() + "-01");
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dACCDATE.ToString("yyyy") + dACCDATE.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dACCDATE.ToString("yy") + dACCDATE.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dACCDATE.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dACCDATE.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID.Trim() + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID.Trim() + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
//string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
//strCONTENT = tempBANKSHEAD + strCONTENT;
//
strRULENOLENGTH = T_ALL_DA.GetStrSQL(strfield, "select top 1 " + strfield + " from [tmswlPcHead] where " + strfield + " like '" + strCONTENT.Trim() + "%' order by " + strfield + " DESC");
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
return strCONTENT;
}
}
}
return "";
}
#endregion
#region 潍坊松达需求
//GetWFSDList MsWlPcHead_WFSDEdit
static public List<MsWlPcHead_WFSDEdit> GetWFSDList ( string strCondition, string userid,string usercode,string username,string companyid,string sort )
{ //合同信息/商品信息
1 year ago
if (!string.IsNullOrWhiteSpace(userid) || !string.IsNullOrWhiteSpace(usercode) || !string.IsNullOrWhiteSpace(username) || !string.IsNullOrWhiteSpace(companyid))
2 years ago
{
1 year ago
var rangstr = GetRangDAStr("index", userid, usercode, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
2 years ago
{
1 year ago
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
2 years ago
}
}
var strSql = new StringBuilder();
strSql.Append(" select CargoID,LoadFactory,PcBillType,PGid,BLTYPE,TRANSSTATUS ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate, dbo.trimdate(expdate) GroupDate ,ArriveDate,ReturnDate ");
1 year ago
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.DrvCode,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty,GOODSCOUNT,CBM ");
2 years ago
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='运费' and FEETYPE=1)YUNFEI ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='回程合计' and FEETYPE=1)HCHJ ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='装卸费' and FEETYPE=1)ZXF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='代垫费' and FEETYPE=1)DDF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename not in('运费','回程合计','装卸费','代垫费') and FEETYPE=1)QTFee ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and FEETYPE=1)TotalFee,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr,ContainerNo,SealNo");
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
1 year ago
strSql.Append(",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS");
strSql.Append(",(select TOP 1 COLOR FROM code_op_status_detail WITH (NOLOCK) WHERE OPSTATUS = (CASE WHEN (SELECT TOP 1 [STATUS] FROM V_OP_STATUS WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) is null THEN '接受委托' else (SELECT TOP 1[STATUS] FROM V_OP_STATUS WHERE BSNO =t.GId ORDER BY COMPTIME DESC, INPUTTIME DESC) end))AS COLOR");
strSql.Append(",t.SALECORPID,(select [NAME] from [company] where GID=t.SALECORPID) as SALECORP,DCLASS,DUNNO");
2 years ago
1 year ago
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName,PORTLOAD,DESTINATION,RtnDocStatus,RtnDocTime,ACCDATE,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(",FuelPrice,FuelQty,RealMil,isEnd");
1 year ago
strSql.Append( " from tMsWlPcHead t ");
2 years ago
if (!string.IsNullOrEmpty(strCondition))
{
//strSql.Append(" where 1=1 AND " + strCondition);
strSql.Append(" where (t.GID=t.PGID OR t.PGID='' OR t.PGID IS NULL) AND EXISTS ( select 1 from tMsWlPcHead WHERE t.GID=tMsWlPcHead.PGID AND " + strCondition + " )");
}
else
{
//strSql.Append(" where 1=1 " );
strSql.Append(" where (t.GID=t.PGID OR t.PGID='' OR t.PGID IS NULL) ");
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by Expdate,billno ");
}
return SetWFSDData(strSql);
}
1 year ago
2 years ago
static public List<MsWlPcHead_WFSDEdit> GetWFSDFenList(string strCondition, string sort)
{ //合同信息/商品信息
var strSql = new StringBuilder();
strSql.Append(" select CargoID,LoadFactory,PcBillType,PGid,BLTYPE,TRANSSTATUS ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate, dbo.trimdate(expdate) GroupDate ,ArriveDate,ReturnDate ");
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty,GOODSCOUNT,CBM ");
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='运费' and FEETYPE=1)YUNFEI ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='回程合计' and FEETYPE=1)HCHJ ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='装卸费' and FEETYPE=1)ZXF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='代垫费' and FEETYPE=1)DDF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename not in('运费','回程合计','装卸费','代垫费') and FEETYPE=1)QTFee ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and FEETYPE=1)TotalFee,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr,ContainerNo,SealNo");
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
1 year ago
strSql.Append(",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS");
strSql.Append(",(select TOP 1 COLOR FROM code_op_status_detail WITH (NOLOCK) WHERE OPSTATUS = (CASE WHEN (SELECT TOP 1 [STATUS] FROM V_OP_STATUS WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) is null THEN '接受委托' else (SELECT TOP 1[STATUS] FROM V_OP_STATUS WHERE BSNO =t.GId ORDER BY COMPTIME DESC, INPUTTIME DESC) end))AS COLOR");
strSql.Append(",t.SALECORPID,(select [NAME] from [company] where GID=t.SALECORPID) as SALECORP,DCLASS,DUNNO");
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName,PORTLOAD,DESTINATION,RtnDocStatus,RtnDocTime,ACCDATE,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ,FuelPrice,FuelQty,RealMil,isEnd ");
strSql.Append(" from tMsWlPcHead t ");
2 years ago
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition.Replace("~", ""));//str.Replace("b","**");
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by Expdate,billno ");
}
return SetWFSDData(strSql);
}
static public MsWlPcHead_WFSDEdit GetWFSDData ( string condition )
{
var strSql = new StringBuilder();
strSql.Append(" select CargoID,LoadFactory,PcBillType,PGid,BLTYPE,TRANSSTATUS ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate, dbo.trimdate(expdate) GroupDate ,ArriveDate,ReturnDate ");
1 year ago
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.DrvCode,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty,GOODSCOUNT,CBM ");
2 years ago
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='运费' and FEETYPE=1)YUNFEI ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='回程合计' and FEETYPE=1)HCHJ ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='装卸费' and FEETYPE=1)ZXF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='代垫费' and FEETYPE=1)DDF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename not in('运费','回程合计','装卸费','代垫费') and FEETYPE=1)QTFee ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and FEETYPE=1)TotalFee,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,ContainerTypeSe,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr,ContainerNo,SealNo");
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
1 year ago
strSql.Append(",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=t.GId ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS");
strSql.Append(",'' AS COLOR");
strSql.Append(",t.SALECORPID,(select [NAME] from [company] where GID=t.SALECORPID) as SALECORP,DCLASS,DUNNO");
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName,PORTLOAD,DESTINATION,RtnDocStatus,RtnDocTime,ACCDATE,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF,FuelPrice,FuelQty,RealMil,isEnd from tMsWlPcHead t ");
2 years ago
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition.Replace("~", ""));//str.Replace("b","**");
}
var list = SetWFSDData(strSql);
if (list.Count > 0)
return list[0];
return new MsWlPcHead_WFSDEdit();
}
private static List<MsWlPcHead_WFSDEdit> SetWFSDData ( StringBuilder strSql )
{
var headList = new List<MsWlPcHead_WFSDEdit>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlPcHead_WFSDEdit data = new MsWlPcHead_WFSDEdit();
#region Set DB data to Object
data.PcBillType = Convert.ToString(reader["PcBillType"]);
data.PcBillTypeREF = Convert.ToString(reader["PcBillTypeREF"]);
data.timeMark = Convert.ToDecimal(reader["timeMark"]);
data.gId = Convert.ToString(reader["gId"]);
data.PGid = Convert.ToString(reader["PGid"]);
data.BLTYPE = Convert.ToString(reader["BLTYPE"]);
data.TRANSSTATUS = Convert.ToString(reader["TRANSSTATUS"]);
data.RowNumber = Convert.ToString(reader["RowNumber"]);
data.BillNo = Convert.ToString(reader["BillNo"]);
data.ExpDate = Convert.ToString(reader["ExpDate"]);
data.GroupDate = Convert.ToString(reader["GroupDate"]);
data.ArriveDate = Convert.ToString(reader["ArriveDate"]);
data.ReturnDate = Convert.ToString(reader["ReturnDate"]);
data.CustomerName = Convert.ToString(reader["CustomerName"]);
data.F_CustomerName = Convert.ToString(reader["F_CustomerName"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
1 year ago
data.DrvCode = Convert.ToString(reader["DrvCode"]);
2 years ago
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.MblNo = Convert.ToString(reader["MblNo"]);
data.LinkMan = Convert.ToString(reader["LinkMan"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.ContainerQty = Convert.ToString(reader["ContainerQty"]);
data.Ton = Convert.ToString(reader["Ton"]);
data.GOODSCOUNT = Convert.ToString(reader["GOODSCOUNT"]);
data.CBM = Convert.ToString(reader["CBM"]);
data.LoadCount = Convert.ToString(reader["LoadCount"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.TruckSpec = Convert.ToString(reader["TruckSpec"]);
data.IsDouble = Convert.ToString(reader["IsDouble"]);
data.Property = Convert.ToString(reader["Property"]);
data.YUNFEI = Convert.ToString(reader["yunfei"]);
data.HCHJ = Convert.ToString(reader["HCHJ"]);
data.ZXF = Convert.ToString(reader["ZXF"]);
data.DDF = Convert.ToString(reader["DDF"]);
data.QTFee = Convert.ToString(reader["QTFee"]);
data.TotalFee = Convert.ToString(reader["TotalFee"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.FEESTATUS = Convert.ToString(reader["FeeStatus"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.LrDate = Convert.ToString(reader["LrDate"]);
data.PCSTATUSREF = Convert.ToString(reader["PCSTATUSREF"]);
data.RefBillNo = Convert.ToString(reader["RefBillNo"]);
data.RefBillNose = Convert.ToString(reader["RefBillNose"]);
data.MblNoSe = Convert.ToString(reader["MblNoSe"]);
data.ContainerType = Convert.ToString(reader["ContainerType"]);
if(BasicDataRefDAL.ReadFieldExist(reader,"ContainerTypeSe"))
data.ContainerTypeSe = Convert.ToString(reader["ContainerTypeSe"]);
data.LinkTel = Convert.ToString(reader["LinkTel"]);
data.YardName = Convert.ToString(reader["YardName"]);
data.LinkManSe = Convert.ToString(reader["LinkManSe"]);
data.LinkTelSe = Convert.ToString(reader["LinkTelSe"]);
data.RtnYardName = Convert.ToString(reader["RtnYardName"]);
data.BsType = Convert.ToString(reader["BsType"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CustLikeManName = Convert.ToString(reader["CustLikeManName"]);
data.CustTel = Convert.ToString(reader["CustTel"]);
data.ChangedReson = Convert.ToString(reader["ChangedReson"]);
data.FactoryAddr = Convert.ToString(reader["FactoryAddr"]);
data.DispatchName = Convert.ToString(reader["DispatchName"]);
data.INVOICENO = Convert.ToString(reader["INVOICENO"]);
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.SalesName = Convert.ToString(reader["SalesName"]);
data.VoyVeg = Convert.ToString(reader["VoyVeg"]);
data.EtDate = Convert.ToString(reader["EtDate"]);
data.EndPortDate = Convert.ToString(reader["EndPortDate"]);
data.GoodsName = Convert.ToString(reader["GoodsName"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.DESTINATION = Convert.ToString(reader["DESTINATION"]);
data.CargoID = Convert.ToString(reader["CARGOID"]);
data.LoadFactory = Convert.ToString(reader["LOADFACTORY"]);
data.RtnDocStatus = Convert.ToString(reader["RtnDocStatus"]);
data.RtnDocTime = Convert.ToString(reader["RtnDocTime"]);
if (reader["RoadFee"] != DBNull.Value)
data.RoadFee = Convert.ToDecimal(reader["RoadFee"]);
data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"]));
data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"]));
if (reader["FEESTATUSREF"] != DBNull.Value)
data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]);//费用状态
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.ContainerNo = Convert.ToString(reader["ContainerNo"]);
data.SealNo = Convert.ToString(reader["SealNo"]);
data.SALECORP = Convert.ToString(reader["SALECORP"]);
data.SALECORPID = Convert.ToString(reader["SALECORPID"]);
1 year ago
data.DCLASS = Convert.ToString(reader["DCLASS"]);
data.DUNNO = Convert.ToString(reader["DUNNO"]);
data.OPSTATUS = Convert.ToString(reader["OPSTATUS"]);
data.COLOR = Convert.ToString(reader["COLOR"]);
1 year ago
data.FuelPrice = Convert.ToString(reader["FuelPrice"]);
data.FuelQty = Convert.ToDecimal(reader["FuelQty"]);
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
data.isEnd = Convert.ToString(reader["isEnd"]);
2 years ago
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult HuiDan(MsWlPcHead_WFSDEdit HeadData,List<MsWlPcHead_WFSDEdit> BodyList)
{
var result = new DBResult();
var RtnDocStatus = HeadData.RtnDocStatus;
var RtnDocTime = HeadData.RtnDocTime;
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var enumValue in BodyList)
{
var cmdUpdate = db.GetSqlStringCommand(
@"UPDATE tMsWlPcHead SET RtnDocStatus='"+RtnDocStatus+ "',RtnDocTime='"+RtnDocTime+ "' WHERE BillNo=@BillNo ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdUpdate, tran);
if (enumValue.BLTYPE == "派车分票") {
var cmdUpdateMaster = db.GetSqlStringCommand(
@"UPDATE PC SET RtnDocStatus=(CASE WHEN F.RCT=F.CT THEN '1' ELSE CASE WHEN F.NRCT=F.CT THEN '' ELSE '0' END END) FROM tMsWlPcHead PC LEFT JOIN (SELECT PGID,SUM(CASE WHEN ISNULL(RtnDocStatus,'')='' THEN 1 ELSE 0 END) NRCT,SUM(CASE WHEN ISNULL(RtnDocStatus,'')='1' THEN 1 ELSE 0 END) RCT,COUNT(GID) CT FROM tMsWlPcHead WHERE PGID='" + enumValue.PGid + "' AND GID<>PGID GROUP BY PGID) F ON (F.PGID=PC.GID) WHERE GID=@GID ");
cmdUpdateMaster.Parameters.Clear();
db.AddInParameter(cmdUpdateMaster, "@GID", DbType.String, enumValue.PGid);
db.ExecuteNonQuery(cmdUpdateMaster, tran);
}
}
tran.Commit();
result.Success = true;
result.Message = "更新成功";
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "更新过程出现错误"+e.Message;
}
}
return result;
}
#endregion
#region 良通捷运
static public List<MsWlPcHead_LTJYEdit> GetLTJYList(string strCondition, string userid, string usercode, string username, string companyid, string sort)
{ //合同信息/商品信息
var rangstr = GetRangDAStr("index", userid, usercode, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append(" select PcBillType,PGid,BLTYPE ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate, dbo.trimdate(expdate) GroupDate ,ArriveDate,ReturnDate ");
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty ");
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='运费' and FEETYPE=1)YUNFEI ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='回程合计' and FEETYPE=1)HCHJ ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='装卸费' and FEETYPE=1)ZXF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='代垫费' and FEETYPE=1)DDF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename not in('运费','回程合计','装卸费','代垫费') and FEETYPE=1)QTFee ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and FEETYPE=1)TotalFee,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr");
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
strSql.Append(",dbo.Trimdate(t.billdate) BillDate,RealMil,ContainerNoSe");
strSql.Append(",case when ( ((select islock from wms where BLNO=t.billno)=1) OR((select islock from wms_out where BSNO=t.billno)=1) ) then 1 else 0 end islock");//用于判断该路单下是否有已锁定的入库单或出库单 如有则在前台禁止删除
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName from tMsWlPcHead t ");
if (!string.IsNullOrEmpty(strCondition))
{
//strSql.Append(" where 1=1 AND " + strCondition);
strSql.Append(" where (t.GID=t.PGID OR t.PGID='' OR t.PGID IS NULL) AND EXISTS ( select 1 from tMsWlPcHead WHERE t.GID=tMsWlPcHead.PGID AND " + strCondition + " )");
}
else
{
//strSql.Append(" where 1=1 " );
strSql.Append(" where (t.GID=t.PGID OR t.PGID='' OR t.PGID IS NULL) ");
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by Expdate,billno ");
}
return SetLTJYData(strSql);
}
static public List<MsWlPcHead_LTJYEdit> GetLTJYFenList(string strCondition, string sort)
{ //合同信息/商品信息
var strSql = new StringBuilder();
strSql.Append(" select PcBillType,PGid,BLTYPE ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate, dbo.trimdate(expdate) GroupDate ,ArriveDate,ReturnDate ");
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty ");
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='运费' and FEETYPE=1)YUNFEI ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='回程合计' and FEETYPE=1)HCHJ ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='装卸费' and FEETYPE=1)ZXF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='代垫费' and FEETYPE=1)DDF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename not in('运费','回程合计','装卸费','代垫费') and FEETYPE=1)QTFee ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and FEETYPE=1)TotalFee,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr");
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
strSql.Append(",dbo.Trimdate(t.billdate) BillDate,RealMil,ContainerNoSe");
strSql.Append(",case when ( ((select islock from wms where BLNO=t.billno)=1) OR((select islock from wms_out where BSNO=t.billno)=1) ) then 1 else 0 end islock");//用于判断该路单下是否有已锁定的入库单或出库单 如有则在前台禁止删除
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName from tMsWlPcHead t ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition.Replace("~", ""));//str.Replace("b","**");
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by Expdate,billno ");
}
return SetLTJYData(strSql);
}
static public MsWlPcHead_LTJYEdit GetLTJYData(string condition)
{
var strSql = new StringBuilder();
strSql.Append(" select PcBillType,PGid,BLTYPE ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,ROW_NUMBER()over (partition by dbo.trimdate(expdate) order by expdate ) RowNumber ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate, dbo.trimdate(expdate) GroupDate ,ArriveDate,ReturnDate ");
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty ");
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='运费' and FEETYPE=1)YUNFEI ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='回程合计' and FEETYPE=1)HCHJ ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='装卸费' and FEETYPE=1)ZXF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename='代垫费' and FEETYPE=1)DDF ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and feename not in('运费','回程合计','装卸费','代垫费') and FEETYPE=1)QTFee ");
strSql.Append(" ,(select sum(amount) from ch_Fee where bsno=t.gid and FEETYPE=1)TotalFee,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr");
strSql.Append(",dbo.F_GetBillDrFeeStatus(t.GId) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(t.GId) CRFEESTATUS");
strSql.Append(",dbo.Trimdate(t.billdate) BillDate,RealMil,ContainerNoSe");
strSql.Append(",case when ( ((select islock from wms where BLNO=t.billno)=1) OR((select islock from wms_out where BSNO=t.billno)=1) ) then 1 else 0 end islock");//用于判断该路单下是否有已锁定的入库单或出库单 如有则在前台禁止删除
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName from tMsWlPcHead t ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition.Replace("~", ""));//str.Replace("b","**");
}
var list = SetLTJYData(strSql);
if (list.Count > 0)
return list[0];
return new MsWlPcHead_LTJYEdit();
}
private static List<MsWlPcHead_LTJYEdit> SetLTJYData(StringBuilder strSql)
{
var headList = new List<MsWlPcHead_LTJYEdit>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlPcHead_LTJYEdit data = new MsWlPcHead_LTJYEdit();
#region Set DB data to Object
data.PcBillType = Convert.ToString(reader["PcBillType"]);
data.PcBillTypeREF = Convert.ToString(reader["PcBillTypeREF"]);
data.timeMark = Convert.ToDecimal(reader["timeMark"]);
data.gId = Convert.ToString(reader["gId"]);
data.PGid = Convert.ToString(reader["PGid"]);
data.BLTYPE = Convert.ToString(reader["BLTYPE"]);
data.RowNumber = Convert.ToString(reader["RowNumber"]);
data.BillNo = Convert.ToString(reader["BillNo"]);
data.ExpDate = Convert.ToString(reader["ExpDate"]);
data.GroupDate = Convert.ToString(reader["GroupDate"]);
data.ArriveDate = Convert.ToString(reader["ArriveDate"]);
data.ReturnDate = Convert.ToString(reader["ReturnDate"]);
data.CustomerName = Convert.ToString(reader["CustomerName"]);
data.F_CustomerName = Convert.ToString(reader["F_CustomerName"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.MblNo = Convert.ToString(reader["MblNo"]);
data.LinkMan = Convert.ToString(reader["LinkMan"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.ContainerQty = Convert.ToString(reader["ContainerQty"]);
data.Ton = Convert.ToString(reader["Ton"]);
data.LoadCount = Convert.ToString(reader["LoadCount"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.TruckSpec = Convert.ToString(reader["TruckSpec"]);
data.IsDouble = Convert.ToString(reader["IsDouble"]);
data.Property = Convert.ToString(reader["Property"]);
data.YUNFEI = Convert.ToString(reader["yunfei"]);
data.HCHJ = Convert.ToString(reader["HCHJ"]);
data.ZXF = Convert.ToString(reader["ZXF"]);
data.DDF = Convert.ToString(reader["DDF"]);
data.QTFee = Convert.ToString(reader["QTFee"]);
data.TotalFee = Convert.ToString(reader["TotalFee"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.FEESTATUS = Convert.ToString(reader["FeeStatus"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.LrDate = Convert.ToString(reader["LrDate"]);
data.PCSTATUSREF = Convert.ToString(reader["PCSTATUSREF"]);
data.RefBillNo = Convert.ToString(reader["RefBillNo"]);
data.RefBillNose = Convert.ToString(reader["RefBillNose"]);
data.MblNoSe = Convert.ToString(reader["MblNoSe"]);
data.ContainerType = Convert.ToString(reader["ContainerType"]);
data.LinkTel = Convert.ToString(reader["LinkTel"]);
data.YardName = Convert.ToString(reader["YardName"]);
data.LinkManSe = Convert.ToString(reader["LinkManSe"]);
data.LinkTelSe = Convert.ToString(reader["LinkTelSe"]);
data.RtnYardName = Convert.ToString(reader["RtnYardName"]);
data.BsType = Convert.ToString(reader["BsType"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CustLikeManName = Convert.ToString(reader["CustLikeManName"]);
data.CustTel = Convert.ToString(reader["CustTel"]);
data.ChangedReson = Convert.ToString(reader["ChangedReson"]);
data.FactoryAddr = Convert.ToString(reader["FactoryAddr"]);
data.DispatchName = Convert.ToString(reader["DispatchName"]);
data.INVOICENO = Convert.ToString(reader["INVOICENO"]);
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.SalesName = Convert.ToString(reader["SalesName"]);
data.VoyVeg = Convert.ToString(reader["VoyVeg"]);
data.EtDate = Convert.ToString(reader["EtDate"]);
data.EndPortDate = Convert.ToString(reader["EndPortDate"]);
if (reader["RoadFee"] != DBNull.Value)
data.RoadFee = Convert.ToDecimal(reader["RoadFee"]);
data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"]));
data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"]));
data.BillDate = Convert.ToString(reader["BillDate"]);
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
data.ContainerNoSe = Convert.ToString(reader["ContainerNoSe"]);
data.IsLock = Convert.ToString(reader["IsLock"]);
data.GoodsName = Convert.ToString(reader["GoodsName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult UpdateFileData(string filename, string billno,string userid )
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"update tMsWlPcHead set ContainerNoSe=@filename where BillNo = @billno ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@filename", DbType.String, filename);
db.AddInParameter(cmdInsert, "@billno", DbType.String, billno);
db.ExecuteNonQuery(cmdInsert, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult UpdateFileData(string filename, string billno, string userid, string TABLENAME)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert = db.GetSqlStringCommand(@"update WMS set FilePath=@filename where WMSNO = @billno ");
if (TABLENAME == "WMS")
{
cmdInsert = db.GetSqlStringCommand(
@"update WMS set FilePath=@filename where WMSNO = @billno ");
}
if (TABLENAME == "WMS_OUT")
{
cmdInsert = db.GetSqlStringCommand(
@"update WMS_OUT set FilePath=@filename where BSNO = @billno ");
}
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@filename", DbType.String, filename);
db.AddInParameter(cmdInsert, "@billno", DbType.String, billno);
db.ExecuteNonQuery(cmdInsert, tran);
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员:" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
static public int DeleteUploadFile(string tempGId)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
var strSql = new StringBuilder();
strSql.Append(" update tMsWlPcHead set ContainerNoSe='', where billno = '" + tempGId + "' ");
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString());
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 参照部分
public static string GetRangDAStr(string tb, string userid,string userCode, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modMsPc' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (t.UserCode='" + userCode + "' OR t.UserName='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (t.UserCode='" + userCode + "' OR t.UserName='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (t.UserCode in (select CODENAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
+ " OR t.UserName in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))";
}
else if (visiblerange == "1")
{
str = " (t.UserCode in (select CODENAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR t.UserName in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')))";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
return str;
}
#endregion
public static DBResult MakeFee(MsWlPcHead_WFSDEdit headData,string USERID)
{
var result = new DBResult();
//var currHead = GetWFSDData($" t.GID='{headData.gId}'");
var cdc = new Common.DB.CommonDataContext();
var taskList = cdc.op_task.Where(x => x.BSNO == headData.gId).ToList();
var task = new op_task_md();
if (taskList == null || taskList.Count == 0)
{
result.SetErrorInfo("没有找到对应的业务");
return result;
}
else {
task = taskList[0];
if (task.ISCOMPLETE == 1) {
result.SetErrorInfo("费用已经生成,无法重新生成");
return result;
}
}
var orderfeeList = cdc.ch_fee_order.Where(x => x.BSNO == headData.gId).ToList();
if (orderfeeList != null && orderfeeList.Count > 0) {
try
{
foreach (var orderfee in orderfeeList)
{
MsChFeeDAL.MakeNewFee(USERID, headData.gId, "车辆费用", "其它", 2, orderfee.FEENAME, orderfee.AMOUNT, "单票", 1, "");
}
task.ISCOMPLETE = 1;
cdc.op_task.AddOrUpdate(task);
cdc.SaveChanges();
result.OK("费用生成成功");
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
return result;
}
}
return result;
}
public static DBResult UnMakeFee(MsWlPcHead_WFSDEdit headData)
{
var result = new DBResult();
var cdc = new Common.DB.CommonDataContext();
var taskList = cdc.op_task.Where(x => x.BSNO == headData.gId).ToList();
var task = new op_task_md();
if (taskList == null || taskList.Count == 0)
{
result.SetErrorInfo("没有找到对应的业务");
return result;
}
else
{
task = taskList[0];
if (task.ISCOMPLETE != 1)
{
result.SetErrorInfo("未生成费用,无法进行取消");
return result;
}
var feelist = cdc.ch_fee.Where(x => x.BSNO == headData.gId ).ToList();
if (feelist != null && feelist.Count > 0) {
var nodelFeeList = feelist.Where(x=>x.FEESTATUS != 1 && x.FEESTATUS != 6).ToList();
if (nodelFeeList != null && nodelFeeList.Count > 0)
{
result.SetErrorInfo("费用已进入审核流程,无法取消生成");
return result;
}
}
cdc.ch_fee.RemoveRange(feelist);
task.ISCOMPLETE = 0;
cdc.op_task.AddOrUpdate(task);
cdc.SaveChanges();
result.OK("费用取消成功");
}
return result;
}
2 years ago
}
}