protected void DelPagePowerSign_Click(object sender, EventArgs e) { int positionId = ConvertHelper.Cint0(hidId.Text); //获取页面传值 positionId string id = GridViewHelper.GetSelectedKey(Grid2, true); //获取未分配的 勾选的Id string _PagePower = PositionBll.GetInstence().GetFieldValue("PagePower", string.Format("Id = {0}", positionId)).ToString(); //获取已有的菜单权限 string parentId = MenuInfoBll.GetInstence().GetFieldValue("ParentId", string.Format("Id = {0}", id)).ToString(); //获取 父ID string removeChar = "|" + id + "|"; _PagePower = _PagePower.Replace(removeChar, "|"); //if (_PagePower.IndexOf("|" + parentId + "|") < 0) //{ // _PagePower += parentId + "|" + id + "|"; //} //else //{ // _PagePower += id + "|"; //} PositionBll.GetInstence().UpdateValue(this, positionId, "PagePower", _PagePower, "", false, false); MenuInfoBll.GetInstence().BandDropDownListShowMenu1(this, Grid1, _PagePower, ""); //绑定菜单和页面权限 MenuInfoBll.GetInstence().BandDropDownListShowMenu2(this, Grid2, _PagePower, ""); //绑定菜单和页面权限 MenuInfoBll.GetInstence().BandDropDownListShowMenu3(this, Grid3, _PagePower, ""); //绑定菜单和页面权限 }
public override void Init() { //逻辑对象赋值 bll = PositionBll.GetInstence(); //表格对象赋值 grid = Grid1; }
/// <summary> /// 关闭子窗口事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void SelectWindows_Close(object sender, WindowCloseEventArgs e) { //读取新选择的职位名称 txtPosition.Text = PositionBll.GetInstence().GetName(hidPositionId.Text); //绑定选择职位按键 ButtonSelectPosition.OnClientClick = SelectWindows.GetSaveStateReference(hidPositionId.ClientID) + SelectWindows.GetShowReference("../Systems/Powers/PositionSelect.aspx?Id=" + hidPositionId.Text + "&" + MenuInfoBll.GetInstence().PageUrlEncryptStringNoKey(hidPositionId.Text)); }
/// <summary>读取数据</summary> public override void LoadData() { int positionId = ConvertHelper.Cint0(hidPositionId.Text); if (positionId != 0) { //获取指定ID的职位内容 var model = PositionBll.GetInstence().GetModelForCache(x => x.Id == positionId); if (model == null) { return; } //对页面窗体进行赋值 txtName.Text = model.Name; //设置下拉列表选择项 labBranchName.Text = model.Branch_Name; //设置页面权限 _pagePower = model.PagePower; //设置页面控件权限 _controlPower = model.ControlPower; } else { //设置部门 var branchModel = BranchBll.GetInstence().GetModelForCache(ConvertHelper.Cint0(hidBranchId.Text)); labBranchName.Text = branchModel.Name; } //创建树节点 var tnode = new FineUI.TreeNode(); //设置节点名称 tnode.Text = "菜单"; //设置节点ID tnode.NodeID = "0"; //设置当前节点是否为最终节点 tnode.Leaf = false; //是否可以选择(打勾) tnode.EnableCheckBox = true; //是否已经选择 tnode.Checked = true; //是否自动扩大 tnode.Expanded = true; //开启点击节点全选或取消事件 tnode.EnableCheckEvent = true; //根据指定的父ID去查询相关的子集ID var dt = MenuInfoBll.GetInstence().GetDataTable(); //获取全部页面权限 var pgdt = PagePowerSignBll.GetInstence().GetDataTable(); //从一级菜单开始添加 AddNode(dt, pgdt, tnode, "0"); MenuTree.Nodes.Add(tnode); }
/// <summary>读取数据</summary> public override void LoadData() { //关闭窗口 ButtonCancel.OnClientClick = ActiveWindow.GetHideReference(); int id = ConvertHelper.Cint0(hidId.Text); if (id != 0) { Solution.DataAccess.Model.Position model = new DataAccess.Model.Position(); //获取指定ID的菜单内容,如果不存在,则创建一个菜单实体 model = PositionBll.GetInstence().GetModelForCache(x => x.Id == id); if (model == null) { return; } txtPosition.Text = model.Name; // ddlParentId.SelectedValue = model.Branch_Id.ToString() + ""; string pagepower = ""; if (model.PagePower != null) { pagepower = model.PagePower.ToString().Substring(1); // pagepower = pagepower.Substring(0, pagepower.Length - 1); } string str_pagepower = pagepower.Replace("|", "','"); str_pagepower = "('" + str_pagepower + "')"; // bll1.BindGrid(Grid1, 0, 0, sqlwhereList, sortList1); // MenuInfoBll bk = new MenuInfoBll(); MenuInfoBll.GetInstence().BandDropDownListShowMenu1(this, Grid1, model.PagePower, model.ControlPower); //绑定菜单和页面权限 MenuInfoBll.GetInstence().BandDropDownListShowMenu2(this, Grid2, model.PagePower, model.ControlPower); //绑定菜单和页面权限 MenuInfoBll.GetInstence().BandDropDownListShowMenu3(this, Grid3, model.PagePower, model.ControlPower); //绑定菜单和页面权限 } else { // MenuInfoBll.GetInstence().BandDropDownListShowMenu(this, Grid1, Grid2,Grid3,"",""); //绑定菜单和页面权限 } // bll.BindGrid(Grid4, InquiryCondition(), sortList); // PositionBll.GetInstence().BandPagePowerSignPublicList(this, Grid4,sortList); }
/// <summary>下拉列表改变事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Positionddl_SelectedIndexChanged(object sender, EventArgs e) { if (!Positionddl.SelectedValue.Equals("1")) { try { Brachddl.Text = PositionBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(Positionddl.SelectedValue), PositionTable.Branch_Id) + ""; } catch { } } }
/// <summary> /// 列表按键绑定——修改列表控件属性 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid4_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { int rowc = Grid4.Rows.Count; int id = ConvertHelper.Cint0(hidId.Text);//获取页面传值 Solution.DataAccess.Model.Position model = new DataAccess.Model.Position(); //获取指定ID的菜单内容,如果不存在,则创建一个菜单实体 model = PositionBll.GetInstence().GetModelForCache(x => x.Id == id); GridRow gr1 = Grid3.Rows[Grid3.SelectedRowIndex]; menuInfoId_ = int.Parse(gr1.Values[0].ToString()); if (model == null) { return; } //绑定是否显示状态列 if (menuInfoId_ != 0) { int o = e.RowIndex; DataRowView row = e.DataItem as DataRowView; string _ControlPower = model.ControlPower;// PositionBll.GetInstence().GetFieldValue(id, "ControlPower", true).ToString(); // GridRow gr = Grid4.Rows[o]; string str = ((System.Data.DataRowView)(row)).Row.Table.Rows[e.RowIndex][0].ToString(); string s = "," + menuInfoId_.ToString() + "|" + str + ","; if (_ControlPower.IndexOf("," + menuInfoId_.ToString() + "|" + str + ",") >= 0) { var lbf = Grid4.FindColumn("IsOrNotLink") as LinkButtonField; lbf.Icon = Icon.BulletTick; lbf.CommandArgument = "0"; } else { var lbf = Grid4.FindColumn("IsOrNotLink") as LinkButtonField; lbf.Icon = Icon.BulletCross; lbf.CommandArgument = "1"; } } }
/// <summary> /// 删除记录 /// </summary> /// <returns></returns> public override string Delete() { //获取要删除的ID int id = ConvertHelper.Cint0(GridViewHelper.GetSelectedKey(Grid1, true)); //如果没有选择记录,则直接退出 if (id == 0) { return("请选择要删除的记录。"); } try { //删除前判断一下 if (BranchBll.GetInstence().Exist(x => x.ParentId == id)) { return("删除失败,本部门下面存在子部门,不能直接删除!"); } //删除前判断一下 if (PositionBll.GetInstence().Exist(x => x.Branch_Id == id)) { return("删除失败,相关职位已绑定本部门,不能直接删除!"); } if (ManagerBll.GetInstence().Exist(x => x.Branch_Id == id)) { return("删除失败,已有员工绑定本部门,不能直接删除!"); } //删除记录 bll.Delete(this, id); return("删除编号ID为[" + id + "]的数据记录成功。"); } catch (Exception e) { string result = "尝试删除编号ID为[" + id + "]的数据记录失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); return(result); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //获取ID值 hidId.Text = RequestHelper.GetInt0("Id") + ""; SHOP00Bll.GetInstence().BandDropDownListShowShop1(this, SHOPdll); //绑定下拉列表 部门 BranchBll.GetInstence().BandDropDownList(this, Brachddl); //绑定下拉列表 职位 PositionBll.GetInstence().BandDropDownList(this, Positionddl); //加载数据 LoadData(); } }
private void BindGrid() { var index = ConvertHelper.Cint0(hidId.Text); if (index == 0) { return; } //设置查询条件 var list = new List <ConditionHelper.SqlqueryCondition>(); list.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, PositionTable.Branch_Id, Comparison.Equals, index)); //设置排序 var order = new List <string>(); order.Add(PagePowerSignTable.Id); //绑定Grid表格 PositionBll.GetInstence().BindGrid(Grid1, Grid1.PageIndex + 1, Grid1.PageSize, list, order); }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtLoginName.Text.Trim())) { return(txtLoginName.Label + "不能为空!"); } if (SHOPdll.SelectedText.Trim() == "请选择分店") { return(SHOPdll.Label + "不能为空!"); } var sName = StringHelper.Left(txtLoginName.Text, 50); if (ManagerBll.GetInstence().Exist(x => x.LoginName == sName && x.Id != id)) { return(txtLoginName.Label + "已存在!请重新输入!"); } if (string.IsNullOrEmpty(txtPwd.Text.Trim())) { return(txtPwd.Label + "不能为空!"); } #endregion #region 赋值 //读取指定部门资料 var model = new Manager(x => x.Id == id); model.LoginName = txtLoginName.Text; model.LoginPass = model.LoginPass == txtPwd.Text.Trim()?model.LoginPass: Encrypt.Md5(Encrypt.Md5(txtPwd.Text));//:model.LoginPass; model.LoginPass == null? model.LoginTime = DateTime.Now; model.LoginIp = "1::"; model.LoginCount = 1; model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; int branch_id = ConvertHelper.Cint0(Brachddl.SelectedValue); var model_b = BranchBll.GetInstence().GetModelForCache(x => x.Id == branch_id); model.Branch_Id = model_b.Id; model.Branch_Code = model_b.Code; model.Branch_Name = model_b.Name; model.IsMultiUser = ConvertHelper.StringToByte(rblIsMultiUser.SelectedValue.ToString()); model.IsWork = ConvertHelper.StringToByte(rblIsWork.SelectedValue); model.IsEnable = ConvertHelper.StringToByte(rblIsEnable.SelectedValue); var model_p = PositionBll.GetInstence().GetModelForCache(x => x.Id == ConvertHelper.Cint0(Positionddl.SelectedValue)); model.Position_Id = model_p.Id.ToString(); model.Position_Name = model_p.Name; model.CName = txtCName.Text; model.EName = txtEName.Text; model.Sex = rblSex.SelectedValue.ToString(); model.PhotoImg = ""; model.Birthday = Birthday.SelectedDate.ToString(); model.NativePlace = txtNativePlace.Text; model.NationalName = txtNationalName.Text; model.Record = txtRecord.Text; model.GraduateCollege = txtGraduateCollege.Text; model.GraduateSpecialty = txtGraduateSpecialty.Text; model.Tel = txtTel.Text; model.Tel = txtMobile.Text; model.Email = txtEmail.Text; model.Qq = txtQq.Text; model.Msn = ""; model.Address = txtAddress.Text; model.Content = txtContent.Text; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); model.SHOP_ID = SHOPdll.SelectedValue; model.SHOP_NAME1 = SHOPdll.SelectedText; #endregion //---------------------------------------------------------- //存储到数据库 ManagerBll.GetInstence().Save(this, model); } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return(result); }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(txtName.Text.Trim())) { return(txtName.Label + "不能为空!"); } var sName = StringHelper.Left(txtName.Text, 50); if (BranchBll.GetInstence().Exist(x => x.Name == sName && x.Id != id)) { return(txtName.Label + "已存在!请重新输入!"); } #endregion #region 赋值 //定义是否更新其他关联表变量 bool isUpdate = false; //获取实体 var model = new Branch(x => x.Id == id); //判断是否有改变名称 if (id > 0 && sName != model.Name) { isUpdate = true; } //修改时间与管理员 model.UpdateDate = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); //设置名称 model.Name = sName; //对应的父类id model.ParentId = ConvertHelper.Cint0(txtParent.Text); //设置备注 model.Notes = StringHelper.Left(txtNotes.Text, 100); //由于限制了编辑时不能修改父节点,所以这里只对新建记录时处理 if (id == 0) { //设定当前的深度与设定当前的层数级 if (model.ParentId == 0) { //设定当前的层数 model.Depth = 0; } else { //设定当前的层数级 model.Depth = ConvertHelper.Cint0(BranchBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(ddlParentId.SelectedValue), BranchTable.Depth)) + 1; } } //设置排序 if (txtSort.Text == "0") { model.Sort = BranchBll.GetInstence().GetSortMax(model.ParentId) + 1; } else { model.Sort = ConvertHelper.Cint0(txtSort.Text); } //新创建部门时,生成对应的部门编码 if (id == 0) { model.Code = SPs.P_Branch_GetMaxBranchCode(model.Depth + 1, model.ParentId).ExecuteScalar().ToString(); } #endregion //---------------------------------------------------------- //存储到数据库 BranchBll.GetInstence().Save(this, model); //如果本次修改改变了相关名称,则同步更新其他关联表的对应名称 if (isUpdate) { PositionBll.GetInstence().UpdateValue_For_Branch_Id(this, model.Id, PositionTable.Branch_Name, model.Name); ManagerBll.GetInstence().UpdateValue_For_Branch_Id(this, model.Id, ManagerTable.Branch_Name, model.Name); } } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return(result); }
//#region 页面控件绑定 ///// <summary>下拉列表改变事件 ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //protected void ddlParentId_SelectedIndexChanged(object sender, EventArgs e) //{ // //初始化路径值 // //获取当前节点的父节点Id // // txtParent.Text = ddlParentId.SelectedValue; // if (!ddlParentId.SelectedValue.Equals("0")) // { // try // { // //获取当前节点的父节点url // txtUrl.Text = MenuInfoBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(ddlParentId.SelectedValue), MenuInfoTable.Url) + ""; // } // catch // { // } // } //} //#endregion #region 保存 /// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); // int Branch_Id = int.Parse(ddlParentId.SelectedValue); try { #region 数据验证 if (string.IsNullOrEmpty(txtPosition.Text.Trim())) { return(txtPosition.Label + "不能为空!"); } if (txtPosition.Text.Trim() == "请选择菜单") { return(txtPosition.Label + "不能为请选择菜单!"); } #endregion #region 赋值 //读取指定部门资料 var model = new Solution.DataAccess.DataModel.Position(x => x.Id == id); //设置名称 model.Name = txtPosition.Text; //连接地址 model.Branch_Id = 100; // int.Parse(ddlParentId.SelectedValue); model.Branch_Code = "0100"; // +ddlParentId.SelectedValue; model.Branch_Name = ""; //ddlParentId.SelectedText; ////设定当前的深度与设定当前的层数级 //if (model.ParentId == 0) //{ // //设定当前的层数级 // model.Depth = 0; //} //else //{ // try // { // //设定当前的层数级 // model.Depth = ConvertHelper.Cint0(MenuInfoBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(ddlParentId.SelectedValue), MenuInfoTable.Depth)) + 1; // } // catch // { // model.Depth = 0; // } //} ////设置排序 //if (txtSort.Text == "0") //{ // //model.Sort = ConvertHelper.Cint0(SPs.P_All_GetOrderId(MenuInfoTable.TableName, MenuInfoTable.ParentId, model.ParentId.ToString(), MenuInfoTable.Sort).ExecuteScalar()) + 1; //} //else //{ // model.Sort = ConvertHelper.Cint0(txtSort.Text); //} ////设定当前项属于菜单还是页面 //model.IsMenu = ConvertHelper.StringToByte(rblIsMenu.SelectedValue); ////设定当前项是否显示 //model.IsDisplay = ConvertHelper.StringToByte(rblIsDisplay.SelectedValue); #endregion //---------------------------------------------------------- //存储到数据库 PositionBll.GetInstence().Save(this, model); } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return(result); }
/// <summary> /// Grid点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid4_RowCommand(object sender, FineUI.GridCommandEventArgs e) { GridRow gr = Grid4.Rows[e.RowIndex]; //获取当前点击列的主键ID int id_public = int.Parse(gr.DataKeys[0].ToString()); switch (e.CommandName) { case "IsOrNotLink": string id_menu = GridViewHelper.GetSelectedKey(Grid3, true); //获取未分配的 勾选的Id if (Grid3.SelectedRowIndexArray.Length > 1 || Grid3.SelectedRowIndexArray.Length == 0) { Alert.Show("请选择一行!", MessageBoxIcon.Warning); break; } //更新状态 // MenuInfoBll.GetInstence().UpdateIsDisplay(this, ConvertHelper.Cint0(id), ConvertHelper.Cint0(e.CommandArgument)); if (e.CommandArgument == "0") { //删除PagePowerSign if (Grid3.SelectedRowIndexArray.Length == 0) { Alert.Show("请搜选菜单项!", MessageBoxIcon.Information); } GridRow gr1 = Grid3.Rows[Grid3.SelectedRowIndex]; menuInfoId_ = int.Parse(gr1.Values[0].ToString()); var model1 = new Solution.DataAccess.DataModel.PagePowerSignPublic(x => x.Id == id_public); var model_p = PagePowerSign.SingleOrDefault(x => x.PagePowerSignPublic_Id == model1.Id && x.MenuInfo_Id == menuInfoId); // PagePowerSignBll.GetInstence().GetModel(model1.Id, menuInfoId_, true); //获取PagePowerSign表 PagePowerSignBll.GetInstence().Delete(this, model_p.Id); int id = ConvertHelper.Cint0(hidId.Text); //获取页面传值 var model = new DataAccess.Model.Position(); //获取指定ID的菜单内容,如果不存在,则创建一个菜单实体 model = PositionBll.GetInstence().GetModelForCache(x => x.Id == id); string new_control = model.ControlPower.Replace(id_menu + "|" + id_public + ",", ""); // model.ControlPower = new_control; PositionBll.GetInstence().UpdateValue(this, id, "ControlPower", new_control, "", true, false); //.UpdateControlPower(this, id, new_control, false, false); // PositionBll.GetInstence().SetModelForCache(model); } else //添加PagePowerSign //Solution.DataAccess.Model.PagePowerSign model = new DataAccess.Model.PagePowerSign(); //model.PagePowerSignPublic_Id = (int)id; //model.CName = { var model1 = new Solution.DataAccess.DataModel.PagePowerSignPublic(x => x.Id == id_public); Solution.DataAccess.DataModel.PagePowerSign pps = new DataAccess.DataModel.PagePowerSign(); pps.PagePowerSignPublic_Id = model1.Id; pps.CName = model1.Cname; pps.EName = model1.Ename; pps.MenuInfo_Id = int.Parse(id_menu); PagePowerSignBll.GetInstence().Save(this, pps); int id = ConvertHelper.Cint0(hidId.Text); //获取页面传值 var model = new DataAccess.Model.Position(); //获取指定ID的菜单内容,如果不存在,则创建一个菜单实体 model = PositionBll.GetInstence().GetModelForCache(x => x.Id == id); string new_control = model.ControlPower + id_menu + "|" + id_public + ","; //model.ControlPower = new_control; PositionBll.GetInstence().UpdateValue(this, id, "ControlPower", new_control, "", true, false); //PositionBll.GetInstence().UpdateControlPower(this, id, new_control, false, false); //PositionBll.GetInstence().SetModelForCache(model); } //重新加载 conditionList = new List <ConditionFun.SqlqueryCondition>(); conditionList.Add(new ConditionFun.SqlqueryCondition(ConstraintType.Where, "1", Comparison.Equals, "1", false, false)); //bll.BindGrid(Grid1, 0, sortList); bll.BindGrid(Grid4, 0, 0, conditionList, sortList); break; } }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; var branchId = ConvertHelper.Cint0(hidBranchId.Text); var positionId = ConvertHelper.Cint0(hidPositionId.Text); try { #region 数据验证 if (branchId == 0) { return("非法路径进入!"); } if (string.IsNullOrEmpty(txtName.Text.Trim())) { return(txtName.Label + "不能为空!"); } //同一个部门里职位不能样同,不同部门可以有同名称的职位 var sName = StringHelper.Left(txtName.Text, 30); if (PositionBll.GetInstence().Exist(x => x.Branch_Id == branchId && x.Name == sName && x.Id != positionId)) { return(txtName.Label + "已存在!请重新输入!"); } #endregion #region 赋值 //定义是否更新其他关联表变量 bool isUpdate = false; //获取实体 var model = new Position(x => x.Id == positionId); //判断是否有改变名称 if (positionId > 0 && sName != model.Name) { isUpdate = true; } //修改时间与管理员 model.UpdateDate = DateTime.Now; model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId(); model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName(); //设置名称 model.Name = sName; //设置部门 var branchModel = BranchBll.GetInstence().GetModelForCache(branchId); model.Branch_Id = branchId; model.Branch_Name = branchModel.Name; model.Branch_Code = branchModel.Code; //设置职位权限 //从树列表中获取勾选的节点 GetCheckTreeNode(MenuTree.Nodes); //赋予权限 model.PagePower = StringHelper.FilterSql(_hidPositionPagePower); model.ControlPower = StringHelper.FilterSql(_hidPositionControlPower); #endregion //---------------------------------------------------------- //存储到数据库 PositionBll.GetInstence().Save(this, model); //如果本次修改改变了相关名称,则同步更新其他关联表的对应名称 if (isUpdate) { ManagerBll.GetInstence().UpdatePositionName(model.Id, model.Name); } } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return(result); }
/// <summary>登录</summary> /// <param name="sender"></param> /// <param name="e"></param> protected void BtnLogin_Click(object sender, EventArgs e) { var ip = IpHelper.GetUserIp(); #region 获取用户输入的参数,并进行数据初步处理 //获取用户名,并进行危险字符过滤 var username = StringHelper.Left(txtusername.Text, 50); //获取用户密码 var userpass = txtpass.Text; //获取验证码 // var strCode = StringHelper.Left(txtcode.Text, 5); #endregion #region 初步验证 //开发测试使用,不用每次都输入帐号与密码 //username = "******"; //userpass = "******"; //strCode = "12345"; //用户名验证 if (string.IsNullOrEmpty(username.Trim())) { txtusername.Focus(); FineUI.Alert.ShowInTop("用户名不能为空,请仔细检查您输入的用户名!", FineUI.MessageBoxIcon.Error); return; } //密码验证 if (string.IsNullOrEmpty(userpass.Trim())) { txtpass.Focus(); FineUI.Alert.ShowInTop("密码不能为空,请仔细检查您输入的密码!", FineUI.MessageBoxIcon.Error); return; } //验证码验证 //if (string.IsNullOrEmpty(strCode)) //{ // txtcode.Focus(); // FineUI.Alert.ShowInParent("验证码不能为空!", FineUI.MessageBoxIcon.Error); // return; //} //判断验证码是否正确 //if (Session["vcode"] == null || !Session["vcode"].ToString().Equals(strCode, StringComparison.InvariantCultureIgnoreCase)) //{ // SessionHelper.RemoveSession("vcode"); // txtpass.Focus(); // //JsHelper.Alert("验证码错误!"); // FineUI.Alert.ShowInParent("验证码错误!", FineUI.MessageBoxIcon.Error); // return; //} //else //{ // //验证码正确,删除验证码Session // SessionHelper.RemoveSession("vcode"); //} #endregion #region 数据库验证 //通过用户给的用户名获取相关实体类 var userinfo = Manager.SingleOrDefault(x => x.LoginName == username); //判断用户是否存在 if (userinfo == null) { LoginLogBll.GetInstence().Save(0, "账号【" + username + "】不存在,登录失败!"); txtusername.Focus(); FineUI.Alert.ShowInParent("用户名不存在,请仔细检查您输入的用户名!", FineUI.MessageBoxIcon.Error); return; } //密码不匹配 if (!userinfo.LoginPass.Equals(Encrypt.Md5(Encrypt.Md5(userpass)))) { LoginLogBll.GetInstence().Save(userinfo.Id, "账号【" + userinfo.LoginName + "】的用户【" + userinfo.CName + "】登录失败!登录密码错误。"); txtpass.Focus(); FineUI.Alert.ShowInParent("您输入的用户密码错误!", FineUI.MessageBoxIcon.Error); return; } if (userinfo.IsWork == 0) { //添加用户登陆日志 LoginLogBll.GetInstence().Save(userinfo.Id, "离职用户登录失败!用户【" + userinfo.CName + "】试图登录系统"); FineUI.Alert.ShowInParent("您已经没有权限登录本系统!", FineUI.MessageBoxIcon.Error); return; } //判断当前账号是否被启用 if (userinfo.IsEnable == 0) { //添加登录日志记录 LoginLogBll.GetInstence().Save(userinfo.Id, "账号【" + userinfo.LoginName + "】的用户【" + userinfo.CName + "】登录失败!用户账号被禁用。"); FineUI.Alert.ShowInParent("当前账号未被启用,请联系管理人员激活!", FineUI.MessageBoxIcon.Error); return; } #endregion #region 存储在线用户资料 #region 获取用户操作权限 if (string.IsNullOrEmpty(userinfo.Position_Id)) { Session["PagePower"] = ""; Session["ControlPower"] = ""; LoginLogBll.GetInstence().Save(0, "账号【" + username + "】未绑定职位,请管理员进行配置!"); FineUI.Alert.ShowInParent("您的账号未绑定职位,请与管理员联系!", FineUI.MessageBoxIcon.Error); return; } else { //获取用户权限并存储到用户Session里 PositionBll.GetInstence().SetUserPower(userinfo.Position_Id); } #endregion #region 当前用户在线信息 //当前时间 var localTime = DateTime.Now.ToLocalTime(); //创建客户端信息获取实体 var clientHelper = new ClientHelper(Request); //创建在线用户实体 var onlineUser = new Solution.DataAccess.Model.OnlineUsers(); //当前用户的Id编号 onlineUser.Manager_Id = userinfo.Id; onlineUser.Manager_LoginName = userinfo.LoginName; onlineUser.Manager_LoginPass = userinfo.LoginPass; onlineUser.Manager_CName = userinfo.CName; onlineUser.LoginTime = localTime; onlineUser.LoginIp = ip; //生成密钥 onlineUser.UserKey = RandomHelper.GetRndNum(32, true); //Md5(密钥+登陆帐号+密码+IP+密钥.Substring(6,8)) onlineUser.Md5 = OnlineUsersBll.GetInstence().GenerateMd5(onlineUser); onlineUser.UpdateTime = localTime; onlineUser.Sex = userinfo.Sex; onlineUser.Branch_Id = userinfo.Branch_Id; onlineUser.Branch_Code = userinfo.Branch_Code; onlineUser.Branch_Name = userinfo.Branch_Name; onlineUser.Position_Id = userinfo.Position_Id; onlineUser.Position_Name = userinfo.Position_Name; onlineUser.CurrentPage = ""; onlineUser.CurrentPageTitle = ""; //SessionId onlineUser.SessionId = Session.SessionID; onlineUser.UserAgent = StringHelper.FilterSql(HttpContext.Current.Request.Headers["User-Agent"] + ""); onlineUser.OperatingSystem = clientHelper.GetSystem(); onlineUser.TerminalType = clientHelper.IsMobileDevice(onlineUser.UserAgent) ? 1 : 0; onlineUser.BrowserName = clientHelper.GetBrowserName(); onlineUser.BrowserVersion = clientHelper.GetBrowserVersion(); onlineUser.SHOP_ID = userinfo.SHOP_ID; onlineUser.SHOP_NAME1 = userinfo.SHOP_NAME1; #endregion #region 记录当前用户UserId //定义HashTable表里Key的名称UserId string userHashKey = ""; //判断当前用户帐户是否支持同一帐号在不同地方登陆功能,取得用户在HashTable表里Key的名称 //不支持则 if (userinfo.IsMultiUser == 0) { userHashKey = userinfo.Id + ""; } //支持则 else { userHashKey = userinfo.Id + "_" + onlineUser.SessionId; } //记录用户的HashTable Key onlineUser.UserHashKey = userHashKey; Session[OnlineUsersTable.UserHashKey] = userHashKey; #endregion #region 将在线用户信息存入全局变量中 //运行在线数据加载函数,如果缓存不存在,则尝试加载数据库中的在线表记录到缓存中 //——主要用于IIS缓存被应用程序池或其他原因回收后,对在线数据进行重新加载,而不会使所有用户都被迫退出系统 OnlineUsersBll.GetInstence().Load(); //判断缓存中["OnlineUsers"]是否存在,不存在则直接将在线实体添加到缓存中 if (CacheHelper.GetCache("OnlineUsers") == null) { //将当前用户信息添加到Hashtable中 var hashtable = new Hashtable(); hashtable.Add(userHashKey, onlineUser); //将在线列表(Hashtable)添中进系统缓存中 CacheHelper.SetCache("OnlineUsers", hashtable); } //存在则将它取出HashTable并进行处理 else { //直接从缓存中读取在线列表数据 var hashtable = (Hashtable)CacheHelper.GetCache("OnlineUsers"); //判断当前用户是否存在在线表中,不存在则直接将当前用户的实体对象存储进HashTable if (hashtable[userHashKey] == null || hashtable.Count == 0) { hashtable.Add(userHashKey, onlineUser); } //存在则 else { //添加用户下线记录 LoginLogBll.GetInstence().Save(userHashKey, "用户【{0}】的账号已经在另一处登录,本次登陆下线!在线时间【{1}】"); //将HashTable里存储的前一登陆帐户移除 OnlineUsersBll.GetInstence().Delete(this, x => x.UserHashKey == userHashKey, false); //移除缓存中的记录 hashtable.Remove(userHashKey); //将当前用户的实体对象存进在线缓存中 hashtable.Add(userHashKey, onlineUser); } } //将在线实体保存到数据库的在线表中 OnlineUsersBll.GetInstence().Save(this, OnlineUsersBll.GetInstence().Transform(onlineUser), null, true, false); //更新在线列表数据,将不在线人员删除 OnlineUsersBll.GetInstence().UpdateUserOnlineCount(); #endregion #endregion #region 更新用户登陆信息 userinfo.LoginIp = ip; userinfo.LoginCount = userinfo.LoginCount++; userinfo.LoginTime = localTime; ManagerBll.GetInstence().Save(this, userinfo, string.Format("用户【{0}】登陆成功,更新登陆信息", userinfo.CName)); #endregion #region 添加用户登录成功日志 LoginLogBll.GetInstence().Save(userHashKey, string.Format("账号【{0}】的用户【{1}】登录成功", userinfo.LoginName, userinfo.CName)); #endregion #region 写Cookies //写入用户的HashTable Key CookieHelper.SetCookie(OnlineUsersTable.UserHashKey, userHashKey); //写入加密值 CookieHelper.SetCookie(OnlineUsersTable.Md5, onlineUser.Md5); #endregion //跳转进入主页面 Response.Redirect("Main.aspx"); }
/// <summary>读取数据</summary> public void LoadData() { //设置排序 var _order = new List <string>(); _order.Add(PositionTable.Id); //设置查询条件 var wheres = new List <ConditionHelper.SqlqueryCondition>(); //判断是否选择了部门,是的话只显示指定部门的职位 if (ddlBranch.SelectedValue != "0") { var branchCode = StringHelper.FilterSql(ddlBranch.SelectedValue, true, true); wheres.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, PositionTable.Branch_Code, Comparison.StartsWith, branchCode)); } //读取职位Id var positionId = StringHelper.FilterSql(hidPositionId.Text, true, true); //如果不存在已选择的职位,则直接运行绑定表格 if (string.IsNullOrEmpty(positionId)) { Grid2.DataSource = null; Grid2.DataBind(); PositionBll.GetInstence().BindGrid(Grid1, 0, 0, wheres, _order); } else { //去掉两边的逗号 positionId = StringHelper.DelStrSign(positionId); //转换成数组 var positionArr = StringHelper.GetArrayStr(positionId); //设置查询条件 var grid1Where = new List <ConditionHelper.SqlqueryCondition>(); //添加条件 grid1Where.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, PositionTable.Id, Comparison.In, positionArr)); //获取DataTable var dt = PositionBll.GetInstence().GetDataTable(false, 0, null, 0, 0, grid1Where, _order); if (dt == null || dt.Rows.Count == 0) { Grid2.DataSource = null; Grid2.DataBind(); PositionBll.GetInstence().BindGrid(Grid1, 0, 0, wheres, _order); } else { //绑定到表格——已绑定控件列表 Grid2.DataSource = dt; Grid2.DataBind(); wheres.Add(new ConditionHelper.SqlqueryCondition(ConstraintType.And, PositionTable.Id, Comparison.NotIn, positionArr)); PositionBll.GetInstence().BindGrid(Grid1, 0, 0, wheres, _order); } } }