/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { lbErr.Visible = false; if (string.IsNullOrEmpty(tbRoleName.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "err", "角色名不能为空!"); tbRoleName.Focus(); } else if (string.IsNullOrEmpty(tbRoleDetails.Text.Trim())) { Common.JShelper.JSAlert(this.Page,"err","角色描述不能为空!"); } else { LabMS.BLL.RoleTable BRT = new LabMS.BLL.RoleTable(); LabMS.Model.RoleTable Mrt = new LabMS.Model.RoleTable(); Mrt.RoleName = tbRoleName.Text.Trim(); Mrt.RoleDetails = tbRoleDetails.Text.Trim(); try { int iRid = BRT.Add(Mrt); if (iRid == 0) { lbErr.Visible = true; lbErr.Text = "角色添加失败"; return; } List<string> liststrFunction = GetPrivaily(); LabMS.BLL.RoleFucntion brf = new LabMS.BLL.RoleFucntion(); LabMS.Model.RoleFucntion mrf = new LabMS.Model.RoleFucntion(); for (int i = 0; i < liststrFunction.Count; ++i) { mrf.FCode = liststrFunction[i].ToString(); mrf.RoleID = iRid; brf.Add(mrf); } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('新增角色成功!');window.location.href='RoleList.aspx';</script>"); } catch { } } }
/// <summary> /// 保存修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbRoleName.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "err", "角色名不能为空!"); tbRoleName.Focus(); } else if (string.IsNullOrEmpty(tbRoleDetails.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "err", "角色描述不能为空!"); } else { LabMS.BLL.RoleTable BRT = new LabMS.BLL.RoleTable(); LabMS.Model.RoleTable Mrt = new LabMS.Model.RoleTable(); int RoleId = int.Parse(Request.QueryString["RoleId"].ToString()); Mrt.RoleId = RoleId; Mrt.RoleName = EBrt.GetRoleNameByRoleID(RoleId); Mrt.RoleName = tbRoleName.Text.Trim(); Mrt.RoleDetails = tbRoleDetails.Text.Trim(); try { BRT.Update(Mrt); ExtendBLL.RoleFucntion erf = new ExtendBLL.RoleFucntion(); erf.delbyWhere("RoleID=" + RoleId.ToString()); List<string> liststrFunction = GetPrivaily(); LabMS.BLL.RoleFucntion brf = new LabMS.BLL.RoleFucntion(); LabMS.Model.RoleFucntion mrf = new LabMS.Model.RoleFucntion(); for (int i = 0; i < liststrFunction.Count; ++i) { mrf.FCode = liststrFunction[i].ToString(); mrf.RoleID = RoleId; brf.Add(mrf); } //Common.JShelper.JSAlert(this.Page, "", "修改角色成功!"); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('修改角色成功!');window.location.href='RoleList.aspx';</script>"); } catch { } } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LabMS.Model.RoleTable GetModel(int RoleId) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 RoleId,RoleName,RoleDetails from RoleTable "); strSql.Append(" where RoleId=@RoleId "); SqlParameter[] parameters = { new SqlParameter("@RoleId", SqlDbType.Int,4)}; parameters[0].Value = RoleId; LabMS.Model.RoleTable model=new LabMS.Model.RoleTable(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["RoleId"].ToString()!="") { model.RoleId=int.Parse(ds.Tables[0].Rows[0]["RoleId"].ToString()); } model.RoleName=ds.Tables[0].Rows[0]["RoleName"].ToString(); model.RoleDetails=ds.Tables[0].Rows[0]["RoleDetails"].ToString(); return model; } else { return null; } }