public static int PageNumber = 2;//每页记录个数
public static int PageCount;//总页数
public static int PageNow = 1;//当前页
public static int cmpid;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Session["cmpID"] = 2;
try
{
cmpid = Convert.ToInt32(Session["cmpID"].ToString());
}
catch (Exception err)
{
Response.Write("<script language='javascript'>alert('登录超时,请重新登录!');location.href='Login.aspx'</script>");
return;
}
Bind();
lblPageIndex.Text = PageNow.ToString() + "/" + PageCount.ToString() + "页";
}
}
//数据绑定
public void Bind()
{
DataSet ds = new DataSet();
ds = BLL.JZ_ZPXX.GetList("GSID=" + cmpid);
grvTradeList.DataSource = ds.Tables[0];
grvTradeList.DataBind();
PageCount = ds.Tables[0].Rows.Count / PageNumber;//总页数
if ((ds.Tables[0].Rows.Count % PageNumber) != 0)
{
PageCount++;
}
if (PageCount == 0)//如果没有记录,则显示0/0页
{
PageNow = 0;
}
lblTj.Text = ds.Tables[0].Rows.Count.ToString();//统计信息数
}
//全选button
protected void btnCheckAll_Click(object sender, EventArgs e)
{
for (int i = grvTradeList.Rows.Count - 1; i >= 0; i--)
{
CheckBox cb1 = (CheckBox)grvTradeList.Rows[i].FindControl("check");
cb1.Checked = true;
}
}
//全选checkbox
protected void checkAll(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
if (cb.Text == "全选")
{
foreach (GridViewRow gvr in grvTradeList.Rows)
{
CheckBox cb1 = (CheckBox)gvr.FindControl("check");
cb1.Checked = cb.Checked;//子checkbox与父checkbox相同
}
}
}
//反选
protected void btnFanxuan_Click(object sender, EventArgs e)
{
for (int i = grvTradeList.Rows.Count - 1; i >= 0; i--)
{
CheckBox cbox = (CheckBox)grvTradeList.Rows[i].FindControl("check");
cbox.Checked = !cbox.Checked;
}
}
//分页
protected void grvTradeList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
pagechange(e.NewPageIndex);
PageNow = e.NewPageIndex + 1;
lblPageIndex.Text = PageNow.ToString() + "/" + PageCount.ToString() + "页";
}
/// <summary>
/// 跳转到指定页
/// </summary>
/// <param name="page">页号</param>
public void pagechange(int page)
{
if (page < 0 || page > PageCount)
{
return;
}
grvTradeList.PageIndex = page;
Bind();
}
//首页
protected void btnfirst_Click(object sender, EventArgs e)
{
pagechange(0);
if (PageCount == 0)
PageNow = 0;
else
PageNow = 1;
lblPageIndex.Text = PageNow.ToString() + "/" + PageCount.ToString() + "页";
}
//上一页
protected void btnPrevious_Click(object sender, EventArgs e)
{
if (grvTradeList.PageIndex > 0)//不是首页
{
PageNow = grvTradeList.PageIndex;
lblPageIndex.Text = PageNow.ToString() + "/" + PageCount.ToString() + "页";
pagechange(grvTradeList.PageIndex - 1);
}
}
//下一页
protected void btnNext_Click(object sender, EventArgs e)
{
if (PageCount != 0)
{
pagechange(grvTradeList.PageIndex + 1);
PageNow = grvTradeList.PageIndex + 1;
lblPageIndex.Text = PageNow.ToString() + "/" + PageCount.ToString() + "页";
}
}
//尾页
protected void btnLast_Click(object sender, EventArgs e)
{
pagechange(PageCount - 1);
PageNow = PageCount;
lblPageIndex.Text = PageNow.ToString() + "/" + PageCount.ToString() + "页";
}
//删除
protected void grvTradeList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
BLL.JZ_ZPXX.Delete(Convert.ToInt32(grvTradeList.Rows[e.RowIndex].Cells[1].Text));
Bind();
}
//编辑
protected void grvTradeList_RowEditing(object sender, GridViewEditEventArgs e)
{
Response.Redirect("cmp_JobsEdit.aspx?jobid=" + grvTradeList.Rows[e.NewEditIndex].Cells[1].Text);
}
//刷新
protected void grvTradeList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Bind();
}
//正常
protected void btnOpen_Click(object sender, EventArgs e)
{
for (int i = grvTradeList.Rows.Count - 1; i >= 0; i--)
{
CheckBox cb1 = (CheckBox)grvTradeList.Rows[i].FindControl("check");
if (cb1.Checked)
{
int id = Convert.ToInt32(grvTradeList.Rows[i].Cells[1].Text);
Model.JZ_ZPXX Model_ZPXX = new Model.JZ_ZPXX();
Model_ZPXX = BLL.JZ_ZPXX.GetModel(id);
Model_ZPXX.ZT = false;
BLL.JZ_ZPXX.Update(Model_ZPXX);
}
}
Bind();
}
//关闭
protected void btnClose_Click(object sender, EventArgs e)
{
for (int i = grvTradeList.Rows.Count - 1; i >= 0; i--)
{
CheckBox cb1 = (CheckBox)grvTradeList.Rows[i].FindControl("check");
if (cb1.Checked)
{
int id = Convert.ToInt32(grvTradeList.Rows[i].Cells[1].Text);
Model.JZ_ZPXX Model_ZPXX = new Model.JZ_ZPXX();
Model_ZPXX = BLL.JZ_ZPXX.GetModel(id);
Model_ZPXX.ZT = true;
BLL.JZ_ZPXX.Update(Model_ZPXX);
}
}
Bind();
}
//删除
protected void btnDelete_Click(object sender, EventArgs e)
{
for (int i = grvTradeList.Rows.Count - 1; i >= 0; i--)
{
CheckBox cb1 = (CheckBox)grvTradeList.Rows[i].FindControl("check");
if (cb1.Checked)
{
int id = Convert.ToInt32(grvTradeList.Rows[i].Cells[1].Text);
BLL.JZ_ZPXX.Delete(id);
}
}
Bind();
}
//状态
protected void Label1_DataBinding(object sender, EventArgs e)
{
Label lb1 = (Label)sender;
if (lb1.Text == "True")
{
lb1.Text = "关闭";
}
else
{
lb1.Text = "正常";
}
}
//招聘岗位
protected void Label2_DataBinding(object sender, EventArgs e)
{
//这里只是显示最终招聘岗位,没有显示其父分类
Label lb2 = (Label)sender;
int FLID = Convert.ToInt32(lb2.Text.Trim());
Model.JZ_GWFL Model_GWFL = new Model.JZ_GWFL();
BLL.JZ_GWFL Bll_GWFL=new BLL.JZ_GWFL();
Model_GWFL = Bll_GWFL.GetModel(FLID);
if (Model_GWFL == null)
{
//如果不存在 则不能对其进行编辑
lb2.Text = "<div style=\"color:red\">该分类已经不存在,请删除这条记录</div>";
GridViewRow grvr = (GridViewRow)lb2.Parent.Parent;
LinkButton lkbEdit = (LinkButton)grvr.FindControl("lkbEdit");
lkbEdit.Enabled = false; ;
}
lb2.Text = Model_GWFL.FLMC;
}