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.

342 lines
12 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.CodeFeeGroupTemplate;
using DSWeb.MvcShipping.Models.MsCodeDuiTemplate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsCodeFeeGroupTemplate
{
public class MsCodeFeeGroupTempldateDAL
{
#region Inquery DataList
static public List<CodeFeeGroup> GetDataList(string strCondition,string sort=null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("DM_ID");
strSql.Append(",RPTNAME,RPTTYPE");
strSql.Append(",REMARKS,INPUTBY,INPUTDATE");
strSql.Append(" from code_feegroup_format ");
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 RPTNAME");
}
return SetData(strSql);
}
static public CodeFeeGroup GetData(string condition)
{
CodeFeeGroup data = null;
var list = GetDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeFeeGroup();
}
return data;
}
private static List<CodeFeeGroup> SetData(StringBuilder strSql)
{
var headList = new List<CodeFeeGroup>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeFeeGroup data = new CodeFeeGroup();
#region Set DB data to Object
data.DM_ID = Convert.ToString(reader["DM_ID"]);
data.RPTNAME = Convert.ToString(reader["RPTNAME"]);
data.RPTTYPE = Convert.ToString(reader["RPTTYPE"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
if (reader["INPUTDATE"] != DBNull.Value)
data.INPUTDATE = Convert.ToString(reader["INPUTDATE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 明细表
static public List<CodeFeeGroupTotal> GetTotalCurrList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("DM_ID,CURRENCY");
strSql.Append(" from code_feegroup_format_total ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetTotalCurrData(strSql);
}
private static List<CodeFeeGroupTotal> SetTotalCurrData(StringBuilder strSql)
{
var bodyList = new List<CodeFeeGroupTotal>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeFeeGroupTotal data = new CodeFeeGroupTotal();
#region Set DB data to Object
data.DM_ID = Convert.ToString(reader["DM_ID"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
public static DBResult SaveDetail(CodeFeeGroup headData, List<CodeDuiTemplateFee> drbodyList, List<CodeDuiTemplateFee> crbodyList, List<CodeFeeGroupTotal> totalcurrList)
{
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_dui_format_fee where DM_ID='" + headData.DM_ID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdDeletework = db.GetSqlStringCommand("delete from code_feegroup_format_total where DM_ID='" + headData.DM_ID + "'");
db.ExecuteNonQuery(cmdDeletework, tran);
var cmdInsert =
db.GetSqlStringCommand(
@"insert into code_dui_format_fee (DM_ID, FEETYPE, FEENAME,CURRENCY,DISPLAYNAME,FEECODE)
values (@DM_ID, @FEETYPE, @FEENAME,@CURRENCY,@DISPLAYNAME,@FEECODE) ");
if (drbodyList != null)
{
foreach (var enumValue in drbodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@DM_ID", DbType.String, headData.DM_ID);
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int32, 1);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsert, "@DISPLAYNAME", DbType.String, enumValue.DisplayName);
db.AddInParameter(cmdInsert, "@FEECODE", DbType.String, enumValue.FeeCode);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
if (crbodyList != null)
{
foreach (var enumValue in crbodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@DM_ID", DbType.String, headData.DM_ID);
db.AddInParameter(cmdInsert, "@FEETYPE", DbType.Int32, 2);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsert, "@DISPLAYNAME", DbType.String, enumValue.DisplayName);
db.AddInParameter(cmdInsert, "@FEECODE", DbType.String, enumValue.FeeCode);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
if (totalcurrList != null)
{
var cmdInsertwork =
db.GetSqlStringCommand(
@"insert into code_feegroup_format_total (DM_ID, CURRENCY)
values (@DM_ID, @CURRENCY) ");
foreach (var enumValue in totalcurrList)
{
cmdInsertwork.Parameters.Clear();
db.AddInParameter(cmdInsertwork, "@DM_ID", DbType.String, headData.DM_ID);
db.AddInParameter(cmdInsertwork, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.ExecuteNonQuery(cmdInsertwork, 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(CodeDuiTemplate 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_feegroup_format where DM_ID='" + headData.DM_ID + "'");
db.ExecuteNonQuery(cmd, tran);
var cmdDelete = db.GetSqlStringCommand("delete from code_dui_format_fee where DM_ID='" + headData.DM_ID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdDeletework = db.GetSqlStringCommand("delete from code_feegroup_format_total where DM_ID='" + headData.DM_ID + "'");
db.ExecuteNonQuery(cmdDeletework, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
#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]='modTruckPj' 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")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
return str;
}
#endregion
}
}