Example #1
0
        private void InitcboBank()
        {
            cBank  oBank = new cBank();
            string strMessage = string.Empty, strCriteria = string.Empty;
            string strbank_code = string.Empty;
            string strYear      = cboBank.SelectedValue;

            strbank_code = cboBank.SelectedValue;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria = " and c_active='Y' ";
            if (oBank.SP_SEL_BANK(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboBank.Items.Clear();
                cboBank.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", ""));
                int i;
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboBank.Items.Add(new ListItem(dt.Rows[i]["bank_name"].ToString(), dt.Rows[i]["bank_code"].ToString()));
                }
                if (cboBank.Items.FindByValue(strbank_code) != null)
                {
                    cboBank.SelectedIndex = -1;
                    cboBank.Items.FindByValue(strbank_code).Selected = true;
                }
            }
        }
Example #2
0
        private void setData()
        {
            cBank   oBank = new cBank();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  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 bank_code = '" + ViewState["bank_code"].ToString() + "' ";
                if (!oBank.SP_SEL_BANK(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]["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
                        txtbank_code.Text = strbank_code;
                        txtbank_name.Text = strbank_name;
                        if (strC_active.Equals("Y"))
                        {
                            txtbank_name.ReadOnly = false;
                            txtbank_name.CssClass = "textbox";
                            chkStatus.Checked     = true;
                        }
                        else
                        {
                            txtbank_name.ReadOnly = true;
                            txtbank_name.CssClass = "textboxdis";
                            chkStatus.Checked     = false;
                        }
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Example #3
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  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);
        }
Example #4
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);
        }
Example #5
0
        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;
                }
            }
        }