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.
195 lines
7.0 KiB
C#
195 lines
7.0 KiB
C#
|
|
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.MsCodeOpStatus;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.EntityDA;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeOpStatusDAL
|
|
{
|
|
public class MsCodeOpStatusDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<MsCodeOpStatus> GetDataList(string strCondition)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("GID,OPTYPE,STTYPE,CORPID,[DESCRIPTION],CREATEUSER");
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96005 and EnumValueID=code_op_status.OPTYPE) as OPTYPESTR");
|
|
strSql.Append(",(CASE WHEN STTYPE='2' THEN '费用状态' ELSE '业务状态' END) as STTYPESTR");
|
|
strSql.Append(" from code_op_status ");
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
|
|
strSql.Append(" order by OPTYPE");
|
|
|
|
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public MsCodeOpStatus GetData(string condition)
|
|
{
|
|
var list = GetDataList(condition);
|
|
if (list.Count > 0)
|
|
return list[0];
|
|
|
|
return new MsCodeOpStatus();
|
|
}
|
|
|
|
|
|
private static List<MsCodeOpStatus> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<MsCodeOpStatus>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsCodeOpStatus data = new MsCodeOpStatus();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
|
|
data.CORPID = Convert.ToString(reader["CORPID"]);
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
data.OPTYPESTR = Convert.ToString(reader["OPTYPESTR"]);
|
|
data.STTYPE = Convert.ToString(reader["STTYPE"]);
|
|
data.STTYPESTR = Convert.ToString(reader["STTYPESTR"]);
|
|
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
|
|
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 明细表
|
|
|
|
static public List<MsCodeOpStatusDetail> GetBodyList(string strCondition)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("GID,SerialNo,OPTYPE,OPSTATUS,STTYPE,CORPID,REMARKS,COLOR");
|
|
strSql.Append(" from code_op_status_detail ");
|
|
if (!string.IsNullOrWhiteSpace(strCondition))
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
strSql.Append(" order by SerialNo ");
|
|
|
|
return SetBodyData(strSql);
|
|
}
|
|
|
|
private static List<MsCodeOpStatusDetail> SetBodyData(StringBuilder strSql)
|
|
{
|
|
var bodyList = new List<MsCodeOpStatusDetail>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsCodeOpStatusDetail data = new MsCodeOpStatusDetail();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
|
|
data.OPTYPE = Convert.ToString(reader["OPTYPE"]);
|
|
data.STTYPE = Convert.ToString(reader["STTYPE"]);
|
|
data.OPSTATUS = Convert.ToString(reader["OPSTATUS"]);
|
|
data.REMARKS = Convert.ToString(reader["REMARKS"]);
|
|
data.CORPID = Convert.ToString(reader["CORPID"]);
|
|
data.COLOR = Convert.ToString(reader["COLOR"]);
|
|
|
|
#endregion
|
|
|
|
bodyList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
return bodyList;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
public static DBResult SaveDetail(MsCodeOpStatus headData, List<MsCodeOpStatusDetail> bodyList, string corpid)
|
|
{
|
|
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_op_status_detail where OPTYPE='" + headData.OPTYPE + "' AND CORPID='"+corpid+"'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
var cmdInsert =
|
|
db.GetSqlStringCommand(
|
|
@"insert into code_op_status_detail (GID, SerialNo, OPTYPE,STTYPE,OPSTATUS,CORPID,REMARKS,COLOR)
|
|
values (@GID, @SerialNo, @OPTYPE, @STTYPE,@OPSTATUS,@CORPID,@REMARKS,@COLOR) ");
|
|
|
|
if (bodyList != null)
|
|
{
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
cmdInsert.Parameters.Clear();
|
|
|
|
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
|
|
db.AddInParameter(cmdInsert, "@SerialNo", DbType.Int32, enumValue.SerialNo);
|
|
db.AddInParameter(cmdInsert, "@OPTYPE", DbType.String, headData.OPTYPE);
|
|
db.AddInParameter(cmdInsert, "@STTYPE", DbType.String, headData.STTYPE);
|
|
db.AddInParameter(cmdInsert, "@OPSTATUS", DbType.String, enumValue.OPSTATUS);
|
|
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
|
|
db.AddInParameter(cmdInsert, "@CORPID", DbType.String, corpid);
|
|
db.AddInParameter(cmdInsert, "@COLOR",DbType.String, enumValue.COLOR);
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
}
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
tran.Rollback();
|
|
|
|
result.Success = false;
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Message = "保存成功";
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|