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.
159 lines
5.6 KiB
C#
159 lines
5.6 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.CodeStlMode;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeStlModeDAL
|
|
{
|
|
public class MsCodeStlModeDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<CodeStlMode> GetDataList(string strCondition, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("*");
|
|
strSql.Append(" from code_stlmode ");
|
|
|
|
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 STLCODE");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public CodeStlMode GetData(string condition)
|
|
{
|
|
CodeStlMode data = null;
|
|
var list = GetDataList(condition);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new CodeStlMode();
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<CodeStlMode> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<CodeStlMode>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CodeStlMode data = new CodeStlMode();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.STLCODE = Convert.ToString(reader["STLCODE"]);
|
|
data.STLNAME = Convert.ToString(reader["STLNAME"]);
|
|
data.FINANCESOFTCODE = Convert.ToString(reader["FINANCESOFTCODE"]);
|
|
data.ENAME = Convert.ToString(reader["ENAME"]);
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
public static DBResult SaveDetail(List<CodeStlMode> bodyList)
|
|
{
|
|
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_stlmode (GID,STLCODE,STLNAME,FINANCESOFTCODE,ENAME)
|
|
values (@GID,@STLCODE,@STLNAME,@FINANCESOFTCODE,@ENAME) ");
|
|
|
|
var cmdUpdate =
|
|
db.GetSqlStringCommand(
|
|
@"update code_stlmode set STLCODE=@STLCODE,STLNAME=@STLNAME,FINANCESOFTCODE=@FINANCESOFTCODE,ENAME=@ENAME 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, "@STLCODE", DbType.String, enumValue.STLCODE);
|
|
db.AddInParameter(cmdInsert, "@STLNAME", DbType.String, enumValue.STLNAME);
|
|
db.AddInParameter(cmdInsert, "@FINANCESOFTCODE", DbType.String, enumValue.FINANCESOFTCODE);
|
|
db.AddInParameter(cmdInsert, "@ENAME", DbType.String, enumValue.ENAME);
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
|
|
|
|
db.AddInParameter(cmdUpdate, "@STLCODE", DbType.String, enumValue.STLCODE);
|
|
db.AddInParameter(cmdUpdate, "@STLNAME", DbType.String, enumValue.STLNAME);
|
|
db.AddInParameter(cmdUpdate, "@FINANCESOFTCODE", DbType.String, enumValue.FINANCESOFTCODE);
|
|
db.AddInParameter(cmdUpdate, "@ENAME", DbType.String, enumValue.ENAME);
|
|
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 参照部分
|
|
|
|
#endregion
|
|
}
|
|
}
|