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.

207 lines
6.9 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsSysParamSet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsSysParamSet
{
public class MsSysParamSetDAL
{
#region Inquery DataList
static public List<SysParamSet> GetDataList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,PARAMNAME,PARAMTYPE,PARAMDESCRIPTION,PARAMVALUE,MODIFIEDUSER,MODIFIEDTIME,FIELDTYPE");
strSql.Append(",(select top 1 DISPVALUE from sys_parameter_value where PARAMNAME=sys_param_set.PARAMNAME and PARAMVALUE=sys_param_set.PARAMVALUE) DISPVALUE");
strSql.Append(" from sys_param_set ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring) && sortstring.Trim()!="")
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by PARAMTYPE,PARAMNAME");
}
return SetData(strSql);
}
static public SysParamSet GetData(string condition)
{
SysParamSet data = null;
var list = GetDataList(condition);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new SysParamSet();
}
return data;
}
private static List<SysParamSet> SetData(StringBuilder strSql)
{
var headList = new List<SysParamSet>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SysParamSet data = new SysParamSet();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PARAMNAME = Convert.ToString(reader["PARAMNAME"]);
data.PARAMTYPE = Convert.ToString(reader["PARAMTYPE"]);
data.PARAMDESCRIPTION = Convert.ToString(reader["PARAMDESCRIPTION"]);
data.PARAMVALUE = Convert.ToString(reader["PARAMVALUE"]);
data.DISPVALUE = Convert.ToString(reader["DISPVALUE"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.FIELDTYPE = Convert.ToString(reader["FIELDTYPE"]);
if (data.FIELDTYPE=="STR")
data.DISPVALUE = data.PARAMVALUE;
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveDetail(List<SysParamSet> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update sys_param_set set PARAMVALUE=@PARAMVALUE,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@PARAMVALUE", DbType.String, enumValue.PARAMVALUE);
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String,userid);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String,DateTime.Now.ToString("yyyy-MM-dd"));
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 SysParamSet枚举值
static public List<SysParamValue> GetParamValueList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,PARAMNAME,PARAMTYPE,PARAMDESCRIPTION,DISPVALUE,PARAMVALUE");
strSql.Append(" from sys_parameter_value ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring) && sortstring.Trim() != "")
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by PARAMTYPE,PARAMNAME");
}
return SetParamValueData(strSql);
}
private static List<SysParamValue> SetParamValueData(StringBuilder strSql)
{
var headList = new List<SysParamValue>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SysParamValue data = new SysParamValue();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PARAMNAME = Convert.ToString(reader["PARAMNAME"]);
data.DISPVALUE = Convert.ToString(reader["DISPVALUE"]);
data.PARAMDESCRIPTION = Convert.ToString(reader["PARAMDESCRIPTION"]);
data.PARAMVALUE = Convert.ToString(reader["PARAMVALUE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
}
}