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_detail_id = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdditem_detail_id");
            cItem_detail oItem_detail      = new cItem_detail();

            try
            {
                if (!oItem_detail.SP_ITEM_DETAIL_DEL(hdditem_detail_id.Value, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oItem_detail.Dispose();
            }
            BindGridView(0);
        }
示例#2
0
        private bool saveData()
        {
            bool         blnResult    = false;
            string       strMessage   = string.Empty;
            string       strScript    = string.Empty;
            Item_detail  item_detail  = new Item_detail();
            cItem_detail oItem_detail = new cItem_detail();
            DataSet      ds           = new DataSet();

            try
            {
                #region set Data
                item_detail.item_detail_id   = string.IsNullOrEmpty(hdditem_detail_id.Value) ? 0 : int.Parse(hdditem_detail_id.Value);
                item_detail.item_detail_code = txtitem_detail_code.Text.Trim();
                item_detail.item_detail_name = txtitem_detail_name.Text.Trim();
                item_detail.item_code        = cboItem.SelectedValue;
                item_detail.c_active         = chkStatus.Checked == true ? "Y" : "N";
                item_detail.c_created_by     = Session["username"].ToString();
                item_detail.c_updated_by     = Session["username"].ToString();
                #endregion

                string strCheckAdd = " and item_detail_id = '" + item_detail.item_detail_id + "' ";
                var    item        = oItem_detail.GET(strCheckAdd);
                if (item != null)
                {
                    blnResult = oItem_detail.SP_ITEM_DETAIL_UPD(item_detail);
                }
                else
                {
                    blnResult = oItem_detail.SP_ITEM_DETAIL_INS(item_detail);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    strScript = @"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก";
                    if (ex.Message.Contains("IX_item_code"))
                    {
                        strScript += "ข้อมูลรหัสรายละเอียดค่าใช้จ่าย : " + txtitem_detail_code.Text + " ซ้ำ";
                    }
                    else if (ex.Message.Contains("IX_item_name"))
                    {
                        strScript += "ข้อมูลรายละเอียดค่าใช้จ่าย : " + txtitem_detail_name.Text + " ซ้ำ";
                    }
                    MsgBox(strScript);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oItem_detail.Dispose();
            }
            return(blnResult);
        }
示例#3
0
        private void setData()
        {
            cItem_detail oItem_detail = new cItem_detail();
            string       strMessage = string.Empty, strCriteria = string.Empty;

            try
            {
                strCriteria = " and item_detail_id = '" + ViewState["item_detail_id"].ToString() + "' ";
                var item = oItem_detail.GET(strCriteria);
                if (item != null)
                {
                    hdditem_detail_id.Value  = item.item_detail_id.ToString();
                    txtitem_detail_code.Text = item.item_detail_code;
                    txtitem_detail_name.Text = item.item_detail_name;
                    InitcboYear();
                    if (cboYear.Items.FindByValue(item.item_year) != null)
                    {
                        cboYear.SelectedIndex = -1;
                        cboYear.Items.FindByValue(item.item_year).Selected = true;
                    }

                    InitcboItem_group();
                    if (cboItem_group.Items.FindByValue(item.item_group_code) != null)
                    {
                        cboItem_group.SelectedIndex = -1;
                        cboItem_group.Items.FindByValue(item.item_group_code).Selected = true;
                    }

                    InitcboItem_group_detail();
                    if (cboItem_group_detail.Items.FindByValue(item.item_group_detail_id.ToString()) != null)
                    {
                        cboItem_group_detail.SelectedIndex = -1;
                        cboItem_group_detail.Items.FindByValue(item.item_group_detail_id.ToString()).Selected = true;
                    }

                    InitcboItem();
                    if (cboItem.Items.FindByValue(item.item_code) != null)
                    {
                        cboItem.SelectedIndex = -1;
                        cboItem.Items.FindByValue(item.item_code).Selected = true;
                    }
                    chkStatus.Checked   = item.c_active == "Y";
                    txtUpdatedBy.Text   = item.c_updated_by;
                    txtUpdatedDate.Text = item.d_created_date.ToString();
                    BindGridView();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
        protected void lbkRefresh_Click(object sender, EventArgs e)
        {
            cItem_detail oItem_detail = new cItem_detail();
            string       strMessage = string.Empty, strCriteria = string.Empty;

            try
            {
                strCriteria = " and item_detail_id = '" + hdditem_detail_id.Value.ToString() + "' ";
                var item = oItem_detail.GET(strCriteria);
                if (item != null)
                {
                    hdditem_detail_id.Value  = item.item_detail_id.ToString();
                    txtitem_detail_code.Text = item.item_detail_code;
                    txtitem_detail_name.Text = item.item_detail_name;

                    InitcboLot();
                    if (cboLot.Items.FindByValue(item.lot_code) != null)
                    {
                        cboLot.SelectedIndex = -1;
                        cboLot.Items.FindByValue(item.lot_code).Selected = true;
                    }

                    InitcboItem_group();
                    if (cboItem_group.Items.FindByValue(item.item_group_code) != null)
                    {
                        cboItem_group.SelectedIndex = -1;
                        cboItem_group.Items.FindByValue(item.item_group_code).Selected = true;
                    }

                    InitcboItemGroupDetail();
                    if (cboItem_group_detail.Items.FindByValue(item.item_group_detail_id.ToString()) != null)
                    {
                        cboItem_group_detail.SelectedIndex = -1;
                        cboItem_group_detail.Items.FindByValue(item.item_group_detail_id.ToString()).Selected = true;
                    }
                    txtitem_detail_code.Text = item.item_detail_code;
                    txtitem_detail_name.Text = item.item_detail_name;
                    txtitem_name.Text        = item.item_name;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }
示例#5
0
        private void BindGridView()
        {
            cItem_detail oItem_detail = new cItem_detail();
            DataSet      ds           = new DataSet();
            string       strMessage   = string.Empty;
            string       strCriteria  = string.Empty;
            string       stritem_code = string.Empty;

            stritem_code = cboItem.SelectedValue;
            strCriteria  = strCriteria + "  And  (item_code = '" + stritem_code + "') ";
            try
            {
                if (!oItem_detail.SP_ITEM_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_detail.Dispose();
                ds.Dispose();
            }
        }
示例#6
0
        private void BindGridView()
        {
            cItem_detail     oItem_detail = new cItem_detail();
            DataSet          ds           = new DataSet();
            string           strMessage   = string.Empty;
            string           strCriteria  = string.Empty;
            view_Item_detail item         = new view_Item_detail();
            string           strScript    = string.Empty;

            if (this.BudgetType == "B")
            {
                item.item_year = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow"].ToString();
            }
            else
            {
                item.item_year = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow2"].ToString();
            }
            item.item_group_type      = cboItem_type.SelectedValue;
            item.lot_code             = cboLot.SelectedValue;
            item.item_group_code      = cboItem_group.SelectedValue;
            item.item_group_detail_id = string.IsNullOrEmpty(cboItem_group_detail.SelectedValue) ? 0 : int.Parse(cboItem_group_detail.SelectedValue);
            item.item_code            = cboItem.SelectedValue;
            item.item_detail_code     = txtitem_detail_code.Text.Replace("'", "''").Trim();
            item.item_detail_name     = txtitem_detail_name.Text.Replace("'", "''").Trim();

            if (!item.item_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_year = '" + item.item_year + "') ";
            }
            if (!item.item_group_type.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_type = '" + item.item_group_type + "') ";
            }
            if (!item.lot_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (lot_code = '" + item.lot_code + "') ";
            }
            if (!item.item_group_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_code = '" + item.item_group_code + "') ";
            }
            if (item.item_group_detail_id.GetValueOrDefault() > 0)
            {
                strCriteria = strCriteria + "  And  (item_group_detail_id = '" + item.item_group_detail_id.GetValueOrDefault() + "') ";
            }
            if (!item.item_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_code = '" + item.item_code + "') ";
            }

            if (!item.item_detail_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_detail_code like '%" + item.item_detail_code + "%') ";
            }
            if (!item.item_detail_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_detail_name like '%" + item.item_detail_name + "%') ";
            }
            strCriteria = strCriteria + "  And  (c_active ='Y') ";

            try
            {
                if (oItem_detail.SP_ITEM_DETAIL_SEL(strCriteria, ref ds, ref strMessage))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        var stritem_detail_id = ds.Tables[0].Rows[0]["item_detail_id"].ToString();
                        if (ViewState["from_page"].ToString().Equals("budget_money_detail_control"))
                        {
                            if (!string.IsNullOrEmpty(ViewState["hdditem_detail_id"].ToString()))
                            {
                                strScript += "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].document.getElementById('" + ViewState["hdditem_detail_id"].ToString() + "').value='" + stritem_detail_id + "';\n ";
                            }
                            if (!string.IsNullOrEmpty(ViewState["lbkRefresh"].ToString()))
                            {
                                strScript += "window.parent.frames['iframeShow" + (int.Parse(ViewState["show"].ToString()) - 1) + "'].__doPostBack('" + ViewState["lbkRefresh"].ToString() + "','');";
                            }
                            strScript += "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
            {
                oItem_detail.Dispose();
                ds.Dispose();
            }
        }
        private void BindGridView(int nPageNo)
        {
            cItem_detail     oitem_detail = new cItem_detail();
            DataSet          ds           = new DataSet();
            string           strMessage   = string.Empty;
            string           strCriteria  = string.Empty;
            view_Item_detail item_detail  = new view_Item_detail();

            item_detail.item_detail_code     = txtitem_detail_code.Text.Replace("'", "''").Trim();
            item_detail.item_detail_name     = txtitem_detail_name.Text.Replace("'", "''").Trim();
            item_detail.item_year            = cboYear.SelectedValue;
            item_detail.item_code            = cboItem.SelectedValue;
            item_detail.item_group_code      = cboItem_group.SelectedValue;
            item_detail.item_group_detail_id = string.IsNullOrEmpty(cboItem_group_detail.SelectedValue) ? 0 : int.Parse(cboItem_group_detail.SelectedValue);

            if (!item_detail.item_detail_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_detail_code like '%" + item_detail.item_detail_code + "%') ";
            }
            if (!item_detail.item_detail_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_detail_name like '%" + item_detail.item_detail_name + "%')";
            }
            if (!item_detail.item_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_year = '" + item_detail.item_year + "') ";
            }
            if (!item_detail.item_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_code = '" + item_detail.item_code + "') ";
            }
            if (!item_detail.item_group_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (item_group_code = '" + item_detail.item_group_code + "') ";
            }
            if (item_detail.item_group_detail_id > 0)
            {
                strCriteria = strCriteria + "  And  (item_group_detail_id = '" + item_detail.item_group_detail_id + "') ";
            }

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

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