/// <summary> /// 绑定Grid /// </summary> protected void BindGrid() { LCheckItemBB checkItemBB = new LCheckItemBB(); DataSet ds = new DataSet(); try { string strWhere = this.StrWhere; if (this.checkItemNo.Text != "")//编码 { strWhere += " and checkItemNo like '%" + this.checkItemNo.Text.Replace("'", "''") + "%'"; } if (checkItemNm.Text != "")//名称 { strWhere += " and checkItemNm like '%" + this.checkItemNm.Text.Replace("'", "''") + "%'"; } ds = checkItemBB.GetList(strWhere); this.grid.DataSource = ds.Tables[0]; this.grid.DataBind(); //赋值记录条数、页面总数 this.Label3.Text = ds.Tables[0].Rows.Count.ToString(); this.Label2.Text = this.grid.PageCount.ToString(); this.currPage.Text = (this.grid.PageIndex + 1).ToString(); } finally { checkItemBB.Dispose(); } }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDel_Click(object sender, EventArgs e) { bool retChecked = false; LCheckItemBB checkItemBB = new LCheckItemBB(); try { //获取选中的数据Id foreach (GridViewRow gvrow in this.grid.Rows) { CheckBox chkId = (CheckBox)gvrow.FindControl("chkId"); if (chkId.Checked == true) { retChecked = true; int id = int.Parse(chkId.ValidationGroup); checkItemBB.DeleteRecord(id); } } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { checkItemBB.Dispose(); } if (retChecked) { this.BindGrid(); } }
private bool ValidatePageControlValue(out string strInfo) { bool ret = true; bool isValidate = true; strInfo = ""; if (this.checkItemNo.Text.Trim() == "") { isValidate = false; strInfo = "编码不能为空!"; } if (this.checkItemNm.Text.Trim() == "") { isValidate = false; strInfo = "名称不能为空!"; } LCheckItemBB checkItemBB = new LCheckItemBB(); DataSet ds = checkItemBB.GetList(" id<>" + this.IdValue.ToString() + " and checkItemNo =" + "'" + this.checkItemNo.Text.Trim() + "'"); DataSet ds2 = checkItemBB.GetList(" id<>" + this.IdValue.ToString() + " and checkItemNm =" + "'" + this.checkItemNm.Text.Trim() + "'"); try { if (ds.Tables[0].Rows.Count > 0) { ret = false; strInfo = "编码已存在,请重新输入!"; return ret; } if (ds2.Tables[0].Rows.Count > 0) { ret = false; strInfo = "名称已存在,请重新输入!"; return ret; } } finally { checkItemBB.Dispose(); } return isValidate; }
/// <summary> /// 数据保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { LCheckItemData model = new LCheckItemData(); LCheckItemBB checkItemBB = new LCheckItemBB(); string strInfo = ""; bool isSuccess = this.ValidatePageControlValue(out strInfo); if (isSuccess) { try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; this.IdValue = checkItemBB.AddRecord(model); } else if (this.State == "2") { model = checkItemBB.GetModel(this.IdValue); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; checkItemBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { checkItemBB.Dispose(); } Response.Redirect("LCheckItemList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false); } else { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + strInfo + "');", true); } }
/// <summary> /// 展示数据 /// </summary> /// <param name="id">记录Id</param> private void ShowInfo(int id) { LCheckItemBB checkItemBB = new LCheckItemBB(); LCheckItemData model = new LCheckItemData(); try { model = checkItemBB.GetModel(id); this.checkItemNo.Text = model.checkItemNo; this.checkItemNm.Text = model.checkItemNm; this.mark.Text = model.mark; } finally { checkItemBB.Dispose(); } }