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 lblfund_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblfund_code"); cFund oFund = new cFund(); try { if (!oFund.SP_DEL_FUND(lblfund_code.Text, "N", strUpdatedBy, ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { if (ex.Message.Contains("REFERENCE constraint")) { MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว"); } else { lblError.Text = ex.Message.ToString(); } } finally { oFund.Dispose(); } BindGridView(0); }
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 lblfund_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblfund_code"); cFund oFund = new cFund(); try { if (!oFund.SP_DEL_FUND(lblfund_code.Text, "N", strUpdatedBy, ref strMessage)) { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oFund.Dispose(); } BindGridView(0); }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string strfund_code = string.Empty, strfund_year = string.Empty, strfund_name = string.Empty, strActive = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty; string strScript = string.Empty; cFund oFund = new cFund(); DataSet ds = new DataSet(); try { #region set Data strfund_code = txtfund_code.Text.Trim(); strfund_name = txtfund_name.Text; strfund_year = cboYear.SelectedItem.Value; 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 edit if (!blnDup) { if (oFund.SP_UPD_FUND(strfund_code, strfund_year, strfund_name, strActive, strUpdatedBy, this.BudgetType, 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 fund_name = '" + strfund_name.Trim() + "' and fund_year = '" + strfund_year + "' "; if (!oFund.SP_SEL_FUND(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strfund_name.Trim() + " ปี " + strfund_year.Trim() + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oFund.SP_INS_FUND(strfund_year, strfund_name, strActive, strCreatedBy, this.BudgetType, ref strMessage)) { string strGetcode = " and fund_name = '" + strfund_name.Trim() + "' and fund_year = '" + strfund_year + "' "; if (!oFund.SP_SEL_FUND(strGetcode, ref ds, ref strMessage)) { lblError.Text = strMessage; } if (ds.Tables[0].Rows.Count > 0) { strfund_code = ds.Tables[0].Rows[0]["fund_code"].ToString(); } ViewState["fund_code"] = strfund_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 { oFund.Dispose(); } return(blnResult); }
private void BindGridView() { cFund ofund = new cFund(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strfund_code = string.Empty; string strfund_name = string.Empty; string strScript = string.Empty; string strfund_year = string.Empty; strfund_code = txtfund_code.Text.Replace("'", "''").Trim(); strfund_name = txtfund_name.Text.Replace("'", "''").Trim(); strfund_year = txtfund_year.Text.Replace("'", "''").Trim();; if (!strfund_code.Equals("")) { strCriteria = strCriteria + " And (fund_code like '%" + strfund_code + "%') "; } if (!strfund_name.Equals("")) { strCriteria = strCriteria + " And (fund_name like '%" + strfund_name + "%')"; } if (!strfund_year.Equals("")) { strCriteria = strCriteria + " And (fund_year = '" + strfund_year + "') "; } strCriteria = strCriteria + " And (c_active ='Y') "; try { if (ofund.SP_SEL_FUND(strCriteria, ref ds, ref strMessage)) { if (ds.Tables[0].Rows.Count == 1) { strfund_code = ds.Tables[0].Rows[0]["fund_code"].ToString(); strfund_name = ds.Tables[0].Rows[0]["fund_name"].ToString(); if (!ViewState["show"].ToString().Equals("1")) { strScript = "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl1"].ToString() + "').value='" + strfund_code + "';\n " + "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strfund_name + "';\n" + "ClosePopUp('" + ViewState["show"].ToString() + "');"; } else { strScript = "window.parent.document.forms[0]." + ViewState["ctrl1"].ToString() + ".value='" + strfund_code + "';\n " + "window.parent.document.forms[0]." + ViewState["ctrl2"].ToString() + ".value='" + strfund_name + "';\n" + "ClosePopUp('" + ViewState["show"].ToString() + "');"; } ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true); } else { ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } } else { lblError.Text = strMessage; } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { ofund.Dispose(); ds.Dispose(); } }
private void BindGridView(int nPageNo) { cFund oFund = new cFund(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strfund_code = string.Empty; string strfund_name = string.Empty; string strActive = string.Empty; string strfund_year = string.Empty; strfund_code = txtfund_code.Text.Replace("'", "''").Trim(); strfund_name = txtfund_name.Text.Replace("'", "''").Trim(); strfund_year = cboYear.SelectedValue; if (!strfund_code.Equals("0")) { strCriteria = strCriteria + " And (fund_code like '%" + strfund_code + "%') "; } if (!strfund_name.Equals("0")) { strCriteria = strCriteria + " And (fund_name like '%" + strfund_name + "%')"; } if (!strfund_year.Equals("0")) { strCriteria = strCriteria + " And (fund_year = '" + strfund_year + "') "; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (c_active ='N') "; } strCriteria = strCriteria + " And budget_type ='" + this.BudgetType + "' "; try { if (!oFund.SP_SEL_FUND(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 { oFund.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }