/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(PRoleData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into PRole("); strSql.Append("roleName,isSys,mark)"); strSql.Append(" values ("); strSql.Append("@roleName,@isSys,@mark)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@roleName", SqlDbType.NVarChar,20), new SqlParameter("@isSys", SqlDbType.Bit), new SqlParameter("@mark", SqlDbType.NVarChar,200) }; parameters[0].Value = model.roleName; parameters[1].Value = model.isSys; parameters[2].Value = model.mark; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
protected void btnSave_Click(object sender, EventArgs e) { PRoleData model = new PRoleData(); PRoleBB roleBB = new PRoleBB(); if (this.roleName.Text == "") { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"��λ���Ʊ�����д!\");", true); } else { try { if (this.State == "1") { this.SetModel(ref model); //model.isrtEmpId = this.currentUser.empId; //model.isrtDt = DateTime.Now.ToString(); this.IdValue = roleBB.AddRecord(model); } else if (this.State == "2") { model = roleBB.GetModel(this.IdValue); this.SetModel(ref model); if (model.isSys) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"����λΪϵͳ��λ�������ġ�\");", true); return; } roleBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { roleBB.Dispose(); } Response.Redirect("PRoleList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main", false); } }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(PRoleData model) { return this.roleDB.ModifyRecord(model); }
//***************************************************************************** //do it later do it later do it later //***************************************************************************** /// <summary> /// ɾ��һ������ /// </summary> /// <param name="id">����ֵ</param> public bool DeleteRecord(int id) { PRoleData roleData = new PRoleData(); roleData = this.GetModel(id); if (roleData.isSys) { throw new Exception("����λΪϵͳ��λ������ɾ����"); } return this.roleDB.DeleteRecord(id); }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(PRoleData model) { return this.roleDB.AddRecord(model); }
//邦定角色名称 private void BindRole() { PRoleData roleData = new PRoleData(); PRoleBB roleBB = new PRoleBB(); try { roleData = roleBB.GetModel(this.RoleId); this.roleNm.Text = "当前角色:" + roleData.roleName; } finally { roleBB.Dispose(); } }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(PRoleData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update PRole set "); strSql.Append("roleName=@roleName,"); strSql.Append("isSys=@isSys,"); strSql.Append("mark=@mark"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@roleName", SqlDbType.NVarChar,20), new SqlParameter("@isSys", SqlDbType.Bit), new SqlParameter("@mark", SqlDbType.NVarChar,200) }; parameters[0].Value = model.id; parameters[1].Value = model.roleName; parameters[2].Value = model.isSys; parameters[3].Value = model.mark; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// �õ�һ��model /// </summary> /// <param name="id">����ֵ</param> /// <returns>model</returns> public PRoleData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from PRole"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; PRoleData model = new PRoleData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["roleName"] != DBNull.Value) { model.roleName = Convert.ToString(row["roleName"]); } if (row["isSys"] != DBNull.Value) { model.isSys = Convert.ToBoolean(row["isSys"]); } if (row["mark"] != DBNull.Value) { model.mark = Convert.ToString(row["mark"]); } return model; } else { return null; } }
private void ShowInfo(int id) { PRoleBB roleBB = new PRoleBB(); PRoleData model = new PRoleData(); try { model = roleBB.GetModel(id); this.roleName.Text = model.roleName; this.isSys.Checked = model.isSys; this.mark.Text = model.mark; } finally { roleBB.Dispose(); } }
private void SetModel(ref PRoleData model) { model.roleName = this.roleName.Text; //model.isSys = this.isSys.Checked; model.mark = this.mark.Text; }
/// <summary> /// ɾ�� /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDel_Click(object sender, EventArgs e) { PRoleBB roleBB = new PRoleBB(); PUserRoleBB userRoleBB = new PUserRoleBB(); PRolePermissionsBB rolePermissionsBB = new PRolePermissionsBB(); //��ȡѡ�е�����Id try { foreach (GridViewRow gvrow in this.grid.Rows) { CheckBox chkId = (CheckBox)gvrow.FindControl("chkId"); int id = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["id"]); if (chkId.Checked == true) { PRoleData roleData = new PRoleData(); roleData = roleBB.GetModel(id); if (roleData.isSys) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"����λΪϵͳ��λ������ɾ����\");", true); return; } else { //ɾ����ɫ��ͬʱ��ɾ����Ա��ɫ����ɫȨ�� roleBB.DeleteRecord(id); userRoleBB.DeleteRecordByRole(id); rolePermissionsBB.DeleteRecordByRole(id, 2); } } } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { roleBB.Dispose(); userRoleBB.Dispose(); rolePermissionsBB.Dispose(); } this.BindGrid(); }
/// <summary> /// �� /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEdit_Click(object sender, EventArgs e) { //��ȡѡ�е�����Id foreach (GridViewRow gvrow in this.grid.Rows) { CheckBox chkId = (CheckBox)gvrow.FindControl("chkId"); int id = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["id"]); if (chkId.Checked == true) { using (PRoleBB roleBB = new PRoleBB()) { PRoleData roleData = new PRoleData(); roleData = roleBB.GetModel(id); if (roleData.isSys) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"����λΪϵͳ��λ�������ġ�\");", true); return; } else { Response.Redirect("PRole.aspx?state=2&itemNo=" + this.itemNo + "&pTypeNo=edit" + "&id=" + id, false); } } } } this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"��ѡ��һ����¼!\");", true); }