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/MsSysInvInterFaceSet/MsSysInvInterFaceSetDAL.cs

169 lines
6.5 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.SysInvInterFaceSet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.DAL.MsSysInvInterFaceSet
{
public class MsSysInvInterFaceSetDAL
{
#region Inquery DataList
static public List<SysInvInterFaceSet> GetDataList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,INVOICELINE,INVITERFACE,[CREATEUSER]");
strSql.Append(",[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME],[COMPANYID]");
strSql.Append(",(select ShowName from [user] where GID=sys_inv_interfaceset.CREATEUSER) as CREATEUSERREF");
strSql.Append(" from sys_inv_interfaceset where 1=1 ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by INVOICELINE");
}
return SetData(strSql);
}
static public SysInvInterFaceSet GetData(string condition, string companyid)
{
SysInvInterFaceSet data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new SysInvInterFaceSet();
}
return data;
}
private static List<SysInvInterFaceSet> SetData(StringBuilder strSql)
{
var headList = new List<SysInvInterFaceSet>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SysInvInterFaceSet data = new SysInvInterFaceSet();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.INVOICELINE = Convert.ToString(reader["INVOICELINE"]);
data.INVITERFACE = Convert.ToString(reader["INVITERFACE"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SaveDetail(List<SysInvInterFaceSet> bodyList, string companyid,string userid,string LOCALCURR)
{
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 sys_inv_interfaceset (GID,INVOICELINE,INVITERFACE,COMPANYID,CREATEUSER,CREATETIME)
values (@GID,@INVOICELINE,@INVITERFACE,@COMPANYID,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update sys_inv_interfaceset set INVOICELINE=@INVOICELINE,INVITERFACE=@INVITERFACE,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, "@INVOICELINE", DbType.String, enumValue.INVOICELINE);
db.AddInParameter(cmdInsert, "@INVITERFACE", DbType.String, enumValue.INVITERFACE);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@INVOICELINE", DbType.String, enumValue.INVOICELINE);
db.AddInParameter(cmdUpdate, "@INVITERFACE", DbType.String, enumValue.INVITERFACE);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误<"+e.Message+">,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
}
}