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/MsCodeLhCustRate/MsCodeLhCustRateDAL.cs

466 lines
18 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.CodeLhCustRate;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsCodeLhCustRateDAL
{
public class MsCodeLhCustRateDAL
{
#region Inquery DataList
static public List<CodeLhCustRate> GetDataList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("*");
strSql.Append(" from code_lhcust_rate ");
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 YEAR DESC ");
}
return SetData(strSql);
}
static public CodeLhCustRate GetData(string condition)
{
CodeLhCustRate data = null;
var list = GetDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeLhCustRate();
}
return data;
}
private static List<CodeLhCustRate> SetData(StringBuilder strSql)
{
var headList = new List<CodeLhCustRate>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeLhCustRate data = new CodeLhCustRate();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.YEAR = Convert.ToString(reader["YEAR"]);
if (reader["RATE"] != DBNull.Value)
data.RATE = Convert.ToDecimal(reader["RATE"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SaveDetail(List<CodeLhCustRate> bodyList,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into code_lhcust_rate (GID,YEAR,RATE,CREATEUSER,CREATETIME)
values (@GID,@YEAR,@RATE,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update code_lhcust_rate set YEAR=@YEAR,RATE=@RATE,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@YEAR", DbType.String, enumValue.YEAR);
db.AddInParameter(cmdInsert, "@RATE", DbType.Decimal, enumValue.RATE);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String,userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@YEAR", DbType.String, enumValue.YEAR);
db.AddInParameter(cmdUpdate, "@RATE", DbType.Decimal, enumValue.RATE);
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#region Inquery DataList
static public List<CodeLhCustCrStlDate> GetLhCustCrStlDateDataList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("*");
strSql.Append(" from code_lhcust_crstldate ");
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 CREATETIME ");
}
return SetLhCustCrStlDateData(strSql);
}
static public CodeLhCustCrStlDate GetLhCustCrStlDateData(string condition)
{
CodeLhCustCrStlDate data = null;
var list = GetLhCustCrStlDateDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeLhCustCrStlDate();
}
return data;
}
private static List<CodeLhCustCrStlDate> SetLhCustCrStlDateData(StringBuilder strSql)
{
var headList = new List<CodeLhCustCrStlDate>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeLhCustCrStlDate data = new CodeLhCustCrStlDate();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
if (reader["CRDAY"] != DBNull.Value)
data.CRDAY = Convert.ToDecimal(reader["CRDAY"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveLhCustCrStlDateDetail(List<CodeLhCustCrStlDate> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into code_lhcust_crstldate (GID,CUSTOMERNAME,CRDAY,CREATEUSER,CREATETIME)
values (@GID,@CUSTOMERNAME,@CRDAY,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update code_lhcust_crstldate set CUSTOMERNAME=@CUSTOMERNAME,CRDAY=@CRDAY,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdInsert, "@CRDAY", DbType.Decimal, enumValue.CRDAY);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdUpdate, "@CRDAY", DbType.Decimal, enumValue.CRDAY);
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region Inquery DataList
static public List<CodeLhCustCrStlDateDetail> GetLhCustCrStlDateDataDetailList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("*");
strSql.Append(" from code_lhcust_crstldate_detail ");
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 CREATETIME ");
}
return SetLhCustCrStlDateDetailData(strSql);
}
static public CodeLhCustCrStlDateDetail GetLhCustCrStlDateDetailData(string condition)
{
CodeLhCustCrStlDateDetail data = null;
var list = GetLhCustCrStlDateDataDetailList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CodeLhCustCrStlDateDetail();
}
return data;
}
private static List<CodeLhCustCrStlDateDetail> SetLhCustCrStlDateDetailData(StringBuilder strSql)
{
var headList = new List<CodeLhCustCrStlDateDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CodeLhCustCrStlDateDetail data = new CodeLhCustCrStlDateDetail();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
if (reader["GRACEDAY"] != DBNull.Value)
data.GRACEDAY = Convert.ToDecimal(reader["GRACEDAY"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveLhCustCrStlDateBsSouceDetail(List<CodeLhCustCrStlDateDetail> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into code_lhcust_crstldate_detail (GID,LINKGID,BSSOURCE,GRACEDAY,CREATEUSER,CREATETIME)
values (@GID,@LINKGID,@BSSOURCE,@GRACEDAY,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update code_lhcust_crstldate_detail set BSSOURCE=@BSSOURCE,GRACEDAY=@GRACEDAY,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, enumValue.LINKGID);
db.AddInParameter(cmdInsert, "@BSSOURCE", DbType.String, enumValue.BSSOURCE);
db.AddInParameter(cmdInsert, "@GRACEDAY", DbType.Decimal, enumValue.GRACEDAY);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@BSSOURCE", DbType.String, enumValue.BSSOURCE);
db.AddInParameter(cmdUpdate, "@GRACEDAY", DbType.Decimal, enumValue.GRACEDAY);
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 参照部分
#endregion
}
}