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/MsWlBsAudit/MsWlBsAuditDAL.cs

298 lines
13 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsWlBsAudit;
using HcUtility.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.TruckMng.DAL.MsWlBsAudit
{
public partial class MsWlBsAuditDAL
{
#region Inquery DataList
static public List<MsWlBizBill> GetDataList(string strCondition, string userid, string usercode, string orgcode, string sort=null)
{
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99028 and EnumValueID=vMsWlBizBill.BillType) as BillType_Ref");
strSql.Append(",BsType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99025 and EnumValueID=vMsWlBizBill.BsType) as BsType_Ref");
strSql.Append(",BillNo,BillStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99026 and EnumValueID=vMsWlBizBill.BillStatus) as BillStatus_Ref");
strSql.Append(",FeeStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99027 and EnumValueID=vMsWlBizBill.FeeStatus) as FeeStatus_Ref");
strSql.Append(",GId,CustName,DispatchName,MblNo,EtDate,CustDate,TruckNo");
strSql.Append(",DrvName,ContainerNos,Remark,FuelQty,BsBillNo,DstArea,YardName");
strSql.Append(",FeeOpStatus,LoadPlace,Ton,DdCode,");
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=vMsWlBizBill.DdCode) as DdCode_Ref,");
strSql.Append("YardCode,(SELECT CODEANDNAME FROM VMSTRUCKCLIENT WHERE CUSTCODE=YARDCODE) AS YardCode_Ref,DGTYPE,DGTYPECODE,ContainerNo,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99035 and EnumValueID=vMsWlBizBill.FeeOpStatus) as FeeOpStatus_Ref");
strSql.Append(" ,DetiNation");
strSql.Append(" from vMsWlBizBill ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by CustDate,TruckNo");
}
return SetData(strSql);
}
static public MsWlBizBill GetData(string condition, string userid, string usercode, string orgcode)
{
var list = GetDataList(condition,userid,usercode,orgcode);
if (list.Count > 0)
return list[0];
return new MsWlBizBill();
}
private static List<MsWlBizBill> SetData(StringBuilder strSql)
{
var headList = new List<MsWlBizBill>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlBizBill data = new MsWlBizBill();
#region Set DB data to Object
data.BillType = Convert.ToString(reader["BillType"]);
data.BillType_Ref = Convert.ToString(reader["BillType_Ref"]);
data.BillNo = Convert.ToString(reader["BillNo"]);
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.CustName = Convert.ToString(reader["CustName"]);
data.DispatchName = Convert.ToString(reader["DispatchName"]);
data.MblNo = Convert.ToString(reader["MblNo"]);
data.EtDate = Convert.ToString(reader["EtDate"]);
data.CustDate = Convert.ToString(reader["CustDate"]);
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.Ton = Convert.ToString(reader["Ton"]);
data.DdCode_Ref = Convert.ToString(reader["DdCode_Ref"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
data.ContainerNos = Convert.ToString(reader["ContainerNos"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.FuelQty = Convert.ToDecimal(reader["FuelQty"]);
data.BsBillNo = Convert.ToString(reader["BsBillNo"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.YardName = Convert.ToString(reader["YardName"]);
data.BsType = Convert.ToString(reader["BsType"]);
data.BsType_Ref = Convert.ToString(reader["BsType_Ref"]);
data.FeeOpStatus = Convert.ToString(reader["FeeOpStatus"]);
data.FeeOpStatus_Ref = Convert.ToString(reader["FeeOpStatus_Ref"]);
data.YardCode = Convert.ToString(reader["YardCode"]);
data.YardCode_Ref = Convert.ToString(reader["YardCode_Ref"]);
data.DGTYPE = Convert.ToString(reader["DGTYPE"]);
data.DGTYPECODE = Convert.ToString(reader["DGTYPECODE"]);
data.ContainerNo = Convert.ToString(reader["ContainerNo"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult Lock(List<MsWlBizBill> billlist, string lockType, string newStatus)
{
var statusFieldName = string.Empty;
if (lockType == "0")
{
statusFieldName = "FeeStatus";
}
else if (lockType == "1")
{
statusFieldName = "BillStatus";
}
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var trans = conn.BeginTransaction();
try
{
var msg = string.Empty;
var isSuccess = true;
foreach (var bill in billlist)
{
string tableName;
string billNo;
if (bill.BillType == "0") //0-委托单
{
tableName = "tMsWlBsHead";
billNo = bill.BsBillNo;
}
else if (bill.BillType == "1") //1-派车单
{
tableName = "tMsWlPcHead";
billNo = bill.BillNo;
}
else throw new NotSupportedException("单据类型不合法");
var cmdGid = db.GetSqlStringCommand("select gid from " + tableName + " where BillNo=@BillNo");
db.AddInParameter(cmdGid, "@BillNo", DbType.String, billNo);
var gId = Convert.ToString(db.ExecuteScalar(cmdGid, trans));
if (string.IsNullOrEmpty(gId))
{
isSuccess = false;
msg = "单据" + bill.BillNo + "已经不存在无法锁定";
break;
}
//费用锁定:整票所有费用全部审核通过才能锁定;
var cmdRejectCount = db.GetSqlStringCommand("select count(*) from ch_fee where BsNo=@BsNo and FeeStatus<>@FeeStatus");
db.AddInParameter(cmdRejectCount, "@BsNo", DbType.String, gId);
db.AddInParameter(cmdRejectCount, "@FeeStatus", DbType.Int32, 0);
var notPassCount = Convert.ToInt32(db.ExecuteScalar(cmdRejectCount, trans));
if (notPassCount > 0)
{
isSuccess = false;
msg = "单据" + billNo + "的费用没有全部审核通过,不允许锁定此单据的费用";
break;
}
var sql = "update " + tableName + " set " + statusFieldName +
"='" + newStatus + "' where BillNo=@BillNo";
var cmd = db.GetSqlStringCommand(sql);
db.AddInParameter(cmd, "@BillNo", DbType.String, bill.BillNo);
db.ExecuteNonQuery(cmd, trans);
}
if (isSuccess)
{
trans.Commit();
result.Success = true;
result.Message = "执行成功";
result.Data = statusFieldName;
}
else
{
trans.Rollback();
result.Success = false;
result.Message = msg;
}
}
catch (Exception)
{
trans.Rollback();
result.Success = false;
result.Message = "执行出现异常,请重试";
}
conn.Close();
}
return result;
}
public static string GetRangDAStr(string tb, string userid, string usercode, string orgcode)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modTruckAudit' 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 + "'";
}
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 + "'))";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
return str;
}
}
}