Esempio 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();
            HiddenField        hdditem_group_detail_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_group_detail_id");
            cItem_group_detail oItem_group_detail      = new cItem_group_detail();

            try
            {
                if (!oItem_group_detail.SP_ITEM_GROUP_DETAIL_DEL(hdditem_group_detail_id.Value, 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
            {
                oItem_group_detail.Dispose();
            }
            BindGridView();
        }
Esempio 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();
            HiddenField        hdditem_group_detail_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_group_detail_id");
            cItem_group_detail oItem_group_detail      = new cItem_group_detail();

            try
            {
                if (!oItem_group_detail.SP_ITEM_GROUP_DETAIL_DEL(hdditem_group_detail_id.Value, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oItem_group_detail.Dispose();
            }
            BindGridView(0);
        }
Esempio n. 3
0
        private bool saveData()
        {
            bool               blnResult          = false;
            string             strMessage         = string.Empty;
            string             strScript          = string.Empty;
            Item_group_detail  item_group_detail  = new Item_group_detail();
            cItem_group_detail oItem_group_detail = new cItem_group_detail();
            DataSet            ds = new DataSet();

            try
            {
                #region set Data
                item_group_detail.item_group_detail_id   = string.IsNullOrEmpty(hdditem_group_detail_id.Value) ? 0 : int.Parse(hdditem_group_detail_id.Value);
                item_group_detail.item_group_detail_code = txtitem_group_detail_code.Text.Trim();
                item_group_detail.item_group_detail_name = txtitem_group_detail_name.Text.Trim();
                item_group_detail.item_group_code        = cboItemGroup.SelectedValue;
                item_group_detail.c_active     = chkStatus.Checked == true ? "Y" : "N";
                item_group_detail.c_created_by = Session["username"].ToString();
                item_group_detail.c_updated_by = Session["username"].ToString();
                #endregion

                string strCheckAdd = " and item_group_detail_id = '" + item_group_detail.item_group_detail_id + "' ";
                var    item        = oItem_group_detail.GET(strCheckAdd);
                if (item != null)
                {
                    blnResult = oItem_group_detail.SP_ITEM_GROUP_DETAIL_UPD(item_group_detail);
                }
                else
                {
                    blnResult = oItem_group_detail.SP_ITEM_GROUP_DETAIL_INS(item_group_detail);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    strScript = @"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก";
                    if (ex.Message.Contains("IX_item_group_detail_code"))
                    {
                        strScript += "ข้อมูลรหัสรายละเอียดหมวดค่าใช้จ่าย : " + txtitem_group_detail_code.Text + " ซ้ำ";
                    }
                    else if (ex.Message.Contains("IX_item_group_detail_name"))
                    {
                        strScript += "ข้อมูลรายละเอียดหมวดค่าใช้จ่าย : " + txtitem_group_detail_name.Text + " ซ้ำ";
                    }
                    MsgBox(strScript);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oItem_group_detail.Dispose();
            }
            return(blnResult);
        }
Esempio n. 4
0
        private void BindGridView()
        {
            cItem_group_detail oItem_group_detail = new cItem_group_detail();
            DataSet            ds                 = new DataSet();
            string             strMessage         = string.Empty;
            string             strCriteria        = string.Empty;
            string             stritem_group_code = string.Empty;

            stritem_group_code = cboItemGroup.SelectedValue;
            strCriteria        = strCriteria + "  And  (item_group_code = '" + stritem_group_code + "') ";
            try
            {
                if (!oItem_group_detail.SP_ITEM_GROUP_DETAIL_SEL(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
            {
                oItem_group_detail.Dispose();
                ds.Dispose();
            }
        }
Esempio n. 5
0
        private void BindGridView(int nPageNo)
        {
            InitcboYear();
            InitcboItem_group();

            cItem_group_detail oitem_group_detail = new cItem_group_detail();
            DataSet            ds          = new DataSet();
            string             strMessage  = string.Empty;
            string             strCriteria = string.Empty;
            string             stritem_group_detail_code = string.Empty;
            string             stritem_group_detail_name = string.Empty;
            string             strItem_group_code        = string.Empty;

            string strActive          = string.Empty;
            string stritem_group_year = string.Empty;

            stritem_group_detail_code = txtitem_group_detail_code.Text.Replace("'", "''").Trim();
            stritem_group_detail_name = txtitem_group_detail_name.Text.Replace("'", "''").Trim();
            stritem_group_year        = cboYear.SelectedValue;
            strItem_group_code        = cboItem_group.SelectedValue;
            if (!stritem_group_detail_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_detail_code like '%" + stritem_group_detail_code + "%') ";
            }
            if (!stritem_group_detail_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_detail_name like '%" + stritem_group_detail_name + "%')";
            }
            if (!stritem_group_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_year = '" + stritem_group_year + "') ";
            }
            if (!strItem_group_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (Item_group_code = '" + strItem_group_code + "') ";
            }

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

            try
            {
                if (!oitem_group_detail.SP_ITEM_GROUP_DETAIL_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_group_detail.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }