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/MvcShipping/DAL/MsCodeFeeTemplate/MsCodeFeeTemplateDAL.cs

499 lines
20 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCodeFeeTemplate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsCodeFeeTemplate
{
public class MsCodeFeeTempldateDAL
{
#region Inquery DataList
static public List<CodeFeeTemplate> 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 + ") or ISPUBLIC='是')";
}
else
{
strCondition = " ((" + rangstr + ") or ISPUBLIC='是')";
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,OPTYPE,FEETYPE,NAME,[DESCRIPTION],CREATEUSER,CREATETIME");
strSql.Append(",MODIFIEDUSER,MODIFIEDTIME,REMARK,CORPID");
strSql.Append(",(CASE FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96002 and EnumValueID=code_fee_template.OPTYPE) as OPTYPEREF");
strSql.Append(",(select ShowName from [user] where GID=code_fee_template.CREATEUSER) as CREATEUSERREF");
strSql.Append(",ISPUBLIC");
strSql.Append(" from code_fee_template ");
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 NAME");
}
return SetData(strSql);
}
static public CodeFeeTemplate GetData(string condition, string userid, string usercode, string orgcode)
{
CodeFeeTemplate data = null;
var list = GetDataList(condition,userid,usercode,orgcode);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeFeeTemplate();
data.CREATEUSER = userid;
data.CORPID = orgcode;
}
return data;
}
private static List<CodeFeeTemplate> SetData(StringBuilder strSql)
{
var headList = new List<CodeFeeTemplate>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeFeeTemplate data = new CodeFeeTemplate();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.OPTYPE = Convert.ToInt16(reader["OPTYPE"]);
data.FEETYPE = Convert.ToInt16(reader["FEETYPE"]);
data.OPTYPEREF = Convert.ToString(reader["OPTYPEREF"]);
data.FEETYPEREF = Convert.ToString(reader["FEETYPEREF"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);
data.ISPUBLIC = Convert.ToString(reader["ISPUBLIC"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
static public string GetDataListStr(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 + ") or ISPUBLIC='是')";
}
else
{
strCondition = " ((" + rangstr + ") or ISPUBLIC='是')";
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,OPTYPE,FEETYPE,NAME,[DESCRIPTION],CREATEUSER,CREATETIME");
strSql.Append(",MODIFIEDUSER,MODIFIEDTIME,REMARK,CORPID");
strSql.Append(",(CASE FEETYPE WHEN 1 THEN '收' ELSE '付' END) AS FEETYPEREF");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96002 and EnumValueID=code_fee_template.OPTYPE) as OPTYPEREF");
strSql.Append(",(select ShowName from [user] where GID=code_fee_template.CREATEUSER) as CREATEUSERREF");
strSql.Append(",ISPUBLIC");
strSql.Append(" from code_fee_template ");
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 NAME");
}
return strSql.ToString();
}
#region 明细表
static public List<CodeFeeTemplateDetail> GetBodyList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,TEMPLATEID,FEENAME,CUSTOMERNAME,CLIENT,UNIT");
strSql.Append(",CURRENCY,UNITPRICE,REMARK,SORT,CREATEUSER,CREATETIME,EXCHANGERATE,ISCTN,TAXRATE,TAXUNITPRICE,TAX,ACCTAXRATE");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96001 and EnumValueID=code_fee_templatedetail.CLIENT) as CLIENTREF");
strSql.Append(",(case ISCTN when 1 then '是' else '否' end) as ISCTNREF,ISINVOICE,ISADVANCEDPAY,FEEFRT,SALECORP,FEEDESCRIPTION ");
strSql.Append(" from code_fee_templatedetail ");
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 SORT ");
}
return SetBodyData(strSql);
}
private static List<CodeFeeTemplateDetail> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<CodeFeeTemplateDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeFeeTemplateDetail data = new CodeFeeTemplateDetail();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.TEMPLATEID = Convert.ToString(reader["TEMPLATEID"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]);
if (reader["EXCHANGERATE"] != DBNull.Value)
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
if (reader["TAXRATE"] != DBNull.Value)
data.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]);
if (reader["TAX"] != DBNull.Value)
data.TAX = Convert.ToDecimal(reader["TAX"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.FEEDESCRIPTION = Convert.ToString(reader["FEEDESCRIPTION"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["CLIENT"] != DBNull.Value)
data.CLIENT = Convert.ToInt16(reader["CLIENT"]);
data.CLIENTREF = Convert.ToString(reader["CLIENTREF"]);
data.UNIT = Convert.ToString(reader["UNIT"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);
data.FEEFRT = Convert.ToString(reader["FEEFRT"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
if (reader["ISCTN"] != DBNull.Value)
data.ISCTN = Convert.ToBoolean(reader["ISCTN"]);
data.ISCTNREF = Convert.ToString(reader["ISCTNREF"]);
if (reader["ISINVOICE"] != DBNull.Value)
data.ISINVOICE = Convert.ToBoolean(reader["ISINVOICE"]);
if (reader["ISADVANCEDPAY"] != DBNull.Value)
data.ISADVANCEDPAY = Convert.ToBoolean(reader["ISADVANCEDPAY"]);
data.SALECORP = Convert.ToString(reader["SALECORP"]);
if (reader["TAXUNITPRICE"] != DBNull.Value)
data.TAXUNITPRICE = Convert.ToDecimal(reader["TAXUNITPRICE"]);
if (reader["ACCTAXRATE"] != DBNull.Value)
data.ACCTAXRATE = Convert.ToDecimal(reader["ACCTAXRATE"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
public static DBResult SaveDetail(CodeFeeTemplate headData, List<CodeFeeTemplateDetail> bodyList,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from code_fee_templatedetail where TEMPLATEID='" + headData.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdInsert =
db.GetSqlStringCommand(
@"insert into code_fee_templatedetail (GID,TEMPLATEID,FEENAME,CUSTOMERNAME,CLIENT,UNIT,CURRENCY,UNITPRICE,REMARK,SORT,CREATEUSER,CREATETIME,EXCHANGERATE,ISCTN,ISINVOICE,ISADVANCEDPAY,FEEFRT,TAXRATE,TAX,SALECORP,TAXUNITPRICE,ACCTAXRATE,FEEDESCRIPTION)
values (@GID,@TEMPLATEID,@FEENAME,@CUSTOMERNAME,@CLIENT,@UNIT,@CURRENCY,@UNITPRICE,@REMARK,@SORT,@CREATEUSER,@CREATETIME,@EXCHANGERATE,@ISCTN,@ISINVOICE,@ISADVANCEDPAY,@FEEFRT,@TAXRATE,@TAX,@SALECORP,@TAXUNITPRICE,@ACCTAXRATE,@FEEDESCRIPTION) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@TEMPLATEID", DbType.String,headData.GID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdInsert, "@CLIENT", DbType.Int32, enumValue.CLIENT);
db.AddInParameter(cmdInsert, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@SORT", DbType.Int32, enumValue.SORT);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString());
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.EXCHANGERATE);
db.AddInParameter(cmdInsert, "@ISCTN", DbType.Boolean, enumValue.ISCTN);
db.AddInParameter(cmdInsert, "@ISINVOICE", DbType.Boolean, enumValue.ISINVOICE);
db.AddInParameter(cmdInsert, "@ISADVANCEDPAY", DbType.Boolean, enumValue.ISADVANCEDPAY);
db.AddInParameter(cmdInsert, "@FEEFRT", DbType.String, enumValue.FEEFRT);
db.AddInParameter(cmdInsert, "@TAXRATE", DbType.Decimal, enumValue.TAXRATE);
db.AddInParameter(cmdInsert, "@TAX", DbType.Decimal, enumValue.TAX);
db.AddInParameter(cmdInsert, "@SALECORP", DbType.String, enumValue.SALECORP);
db.AddInParameter(cmdInsert, "@TAXUNITPRICE", DbType.Decimal, enumValue.TAXUNITPRICE);
db.AddInParameter(cmdInsert, "@ACCTAXRATE", DbType.Decimal, enumValue.ACCTAXRATE);
db.AddInParameter(cmdInsert, "@FEEDESCRIPTION", DbType.String, enumValue.FEEDESCRIPTION);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult DeleteDetail(CodeFeeTemplate headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmd = db.GetSqlStringCommand("delete from code_fee_template where GID='" + headData.GID + "'");
db.ExecuteNonQuery(cmd, tran);
var cmdDelete = db.GetSqlStringCommand("delete from code_fee_templatedetail where TEMPLATEID='" + headData.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
public static List<FeeUnit> GetFeeUnit(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT CTN from code_ctn");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<FeeUnit>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
FeeUnit Data = new FeeUnit();
Data.UNIT = Convert.ToString(reader["CTN"]);
evList.Add(Data);
}
reader.Close();
}
var data = new FeeUnit();
data.UNIT = "单票";
evList.Add(data);
var data1 = new FeeUnit();
data1.UNIT = "重量";
evList.Add(data1);
var data2 = new FeeUnit();
data2.UNIT = "尺码";
evList.Add(data2);
var data3 = new FeeUnit();
data3.UNIT = "TEU";
evList.Add(data3);
var data4 = new FeeUnit();
data4.UNIT = "箱型";
evList.Add(data4);
var data5 = new FeeUnit();
data5.UNIT = "CBM";
evList.Add(data5);
var data6 = new FeeUnit();
data6.UNIT = "BILL";
evList.Add(data6);
var data7 = new FeeUnit();
data7.UNIT = "件数";
evList.Add(data7);
var data8 = new FeeUnit();
data8.UNIT = "车";
evList.Add(data8);
var data9 = new FeeUnit();
data9.UNIT = "自然箱";
evList.Add(data9);
var data10 = new FeeUnit();
data10.UNIT = "小时";
evList.Add(data10);
var data13 = new FeeUnit();
data13.UNIT = "天";
evList.Add(data13);
var data11 = new FeeUnit();
data11.UNIT = "个";
evList.Add(data11);
var data12 = new FeeUnit();
data12.UNIT = "计费吨";
evList.Add(data12);
return evList;
}
#region 参照部分
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]='modCodeFeeTemplateSet' 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 = " CREATEUSER='" + userid + "'";
}
else
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
}
else if (visiblerange == "2")
{
if (tb == "index")
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
else
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(CORPID)='" + orgcode + "'";
}
return str;
}
#endregion
}
}