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.
399 lines
14 KiB
C#
399 lines
14 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.MsSysIpWhile;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsSysIpWhile
|
|
{
|
|
public class MsSysIpWhileDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<SysIpWhile> GetDataList(string strCondition, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("BSNO,IP,MODIFYUSER,MODIFYTIME,CREATEUSER,CREATETIME");
|
|
|
|
strSql.Append(" from sys_ipwhile ");
|
|
|
|
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 CREATETIME");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public SysIpWhile GetData(string condition)
|
|
{
|
|
SysIpWhile data = null;
|
|
var list = GetDataList(condition);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new SysIpWhile();
|
|
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<SysIpWhile> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<SysIpWhile>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
SysIpWhile data = new SysIpWhile();
|
|
#region Set DB data to Object
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
data.IP = Convert.ToString(reader["IP"]);
|
|
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
|
|
data.MODIFYUSER = Convert.ToString(reader["MODIFYUSER"]);
|
|
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
|
|
data.MODIFYTIME = Convert.ToString(reader["MODIFYTIME"]);
|
|
|
|
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
|
|
public static DBResult SaveDetail(List<SysIpWhile> bodyList, string userid)
|
|
{
|
|
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_ipwhile (BSNO,IP,CREATEUSER,CREATETIME,MODIFYUSER,MODIFYTIME)
|
|
values (@BSNO,@IP,@CREATEUSER,@CREATETIME,@MODIFYUSER,@MODIFYTIME) ");
|
|
|
|
var cmdUpdate =
|
|
db.GetSqlStringCommand(
|
|
@"update sys_ipwhile set IP=@IP,MODIFYUSER=@MODIFYUSER,MODIFYTIME=@MODIFYTIME where BSNO=@BSNO ");
|
|
|
|
if (bodyList != null)
|
|
{
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
|
|
if (enumValue.BSNO == "*" || enumValue.BSNO == "")
|
|
{
|
|
cmdInsert.Parameters.Clear();
|
|
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, Guid.NewGuid().ToString());
|
|
db.AddInParameter(cmdInsert, "@IP", DbType.String, enumValue.IP);
|
|
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
|
|
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
db.AddInParameter(cmdInsert, "@MODIFYUSER", DbType.String, userid);
|
|
db.AddInParameter(cmdInsert, "@MODIFYTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
|
|
db.AddInParameter(cmdUpdate, "@IP", DbType.String, enumValue.IP);
|
|
db.AddInParameter(cmdUpdate, "@MODIFYUSER", DbType.String, userid);
|
|
db.AddInParameter(cmdUpdate, "@MODIFYTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
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;
|
|
}
|
|
|
|
public static DBResult DeleteDetail(List<SysIpWhile> headData)
|
|
{
|
|
var result = new DBResult();
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (var conn = db.CreateConnection())
|
|
{
|
|
conn.Open();
|
|
var tran = conn.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
if (headData != null)
|
|
{
|
|
foreach (var enumValue in headData)
|
|
{
|
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from sys_ipwhile where BSNO='" + enumValue.BSNO + "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
}
|
|
}
|
|
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
tran.Rollback();
|
|
|
|
result.Success = false;
|
|
result.Message = "删除出现错误,请重试或联系系统管理员";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Message = "删除成功";
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Inquery DataList2
|
|
|
|
static public List<SysUserWhile> GetUserDataList(string strCondition, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("BSNO,USERID,MODIFYUSER,MODIFYTIME,CREATEUSER,CREATETIME");
|
|
strSql.Append(",(select ShowName from [user] where GID=sys_userwhile.USERID) as USERNAME");
|
|
|
|
|
|
strSql.Append(" from sys_userwhile ");
|
|
|
|
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 CREATETIME");
|
|
|
|
}
|
|
return SetUserData(strSql);
|
|
}
|
|
|
|
static public SysUserWhile GetUserData(string condition)
|
|
{
|
|
SysUserWhile data = null;
|
|
var list = GetUserDataList(condition);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new SysUserWhile();
|
|
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<SysUserWhile> SetUserData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<SysUserWhile>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
SysUserWhile data = new SysUserWhile();
|
|
#region Set DB data to Object
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
data.USERID = Convert.ToString(reader["USERID"]);
|
|
data.USERNAME = Convert.ToString(reader["USERNAME"]);
|
|
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
|
|
data.MODIFYUSER = Convert.ToString(reader["MODIFYUSER"]);
|
|
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
|
|
data.MODIFYTIME = Convert.ToString(reader["MODIFYTIME"]);
|
|
|
|
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
|
|
public static DBResult SaveUserDetail(List<SysUserWhile> bodyList, string userid)
|
|
{
|
|
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_userwhile (BSNO,USERID,CREATEUSER,CREATETIME,MODIFYUSER,MODIFYTIME)
|
|
values (@BSNO,@USERID,@CREATEUSER,@CREATETIME,@MODIFYUSER,@MODIFYTIME) ");
|
|
|
|
var cmdUpdate =
|
|
db.GetSqlStringCommand(
|
|
@"update sys_userwhile set USERID=@USERID,MODIFYUSER=@MODIFYUSER,MODIFYTIME=@MODIFYTIME where BSNO=@BSNO ");
|
|
|
|
if (bodyList != null)
|
|
{
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
|
|
if (enumValue.BSNO == "*" || enumValue.BSNO == "")
|
|
{
|
|
cmdInsert.Parameters.Clear();
|
|
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, Guid.NewGuid().ToString());
|
|
db.AddInParameter(cmdInsert, "@USERID", DbType.String, enumValue.USERID);
|
|
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
|
|
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
db.AddInParameter(cmdInsert, "@MODIFYUSER", DbType.String, userid);
|
|
db.AddInParameter(cmdInsert, "@MODIFYTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
|
|
cmdUpdate.Parameters.Clear();
|
|
db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, enumValue.BSNO);
|
|
db.AddInParameter(cmdUpdate, "@USERID", DbType.String, enumValue.USERID);
|
|
db.AddInParameter(cmdUpdate, "@MODIFYUSER", DbType.String, userid);
|
|
db.AddInParameter(cmdUpdate, "@MODIFYTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
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;
|
|
}
|
|
|
|
public static DBResult DeleteUserDetail(List<SysUserWhile> headData)
|
|
{
|
|
var result = new DBResult();
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (var conn = db.CreateConnection())
|
|
{
|
|
conn.Open();
|
|
var tran = conn.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
if (headData != null)
|
|
{
|
|
foreach (var enumValue in headData)
|
|
{
|
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from sys_userwhile where BSNO='" + enumValue.BSNO + "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
}
|
|
}
|
|
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
tran.Rollback();
|
|
|
|
result.Success = false;
|
|
result.Message = "删除出现错误,请重试或联系系统管理员";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Message = "删除成功";
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
}
|