You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
8.8 KiB
277 lines
8.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// BaseUserHandler 的摘要说明
|
|
/// </summary>
|
|
public class BaseUserHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.BaseUserBLL bll = new BLL.BaseUserBLL();
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/json";
|
|
string action = context.Request.Params["Action"];
|
|
string returnstr = "";
|
|
switch (action)
|
|
{
|
|
case "List":
|
|
returnstr = GetUserList(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddUser(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditUser(context);
|
|
break;
|
|
case "Del":
|
|
returnstr = DelUser(context);
|
|
break;
|
|
case "EditPwd":
|
|
returnstr = EditPwd(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
}
|
|
//查询
|
|
private string GetUserList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string keywords = context.Request.Params["keywords"];
|
|
string where = null;
|
|
if (!string.IsNullOrEmpty(keywords))
|
|
{
|
|
where = "USERS_UID like '" + keywords + "' or USERS_NAME like '" + keywords + "' ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
|
|
List<FangYar.Model.BaseUserModel> list = bll.QueryList(1, 10, where, null);
|
|
returnstr += "\"count\":" + list.Count + ",\"data\":";
|
|
if (list.Count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(list);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch
|
|
{
|
|
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]";
|
|
}
|
|
return returnstr;
|
|
}
|
|
//添加
|
|
private string AddUser(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string userUID = context.Request.Params["userUID"];
|
|
string userPwd = context.Request.Params["userPwd"];
|
|
string userType = context.Request.Params["userType"];
|
|
string userName = context.Request.Params["userName"];
|
|
|
|
if (string.IsNullOrEmpty(userUID))
|
|
{
|
|
msg = "账号不能为空!";
|
|
}
|
|
else if (userUID.Length < 4)
|
|
{
|
|
msg = "账号长度最少为4个字符!";
|
|
}
|
|
|
|
else if (string.IsNullOrEmpty(userPwd))
|
|
{
|
|
msg = "密码不能为空!";
|
|
}
|
|
else if (userUID.Length < 4)
|
|
{
|
|
msg = "密码长度最少为4个字符!";
|
|
}
|
|
else if (string.IsNullOrEmpty(userName))
|
|
{
|
|
msg = "名称不能为空!";
|
|
}
|
|
else if (bll.CheckLoginByUserID(userUID) != null)
|
|
{
|
|
msg = "用户已存在!";
|
|
}
|
|
else
|
|
{
|
|
FangYar.Model.BaseUserModel model = new Model.BaseUserModel();
|
|
model.ID = Guid.NewGuid().ToString("N");
|
|
model.USERS_UID = userUID;
|
|
model.USERS_PWD = FangYar.Common.Md5.GetMD5String(userPwd);
|
|
model.USERS_NAME = userName;
|
|
model.USERS_TYPE = userType;
|
|
if (bll.AddUser(model))
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "添加失败!";
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
msg = "添加失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//修改
|
|
private string EditUser(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string userUID = context.Request.Params["userUID"];
|
|
string userPwd = context.Request.Params["userPwd"];
|
|
string userType = context.Request.Params["userType"];
|
|
string userName = context.Request.Params["userName"];
|
|
|
|
FangYar.Model.BaseUserModel model = bll.GetUserByID(ID);
|
|
if (model == null)
|
|
{
|
|
msg = "用户不存在!";
|
|
}
|
|
else
|
|
{
|
|
|
|
model.USERS_UID = userUID;
|
|
model.USERS_PWD = FangYar.Common.Md5.GetMD5String(userPwd);
|
|
model.USERS_NAME = userName;
|
|
model.USERS_TYPE = userType;
|
|
if (bll.EditUser(model))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//删除
|
|
private string DelUser(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = UIDList.Replace(",", "','");
|
|
if (bll.DeleteUser(UIDList))
|
|
{
|
|
msg = "删除成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//修改密码
|
|
private string EditPwd(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string userUID = context.Request.Params["UsersUid"];
|
|
string userPwd = context.Request.Params["oldPwd"];
|
|
string newPwd = context.Request.Params["newPwd"];
|
|
string confirmPwd = context.Request.Params["confirmPwd"];
|
|
FangYar.Model.BaseUserModel model = bll.GetUserByUserID(userUID);
|
|
if (string.IsNullOrEmpty(userPwd))
|
|
{
|
|
msg = "密码不能为空!";
|
|
}
|
|
else if (newPwd.Length < 4)
|
|
{
|
|
msg = "密码长度最少为4个字符!";
|
|
}
|
|
else if (confirmPwd != newPwd)
|
|
{
|
|
msg = "两次输入密码不一致!";
|
|
}
|
|
else if (model == null)
|
|
{
|
|
msg = "用户不存在!";
|
|
}
|
|
else if
|
|
(model.USERS_PWD == FangYar.Common.Md5.GetMD5String(newPwd))
|
|
{
|
|
msg = "修改密码不能和旧密码一致!";
|
|
}
|
|
else
|
|
{
|
|
|
|
model.USERS_PWD = FangYar.Common.Md5.GetMD5String(newPwd);
|
|
if (bll.ChangePwd(model))
|
|
{
|
|
msg = "密码修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "密码修改失败!";
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
msg = "密码修改失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|