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/SoftMng/DAL/user.cs

251 lines
12 KiB
C#

3 years ago
using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using DSWeb.SoftMng.DBUtility;
// ReSharper disable once CheckNamespace
namespace DSWeb.SoftMng.DAL
{
//user
public partial class userDAL
{
public bool Exists(string GID)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) from [user]");
strSql.Append(" where ");
strSql.Append(" GID = @GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
return DbHelperSQL.Exists(strSql.ToString(),parameters);
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(DSWeb.SoftMng.Model.user model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into [user](");
strSql.Append("GID,USERNAME,CODENAME,PASSWORD,SHOWNAME,ENROLLTIME,CREATEUSER,MODIFIEDUSER,MODIFIEDTIME,ISDELETED,ISDISABLE,DELETEUSER,DELETETIME,NOCODE,OPENID,WeChatAccount");
strSql.Append(") values (");
strSql.Append("@GID,@USERNAME,@CODENAME,@PASSWORD,@SHOWNAME,@ENROLLTIME,@CREATEUSER,@MODIFIEDUSER,@MODIFIEDTIME,@ISDELETED,@ISDISABLE,@DELETEUSER,@DELETETIME,@NOCODE,@OPENID,@WeChatAccount");
strSql.Append(") ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@USERNAME", SqlDbType.VarChar,150) ,
new SqlParameter("@CODENAME", SqlDbType.VarChar,6) ,
new SqlParameter("@PASSWORD", SqlDbType.VarChar,150) ,
new SqlParameter("@SHOWNAME", SqlDbType.VarChar,150) ,
new SqlParameter("@ENROLLTIME", SqlDbType.DateTime) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@ISDELETED", SqlDbType.Bit,1) ,
new SqlParameter("@ISDISABLE", SqlDbType.Bit,1) ,
new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@NOCODE", SqlDbType.VarChar,10) ,
new SqlParameter("@OPENID", SqlDbType.NVarChar,200) ,
new SqlParameter("@WeChatAccount", SqlDbType.NVarChar,200)
};
parameters[0].Value = model.GID??(Object)DBNull.Value;
parameters[1].Value = model.USERNAME??(Object)DBNull.Value;
parameters[2].Value = model.CODENAME??(Object)DBNull.Value;
parameters[3].Value = model.PASSWORD??(Object)DBNull.Value;
parameters[4].Value = model.SHOWNAME??(Object)DBNull.Value;
parameters[5].Value = model.ENROLLTIME??(Object)DBNull.Value;
parameters[6].Value = model.CREATEUSER??(Object)DBNull.Value;
parameters[7].Value = model.MODIFIEDUSER??(Object)DBNull.Value;
parameters[8].Value = model.MODIFIEDTIME??(Object)DBNull.Value;
parameters[9].Value = model.ISDELETED??(Object)DBNull.Value;
parameters[10].Value = model.ISDISABLE??(Object)DBNull.Value;
parameters[11].Value = model.DELETEUSER??(Object)DBNull.Value;
parameters[12].Value = model.DELETETIME??(Object)DBNull.Value;
parameters[13].Value = model.NOCODE??(Object)DBNull.Value;
parameters[14].Value = model.OPENID??(Object)DBNull.Value;
parameters[15].Value = model.WeChatAccount??(Object)DBNull.Value;
return DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(DSWeb.SoftMng.Model.user model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update [user] set ");
strSql.Append(" GID = @GID,");
strSql.Append(" USERNAME = @USERNAME,");
strSql.Append(" CODENAME = @CODENAME,");
strSql.Append(" PASSWORD = @PASSWORD,");
strSql.Append(" SHOWNAME = @SHOWNAME,");
strSql.Append(" ENROLLTIME = @ENROLLTIME,");
strSql.Append(" CREATEUSER = @CREATEUSER,");
strSql.Append(" MODIFIEDUSER = @MODIFIEDUSER,");
strSql.Append(" MODIFIEDTIME = @MODIFIEDTIME,");
strSql.Append(" ISDELETED = @ISDELETED,");
strSql.Append(" ISDISABLE = @ISDISABLE,");
strSql.Append(" DELETEUSER = @DELETEUSER,");
strSql.Append(" DELETETIME = @DELETETIME,");
strSql.Append(" NOCODE = @NOCODE,");
strSql.Append(" OPENID = @OPENID,");
strSql.Append(" WeChatAccount = @WeChatAccount");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@USERNAME", SqlDbType.VarChar,150) ,
new SqlParameter("@CODENAME", SqlDbType.VarChar,6) ,
new SqlParameter("@PASSWORD", SqlDbType.VarChar,150) ,
new SqlParameter("@SHOWNAME", SqlDbType.VarChar,150) ,
new SqlParameter("@ENROLLTIME", SqlDbType.DateTime) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@ISDELETED", SqlDbType.Bit,1) ,
new SqlParameter("@ISDISABLE", SqlDbType.Bit,1) ,
new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@NOCODE", SqlDbType.VarChar,10) ,
new SqlParameter("@OPENID", SqlDbType.NVarChar,200) ,
new SqlParameter("@WeChatAccount", SqlDbType.NVarChar,200)
};
parameters[0].Value = model.GID??(Object)DBNull.Value;
parameters[1].Value = model.USERNAME??(Object)DBNull.Value;
parameters[2].Value = model.CODENAME??(Object)DBNull.Value;
parameters[3].Value = model.PASSWORD??(Object)DBNull.Value;
parameters[4].Value = model.SHOWNAME??(Object)DBNull.Value;
parameters[5].Value = model.ENROLLTIME??(Object)DBNull.Value;
parameters[6].Value = model.CREATEUSER??(Object)DBNull.Value;
parameters[7].Value = model.MODIFIEDUSER??(Object)DBNull.Value;
parameters[8].Value = model.MODIFIEDTIME??(Object)DBNull.Value;
parameters[9].Value = model.ISDELETED??(Object)DBNull.Value;
parameters[10].Value = model.ISDISABLE??(Object)DBNull.Value;
parameters[11].Value = model.DELETEUSER??(Object)DBNull.Value;
parameters[12].Value = model.DELETETIME??(Object)DBNull.Value;
parameters[13].Value = model.NOCODE??(Object)DBNull.Value;
parameters[14].Value = model.OPENID??(Object)DBNull.Value;
parameters[15].Value = model.WeChatAccount??(Object)DBNull.Value;
return DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(string GID)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from [user] ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
return DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
}
/// <summary>
/// 按条件批量删除
/// </summary>
public int DeleteListWhere(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from [user] ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
return DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public DataSet GetModel(string GID)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select GID, USERNAME, CODENAME, PASSWORD, SHOWNAME, ENROLLTIME, CREATEUSER, MODIFIEDUSER, MODIFIEDTIME, ISDELETED, ISDISABLE, DELETEUSER, DELETETIME, NOCODE, OPENID, WeChatAccount ");
strSql.Append(" from [user] ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
DSWeb.SoftMng.Model.user model=new DSWeb.SoftMng.Model.user();
return DbHelperSQL.Query(strSql.ToString(),parameters);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM [user] ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top,string strWhere,string filedOrder)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select ");
if(Top>0)
{
strSql.Append(" top "+Top.ToString());
}
strSql.Append(" * ");
strSql.Append(" FROM [user] ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
//动软代码
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
strSql.Append("order by T." + orderby);
strSql.Append(")AS Row, T.* from [user] T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row > {0} and TT.Row <= {1}", startIndex, endIndex);
//公共代码
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获取记录总数
/// </summary>
public int GetRecordCount(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) FROM [user] ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
return DbHelperSQL.ExcuteScalarSQL(strSql.ToString());
}
}
}