//保存修改 protected void btnSave_Click(object sender, EventArgs e) { #region 逻辑检查 BLL.tb_SYS_Role bllRole = new BLL.tb_SYS_Role(); DataSet dsRole = bllRole.GetList("RoleName='" + txbRoleName.Text.ToString() + "'"); if (dsRole.Tables[0].Rows.Count > 0) { Alert.ShowInTop("该角色名称已存在", "提示信息", MessageBoxIcon.Error); return; } #endregion #region 保存数据 Model.tb_SYS_Role modelRole = new Model.tb_SYS_Role(); modelRole.ID = Guid.NewGuid().ToString(); modelRole.RoleNO = roleid.Text.ToString(); modelRole.RoleName = txbRoleName.Text.ToString(); modelRole.DefaultUrl = txbDefaultUrl.Text.ToString(); modelRole.ParentID = hdfParentID.Text.ToString(); modelRole.State = ddlState.SelectedValue.ToString(); modelRole.CreateID = Session["AccountID"].ToString(); modelRole.CreateTime = DateTime.Now; bool result = bllRole.Add(modelRole); if (!result) { Alert.ShowInTop("添加失败", "提示信息", MessageBoxIcon.Error, ActiveWindow.GetHideRefreshReference()); } else { Alert.ShowInTop("添加成功", "提示信息", MessageBoxIcon.Information, ActiveWindow.GetHideRefreshReference()); } #endregion }
//绑定角色名称 protected string getRoleName(string roleID) { BLL.tb_SYS_Role bllRole = new BLL.tb_SYS_Role(); DataSet dsRole = bllRole.GetList("ID='" + roleID + "'"); string roleName = dsRole.Tables[0].Rows[0]["RoleName"].ToString(); return(roleName); }
//加载数据 private void LoadData() { //绑定修改前数据 BLL.tb_SYS_Role bllRole = new BLL.tb_SYS_Role(); DataSet dsRole = bllRole.GetList("ID='" + Request.QueryString["ID"] + "'"); roleid.Text = dsRole.Tables[0].Rows[0]["RoleNO"].ToString(); txbRoleName.Text = dsRole.Tables[0].Rows[0]["RoleName"].ToString(); txbDefaultUrl.Text = dsRole.Tables[0].Rows[0]["DefaultUrl"].ToString(); tgbParentName.Text = Request.QueryString["ParentName"].ToString(); ddlState.SelectedValue = dsRole.Tables[0].Rows[0]["State"].ToString(); hdfParentID.Text = dsRole.Tables[0].Rows[0]["ParentID"].ToString(); }
//Grid绑定数据源 private void BindGrid() { string strWhere = string.Format("1=1"); string order = string.Format("{0} {1}", gridRole.SortField, gridRole.SortDirection); int pageSize = gridRole.PageSize; int pageIndex = gridRole.PageIndex; long recordCount; BLL.tb_SYS_Role bllRole = new BLL.tb_SYS_Role(); DataSet dsRole = bllRole.GetListByPage(strWhere, order, pageSize, pageIndex, out recordCount); DataTable dtSource = dsRole.Tables[0]; gridRole.DataSource = dtSource; gridRole.RecordCount = (int)recordCount; gridRole.DataBind(); }
//保存修改 protected void btnSave_Click(object sender, EventArgs e) { #region 逻辑检查 StringBuilder strWhere = new StringBuilder("RoleName='"); strWhere.Append(txbRoleName.Text.ToString()); strWhere.Append("' and ID!='"); strWhere.Append(Request.QueryString["ID"]); strWhere.Append("'"); BLL.tb_SYS_Role bllRole = new BLL.tb_SYS_Role(); DataSet dsRole = bllRole.GetList(strWhere.ToString()); if (dsRole.Tables[0].Rows.Count > 0) { Alert.ShowInTop("该菜单名称已存在", "提示信息", MessageBoxIcon.Error); return; } #endregion #region 保存数据 Model.tb_SYS_Role modelRole = new Model.tb_SYS_Role(); modelRole.ID = Request.QueryString["ID"]; modelRole.RoleNO = roleid.Text.ToString(); modelRole.RoleName = txbRoleName.Text.ToString(); modelRole.DefaultUrl = txbDefaultUrl.Text.ToString(); modelRole.ParentID = hdfParentID.Text.ToString(); modelRole.State = ddlState.SelectedValue.ToString(); modelRole.UpdateID = Session["AccountID"].ToString(); modelRole.UpdateTime = DateTime.Now; bool result = bllRole.Update(modelRole); if (!result) { Alert.ShowInTop("更新失败", "提示信息", MessageBoxIcon.Error, ActiveWindow.GetHideRefreshReference()); } else { Alert.ShowInTop("更新成功", "提示信息", MessageBoxIcon.Information, ActiveWindow.GetHideRefreshReference()); } #endregion }
//删除选中记录集 protected void btnDelete_Click(object sender, EventArgs e) { string id = gridRole.DataKeys[gridRole.SelectedRowIndex][0].ToString(); BLL.tb_SYS_Role bllRole = new BLL.tb_SYS_Role(); string result = bllRole.Delete(id); if (result == "0") { Alert.ShowInTop("删除成功", "提示信息", MessageBoxIcon.Information); BindGrid(); } else { hdfMarkRawNO.Text = gridRole.SelectedRowIndex.ToString(); Alert.ShowInTop("该项被其他项引用,不能删除!", "提示信息", MessageBoxIcon.Error, "highlightRows();"); } BLL.tb_SYS_RoleXML bllRoleXML = new BLL.tb_SYS_RoleXML(); bllRoleXML.Delete(id); BLL.tb_SYS_RoleMenu bllRoleMenu = new BLL.tb_SYS_RoleMenu(); bllRoleMenu.Delete("RoleID='" + id + "'"); }