|
using Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Text;
|
using Common;
|
using System.Collections;
|
|
namespace BLL
|
{
|
public class DALUserInfo : IDALUserInfo
|
{
|
public bool IsExist(string name, string value)
|
{
|
bool result = false;
|
try
|
{
|
string[] para = new string[] { value };
|
int dt = DataFactory.SqlDataBase().IsExist("UserInfo", name, para);
|
if (dt > 0) result = true;
|
return result;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
public bool IsExist(Hashtable ht)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("UserInfo", ht);
|
if (dt > 0) result = true;
|
return result;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
public bool Add(UserInfo model, string loginUser)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
ht["UserCode"] = "'" + model.UserCode + "'";
|
ht["Username"] = "'" + model.Username + "'";
|
ht["Pwd"] = "'" + Md5Helper.Md5(model.Pwd, 32) + "'";
|
ht["RealName"] = "'" + model.RealName + "'";
|
ht["RoleNum"] = "'" + model.RoleName + "'";
|
ht["DepartNum"] = "'" + model.DepartName + "'";
|
ht["Mobile"] = "'" + model.Mobile + "'";
|
ht["Phone"] = "'" + model.Phone + "'";
|
ht["Email"] = "'" + model.email + "'";
|
ht["Ord"] = "(select isnull(Max(Ord),0) from UserInfo) + 1";
|
ht["IsDel"] = 0;
|
ht["CreatUser"] = "'" + model.CreatUser + "'";
|
ht["UpdateTime"] = "GetDate()";
|
ht["CreatTime"] = "GetDate()";
|
ht["Demo"] = "'" + model.Demo + "'";
|
ht["UpdateUser"] = "'" + model.CreatUser + "'";
|
ht["Sex"] = "" + model.Sex + "";
|
ht["IDcard"] = "'" + model.IDcard + "'";
|
ht["Address"] = "'" + model.Address + "'";
|
|
int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("UserInfo", ht);
|
|
if (_ret == 1) result = true;
|
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public bool Update(UserInfo model)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
ht["RealName"] = string.IsNullOrEmpty(model.RealName) ? "''" : "'" + model.RealName + "'";
|
ht["RoleNum"] = "'" + model.RoleName + "'";
|
ht["DepartNum"] = "'" + model.DepartName + "'";
|
ht["Mobile"] = string.IsNullOrEmpty(model.Mobile) ? "''" : "'" + model.Mobile + "'";
|
ht["Phone"] = string.IsNullOrEmpty(model.Phone) ? "''" : "'" + model.Phone + "'";
|
ht["Email"] = string.IsNullOrEmpty(model.email) ? "''" : "'" + model.email + "'";
|
ht["UpdateTime"] = "GetDate()";
|
ht["UpdateUser"] = string.IsNullOrEmpty(model.UpdateUser) ? "''" : "'" + model.UpdateUser + "'";
|
ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'";
|
ht["Sex"] = "'" + model.Sex + "'";
|
ht["IDcard"] = string.IsNullOrEmpty(model.IDcard) ? "''" : "'" + model.IDcard + "'";
|
ht["Address"] = string.IsNullOrEmpty(model.Address) ? "''" : "'" + model.Address + "'";
|
|
string UserCode = "'" + model.UserCode + "'";
|
|
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("UserInfo", "UserCode", UserCode, ht);
|
|
if (_ret == 1) result = true;
|
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
public bool Update(string UserCode, string Pwd, string UpdateUser)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
ht["Pwd"] = string.IsNullOrEmpty(Pwd) ? "''" : "'" + Md5Helper.Md5(Pwd, 32) + "'";
|
if (UserCode != null)
|
{
|
ht["UpdateUser"] = "'" + UserCode + "'";
|
ht["UpdateTime"] = "getdate()";
|
UserCode = "'" + UserCode + "'";
|
}
|
int _ret = DataFactory.SqlDataBase().UpdateByHashtable("UserInfo", "UserCode", UserCode, ht);
|
|
if (_ret == 1) result = true;
|
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
public UserInfo DataRowToModel(DataRow row)
|
{
|
throw new NotImplementedException();
|
}
|
|
public bool Delete(string UserCode)
|
{
|
bool result = false;
|
try
|
{
|
Hashtable ht = new Hashtable();
|
|
int _ret = DataFactory.SqlDataBase().DeleteData("UserInfo", "UserCode", UserCode);
|
|
if (_ret == 1) result = true;
|
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public bool BatchDelete(string[] UserCode)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("UserInfo", "UserCode", UserCode);
|
if (dt >= UserCode.Length)
|
{
|
StringBuilder sql = new StringBuilder();
|
foreach (string code in UserCode)
|
{
|
sql.Append("update UserInfo set IsDel=1 where UserCode='" + code + "';");
|
}
|
|
int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
|
if (_ret > UserCode.Length) result = true;
|
}
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public bool StartUser(string[] UserCode)
|
{
|
bool result = false;
|
try
|
{
|
int dt = DataFactory.SqlDataBase().IsExist("UserInfo", "UserCode", UserCode);
|
if (dt >= UserCode.Length)
|
{
|
StringBuilder sql = new StringBuilder();
|
foreach (string code in UserCode)
|
{
|
sql.Append("update UserInfo set IsDel=0 where UserCode='" + code + "';");
|
}
|
|
int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
|
if (_ret > UserCode.Length) result = true;
|
}
|
return result;
|
|
}
|
catch
|
{
|
return result;
|
}
|
}
|
|
public IList<UserInfo> GetList(string strWhere)
|
{
|
throw new NotImplementedException();
|
}
|
|
public IList<UserInfo> GetList(AjaxUserList Json,ref PageInfo pageInfo)
|
{
|
try {
|
|
IList<UserInfo> list = new List<UserInfo>();
|
StringBuilder strSql = new StringBuilder();
|
List<SqlParam> para = new List<SqlParam>();
|
strSql.Append("Select UserCode,UserName,RealName,Phone,Sex,IDcard,Mobile, ");
|
strSql.Append("Email,RoleName,DepartName,CreatUser,CreatTime,UpdateUser,UpdateTime,");
|
strSql.Append("Demo,Ord,IsDel,case when IsDel = 0 then '启用' else '停用' end as Statu ");
|
strSql.Append("from View_UserInfo ");
|
|
if (Json.UserCode != null && Json.UserCode != "")
|
{
|
if (para.Count <1 ) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("UserCode like '%' + @UserCode + '%' ");
|
para.Add(new SqlParam("@UserCode", Json.UserCode));
|
}
|
|
if (Json.UserName != null && Json.UserName != "")
|
{
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("Username like '%' + @Username + '%' ");
|
para.Add(new SqlParam("@Username", Json.UserName));
|
}
|
|
if (Json.RoleNum != null && Json.RoleNum != "")
|
{
|
string RoleName = Json.RoleNum;
|
if (para.Count <1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("RoleNum = '" + RoleName + "' ");
|
para.Add(new SqlParam("@RoleNum", Json.RoleNum));
|
}
|
|
if (Json.DepartNum != null && Json.DepartNum != "")
|
{
|
string DepartMent = Json.DepartNum;
|
if (para.Count <1) strSql.Append("where ");else strSql.Append(" and ");
|
strSql.Append("DepartNum = '" + DepartMent +" '");
|
para.Add(new SqlParam("@DepartMent", Json.DepartNum));
|
}
|
if (Json.IsDel != "-1")
|
{
|
string IsDel = Json.IsDel;
|
if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
|
strSql.Append("IsDel = '" + IsDel + " '");
|
para.Add(new SqlParam("@IsDel", Json.IsDel));
|
}
|
if (para.Count < 1 )
|
{
|
strSql.Append(" Where UserCode <> 'SuperUser'");
|
}
|
else
|
{
|
strSql.Append(" and UserCode <> 'SuperUser'");
|
}
|
|
|
SqlParam[] param = null;
|
if (para != null)
|
param = para.ToArray();
|
|
|
DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "isdel", "ASC", ref pageInfo);
|
list = ModelConvertHelper<UserInfo>.DataTableToModel(dt);
|
|
return list;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
public UserInfo GetModel(string username, string pwd)
|
{
|
try
|
{
|
UserInfo us = null;
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("SELECT ui.*,dm.AccessCode FROM UserInfo ui LEFT JOIN dbo.DepartMent dm ON ui.DepartNum=dm.guid WHERE ");
|
strSql.Append("ui.Username = @Username ");
|
strSql.Append("and ui.Pwd = @Pwd ");
|
strSql.Append("and ui.IsDel != 1");
|
SqlParam[] para = new SqlParam[]
|
{
|
new SqlParam("@Username", username),
|
new SqlParam("@Pwd", Md5Helper.Md5(pwd, 32))
|
};
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
|
|
//IList<UserInfo> Lu = ModelConvertHelper<UserInfo>.DataReaderToModel(dt);
|
|
us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
|
|
return us;
|
}
|
catch(Exception e)
|
{
|
throw new NotImplementedException();
|
}
|
}
|
public UserInfo GetModel(string usercode)
|
{
|
try
|
{
|
UserInfo us = null;
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("Select UserCode,UserName,RealName,Phone,Mobile,Email,RoleName,RoleNum,DepartName,DepartNum,");
|
strSql.Append("CreatUser,CreatTime,UpdateUser,UpdateTime,Demo,Ord,IsDel,Sex,IDcard,Address from View_UserInfo where ");
|
strSql.Append("UserCode = @UserCode ");
|
//strSql.Append("and IsDel != 1");
|
SqlParam[] para = new SqlParam[]
|
{
|
new SqlParam("@UserCode", usercode),
|
};
|
|
IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
|
|
us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
|
|
return us;
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
}
|
|
|
public DataTable GetDataTable(string[] strWhere)
|
{
|
DataTable dt = null;
|
try
|
{
|
int index = 0;
|
string str = "@UserCode" + index;
|
SqlParam[] param = new SqlParam[strWhere.Length];
|
StringBuilder sql = new StringBuilder();
|
sql.Append("Select Username as 用户名,UserCode as 员工编号,RealName as 真名,Email as 邮箱,Mobile as 手机,Phone as 固话,CreatTime as 创建时间,DepartName as 部门,RoleName as 角色,Demo as 备注 FROM View_UserInfo where UserCode in (");
|
|
for (int i = 0; i < param.Length - 1; i++)
|
{
|
string obj2 = strWhere[i];
|
str = "@UserCode" + index;
|
sql.Append(str).Append(",");
|
param[index] = new SqlParam(str, obj2);
|
index++;
|
}
|
str = "@UserCode" + index;
|
sql.Append(str);
|
param[index] = new SqlParam(str, strWhere[index]);
|
sql.Append(")");
|
|
dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql, param,"");
|
|
return dt;
|
|
}
|
catch
|
{
|
throw new NotImplementedException();
|
}
|
|
}
|
|
public DataTable GetDataTable(int PageSize, int PageIndex, string strWhere)
|
{
|
throw new NotImplementedException();
|
}
|
|
public List<LoginLog> GetLogInUserRecordList()
|
{
|
StringBuilder strSql = new StringBuilder();
|
strSql.Append("select Top(1000) * from Login_Log order by LoginTime desc");
|
|
strSql.Append("Select Top(1000) Username as 用户名,UserCode as 员工编号,RealName as 真名,Email as 邮箱,Mobile as 手机,Phone as 固话,CreatTime as 创建时间,DepartName as 部门,RoleName as 角色,Demo as 备注 FROM Login_Log order by LoginTime desc ");
|
|
List<LoginLog> list = new List<LoginLog>();
|
//DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
|
//list = (List<LoginLog>)ModelConvertHelper<LoginLog>.DataTableToModel(dt);
|
return list;
|
}
|
|
|
}
|
}
|