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/MsWlBs_HT/MsWlBsDAL.cs

346 lines
16 KiB
C#

3 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.EntityDA;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.TruckMng.DAL.MsWlBs_HT
{
public partial class MsWlBs_HTDAL
{
#region 主表
static public List<MsWlBsHead> GetDataList(string condition, string userid, string usercode, string orgcode,string sort=null)
{
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(condition))
{
condition = condition + " and " + rangstr;
}
else
{
condition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,LrDate,JzDate,UserCode,UserName,OrgCode,OrgName");
strSql.Append(",LogisticsNo,CustCode,CustName,CustName as CustName_Ref");
//strSql.Append("(select CustName from vMsTruckClient where CustCode=tMsWlBsHead.CustCode) as CustName_Ref");
strSql.Append(",CustDate,VoyVeg,");
strSql.Append("(select VoyName from vMsTruckVoyInfo where VoyCode=tMsWlBsHead.VoyVeg) as VoyVeg_Ref");
strSql.Append(",EtDate,EndPortDate,MblNo,SalesCode,");
strSql.Append("(select UserName from vMsTruckUser where UserCode=tMsWlBsHead.SalesCode) as SalesCode_Ref");
strSql.Append(",SalesName,DispatchCode,");
strSql.Append("(select UserName from vMsTruckUser where UserCode=tMsWlBsHead.DispatchCode) as DispatchCode_Ref");
strSql.Append(",DispatchName,SendYardCode,");
strSql.Append("(select CustName from vMsTruckClient where CustCode=tMsWlBsHead.SendYardCode) as SendYardCode_Ref");
strSql.Append(",SendYardName,RtnYardCode,RtnYard,DstArea,DetiNation,DetiLinkTel,DetiLinkMan");
strSql.Append(",Remark,BsType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99025 and EnumValueID=tMsWlBsHead.BsType) as BsType_Ref");
strSql.Append(",BillStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99026 and EnumValueID=tMsWlBsHead.BillStatus) as BillStatus_Ref");
strSql.Append(",FeeStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99027 and EnumValueID=tMsWlBsHead.FeeStatus) as FeeStatus_Ref");
strSql.Append(",GId, convert(bigint ,TimeMark) as TimeMark");
strSql.Append(",CustLikeManCode,CustLikeManName,CustTel");
strSql.Append(",NeadLoadDate,NeedArriveDate,BillRises1");
strSql.Append(",FeeOpStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99035 and EnumValueID=tMsWlBsHead.FeeOpStatus) as FeeOpStatus_Ref");
strSql.Append(",VoyVegSe,GoodsName");
strSql.Append(" from tMsWlBsHead ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by LrDate desc ");
}
return SetData(strSql);
}
private static List<MsWlBsHead> SetData(StringBuilder strSql)
{
var headList = new List<MsWlBsHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlBsHead data = new MsWlBsHead();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
if (reader["LrDate"] != DBNull.Value)
data.LrDate = Convert.ToDateTime(reader["LrDate"]);
if (reader["JzDate"] != DBNull.Value)
data.JzDate = Convert.ToDateTime(reader["JzDate"]);
data.UserCode = Convert.ToString(reader["UserCode"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgName = Convert.ToString(reader["OrgName"]);
data.LogisticsNo = Convert.ToString(reader["LogisticsNo"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CustName_Ref = Convert.ToString(reader["CustName_Ref"]);
data.CustDate = Convert.ToString(reader["CustDate"]);
data.VoyVeg = Convert.ToString(reader["VoyVeg"]);
data.VoyVeg_Ref = Convert.ToString(reader["VoyVeg_Ref"]);
data.EtDate = Convert.ToString(reader["EtDate"]);
data.EndPortDate = Convert.ToString(reader["EndPortDate"]);
data.MblNo = Convert.ToString(reader["MblNo"]);
data.SalesCode = Convert.ToString(reader["SalesCode"]);
data.SalesCode_Ref = Convert.ToString(reader["SalesCode_Ref"]);
data.SalesName = Convert.ToString(reader["SalesName"]);
data.DispatchCode = Convert.ToString(reader["DispatchCode"]);
data.DispatchCode_Ref = Convert.ToString(reader["DispatchCode_Ref"]);
data.DispatchName = Convert.ToString(reader["DispatchName"]);
data.SendYardCode = Convert.ToString(reader["SendYardCode"]);
data.SendYardCode_Ref = Convert.ToString(reader["SendYardCode_Ref"]);
data.SendYardName = Convert.ToString(reader["SendYardName"]);
data.RtnYardCode = Convert.ToString(reader["RtnYardCode"]);
data.RtnYard = Convert.ToString(reader["RtnYard"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.DetiLinkTel = Convert.ToString(reader["DetiLinkTel"]);
data.DetiLinkMan = Convert.ToString(reader["DetiLinkMan"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.BsType = Convert.ToString(reader["BsType"]);
data.BsType_Ref = Convert.ToString(reader["BsType_Ref"]);
data.BillStatus = Convert.ToString(reader["BillStatus"]);
data.BillStatus_Ref = Convert.ToString(reader["BillStatus_Ref"]);
data.FeeStatus = Convert.ToString(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
data.GId = Convert.ToString(reader["GId"]);
data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.CustLikeManCode = Convert.ToString(reader["CustLikeManCode"]);
data.CustLikeManName = Convert.ToString(reader["CustLikeManName"]);
data.CustTel = Convert.ToString(reader["CustTel"]);
data.NeadLoadDate = Convert.ToString(reader["NeadLoadDate"]);
data.NeedArriveDate = Convert.ToString(reader["NeedArriveDate"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.FeeOpStatus = Convert.ToString(reader["FeeOpStatus"]);
data.FeeOpStatus_Ref = Convert.ToString(reader["FeeOpStatus_Ref"]);
data.VoyVegSe = Convert.ToString(reader["VoyVegSe"]);
data.GoodsName = Convert.ToString(reader["GoodsName"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public MsWlBsHead GetHeadDataByBillNo(string billno, string userid, string usercode, string orgcode)
{
MsWlBsHead data = null;
var list = GetDataList(" BillNo='" + billno + "'",userid,usercode,orgcode);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsWlBsHead();
}
return data;
}
#endregion
#region 明细表
static public List<MsWlBsFixed> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,SerialNo,CreditDebit,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=tMsWlBsFixed.CreditDebit) as CreditDebit_Ref");
strSql.Append(",FeeTypeCode,");
strSql.Append("(select Name from vMsTruckFeeType where FeeCode=tMsWlBsFixed.FeeTypeCode) as FeeTypeCode_Ref");
strSql.Append(",FeeTypeName,DistCount,Price,FsTotal,JsTotal,Remark,GId");
strSql.Append(",FeeStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=tMsWlBsFixed.FeeStatus) as FeeStatus_Ref");
strSql.Append(",SubmitDate,Auditoperator,AuditDate,AuditStatus");
strSql.Append(" from tMsWlBsFixed ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetBodyData(strSql);
}
private static List<MsWlBsFixed> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsWlBsFixed>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlBsFixed data = new MsWlBsFixed();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.CreditDebit = Convert.ToString(reader["CreditDebit"]);
data.CreditDebit_Ref = Convert.ToString(reader["CreditDebit_Ref"]);
data.FeeTypeCode = Convert.ToString(reader["FeeTypeCode"]);
data.FeeTypeCode_Ref = Convert.ToString(reader["FeeTypeCode_Ref"]);
data.FeeTypeName = Convert.ToString(reader["FeeTypeName"]);
data.DistCount = Convert.ToDecimal(reader["DistCount"]);
data.Price = Convert.ToDecimal(reader["Price"]);
data.FsTotal = Convert.ToDecimal(reader["FsTotal"]);
data.JsTotal = Convert.ToDecimal(reader["JsTotal"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.GId = Convert.ToString(reader["GId"]);
data.FeeStatus = Convert.ToDecimal(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
if (reader["SubmitDate"] != DBNull.Value)
data.SubmitDate = Convert.ToDateTime(reader["SubmitDate"]);
data.Auditoperator = Convert.ToString(reader["Auditoperator"]);
if (reader["AuditDate"] != DBNull.Value)
data.AuditDate = Convert.ToDateTime(reader["AuditDate"]);
data.AuditStatus = Convert.ToDecimal(reader["AuditStatus"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 参照部分
public static string GetRangDAStr(string tb, string userid, string usercode, string orgcode)
{
string str = "";
if (userid == "")
{
return str;
}
else
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modTruckBs' 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 = "1=2";
}
else if (visiblerange == "3")
{
if (tb == "index")
{
str = " (UserCode='" + usercode + "' or DispatchCode='"+usercode+"')";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (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 DispatchCode 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 + "')))";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
return str;
}
}
internal static Boolean GetBsIsPrint(string billno,string Gid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT count(B.Gid) as RecCount ");
strSql.Append(" from ch_fee B left join vMsWlPcHeadPrint A on A.Gid=B.BsNo where ");
strSql.Append(" B.FeeStatus in (1,2,6) and A.Gid=B.BsNo and A.RefBillNo='" + billno + "' or B.bsno='" + Gid + "'");
var Rcount = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
#region Set DB data to Object
Rcount = Convert.ToInt16(reader["RecCount"]);
#endregion
}
reader.Close();
}
if (Rcount==0) {
return true;
} else {
return false;
}
}
#endregion
}
}