Exemplo 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        lblbudget_plan_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbudget_plan_code");
            cBudget_plan oBudget_plan        = new cBudget_plan();

            try
            {
                if (!oBudget_plan.SP_BUDGET_PLAN_DEL(lblbudget_plan_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
            {
                oBudget_plan.Dispose();
            }
            BindGridView(0);
        }
Exemplo 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        lblbudget_plan_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblbudget_plan_code");
            cBudget_plan oBudget_plan        = new cBudget_plan();

            try
            {
                if (!oBudget_plan.SP_BUDGET_PLAN_DEL(lblbudget_plan_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oBudget_plan.Dispose();
            }
            BindGridView(0);
        }
Exemplo n.º 3
0
        protected void lbkRefresh_Click(object sender, EventArgs e)
        {
            cBudget_plan oBudget_plan = new cBudget_plan();
            string       strMessage = string.Empty, strCriteria = string.Empty;

            try
            {
                strCriteria = " and budget_plan_code = '" + txtbudget_plan_code.Text + "' ";
                var item = oBudget_plan.GET(strCriteria);
                if (item != null)
                {
                    txtbudget_plan_code.Text = item.budget_plan_code;
                    txtdirector_name.Text    = item.director_name;
                    txtunit_name.Text        = item.unit_name;
                    txtbudget_name.Text      = item.budget_name;
                    txtproduce_name.Text     = item.produce_name;
                    txtactivity_name.Text    = item.activity_name;
                    txtplan_name.Text        = item.plan_name;
                    txtwork_name.Text        = item.work_name;
                    txtfund_name.Text        = item.fund_name;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Exemplo n.º 4
0
        private void BindGridView(int nPageNo)
        {
            InitcboYear();
            cBudget_plan oBudget_plan        = new cBudget_plan();
            DataSet      ds                  = new DataSet();
            string       strMessage          = string.Empty;
            string       strCriteria         = string.Empty;
            string       strbudget_plan_year = string.Empty;
            string       strbudget_plan_code = string.Empty;
            string       strbudget_code      = string.Empty;
            string       strproduce_code     = string.Empty;
            string       strunit_code        = string.Empty;
            string       strdirector_code    = string.Empty;
            string       stractivity_code    = string.Empty;
            string       strplan_code        = string.Empty;
            string       strwork_code        = string.Empty;
            string       strwork_name        = string.Empty;
            string       stractive           = string.Empty;
            string       strScript           = string.Empty;

            #region Criteria
            strbudget_plan_year = cboYear.SelectedValue;
            strbudget_plan_code = txtbudget_plan_code.Text.Replace("'", "''").Trim();
            strbudget_code      = cboBudget.SelectedValue;
            strproduce_code     = cboProduce.SelectedValue;
            strdirector_code    = cboDirector.SelectedValue;
            strunit_code        = cboUnit.SelectedValue;
            stractivity_code    = cboActivity.SelectedValue;
            strplan_code        = cboPlan_code.SelectedValue;

            if (!strbudget_plan_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (budget_plan_year = '" + strbudget_plan_year + "') ";
            }
            if (!strbudget_plan_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (budget_plan_code ='" + strbudget_plan_code + "') ";
            }

            if (!strproduce_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (produce_code ='" + strproduce_code + "') ";
            }

            if (!strbudget_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (budget_code ='" + strbudget_code + "') ";
            }

            if (!strdirector_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (director_code ='" + strdirector_code + "') ";
            }

            if (!strunit_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (unit_code ='" + strunit_code + "') ";
            }
            if (!stractivity_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (activity_code = '" + stractivity_code + "') ";
            }
            if (!strplan_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (plan_code = '" + strplan_code + "') ";
            }
            if (!strwork_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (work_code like '%" + strwork_code + "%') ";
            }
            if (!strwork_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (work_name like '%" + strwork_name + "%') ";
            }

            if (DirectorLock == "Y")
            {
                strCriteria += " and substring(director_code,4,2) = substring('" + DirectorCode + "',4,2) ";
            }

            #endregion

            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 (!oBudget_plan.SP_BUDGET_PLAN_SEL(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
            {
                oBudget_plan.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Exemplo n.º 5
0
        private void setData()
        {
            cBudget_plan oBudget_plan = new cBudget_plan();
            DataSet      ds = new DataSet();
            string       strMessage = string.Empty, strCriteria = string.Empty;
            string       strbudget_plan_code = string.Empty,
                         strdirector_code    = string.Empty,
                         strunit_code        = string.Empty,
                         strbudget_code      = string.Empty,
                         strproduce_code     = string.Empty,
                         stractivity_code    = string.Empty,
                         strplan_code        = string.Empty,
                         strwork_code        = string.Empty,
                         strfund_code        = string.Empty,
                         strYear        = string.Empty,
                         strC_active    = string.Empty,
                         strCreatedBy   = string.Empty,
                         strUpdatedBy   = string.Empty,
                         strCreatedDate = string.Empty,
                         strUpdatedDate = string.Empty;

            try
            {
                strCriteria = " and budget_plan_code = '" + ViewState["budget_plan_code"].ToString() + "' ";
                if (!oBudget_plan.SP_BUDGET_PLAN_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strbudget_plan_code = ds.Tables[0].Rows[0]["budget_plan_code"].ToString();
                        strdirector_code    = ds.Tables[0].Rows[0]["director_code"].ToString();
                        strunit_code        = ds.Tables[0].Rows[0]["unit_code"].ToString();
                        strbudget_code      = ds.Tables[0].Rows[0]["budget_code"].ToString();
                        strproduce_code     = ds.Tables[0].Rows[0]["produce_code"].ToString();
                        stractivity_code    = ds.Tables[0].Rows[0]["activity_code"].ToString();
                        strplan_code        = ds.Tables[0].Rows[0]["plan_code"].ToString();
                        strwork_code        = ds.Tables[0].Rows[0]["work_code"].ToString();
                        strfund_code        = ds.Tables[0].Rows[0]["fund_code"].ToString();
                        strYear             = ds.Tables[0].Rows[0]["budget_plan_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

                        InitcboYear();
                        if (cboYear.Items.FindByValue(strYear) != null)
                        {
                            cboYear.SelectedIndex = -1;
                            cboYear.Items.FindByValue(strYear).Selected = true;
                        }

                        InitcboDirector();
                        if (cboDirector.Items.FindByValue(strdirector_code) != null)
                        {
                            cboDirector.SelectedIndex = -1;
                            cboDirector.Items.FindByValue(strdirector_code).Selected = true;
                        }

                        InitcboUnit();
                        if (cboUnit.Items.FindByValue(strunit_code) != null)
                        {
                            cboUnit.SelectedIndex = -1;
                            cboUnit.Items.FindByValue(strunit_code).Selected = true;
                        }

                        InitcboBudget();
                        if (cboBudget.Items.FindByValue(strbudget_code) != null)
                        {
                            cboBudget.SelectedIndex = -1;
                            cboBudget.Items.FindByValue(strbudget_code).Selected = true;
                        }

                        InitcboProduce();
                        if (cboProduce.Items.FindByValue(strproduce_code) != null)
                        {
                            cboProduce.SelectedIndex = -1;
                            cboProduce.Items.FindByValue(strproduce_code).Selected = true;
                        }

                        InitcboActivity();
                        if (cboActivity.Items.FindByValue(stractivity_code) != null)
                        {
                            cboActivity.SelectedIndex = -1;
                            cboActivity.Items.FindByValue(stractivity_code).Selected = true;
                        }

                        InitcboPlan();
                        if (cboPlan_code.Items.FindByValue(strplan_code) != null)
                        {
                            cboPlan_code.SelectedIndex = -1;
                            cboPlan_code.Items.FindByValue(strplan_code).Selected = true;
                        }

                        InitcboWork();
                        if (cboWork.Items.FindByValue(strwork_code) != null)
                        {
                            cboWork.SelectedIndex = -1;
                            cboWork.Items.FindByValue(strwork_code).Selected = true;
                        }

                        InitcboFund();
                        if (cboFund.Items.FindByValue(strfund_code) != null)
                        {
                            cboFund.SelectedIndex = -1;
                            cboFund.Items.FindByValue(strfund_code).Selected = true;
                        }

                        cboYear.Enabled = false;

                        if (strC_active.Equals("Y"))
                        {
                            txtbudget_plan_code.ReadOnly = true;
                            txtbudget_plan_code.Text     = strbudget_plan_code;
                            txtbudget_plan_code.CssClass = "textboxdis";
                            chkStatus.Checked            = true;
                        }
                        else
                        {
                            txtbudget_plan_code.ReadOnly = true;
                            txtbudget_plan_code.Text     = strbudget_plan_code;
                            txtbudget_plan_code.CssClass = "textboxdis";
                            chkStatus.Checked            = false;
                        }

                        txtUpdatedBy.Text   = strUpdatedBy;
                        txtUpdatedDate.Text = strUpdatedDate;

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
Exemplo n.º 6
0
        private bool saveData()
        {
            //  InitcboYear();
            bool   blnResult           = false;
            bool   blnDup              = false;
            string strMessage          = string.Empty;
            string strbudget_plan_code = string.Empty,
                   strbudget_plan_year = string.Empty,
                   strunit_code        = string.Empty,
                   stractivity_code    = string.Empty,
                   strplan_code        = string.Empty,
                   strwork_code        = string.Empty,
                   strfund_code        = string.Empty,
                   strActive           = string.Empty,
                   strCreatedBy        = string.Empty,
                   strUpdatedBy        = string.Empty;
            string       strScript     = string.Empty;
            cBudget_plan oBudget_plan  = new cBudget_plan();
            DataSet      ds            = new DataSet();

            try
            {
                #region set Data
                strbudget_plan_code = txtbudget_plan_code.Text.Trim();
                strbudget_plan_year = cboYear.SelectedValue;
                strunit_code        = cboUnit.SelectedValue;
                stractivity_code    = cboActivity.SelectedValue;
                strplan_code        = cboPlan_code.SelectedValue;
                strwork_code        = cboWork.SelectedValue;
                strfund_code        = cboFund.SelectedValue;
                if (chkStatus.Checked == true)
                {
                    strActive = "Y";
                }
                else
                {
                    strActive = "N";
                }
                strCreatedBy = Session["username"].ToString();
                strUpdatedBy = Session["username"].ToString();
                #endregion

                string strCheckAdd = " and budget_plan_code = '" + strbudget_plan_code.Trim() + "' ";
                if (!oBudget_plan.SP_BUDGET_PLAN_SEL(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 unit_code='" + strunit_code + "' " +
                                      " and activity_code='" + stractivity_code + "' " +
                                      " and plan_code='" + strplan_code + "' " +
                                      " and work_code='" + strwork_code + "' " +
                                      " and fund_code='" + strfund_code + "' " +
                                      " and budget_plan_code <>'" + strbudget_plan_code + "' ";
                        if (!oBudget_plan.SP_BUDGET_PLAN_SEL(strCheckDup, ref ds, ref strMessage))
                        {
                            lblError.Text = strMessage;
                        }
                        else
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strScript =
                                    "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก ข้อมูลผังงบประมาณซ้ำ\");\n";
                                blnDup = true;
                            }
                        }
                        #endregion
                        #region edit
                        if (!blnDup)
                        {
                            if (oBudget_plan.SP_BUDGET_PLAN_UPD(strbudget_plan_code, strbudget_plan_year,
                                                                strunit_code, stractivity_code, strplan_code, strwork_code, strfund_code,
                                                                strActive, strUpdatedBy, this.BudgetType, 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 unit_code='" + strunit_code + "' " +
                                      " and activity_code='" + stractivity_code + "' " +
                                      " and plan_code='" + strplan_code + "' " +
                                      " and work_code='" + strwork_code + "' " +
                                      " and fund_code='" + strfund_code + "' ";
                        if (!oBudget_plan.SP_BUDGET_PLAN_SEL(strCheckDup, ref ds, ref strMessage))
                        {
                            lblError.Text = strMessage;
                        }
                        else
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strScript =
                                    "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก ข้อมูลผังงบประมาณซ้ำ\");\n";
                                blnDup = true;
                            }
                        }
                        #endregion
                        #region insert
                        if (!blnDup)
                        {
                            if (oBudget_plan.SP_BUDGET_PLAN_INS(strbudget_plan_year, strunit_code, stractivity_code, strplan_code,
                                                                strwork_code, strfund_code, strActive, strCreatedBy, this.BudgetType, ref strMessage))
                            {
                                string strGetcode = " and unit_code='" + strunit_code + "' " +
                                                    " and activity_code='" + stractivity_code + "' " +
                                                    " and plan_code='" + strplan_code + "' " +
                                                    " and work_code='" + strwork_code + "' " +
                                                    " and fund_code='" + strfund_code + "' ";

                                if (!oBudget_plan.SP_BUDGET_PLAN_SEL(strGetcode, ref ds, ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    strbudget_plan_code = ds.Tables[0].Rows[0]["budget_plan_code"].ToString();
                                }
                                ViewState["budget_plan_code"] = strbudget_plan_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
            {
                oBudget_plan.Dispose();
            }
            return(blnResult);
        }
Exemplo n.º 7
0
        private void setData()
        {
            cBudget_plan obudget_plan = new cBudget_plan();
            DataSet      ds = new DataSet();
            string       strMessage = string.Empty, strCriteria = string.Empty;
            string       strbudget_plan_code = string.Empty,
                         strunit_code        = string.Empty,
                         stractivity_code    = string.Empty,
                         strplan_code        = string.Empty,
                         strwork_code        = string.Empty,
                         strfund_code        = string.Empty,
                         strlot_code         = string.Empty,
                         strunit_name        = string.Empty,
                         strdirector_code    = string.Empty,
                         strdirector_name    = string.Empty,
                         stractivity_name    = string.Empty,
                         strproduce_code     = string.Empty,
                         strproduce_name     = string.Empty,
                         strbudget_code      = string.Empty,
                         strbudget_name      = string.Empty,
                         strplan_name        = string.Empty,
                         strwork_name        = string.Empty,
                         strfund_name        = string.Empty,
                         strlot_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 budget_plan_code = '" + ViewState["budget_plan_code"].ToString() + "' ";
                if (!obudget_plan.SP_BUDGET_PLAN_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strbudget_plan_code = ds.Tables[0].Rows[0]["budget_plan_code"].ToString();
                        strunit_code        = ds.Tables[0].Rows[0]["unit_code"].ToString();
                        strunit_name        = ds.Tables[0].Rows[0]["unit_name"].ToString();
                        stractivity_code    = ds.Tables[0].Rows[0]["activity_code"].ToString();
                        stractivity_name    = ds.Tables[0].Rows[0]["activity_name"].ToString();
                        strplan_code        = ds.Tables[0].Rows[0]["plan_code"].ToString();
                        strplan_name        = ds.Tables[0].Rows[0]["plan_name"].ToString();
                        strwork_code        = ds.Tables[0].Rows[0]["work_code"].ToString();
                        strwork_name        = ds.Tables[0].Rows[0]["work_name"].ToString();
                        strfund_code        = ds.Tables[0].Rows[0]["fund_code"].ToString();
                        strfund_name        = ds.Tables[0].Rows[0]["fund_name"].ToString();
                        //strlot_code = ds.Tables[0].Rows[0]["lot_code"].ToString();
                        //strlot_name = ds.Tables[0].Rows[0]["lot_name"].ToString();
                        strdirector_code = ds.Tables[0].Rows[0]["director_code"].ToString();
                        strdirector_name = ds.Tables[0].Rows[0]["director_name"].ToString();
                        strproduce_code  = ds.Tables[0].Rows[0]["produce_code"].ToString();
                        strproduce_name  = ds.Tables[0].Rows[0]["produce_name"].ToString();
                        strbudget_code   = ds.Tables[0].Rows[0]["budget_code"].ToString();
                        strbudget_name   = ds.Tables[0].Rows[0]["budget_name"].ToString();
                        strYear          = ds.Tables[0].Rows[0]["budget_plan_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
                        txtbudget_plan_code.Text = strbudget_plan_code;
                        txtunit_code.Text        = strunit_code;
                        txtunit_name.Text        = strunit_name;
                        txtactivity_code.Text    = stractivity_code;
                        txtactivity_name.Text    = stractivity_name;
                        txtplan_code.Text        = strplan_code;
                        txtplan_name.Text        = strplan_name;
                        txtwork_code.Text        = strwork_code;
                        txtwork_name.Text        = strwork_name;
                        txtfund_code.Text        = strfund_code;
                        txtfund_name.Text        = strfund_name;
                        //txtlot_code.Text = strlot_code;
                        //txtlot_name.Text = strlot_name;
                        txtdirector_code.Text = strdirector_code;
                        txtdirector_name.Text = strdirector_name;
                        txtproduce_code.Text  = strproduce_code;
                        txtproduce_name.Text  = strproduce_name;
                        txtbudget_code.Text   = strbudget_code;
                        txtbudget_name.Text   = strbudget_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();
            }
        }