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/SysMng/DAL/Enum/EnumDAL.cs

182 lines
6.3 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.SysMng.Models.Enum;
using HcUtility.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace DSWeb.Areas.SysMng.DAL.Enum
{
public partial class EnumDAL
{
#region 主表
static public List<SysEnumType> GetDataList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("LangID,EnumTypeID,EnumTypeName,VerNo");
strSql.Append(" from tSysEnumType ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetData(strSql);
}
private static List<SysEnumType> SetData(StringBuilder strSql)
{
var headList = new List<SysEnumType>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SysEnumType data = new SysEnumType();
#region Set DB data to Object
data.LangID = Convert.ToDecimal(reader["LangID"]);
data.EnumTypeID = Convert.ToDecimal(reader["EnumTypeID"]);
data.EnumTypeName = Convert.ToString(reader["EnumTypeName"]);
data.VerNo = Convert.ToString(reader["VerNo"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public SysEnumType GetHeadDataByBillNo(string billno)
{
SysEnumType data = null;
var list = GetDataList(" EnumTypeID=" + billno);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new SysEnumType();
}
return data;
}
#endregion
#region 明细表
static public List<SysEnumValue> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("LangID,EnumTypeID,EnumValueID,EnumValueName,EnumValueName_2,IsDefault,DispIndex,VerNo");
strSql.Append(" from tSysEnumValue ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetBodyData(strSql);
}
private static List<SysEnumValue> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<SysEnumValue>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SysEnumValue data = new SysEnumValue();
#region Set DB data to Object
data.LangID = Convert.ToDecimal(reader["LangID"]);
data.EnumTypeID = Convert.ToString(reader["EnumTypeID"]);
data.EnumValueID = Convert.ToString(reader["EnumValueID"]);
data.EnumValueName = Convert.ToString(reader["EnumValueName"]);
data.EnumValueName_2 = Convert.ToString(reader["EnumValueName_2"]);
data.IsDefault = Convert.ToString(reader["IsDefault"]);
data.DispIndex = Convert.ToDecimal(reader["DispIndex"]);
data.VerNo = Convert.ToString(reader["VerNo"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 参照部分
#endregion
public static DBResult Save(SysEnumType headData, List<SysEnumValue> bodyList)
{
var result=new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var enumTypeId = headData.EnumTypeID;
var cmdDelete = db.GetSqlStringCommand("delete from tSysEnumValue where LangID=0 and EnumTypeID=" + enumTypeId);
db.ExecuteNonQuery(cmdDelete, tran);
var cmdInsert =
db.GetSqlStringCommand(
@"insert into tSysEnumValue (LANGID, ENUMTYPEID, ENUMVALUEID, ENUMVALUENAME, ISDEFAULT, DISPINDEX, VERNO)
values (@LANGID, @ENUMTYPEID, @ENUMVALUEID, @ENUMVALUENAME, @ISDEFAULT, @DISPINDEX, @VERNO) ");
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@LANGID", DbType.Int32, enumValue.LangID);
db.AddInParameter(cmdInsert, "@ENUMTYPEID", DbType.Int32, enumTypeId);
db.AddInParameter(cmdInsert, "@ENUMVALUEID", DbType.String, enumValue.EnumValueID);
db.AddInParameter(cmdInsert, "@ENUMVALUENAME", DbType.String, enumValue.EnumValueName);
db.AddInParameter(cmdInsert, "@ISDEFAULT", DbType.String, enumValue.IsDefault);
db.AddInParameter(cmdInsert, "@DISPINDEX", DbType.String, enumValue.DispIndex);
db.AddInParameter(cmdInsert, "@VERNO", DbType.String, enumValue.VerNo);
db.ExecuteNonQuery(cmdInsert, tran);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
}
}