protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string strMessage = string.Empty; string strCheck = string.Empty; string strScript = string.Empty; string strUpdatedBy = Session["username"].ToString(); Label lblbank_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbank_code"); cBank oBank = new cBank(); try { if (!oBank.SP_DEL_BANK(lblbank_code.Text, "N", strUpdatedBy, ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oBank.Dispose(); } BindGridView(0); }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string strbank_code = string.Empty, strbank_name = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cBank oBank = new cBank(); DataSet ds = new DataSet(); try { #region set Data strbank_code = txtbank_code.Text.Trim(); strbank_name = txtbank_name.Text; if (chkStatus.Checked == true) { strActive = "Y"; } else { strActive = "N"; } strCreatedBy = Session["username"].ToString(); strUpdatedBy = Session["username"].ToString(); #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { #region check dup string strCheckDup = string.Empty; strCheckDup = " and bank_name = '" + strbank_name.Trim() + "' " + " and bank_code <> '" + strbank_code.Trim() + "' "; if (!oBank.SP_SEL_BANK(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถแก้ไขข้อมูล เนื่องจากข้อมูล " + strbank_code.Trim() + " : " + strbank_name.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region edit if (!blnDup) { if (oBank.SP_UPD_BANK(strbank_code, strbank_name, strActive, strUpdatedBy, ref strMessage)) { blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } else { #region check dup string strCheckDup = string.Empty; strCheckDup = " and bank_code = '" + strbank_code.Trim() + "' "; if (!oBank.SP_SEL_BANK(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strbank_code.Trim() + " : " + strbank_name.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oBank.SP_INS_BANK(strbank_code, strbank_name, strActive, strCreatedBy, ref strMessage)) { ViewState["bank_code"] = strbank_code; blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oBank.Dispose(); } return(blnResult); }
private void BindGridView(int nPageNo) { cBank oBank = new cBank(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strbank_code = string.Empty; string strbank_name = string.Empty; string strActive = string.Empty; strbank_code = txtbank_code.Text.Replace("'", "''").Trim(); strbank_name = txtbank_name.Text.Replace("'", "''").Trim(); if (!strbank_code.Equals("0")) { strCriteria = strCriteria + " And (bank_code like '%" + strbank_code + "%') "; } if (!strbank_name.Equals("0")) { strCriteria = strCriteria + " And (bank_name like '%" + strbank_name + "%')"; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (c_active ='N') "; } try { if (!oBank.SP_SEL_BANK(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { try { GridView1.PageIndex = nPageNo; txthTotalRecord.Value = ds.Tables[0].Rows.Count.ToString(); ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch { GridView1.PageIndex = 0; txthTotalRecord.Value = ds.Tables[0].Rows.Count.ToString(); ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oBank.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }