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    lblproduce_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblproduce_code");
            cProduce oproduce        = new cProduce();

            try
            {
                if (!oproduce.SP_DEL_PRODUCE(lblproduce_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
            {
                oproduce.Dispose();
            }
            BindGridView();
        }
        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    lblproduce_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblproduce_code");
            cProduce oproduce        = new cProduce();

            try
            {
                if (!oproduce.SP_DEL_PRODUCE(lblproduce_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oproduce.Dispose();
            }
            BindGridView(0);
        }
        private void BindGridView()
        {
            cProduce oproduce       = new cProduce();
            DataSet  ds             = new DataSet();
            string   strMessage     = string.Empty;
            string   strCriteria    = string.Empty;
            string   strbudget_code = string.Empty;

            strbudget_code = cboBudget.SelectedValue;
            strCriteria    = strCriteria + "  And  (produce.budget_code = '" + strbudget_code + "') ";
            try
            {
                if (!oproduce.SP_SEL_PRODUCE(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
            {
                //if (this.BudgetType == "R")
                //{
                //    foreach (Control c in GridView1.Controls)
                //    {
                //        base.SetLabel(c, old_str, new_str);
                //        base.SetLabel(c, "แผนงบประมาณ", "แผนงาน");
                //    }
                //}

                oproduce.Dispose();
                ds.Dispose();
            }
        }
Exemple #4
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    lblproduce_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblproduce_code");
            cProduce oproduce        = new cProduce();

            try
            {
                if (!oproduce.SP_DEL_PRODUCE(lblproduce_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    if (strMessage.Contains("REFERENCE constraint"))
                    {
                        MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                    }
                    else
                    {
                        lblError.Text = strMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oproduce.Dispose();
            }
            BindGridView(0);
        }
        private bool saveData()
        {
            // InitcboYear();
            //  InitcboBudget();
            bool   blnResult       = false;
            bool   blnDup          = false;
            string strMessage      = string.Empty;
            string strproduce_code = string.Empty,
                   strproduce_year = string.Empty,
                   strproduce_name = string.Empty,
                   strbudget_code  = string.Empty,
                   strActive       = string.Empty,
                   strCreatedBy    = string.Empty,
                   strUpdatedBy    = string.Empty;
            string   strScript     = string.Empty;
            cProduce oProduce      = new cProduce();
            DataSet  ds            = new DataSet();

            try
            {
                #region set Data
                strproduce_code = txtproduce_code.Text;
                strproduce_name = txtproduce_name.Text;
                //produce_year
                strproduce_year = cboYear.SelectedValue;
                //budget_code
                strbudget_code = cboBudget.SelectedValue;
                if (Request.Form["ctl00$ASPxRoundPanel1$ContentPlaceHolder1$cboBudget"] != null)
                {
                    strbudget_code = Request.Form["ctl00$ASPxRoundPanel1$ContentPlaceHolder1$cboBudget"].ToString();
                }
                if (chkStatus.Checked == true)
                {
                    strActive = "Y";
                }
                else
                {
                    strActive = "N";
                }
                strCreatedBy = Session["username"].ToString();
                strUpdatedBy = Session["username"].ToString();
                #endregion

                string strCheckAdd = " and produce.produce_code = '" + strproduce_code.Trim() + "' ";
                if (!oProduce.SP_SEL_PRODUCE(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 produce.produce_name = '" + strproduce_name.Trim() + "' and produce.produce_year = '" + strproduce_year.Trim() + "' " +
                                      " and produce.budget_code='" + strbudget_code.Trim() + "'  and  produce.produce_code <> '" + strproduce_code.Trim() + "' ";
                        if (!oProduce.SP_SEL_PRODUCE(strCheckDup, ref ds, ref strMessage))
                        {
                            lblError.Text = strMessage;
                        }
                        else
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strScript =
                                    "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก" +
                                    "\\nข้อมูล : " + strproduce_name.Trim() +
                                    "\\nข้อมูล : " + cboBudget.SelectedItem.Text +
                                    "\\n ปี : " + strproduce_year.Trim() +
                                    "\\nซ้ำ\");\n";
                                blnDup = true;
                            }
                        }
                        #endregion
                        #region edit
                        if (!blnDup)
                        {
                            if (oProduce.SP_UPD_PRODUCE(strproduce_code, strproduce_year, strproduce_name, strbudget_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 produce.produce_name = '" + strproduce_name.Trim() + "' and produce.produce_year = '" + strproduce_year + "' " +
                                      " and produce.budget_code='" + strbudget_code.Trim() + "' ";
                        if (!oProduce.SP_SEL_PRODUCE(strCheckDup, ref ds, ref strMessage))
                        {
                            lblError.Text = strMessage;
                        }
                        else
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strScript =
                                    "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" +
                                    "\\nข้อมูล : " + strproduce_name.Trim() +
                                    "\\nข้อมูล : " + cboBudget.SelectedItem.Text +
                                    "\\n ปี : " + strproduce_year.Trim() +
                                    "\\nซ้ำ\");\n";
                                blnDup = true;
                            }
                        }
                        #endregion
                        #region insert
                        if (!blnDup)
                        {
                            if (oProduce.SP_INS_PRODUCE(strproduce_year, strproduce_name, strbudget_code, strActive, strCreatedBy, this.BudgetType, ref strMessage))
                            {
                                string strGetcode = " and produce_name = '" + strproduce_name.Trim() + "' and produce_year = '" + strproduce_year + "' " +
                                                    " and produce.budget_code='" + strbudget_code.Trim() + "' ";
                                if (!oProduce.SP_SEL_PRODUCE(strGetcode, ref ds, ref strMessage))
                                {
                                    lblError.Text = strMessage;
                                }
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    strproduce_code = ds.Tables[0].Rows[0]["produce_code"].ToString();
                                }
                                ViewState["produce_code"] = strproduce_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
            {
                oProduce.Dispose();
            }
            return(blnResult);
        }
Exemple #6
0
        private void BindGridView(int nPageNo)
        {
            InitcboYear();
            InitcboBudget();

            cProduce oproduce        = new cProduce();
            DataSet  ds              = new DataSet();
            string   strMessage      = string.Empty;
            string   strCriteria     = string.Empty;
            string   strproduce_code = string.Empty;
            string   strproduce_name = string.Empty;
            string   strbudget_code  = string.Empty;

            string strActive       = string.Empty;
            string strproduce_year = string.Empty;

            strproduce_code = txtproduce_code.Text.Replace("'", "''").Trim();
            strproduce_name = txtproduce_name.Text.Replace("'", "''").Trim();
            strproduce_year = cboYear.SelectedValue;
            if (cboBudget.SelectedValue != "")
            {
                strbudget_code = cboBudget.SelectedValue;
            }
            else
            {
                strbudget_code = "";
            }
            if (!strproduce_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (produce.produce_code like '%" + strproduce_code + "%') ";
            }
            if (!strproduce_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (produce.produce_name like '%" + strproduce_name + "%')";
            }
            if (!strproduce_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (produce.produce_year = '" + strproduce_year + "') ";
            }
            if (!strbudget_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (produce.budget_code = '" + strbudget_code + "') ";
            }

            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (produce.c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (produce.c_active ='N') ";
            }

            strCriteria = strCriteria + "  And produce.budget_type ='" + this.BudgetType + "' ";

            try
            {
                if (!oproduce.SP_SEL_PRODUCE(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
            {
                oproduce.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
                //if (this.BudgetType == "R")
                //{
                //    foreach (Control c in GridView1.Controls)
                //    {
                //        base.SetLabel(c, old_str, new_str);
                //        base.SetLabel(c, "แผนงบประมาณ ", "แผนงาน(เงินรายได้)");
                //    }
                //}
            }
        }