using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
namespace Com.Jpsoft.Hospital.Web.Module.Sys.Role
{
public partial class List :Com.Jpsoft.Hospital.Web.Common.BasePage
{
Com.Jpsoft.Hospital.BLL.jp_sys_role role = new Com.Jpsoft.Hospital.BLL.jp_sys_role();
Com.Jpsoft.Hospital.Model.jp_sys_role model = new Com.Jpsoft.Hospital.Model.jp_sys_role();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int currentpage = 1;
int id = 0;
string cmd = string.Empty;
FetchQueryString("curpage", out currentpage);
FetchQueryString("id", out id);
FetchQueryString("cmd", out cmd);
AspNetPager1.RecordCount = currentpage * AspNetPager1.PageSize;
if (cmd == "del")
{
Delete(id,currentpage);
}
BindData();
}
}
///
/// delete by yqh
///
///
///
private void Delete(int id, int currentpage)
{
try
{
//删除角色表信息
role.Delete(id);
//删除权限表中相应的角色信息
Com.Jpsoft.Hospital.BLL.jp_sys_right right = new Com.Jpsoft.Hospital.BLL.jp_sys_right();
DataTable dt = right.GetList(" right_roleid=" + id).Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
int rightid = int.Parse(dt.Rows[i]["right_id"].ToString());
right.Delete(rightid);
}
}
Response.Write("");
}
catch (Exception ex)
{
Response.Write("");
}
}
///
/// select by yqh
///
///
///
protected void btncheck_Click(object sender, EventArgs e)
{
StringBuilder strWhere = new StringBuilder();
strWhere.Append(" where 1=1 ");
int role_id = int.Parse(this.ddl.SelectedValue.ToString().Trim());
if (role_id!= 0)
{
strWhere.Append(" and role_id="+role_id);
}
ViewState["SearchTerms"] = strWhere.ToString();
BindData();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("Insert.aspx");
}
/////
///// 行绑定
/////
/////
/////
//protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
//{
// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// if (e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Normal)
// {
// ((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick", "return confirm('确定要删除吗?');");
// }
// }
//}
/////
///// 删除行数据
/////
/////
/////
//protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
//{
// int roleid = int.Parse(this.gv.DataKeys[e.RowIndex].Value.ToString());
// try {
// role.Delete(roleid);
// Response.Write("");
// }
// catch (Exception ex)
// {
// Response.Write("");
// }
// BindData();
//}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindData();
}
///
/// 绑定数据
///
private void BindData()
{
string strWhere = " where 1=1 ";
int recordCount = 0;
if (string.IsNullOrEmpty((string)ViewState["SearchTerms"]))
{
}
else
{
strWhere = ViewState["SearchTerms"].ToString();
}
string orderby = " order by role_id DESC";
using (IDataReader idr = Com.Jpsoft.Hospital.DAL.jp_sys_roleEx.SelectPage(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, strWhere, orderby))
{
if (idr.Read())
{
recordCount = int.Parse(idr["RecordCount"].ToString());
}
AspNetPager1.RecordCount = recordCount;
idr.NextResult();
this.gv.DataSource = idr;
this.gv.DataBind();
idr.Close();
}
DataTable dt = role.GetAllList().Tables[0];
if (dt.Rows.Count > 0)
{
this.ddl.Items.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
this.ddl.Items.Add(new ListItem(dt.Rows[i]["role_name"].ToString(), dt.Rows[i]["role_id"].ToString()));
}
this.ddl.Items.Insert(0, new ListItem("==请选择角色名称==","0"));
}
}
}
}