示例#1
0
        private void InitcboItem_acc()
        {
            cItem_acc oItem_acc        = new cItem_acc();
            string    strMessage       = string.Empty,
                      strCriteria      = string.Empty,
                      strItem_acc_code = string.Empty;

            strItem_acc_code = cboItem_acc.SelectedValue;
            string    strYear = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow"].ToString();
            int       i;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria = "and item_acc_year='" + strYear + "' and c_active='Y' ";
            if (oItem_acc.SP_ITEM_ACC_SEL(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboItem_acc.Items.Clear();
                cboItem_acc.Items.Add(new ListItem("---- กรุณาเลือกข้อมูล ----", ""));
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboItem_acc.Items.Add(new ListItem(dt.Rows[i]["Item_acc_name"].ToString(), dt.Rows[i]["item_acc_id"].ToString()));
                }
                if (cboItem_acc.Items.FindByValue(strItem_acc_code) != null)
                {
                    cboItem_acc.SelectedIndex = -1;
                    cboItem_acc.Items.FindByValue(strItem_acc_code).Selected = true;
                }
            }
        }
示例#2
0
        private void setData()
        {
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds = new DataSet();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    stritem_acc_code = string.Empty,
                      stritem_acc_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 item_acc_code = '" + ViewState["item_acc_code"].ToString() + "' ";
                if (!oItem_acc.SP_ITEM_ACC_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_code"].ToString();
                        stritem_acc_name = ds.Tables[0].Rows[0]["item_acc_name"].ToString();
                        strYear          = ds.Tables[0].Rows[0]["item_acc_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
                        txtitem_acc_code.Text = stritem_acc_code;
                        txtitem_acc_name.Text = stritem_acc_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();
            }
        }
示例#3
0
        private void BindGridView(int nPageNo)
        {
            cItem_acc oItem_acc        = new cItem_acc();
            DataSet   ds               = new DataSet();
            string    strMessage       = string.Empty;
            string    strCriteria      = string.Empty;
            string    stritem_acc_code = string.Empty;
            string    stritem_acc_name = string.Empty;
            string    strActive        = string.Empty;
            string    stritem_acc_year = string.Empty;

            stritem_acc_code = txtitem_acc_code.Text.Replace("'", "''").Trim();
            stritem_acc_name = txtitem_acc_name.Text.Replace("'", "''").Trim();
            stritem_acc_year = cboYear.SelectedValue;
            if (!stritem_acc_code.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (item_acc_code like '%" + stritem_acc_code + "%') ";
            }
            if (!stritem_acc_name.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (item_acc_name like '%" + stritem_acc_name + "%')";
            }
            if (!stritem_acc_year.Equals("0"))
            {
                strCriteria = strCriteria + "  And  (item_acc_year = '" + stritem_acc_year + "') ";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }


            try
            {
                if (!oItem_acc.SP_ITEM_ACC_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
            {
                oItem_acc.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
        private void setData()
        {
            cItem_acc oItem_acc = new cItem_acc();
            DataSet   ds = new DataSet();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    stritem_acc_code = string.Empty,
                      stritem_acc_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 item_acc_id = '" + ViewState["item_acc_id"].ToString() + "' ";
                if (!oItem_acc.SP_ITEM_ACC_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        #region get Data
                        stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_code"].ToString();
                        stritem_acc_name = ds.Tables[0].Rows[0]["item_acc_name"].ToString();
                        strYear          = ds.Tables[0].Rows[0]["item_acc_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
                        hdditem_acc_id.Value  = ds.Tables[0].Rows[0]["item_acc_id"].ToString();
                        txtitem_acc_code.Text = stritem_acc_code;
                        txtitem_acc_name.Text = stritem_acc_name;
                        InitcboYear();
                        if (cboYear.Items.FindByValue(strYear) != null)
                        {
                            cboYear.SelectedIndex = -1;
                            cboYear.Items.FindByValue(strYear).Selected = true;
                        }
                        if (strC_active.Equals("Y"))
                        {
                            txtitem_acc_name.ReadOnly = false;
                            txtitem_acc_name.CssClass = "textbox";
                            chkStatus.Checked         = true;
                        }
                        else
                        {
                            txtitem_acc_name.ReadOnly = true;
                            txtitem_acc_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();
            }
        }
        private bool saveData()
        {
            bool   blnResult        = false;
            bool   blnDup           = false;
            string strMessage       = string.Empty;
            string stritem_acc_code = string.Empty,
                   stritem_acc_year = string.Empty,
                   stritem_acc_name = string.Empty,
                   strActive        = string.Empty,
                   strCreatedBy     = string.Empty,
                   strUpdatedBy     = string.Empty;
            string    strScript     = string.Empty;
            cItem_acc oItem_acc     = new cItem_acc();
            DataSet   ds            = new DataSet();

            try
            {
                #region set Data
                stritem_acc_code = txtitem_acc_code.Text.Trim();
                stritem_acc_name = txtitem_acc_name.Text;
                stritem_acc_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 (oItem_acc.SP_ITEM_ACC_UPD(hdditem_acc_id.Value.ToString(), stritem_acc_code,
                                                      stritem_acc_year, stritem_acc_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 item_acc_name = '" + stritem_acc_name.Trim() + "' and item_acc_year = '" + stritem_acc_year + "' ";
                    if (!oItem_acc.SP_ITEM_ACC_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + stritem_acc_name.Trim() + " ปี " + stritem_acc_year.Trim() + "  ซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    #region insert
                    if (!blnDup)
                    {
                        if (oItem_acc.SP_ITEM_ACC_INS(stritem_acc_year, stritem_acc_code, stritem_acc_name, strActive, strCreatedBy, ref strMessage))
                        {
                            string strGetcode = " and item_acc_name = '" + stritem_acc_name.Trim() + "' and item_acc_year = '" + stritem_acc_year + "' ";
                            if (!oItem_acc.SP_ITEM_ACC_SEL(strGetcode, ref ds, ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                stritem_acc_code = ds.Tables[0].Rows[0]["item_acc_id"].ToString();
                            }
                            ViewState["item_acc_id"] = stritem_acc_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
            {
                oItem_acc.Dispose();
            }
            return(blnResult);
        }