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.

301 lines
12 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsFeeTemplate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using HcUtility.Core;
namespace DSWeb.MvcShipping.DAL.MsFeeTemplate
{
public partial class MsFeeTemplateDAL
{
#region Inquery DataList
static public List<FeeTemplate> GetDataList(string strCondition, string userid, string companyid, string deptname,string sort = null)
{
var rangstr = GetRangDAStr("", userid, companyid, deptname);
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,Name");
strSql.Append(",Description");
strSql.Append(",OpType,FeeType");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96002 and EnumValueID=code_fee_template.OpType) as OpTyperef");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96003 and EnumValueID=code_fee_template.FeeType) as FeeTyperef");
strSql.Append(",CreateUser,CreateTime,ModifiedUser,ModifiedTime,Remark");
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 ModifiedTime Desc,Name");
}
return SetData(strSql);
}
static public FeeTemplate GetData(string condition, string userid, string companyid, string deptname)
{
FeeTemplate data = null;
var list = GetDataList(condition,userid,companyid,deptname);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new FeeTemplate();
}
return data;
}
private static List<FeeTemplate> SetData(StringBuilder strSql)
{
var headList = new List<FeeTemplate>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
FeeTemplate data = new FeeTemplate();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.Name = Convert.ToString(reader["Name"]);
data.Description = Convert.ToString(reader["Description"]);
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.CreateUser = Convert.ToString(reader["CreateUser"]);
data.CreateTime = Convert.ToDateTime(reader["CreateTime"]);
data.ModifiedUser = Convert.ToString(reader["ModifiedUser"]);
if (reader["ModifiedTime"] != DBNull.Value)
data.ModifiedTime = Convert.ToDateTime(reader["ModifiedTime"]);
data.Remark = Convert.ToString(reader["Remark"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region detail DataList
static public List<FeeTemplateDetail> GetDetailDataList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,TEMPLATEID");
strSql.Append(",FEECODE,FEENAME,CUSTOMERNAME,CLIENT,UNIT,CURRENCY,UNITPRICE");
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96001 and EnumValueID=code_fee_templatedetail.CLIENT) as CustomerType");
strSql.Append(",REMARK,SORT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,FEETYPE,EXCHANGERATE,ISCTN,TAXRATE,TAX");
strSql.Append(",(case ISCTN when 1 then '是' else '否' end) as ISCTNREF,ISINVOICE,ISADVANCEDPAY,FEEFRT,SALECORP");
strSql.Append(" from code_fee_templatedetail ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by SORT ");
return SetDetailData(strSql);
}
static public FeeTemplateDetail GetDetailData(string condition)
{
FeeTemplateDetail data = null;
var list = GetDetailDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new FeeTemplateDetail();
}
return data;
}
private static List<FeeTemplateDetail> SetDetailData(StringBuilder strSql)
{
var headList = new List<FeeTemplateDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
FeeTemplateDetail data = new FeeTemplateDetail();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.TemplateID = Convert.ToString(reader["TEMPLATEID"]);
data.FeeCode = Convert.ToString(reader["FEECODE"]);
data.FeeName = Convert.ToString(reader["FEENAME"]);
data.CustomerName = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["CLIENT"] != DBNull.Value)
data.Client = Convert.ToInt16(reader["CLIENT"]);
data.CustomerType = Convert.ToString(reader["CustomerType"]);
data.Unit = Convert.ToString(reader["UNIT"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]);
if (reader["SORT"] != DBNull.Value)
data.Sort = Convert.ToInt16(reader["SORT"]);
if (reader["FeeType"] != DBNull.Value)
data.FeeType = Convert.ToInt16(reader["FeeType"]);
data.Currency = Convert.ToString(reader["CURRENCY"]);
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.CreateUser = Convert.ToString(reader["CreateUser"]);
data.CreateTime = Convert.ToDateTime(reader["CreateTime"]);
data.ModifiedUser = Convert.ToString(reader["ModifiedUser"]);
if (reader["ModifiedTime"] != DBNull.Value)
data.ModifiedTime = Convert.ToDateTime(reader["ModifiedTime"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.FEEFRT = Convert.ToString(reader["FEEFRT"]);
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"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult UpdateTemplate(string templateid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmUpdate = db.GetSqlStringCommand("update code_fee_template set MODIFIEDTIME=GETDATE() where GID='" + templateid + "'");
db.ExecuteNonQuery(cmUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "更新出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "操作成功";
return result;
}
#region 参照部分
public static string GetRangDAStr(string tb, string userid, string companyid, string deptname)
{
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 = " CreateUser='" + userid + "'";
}
}
else if (visiblerange == "2")
{
str = " CreateUser in (select userid from user_baseinfo where DEPTNAME='" + deptname + "') and CreateUser in (select USERID from user_company where COMPANYID='" + companyid + "') ";
}
else if (visiblerange == "1")
{
str = " CreateUser in (select USERID from user_company where COMPANYID='" + companyid + "') ";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
return str;
}
#endregion
}
}