private void GetPwd(HttpContext context, string btn) { if (btn != "btnGetPwd") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } try { int perId = RequestHelper.GetInt("id", 0); BLL.System.sys_Person bll = new BLL.System.sys_Person(); string pwd = bll.GetPwd(perId); StringBuilder jsonStr = new StringBuilder(); jsonStr.Append("{\"status\":\"1\",\"msg\":\"获取数据成功!\",\"info\":"); jsonStr.Append(pwd); jsonStr.Append("}"); context.Response.Write(jsonStr); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void GetData(HttpContext context, string btn) { if (btn != "show") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } try { int perId = RequestHelper.GetInt("id", 0); BLL.System.sys_Person bll = new BLL.System.sys_Person(); DataTable dt = bll.GetList(perId).Tables[0]; if (dt.Rows.Count == 0) { context.Response.Write("{\"status\":\"0\",\"msg\":\"该条数据已被其他人删除!\"}"); return; } string rowsStr = Utils.ToJson(dt); StringBuilder jsonStr = new StringBuilder(); jsonStr.Append("{\"status\":\"1\",\"msg\":\"获取数据成功!\",\"info\":"); jsonStr.Append(rowsStr); jsonStr.Append("}"); context.Response.Write(jsonStr); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void ModifyPwd(HttpContext context) { try { string loginSalt = RequestHelper.GetQueryString("LoginSalt"); if (loginSalt == "") { context.Response.Write("{\"status\":\"0.1\",\"msg\":\"Salt不能为空!\"}"); return; } Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); if (loginUserModel == null || loginUserModel.Salt != loginSalt) { context.Response.Write("{\"status\":\"0.1\",\"msg\":\"登录超时,请重新登录!\"}"); return; } string oldPwd = RequestHelper.GetString("oldPwd"); string newPwd = RequestHelper.GetString("newPwd"); BLL.System.sys_Person bll = new BLL.System.sys_Person(); string errMessage = bll.UpdatePwd(loginUserModel.Account, oldPwd, newPwd); if (errMessage != "") { context.Response.Write("{\"status\":\"0\",\"msg\":\"" + errMessage + "\"}"); return; } //写入操作日志 Model.System.sys_OperaLog operaModel = BaseWeb.GetOperaModel(loginUserModel); operaModel.OperaType = Enums.ActionEnum.Login.ToString(); operaModel.Memo = "修改密码"; new BLL.System.sys_OperaLog().Add(operaModel); context.Response.Write("{\"status\":\"1\",\"msg\":\"密码修改成功!\"}"); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void GetPersonCombo(HttpContext context, string btn) { string emptyStr = "[{\"PerId\":\"0\",\"PerName\":\"无\",\"DepName\":\"无\",\"DepId\":\"0\"}]"; if (btn != "show") { context.Response.Write(emptyStr); return; } try { BLL.System.sys_Person bll = new BLL.System.sys_Person(); string DepId = RequestHelper.GetString("DepId"); string PostId = RequestHelper.GetString("PostId"); string FlagCtrl = RequestHelper.GetString("FlagCtrl"); string PerName = RequestHelper.GetString("q").Trim(); StringBuilder strWhere = new StringBuilder(); if (DepId != "") { strWhere.Append(" and a.DepId in(select ID from sys_Department where ','+SupList like '%," + DepId + ",%' or ID=" + DepId + ")"); } if (PostId != "") { strWhere.Append(" and a.PostId in(" + PostId + ")"); } if (FlagCtrl == "1") { Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); strWhere.Append(" and a.ID in(select CtrlPerId from v_sys_PersonCtrl where PerId=" + loginUserModel.ID.ToString() + ")"); } if (PerName != "") { strWhere.Append(" and a.PerName like '%" + PerName + "%' "); } DataTable dt = bll.GetComboList(strWhere.ToString()).Tables[0]; string rowsStr = Utils.ToJson(dt); context.Response.Write(rowsStr); } catch { context.Response.Write(emptyStr); } }
private void DelData(HttpContext context, string btn) { if (btn != "btnDel") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } string idStr = RequestHelper.GetString("idStr"); string nameStr = RequestHelper.GetString("nameStr"); if (idStr == "") { context.Response.Write("{\"status\":\"0\",\"msg\":\"请选择需要删除的记录!\"}"); return; } BLL.System.sys_Person bll = new BLL.System.sys_Person(); Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); string operaMessage = ""; string status = "0"; string operaAction = ""; string operaMemo = ""; try { if (bll.DeleteList(PageValidate.SafeLongFilter(idStr, 0), out operaMessage)) { status = "1"; operaAction = Enums.ActionEnum.Delete.ToString(); operaMemo = "删除人员:" + nameStr + "(" + idStr + ")"; //写入操作日志 BaseWeb.AddOpera(loginUserModel, int.Parse(RequestHelper.GetQueryString("MenuId")), operaAction, operaMemo); } context.Response.Write("{\"status\":\"" + status + "\",\"msg\":\"" + operaMessage + "\"}"); return; } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void GetMenu(HttpContext context) { try { string loginSalt = RequestHelper.GetQueryString("LoginSalt"); if (loginSalt == "") { context.Response.Write("身份验证失败"); return; } Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); if (loginUserModel == null || loginUserModel.Salt != loginSalt) { //context.Response.Write("{\"status\":\"0\",\"msg\":\"身份验证失败!\"}"); context.Response.Write("身份验证失败"); return; } string htmlStr = ""; DataTable dt = null; if (loginUserModel.IsAdmin == true) { dt = new BLL.System.sys_Menu().GetList("").Tables[0]; } else { dt = new BLL.System.sys_Person().GetUserMenu(loginUserModel.ID).Tables[0]; } DataTable btnDT = new BLL.System.sys_Menu().GetNoPowerBtn(loginUserModel.ID).Tables[0]; int levelOpenId = dt.Select("levelId=1").Length > 4 ? 1 : 2; htmlStr = AddNode(dt, btnDT, 1, levelOpenId, "0", "ID", "menuName", "supId", "sortId", "linkUrl", "levelId"); context.Response.Write(htmlStr); } catch { context.Response.Write("身份验证失败"); return; } }
private void InitPwd(HttpContext context, string btn) { if (btn != "btnInitPwd") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } try { int perId = RequestHelper.GetInt("id", 0); Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); string operaAction = ""; string operaMemo = ""; BLL.System.sys_Person bll = new BLL.System.sys_Person(); string pwd = bll.InitPwd(perId); if (pwd == "") { context.Response.Write("{\"status\":\"1\",\"msg\":\"初始化密码失败!\"}"); return; } else { operaAction = Enums.ActionEnum.Edit.ToString(); operaMemo = "初始化密码:(" + perId + ")"; //写入操作日志 BaseWeb.AddOpera(loginUserModel, int.Parse(RequestHelper.GetQueryString("MenuId")), operaAction, operaMemo); } context.Response.Write("{\"status\":\"1\",\"msg\":\"初始化成功,密码为" + pwd + "!\"}"); return; } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void GePerTree(HttpContext context, string btn) { if (btn != "show") { context.Response.Write("[]"); return; } try { string treeJsonStr = "[]"; BLL.System.sys_Person bll = new BLL.System.sys_Person(); DataTable dt = bll.GetDepPersonList().Tables[0]; if (dt != null && dt.Rows.Count > 0) { treeJsonStr = DtToTreeJson(dt, "ID", "Name", "SupId", "SortId", "B0", "B0"); } context.Response.Write(treeJsonStr); } catch { context.Response.Write("[]"); } }
private void Login(HttpContext context) { try { string account = RequestHelper.GetString("account"); string pwd = RequestHelper.GetString("pwd"); string url = RequestHelper.GetUrlReferrer(); //判断登录错误次数 if (context.Session["LoginNum"] != null && Convert.ToInt32(context.Session["LoginNum"]) > 5) { context.Response.Write("{\"status\":\"0\",\"msg\":\"错误超过5次,关闭浏览器重新登录!\"}"); return; } if (account.Trim() == "") { WriteError(context); context.Response.Write("{\"status\":\"0\",\"msg\":\"账号不能为空!\"}"); return; } if (pwd.Trim() == "") { WriteError(context); context.Response.Write("{\"status\":\"0\",\"msg\":\"密码不能为空!\"}"); return; } if (url.Trim() == "") { WriteError(context); context.Response.Write("{\"status\":\"0.1\",\"msg\":\"非法传入页面!\"}"); return; } String domain = Utils.GetUrlDomain(url).ToLower(); if (domain != "localhost" || RequestHelper.GetIP() != "127.0.0.1") { Model.System.sys_Config configModel = new BLL.System.sys_Config().loadConfig(); string[] domainArray = (configModel.webinsideurl + "," + configModel.weburl).Split(','); if (domain == "" || !domainArray.Contains(domain)) { WriteError(context); context.Response.Write("{\"status\":\"0.1\",\"msg\":\"非法传入页面!\"}"); return; } } BLL.System.sys_Person bll = new BLL.System.sys_Person(); Model.System.sys_LoginUser model = bll.GetModel(account, pwd, true); if (model == null) { WriteError(context); context.Response.Write("{\"status\":\"0\",\"msg\":\"用户名或密码有误,请重试!\"}"); return; } model.Salt = Utils.GetLetterOrNumberRandom(10); model.LoginTime = DateTime.Now; model.LoginIP = RequestHelper.GetIP(); // 保存登录人的Sessin context.Session[Keys.SESSION_LoginUser] = model; context.Session.Timeout = 45; //写入登录日志 string operaAction = Enums.ActionEnum.Login.ToString(); string operaMemo = "用户登录"; BaseWeb.AddOpera(model, 0, operaAction, operaMemo); context.Response.Write("{\"status\":\"1\",\"msg\":\"权限获取成功!\",\"userName\":\"" + model.PerName + "\",\"loginSalt\":\"" + model.Salt + "\"}"); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"" + e.Message + "\"}"); } }
protected void btnSubmit_Click(object sender, EventArgs e) { //判断登录错误次数 if (Session["LoginNum"] != null && Convert.ToInt32(Session["LoginNum"]) > 5) { msgtip.InnerHtml = "错误超过5次,请关闭浏览器重新登录!"; tipsDiv.Style["display"] = ""; return; } string userAccount = txtAccount.Text.Trim(); string userPwd = txtPassword.Text.Trim(); if (userAccount.Equals("")) { msgtip.InnerHtml = "请输入账号!"; tipsDiv.Style["display"] = ""; txtAccount.Focus(); CalErrNum(); return; } if (userPwd.Equals("")) { msgtip.InnerHtml = "请输入密码!"; tipsDiv.Style["display"] = ""; txtPassword.Focus(); CalErrNum(); return; } BLL.System.sys_Person bll = new BLL.System.sys_Person(); Model.System.sys_LoginUser model = bll.GetModel(userAccount, userPwd, true); if (model == null) { msgtip.InnerHtml = "账号或密码错误!"; tipsDiv.Style["display"] = ""; txtPassword.Focus(); CalErrNum(); return; } model.Salt = Utils.GetLetterOrNumberRandom(10); model.LoginTime = DateTime.Now; model.LoginIP = RequestHelper.GetIP(); // 保存登录人的Sessin Session[Keys.SESSION_LoginUser] = model; Session.Timeout = 45; //写入登录日志 string operaAction = Enums.ActionEnum.Login.ToString(); string operaMemo = "用户登录"; BaseWeb.AddOpera(model, 0, operaAction, operaMemo); ////写入Cookies Utils.WriteCookie("SCZMLoginSalt", model.Salt); Utils.WriteCookie("SCZMAccount", userAccount, 43200); Utils.WriteCookie("SCZMUserName", model.PerName); Utils.WriteCookie("SCZMUserId", model.ID.ToString()); Utils.WriteCookie("SCZMDepId", model.DepId.ToString()); Response.Redirect("index.html"); }
/// <summary> /// 得到界面按钮列表 重新获取数据 /// </summary> /// <param name="perId"></param> /// <param name="pageId"></param> /// <returns>string[] 包含两列 第一列为btn,第二列为0,1;0没有权限,1有权限</returns> public static List <string[]> GetPageElementList(int perId, int pageId, out string roleIdStr) { List <string[]> pageElementPowerList = new List <string[]>(); string[] item; roleIdStr = ""; if (pageId == 0) { return(pageElementPowerList); } BLL.System.sys_Menu menuBll = new BLL.System.sys_Menu(); DataTable menuPageElementDT = menuBll.GetListByCache_sys_MenuPageElement().Tables[0]; DataRow[] powerDR = menuPageElementDT.Select("PageId=" + pageId); int powerCount = 0; for (int i = 0; i < powerDR.Length; i++) { string btn = powerDR[i]["ElementName"].ToString(); item = new string[] { btn, "1" }; if (CheckListContain(pageElementPowerList, item) == 0) { powerCount = 0; DataTable personRoleDT = new BLL.System.sys_Person().GetListByCache_sys_PersonRole(perId).Tables[0]; for (int j = 0; j < personRoleDT.Rows.Count; j++) { string tmpRoleIdstr = ",Cache_sys_RolePower_" + personRoleDT.Rows[j]["RoleId"].ToString(); if (!(roleIdStr + ",").Contains(tmpRoleIdstr + ",")) { roleIdStr += tmpRoleIdstr; } if (powerCount == 0) { DataTable rolePowerDT = new BLL.System.sys_Role().GetListByCache_sys_RolePower(Utils.ObjToInt(personRoleDT.Rows[j]["RoleId"], 0)).Tables[0]; powerCount += rolePowerDT.Select("PowerId=" + powerDR[i]["PowerId"].ToString()).Length; } } if (powerCount == 0) { DataTable personPowerDT = new BLL.System.sys_PersonPower().GetListByCache_sys_PersonPower(perId).Tables[0]; powerCount = personPowerDT.Select("PowerId=" + powerDR[i]["PowerId"].ToString()).Length; } item = new string[2] { btn, "0" }; int index = CheckListContain(pageElementPowerList, item); if (index > 0) { if (powerCount > 0) { pageElementPowerList.RemoveAt(index - 1); pageElementPowerList.Add(new string[] { btn, "1" }); } } else { if (powerCount > 0) { pageElementPowerList.Add(new string[] { btn, "1" }); } else { pageElementPowerList.Add(new string[] { btn, "0" }); } } } } return(pageElementPowerList); }
private void GetList(HttpContext context, string btn) { if (btn != "show") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } try { int depId = RequestHelper.GetInt("depId", 1); string filterFlag = RequestHelper.GetString("filterFlag"); StringBuilder strWhere = new StringBuilder(); List <SqlParameter> parameterList = new List <SqlParameter>(); SqlParameter tempParameter = new SqlParameter(); if (filterFlag == "") { strWhere.Append("a.DepId=@DepId and "); tempParameter = new SqlParameter("@DepId", SqlDbType.Int, 4); tempParameter.Value = depId; parameterList.Add(tempParameter); } else { string perName = RequestHelper.GetString("perName"); string account = RequestHelper.GetString("account"); string postId = RequestHelper.GetString("postId"); string roleId = RequestHelper.GetString("roleId"); if (perName != "") { strWhere.Append("a.PerName like '%'+ @PerName +'%' and "); tempParameter = new SqlParameter("@PerName", SqlDbType.NVarChar); tempParameter.Value = perName; parameterList.Add(tempParameter); } if (account != "") { strWhere.Append("a.Account like '%'+ @Account +'%' and "); tempParameter = new SqlParameter("@Account", SqlDbType.NVarChar); tempParameter.Value = account; parameterList.Add(tempParameter); } if (postId != "") { strWhere.Append("a.PostId =@PostId and "); tempParameter = new SqlParameter("@PostId", SqlDbType.Int); tempParameter.Value = Utils.StrToInt(postId, 0).ToString(); parameterList.Add(tempParameter); } if (roleId != "") { strWhere.Append("','+a.RoleId+',' like '%,'+ @RoleId +',%' and "); tempParameter = new SqlParameter("@RoleId", SqlDbType.VarChar); tempParameter.Value = roleId; parameterList.Add(tempParameter); } } BLL.System.sys_Person bll = new BLL.System.sys_Person(); DataTable dt = bll.GetList(Utils.DelLastChar(strWhere.ToString(), " and "), parameterList).Tables[0]; string rowsStr = Utils.ToJson(dt); StringBuilder jsonStr = new StringBuilder(); jsonStr.Append("{\"status\":\"1\",\"msg\":\"数据获取成功!\",\"info\":"); jsonStr.Append("{\"total\":" + dt.Rows.Count + ",\"rows\":"); jsonStr.Append(rowsStr); jsonStr.Append("}}"); context.Response.Write(jsonStr); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void SaveData(HttpContext context, string btn) { if (btn != "btnSave") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } string id = RequestHelper.GetString("id"); string depId = RequestHelper.GetString("depId"); string postId = RequestHelper.GetString("postId"); string perName = RequestHelper.GetString("perName"); string account = RequestHelper.GetString("account"); string perTel = RequestHelper.GetString("perTel"); string perEmail = RequestHelper.GetString("perEmail"); string ddNo = RequestHelper.GetString("ddNo"); string wxNo = RequestHelper.GetString("wxNo"); string roleId = RequestHelper.GetString("roleId"); string roleName = RequestHelper.GetString("roleName"); string ctrlPersonType = RequestHelper.GetString("ctrlPersonType"); string ctrlDepId = RequestHelper.GetString("ctrlDepId"); string ctrlPerId = RequestHelper.GetString("ctrlPerId"); if (depId == "") { context.Response.Write("{\"status\":\"0\",\"msg\":\"部门不能为空!\"}"); return; } if (perName == "") { context.Response.Write("{\"status\":\"0\",\"msg\":\"姓名不能为空!\"}"); return; } Model.System.sys_LoginUser loginUserModel = BaseWeb.GetLoginInfo(); BLL.System.sys_Person bll = new BLL.System.sys_Person(); Model.System.sys_Person model = new Model.System.sys_Person(); model.ID = Utils.StrToInt(id, 0); model.DepId = Utils.StrToInt(depId, 0); model.PostId = Utils.StrToInt(postId, 0); model.PerName = perName; model.Account = account; model.PerTel = perTel; model.PerEmail = perEmail; model.DDNo = ddNo; model.WXNo = wxNo; model.RoleId = roleId; model.RoleName = roleName; model.CtrlPersonType = Utils.StrToInt(ctrlPersonType, 1); model.CtrlDepId = Utils.StrToInt(ctrlDepId, 0); model.CtrlPerId = ctrlPerId; model.OperaName = loginUserModel.PerName; model.OperaTime = DateTime.Now; string operaMessage = ""; string status = "0"; string operaAction = ""; string operaMemo = ""; try { if (id == "") { model.ID = bll.Add(model, out operaMessage); if (model.ID > 0) { status = "1"; operaAction = Enums.ActionEnum.Add.ToString(); operaMemo = "新增人员:" + model.PerName + "(" + model.ID + ")"; //写入操作日志 BaseWeb.AddOpera(loginUserModel, int.Parse(RequestHelper.GetQueryString("MenuId")), operaAction, operaMemo); } } else { if (bll.Update(model, out operaMessage)) { status = "1"; operaAction = Enums.ActionEnum.Edit.ToString(); operaMemo = "修改人员:" + model.PerName + "(" + model.ID + ")"; //写入操作日志 BaseWeb.AddOpera(loginUserModel, int.Parse(RequestHelper.GetQueryString("MenuId")), operaAction, operaMemo); } } context.Response.Write("{\"status\":\"" + status + "\",\"msg\":\"" + operaMessage + "\"}"); return; } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }