Exemplo n.º 1
0
        private void InitcboPlan()
        {
            cPlan  oPlan        = new cPlan();
            string strMessage   = string.Empty,
                   strCriteria  = string.Empty,
                   strplan_code = string.Empty;
            string strYear      = cboYear.SelectedValue;

            strplan_code = cboPlan_code.SelectedValue;
            int       i;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria = " and plan_year = '" + strYear + "'  and  c_active='Y' ";
            strCriteria = strCriteria + "  And budget_type ='" + this.BudgetType + "' ";
            if (oPlan.SP_SEL_PLAN(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboPlan_code.Items.Clear();
                cboPlan_code.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", ""));
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboPlan_code.Items.Add(new ListItem(dt.Rows[i]["plan_name"].ToString(), dt.Rows[i]["plan_code"].ToString()));
                }
                if (cboPlan_code.Items.FindByValue(strplan_code) != null)
                {
                    cboPlan_code.SelectedIndex = -1;
                    cboPlan_code.Items.FindByValue(strplan_code).Selected = true;
                }
            }
        }
Exemplo n.º 2
0
        private void setData()
        {
            cPlan   oPlan = new cPlan();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  strplan_code   = string.Empty,
                    strplan_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 plan_code = '" + ViewState["plan_code"].ToString() + "' ";
                if (!oPlan.SP_SEL_PLAN(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strplan_code   = ds.Tables[0].Rows[0]["plan_code"].ToString();
                        strplan_name   = ds.Tables[0].Rows[0]["plan_name"].ToString();
                        strYear        = ds.Tables[0].Rows[0]["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
                        txtplan_code.Text = strplan_code;
                        txtplan_name.Text = strplan_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();
            }
        }
Exemplo n.º 3
0
        private void setData()
        {
            cPlan   oPlan = new cPlan();
            DataSet ds = new DataSet();
            string  strMessage = string.Empty, strCriteria = string.Empty;
            string  strplan_code   = string.Empty,
                    strplan_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 plan_code = '" + ViewState["plan_code"].ToString() + "' ";
                if (!oPlan.SP_SEL_PLAN(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        strplan_code   = ds.Tables[0].Rows[0]["plan_code"].ToString();
                        strplan_name   = ds.Tables[0].Rows[0]["plan_name"].ToString();
                        strYear        = ds.Tables[0].Rows[0]["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
                        txtplan_code.Text = strplan_code;
                        txtplan_name.Text = strplan_name;
                        InitcboYear();
                        if (cboYear.Items.FindByValue(strYear) != null)
                        {
                            cboYear.SelectedIndex = -1;
                            cboYear.Items.FindByValue(strYear).Selected = true;
                        }
                        if (strC_active.Equals("Y"))
                        {
                            txtplan_name.ReadOnly = false;
                            txtplan_name.CssClass = "textbox";
                            chkStatus.Checked     = true;
                        }
                        else
                        {
                            txtplan_name.ReadOnly = true;
                            txtplan_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();
            }
        }
Exemplo n.º 4
0
        private bool saveData()
        {
            bool   blnResult    = false;
            bool   blnDup       = false;
            string strMessage   = string.Empty;
            string strplan_code = string.Empty,
                   strplan_year = string.Empty,
                   strplan_name = string.Empty,
                   strActive    = string.Empty,
                   strCreatedBy = string.Empty,
                   strUpdatedBy = string.Empty;
            string  strScript   = string.Empty;
            cPlan   oPlan       = new cPlan();
            DataSet ds          = new DataSet();

            try
            {
                #region set Data
                strplan_code = txtplan_code.Text.Trim();
                strplan_name = txtplan_name.Text;
                strplan_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 (oPlan.SP_UPD_PLAN(strplan_code, strplan_year, strplan_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 plan_name = '" + strplan_name.Trim() + "' and plan_year = '" + strplan_year + "' ";
                    if (!oPlan.SP_SEL_PLAN(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + strplan_name.Trim() + " ปี " + strplan_year.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oPlan.SP_INS_PLAN(strplan_year, strplan_name, strActive, strCreatedBy, this.BudgetType, ref strMessage))
                        {
                            string strGetcode = " and plan_name = '" + strplan_name.Trim() + "' and plan_year = '" + strplan_year + "' ";
                            if (!oPlan.SP_SEL_PLAN(strGetcode, ref ds, ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                strplan_code = ds.Tables[0].Rows[0]["plan_code"].ToString();
                            }
                            ViewState["plan_code"] = strplan_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
            {
                oPlan.Dispose();
            }
            return(blnResult);
        }
Exemplo n.º 5
0
        private void BindGridView(int nPageNo)
        {
            cPlan   oPlan        = new cPlan();
            DataSet ds           = new DataSet();
            string  strMessage   = string.Empty;
            string  strCriteria  = string.Empty;
            string  strplan_code = string.Empty;
            string  strplan_name = string.Empty;
            string  strActive    = string.Empty;
            string  strplan_year = string.Empty;

            strplan_code = txtplan_code.Text.Replace("'", "''").Trim();
            strplan_name = txtplan_name.Text.Replace("'", "''").Trim();
            strplan_year = cboYear.SelectedValue;
            if (!strplan_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (plan_code like '%" + strplan_code + "%') ";
            }
            if (!strplan_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (plan_name like '%" + strplan_name + "%')";
            }
            if (!strplan_year.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (plan_year = '" + strplan_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 (!oPlan.SP_SEL_PLAN(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
            {
                //if (this.BudgetType == "R")
                //{
                //    foreach (Control c in Page.Controls)
                //    {
                //        base.SetLabel(c, "แผนงาน", "งานย่อย");
                //    }
                //}
                oPlan.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Exemplo n.º 6
0
        private void BindGridView()
        {
            cPlan   oplan        = new cPlan();
            DataSet ds           = new DataSet();
            string  strMessage   = string.Empty;
            string  strCriteria  = string.Empty;
            string  strplan_code = string.Empty;
            string  strplan_name = string.Empty;
            string  strScript    = string.Empty;
            string  strplan_year = string.Empty;

            strplan_code = txtplan_code.Text.Replace("'", "''").Trim();
            strplan_name = txtplan_name.Text.Replace("'", "''").Trim();
            strplan_year = txtplan_year.Text.Replace("'", "''").Trim();;
            if (!strplan_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (plan_code like '%" + strplan_code + "%') ";
            }
            if (!strplan_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (plan_name like '%" + strplan_name + "%')";
            }
            if (!strplan_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (plan_year = '" + strplan_year + "') ";
            }
            strCriteria = strCriteria + "  And  (c_active ='Y') ";
            try
            {
                if (oplan.SP_SEL_PLAN(strCriteria, ref ds, ref strMessage))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        strplan_code = ds.Tables[0].Rows[0]["plan_code"].ToString();
                        strplan_name = ds.Tables[0].Rows[0]["plan_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='" + strplan_code + "';\n " +
                                        "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["ctrl2"].ToString() + "').value='" + strplan_name + "';\n" +
                                        "ClosePopUp('" + ViewState["show"].ToString() + "');";
                        }
                        else
                        {
                            strScript = "window.parent.document.forms[0]." + ViewState["ctrl1"].ToString() + ".value='" + strplan_code + "';\n " +
                                        "window.parent.document.forms[0]." + ViewState["ctrl2"].ToString() + ".value='" + strplan_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
            {
                oplan.Dispose();
                ds.Dispose();
            }
        }