Example #1
0
        private void InitcboFund()
        {
            cFund  oFund        = new cFund();
            string strMessage   = string.Empty,
                   strCriteria  = string.Empty,
                   strfund_code = string.Empty;
            string strYear      = cboYear.SelectedValue;

            strfund_code = cboFund.SelectedValue;
            int       i;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria = " and fund_year = '" + strYear + "'  and  c_active='Y' ";
            strCriteria = strCriteria + " and budget_type ='" + this.BudgetType + "' ";

            if (oFund.SP_SEL_FUND(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboFund.Items.Clear();
                cboFund.Items.Add(new ListItem("---- กรุณาเลือกข้อมูล ----", ""));
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboFund.Items.Add(new ListItem(dt.Rows[i]["fund_name"].ToString(), dt.Rows[i]["fund_code"].ToString()));
                }
                if (cboFund.Items.FindByValue(strfund_code) != null)
                {
                    cboFund.SelectedIndex = -1;
                    cboFund.Items.FindByValue(strfund_code).Selected = true;
                }
            }
        }
Example #2
0
        private void setData()
        {
            cFund   oFund = new cFund();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  strfund_code   = string.Empty,
                    strfund_name   = string.Empty,
                    strYear        = string.Empty,
                    strC_active    = string.Empty,
                    strCreatedBy   = string.Empty,
                    strUpdatedBy   = string.Empty,
                    strCreatedDate = string.Empty,
                    strUpdatedDate = string.Empty;

            try
            {
                strCriteria = " and fund_code = '" + ViewState["fund_code"].ToString() + "' ";
                if (!oFund.SP_SEL_FUND(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strfund_code   = ds.Tables[0].Rows[0]["fund_code"].ToString();
                        strfund_name   = ds.Tables[0].Rows[0]["fund_name"].ToString();
                        strYear        = ds.Tables[0].Rows[0]["fund_year"].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
                        txtfund_code.Text = strfund_code;
                        txtfund_name.Text = strfund_name;
                        txtyear.Text      = strYear;
                        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();
            }
        }
Example #3
0
        private void setData()
        {
            cFund   oFund = new cFund();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  strfund_code   = string.Empty,
                    strfund_name   = string.Empty,
                    strYear        = string.Empty,
                    strC_active    = string.Empty,
                    strCreatedBy   = string.Empty,
                    strUpdatedBy   = string.Empty,
                    strCreatedDate = string.Empty,
                    strUpdatedDate = string.Empty;

            try
            {
                strCriteria = " and fund_code = '" + ViewState["fund_code"].ToString() + "' ";
                if (!oFund.SP_SEL_FUND(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strfund_code   = ds.Tables[0].Rows[0]["fund_code"].ToString();
                        strfund_name   = ds.Tables[0].Rows[0]["fund_name"].ToString();
                        strYear        = ds.Tables[0].Rows[0]["fund_year"].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
                        txtfund_code.Text = strfund_code;
                        txtfund_name.Text = strfund_name;
                        InitcboYear();
                        if (cboYear.Items.FindByValue(strYear) != null)
                        {
                            cboYear.SelectedIndex = -1;
                            cboYear.Items.FindByValue(strYear).Selected = true;
                        }
                        if (strC_active.Equals("Y"))
                        {
                            txtfund_name.ReadOnly = false;
                            txtfund_name.CssClass = "textbox";
                            chkStatus.Checked     = true;
                        }
                        else
                        {
                            txtfund_name.ReadOnly = true;
                            txtfund_name.CssClass = "textboxdis";
                            chkStatus.Checked     = false;
                        }
                        cboYear.Enabled     = false;
                        cboYear.CssClass    = "textboxdis";
                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Example #4
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);
        }
Example #5
0
        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();
            }
        }
Example #6
0
        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;
                }
            }
        }