//private void imgSave_Click(object sender, System.Web.UI.ImageClickEventArgs e) //{ // bool blnResult = false; // string strScript = string.Empty; // blnResult = saveData(); // if (blnResult) // { // strScript = "self.opener.document.forms[0].ctl00$ASPxRoundPanel1$ContentPlaceHolder2$txthpage.value=" + ViewState["page"].ToString() + ";\n" + // "self.opener.document.forms[0].submit();\n" + // "self.close();\n"; // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript, true); // } //} private void BindGridView() { cBranch oBranch = new cBranch(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strbank_code = string.Empty; strbank_code = cboBank.SelectedValue; strCriteria = strCriteria + " And (branch.bank_code = '" + strbank_code + "') "; try { if (!oBranch.SP_SEL_BRANCH(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { try { ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"]; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch { GridView1.PageIndex = 0; 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 { oBranch.Dispose(); ds.Dispose(); } }
//private void imgSaveOnly_Click(object sender, System.Web.UI.ImageClickEventArgs e) //{ // if (saveData()) // { // if (ViewState["mode"].ToString().ToLower().Equals("add")) // { // Response.Redirect("branch_control.aspx?mode=edit&branch_code=" + ViewState["branch_code"].ToString() + "&page=" + ViewState["page"].ToString() + "&PageStatus=save", true); // } // else if (ViewState["mode"].ToString().ToLower().Equals("edit")) // { // txtbranch_code.Text = ""; // txtbranch_name.Text = ""; // txtbranch_name.ReadOnly = false; // txtbranch_name.CssClass = "textbox"; // chkStatus.Checked = true; // string strScript1 = // "self.opener.document.forms[0].ctl00$ASPxRoundPanel1$ContentPlaceHolder2$txthpage.value=" + ViewState["page"].ToString() + ";\n" + // "self.opener.document.forms[0].submit();\n" + // "self.focus();\n"; // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript1, true); // } // BindGridView(); // } //} private void setData() { cBranch oBranch = new cBranch(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string strbranch_code = string.Empty, strbranch_name = string.Empty, strbank_code = string.Empty, strC_active = string.Empty, strCreatedBy = string.Empty, strUpdatedBy = string.Empty, strCreatedDate = string.Empty, strUpdatedDate = string.Empty; try { strCriteria = " and branch.branch_code = '" + ViewState["branch_code"].ToString() + "' "; if (!oBranch.SP_SEL_BRANCH(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data strbranch_code = ds.Tables[0].Rows[0]["branch_code"].ToString(); strbranch_name = ds.Tables[0].Rows[0]["branch_name"].ToString(); strbank_code = ds.Tables[0].Rows[0]["bank_code"].ToString(); strC_active = ds.Tables[0].Rows[0]["c_active"].ToString(); strCreatedBy = ds.Tables[0].Rows[0]["c_created_by"].ToString(); strUpdatedBy = ds.Tables[0].Rows[0]["c_updated_by"].ToString(); strCreatedDate = ds.Tables[0].Rows[0]["d_created_date"].ToString(); strUpdatedDate = ds.Tables[0].Rows[0]["d_updated_date"].ToString(); #endregion #region set Control txtbranch_code.Text = strbranch_code; txtbranch_name.Text = strbranch_name; InitcboBank(); if (cboBank.Items.FindByValue(strbank_code) != null) { cboBank.SelectedIndex = -1; cboBank.Items.FindByValue(strbank_code).Selected = true; } if (strC_active.Equals("Y")) { txtbranch_name.ReadOnly = false; txtbranch_name.CssClass = "textbox"; chkStatus.Checked = true; } else { txtbranch_name.ReadOnly = true; txtbranch_name.CssClass = "textboxdis"; chkStatus.Checked = false; } cboBank.Enabled = false; cboBank.CssClass = "textboxdis"; txtUpdatedBy.Text = strUpdatedBy; txtUpdatedDate.Text = strUpdatedDate; BindGridView(); #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
private void BindGridView(int nPageNo) { InitcboBank(); cBranch oBranch = new cBranch(); DataSet ds = new DataSet(); string strMessage = string.Empty; string strCriteria = string.Empty; string strbranch_code = string.Empty; string strbranch_name = string.Empty; string strbank_code = string.Empty; string strActive = string.Empty; strbranch_code = txtbranch_code.Text.Replace("'", "''").Trim(); strbranch_name = txtbranch_name.Text.Replace("'", "''").Trim(); strbank_code = cboBank.SelectedValue; if (Request.Form[strPrefixCtr + "cboBank"] != null) { strbank_code = Request.Form[strPrefixCtr + "cboBank"].ToString(); } if (!strbranch_code.Equals("")) { strCriteria = strCriteria + " And (branch.branch_code like '%" + strbranch_code + "%') "; } if (!strbranch_name.Equals("")) { strCriteria = strCriteria + " And (branch.branch_name like '%" + strbranch_name + "%')"; } if (!strbank_code.Equals("")) { strCriteria = strCriteria + " And (branch.bank_code = '" + strbank_code + "') "; } if (RadioActive.Checked) { strCriteria = strCriteria + " And (branch.c_active ='Y') "; } else if (RadioCancel.Checked) { strCriteria = strCriteria + " And (branch.c_active ='N') "; } try { if (!oBranch.SP_SEL_BRANCH(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 { oBranch.Dispose(); ds.Dispose(); if (GridView1.Rows.Count > 0) { GridView1.TopPagerRow.Visible = true; } } }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strMessage = string.Empty; string strbranch_code = string.Empty, strbranch_name = string.Empty, strbank_code = string.Empty, stractive = string.Empty, strcreatedby = string.Empty, strupdatedby = string.Empty; string strScript = string.Empty; cBranch oBranch = new cBranch(); DataSet ds = new DataSet(); try { #region set Data strbranch_code = txtbranch_code.Text; strbranch_name = txtbranch_name.Text; //Bank_code strbank_code = cboBank.SelectedValue; if (Request.Form["ctl00$ASPxRoundPanel1$ContentPlaceHolder1$cboBank"] != null) { strbank_code = Request.Form["ctl00$ASPxRoundPanel1$ContentPlaceHolder1$cboBank"].ToString(); } if (chkStatus.Checked == true) { stractive = "Y"; } else { stractive = "N"; } strcreatedby = Session["username"].ToString(); strupdatedby = Session["username"].ToString(); #endregion string strCheckAdd = " and branch.branch_code = '" + strbranch_code.Trim() + "' "; if (!oBranch.SP_SEL_BRANCH(strCheckAdd, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region check dup string strCheckDup = string.Empty; strCheckDup = " and branch.branch_name = '" + strbranch_name.Trim() + "' " + " and branch.bank_code='" + strbank_code.Trim() + "' and branch.branch_code <> '" + strbranch_code.Trim() + "' "; if (!oBranch.SP_SEL_BRANCH(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก" + "\\nข้อมูลธนาคาร : " + cboBank.SelectedItem.Text + "\\nข้อมูลสาขา : " + strbranch_name.Trim() + "\\nซ้ำ\");\n"; blnDup = true; } } #endregion #region edit if (!blnDup) { if (oBranch.SP_UPD_BRANCH(strbranch_code, strbranch_name, strbank_code, stractive, strupdatedby, ref strMessage)) { blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "chkdup", strScript, true); } #endregion } else { #region check dup string strCheckDup = string.Empty; strCheckDup = " and branch.branch_name = '" + strbranch_name + "' " + " and branch.bank_code='" + strbank_code.Trim() + "' "; if (!oBranch.SP_SEL_BRANCH(strCheckDup, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" + "\\nข้อมูลธนาคาร: " + cboBank.SelectedItem.Text + "\\nข้อมูลสาขา : " + strbranch_name.Trim() + "\\nซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oBranch.SP_INS_BRANCH(strbranch_name, strbank_code, stractive, strcreatedby, ref strMessage)) { string strGetcode = " and branch.branch_name = '" + strbranch_name.Trim() + "' " + " and branch.bank_code = '" + strbank_code.Trim() + "' "; if (!oBranch.SP_SEL_BRANCH(strGetcode, ref ds, ref strMessage)) { lblError.Text = strMessage; } if (ds.Tables[0].Rows.Count > 0) { strbranch_code = ds.Tables[0].Rows[0]["branch_code"].ToString(); } ViewState["branch_code"] = strbranch_code; blnResult = true; } else { lblError.Text = strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true); } #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oBranch.Dispose(); } return(blnResult); }
private void setData() { cBranch oBranch = new cBranch(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; string strbranch_code = string.Empty, strbranch_name = string.Empty, strbank_code = string.Empty, strbank_name = string.Empty, strc_active = string.Empty, strcreatedBy = string.Empty, strupdatedBy = string.Empty, strcreatedDate = string.Empty, strupdatedDate = string.Empty; try { strCriteria = " and branch_code = '" + ViewState["branch_code"].ToString() + "' "; if (!oBranch.SP_SEL_BRANCH(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data strbank_code = ds.Tables[0].Rows[0]["branch_code"].ToString(); strbranch_name = ds.Tables[0].Rows[0]["branch_name"].ToString(); strbank_code = ds.Tables[0].Rows[0]["bank_code"].ToString(); strbank_name = ds.Tables[0].Rows[0]["bank_name"].ToString(); strc_active = ds.Tables[0].Rows[0]["c_active"].ToString(); strcreatedBy = ds.Tables[0].Rows[0]["c_created_by"].ToString(); strupdatedBy = ds.Tables[0].Rows[0]["c_updated_by"].ToString(); strcreatedDate = ds.Tables[0].Rows[0]["d_created_date"].ToString(); strupdatedDate = ds.Tables[0].Rows[0]["d_updated_date"].ToString(); #endregion #region set Control txtbranch_code.Text = strbank_name; txtbranch_name.Text = strbranch_name; txtbank_code.Text = strbank_code; txtbank_name.Text = strbank_name; if (strc_active.Equals("Y")) { chkStatus.Checked = true; } else { chkStatus.Checked = false; } txtUpdatedBy.Text = strupdatedBy; txtUpdatedDate.Text = strupdatedDate; #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }