Esempio n. 1
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   lblbranch_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbranch_code");
            cBranch oBranch        = new cBranch();

            try
            {
                if (!oBranch.SP_DEL_BRANCH(lblbranch_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    string strScript1 = "RefreshMain('" + ViewState["page"].ToString() + "');";
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript1, true);
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oBranch.Dispose();
            }
            BindGridView();
        }
Esempio n. 2
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   lblbranch_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbranch_code");
            cBranch oBranch        = new cBranch();

            try
            {
                if (!oBranch.SP_DEL_BRANCH(lblbranch_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oBranch.Dispose();
            }
            BindGridView(0);
        }
Esempio n. 3
0
        //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();
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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;
                }
            }
        }