Ejemplo 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();
            Label      lblrecv_item_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblrecv_item_code");
            cRecv_item oRecv_item        = new cRecv_item();

            try
            {
                oRecv_item.SP_RECV_ITEM_DEL(lblrecv_item_code.Text);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains(" REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oRecv_item.Dispose();
            }
            BindGridView(0);
        }
Ejemplo n.º 2
0
        private bool saveData()
        {
            bool       blnResult  = false;
            string     strScript  = string.Empty;
            cRecv_item oRecv_Item = new cRecv_item();
            DataSet    ds         = new DataSet();

            try
            {
                #region set Data
                var recv_item = new Recv_item()
                {
                    recv_item_code        = txtrecv_item_code.Text.Trim(),
                    recv_item_name        = txtrecv_item_name.Text,
                    recv_item_remark      = txtrecv_item_remark.Text.Trim(),
                    recv_item_year        = cboYear.SelectedItem.Value,
                    recv_item_rate        = decimal.Parse(txtrecv_item_rate.Value.ToString()),
                    recv_item_is_director = chkRecv_item_is_director.Checked,
                    recv_item_type        = cboRecv_item_type.SelectedValue,
                    c_active     = chkStatus.Checked ? "Y" : "N",
                    c_created_by = Session["username"].ToString(),
                    c_updated_by = Session["username"].ToString()
                };
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    oRecv_Item.SP_RECV_ITEM_UPD(recv_item);
                }
                else
                {
                    oRecv_Item.SP_RECV_ITEM_INS(recv_item);
                }
                blnResult = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("duplicate key"))
                {
                    strScript = @"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก";
                    //if (ex.Message.Contains("IX_recv_item_group_detail_code"))
                    //{
                    //    strScript += "ข้อมูลรหัสรายละเอียดหมวดค่าใช้จ่าย : " + txtrecv_item_group_detail_code.Text + " ซ้ำ";
                    //}
                    //else if (ex.Message.Contains("IX_recv_item_group_detail_name"))
                    //{
                    //    strScript += "ข้อมูลรายละเอียดหมวดค่าใช้จ่าย : " + txtrecv_item_group_detail_name.Text + " ซ้ำ";
                    //}
                    MsgBox(strScript);
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oRecv_Item.Dispose();
            }
            return(blnResult);
        }
Ejemplo n.º 3
0
        private void BindGridView(int nPageNo)
        {
            InitcboYear();
            cRecv_item oRecv_item  = new cRecv_item();
            DataSet    ds          = new DataSet();
            string     strMessage  = string.Empty;
            string     strCriteria = string.Empty;
            var        recv_item   = new Recv_item
            {
                recv_item_year = cboYear.SelectedValue,
                recv_item_code = txtrecv_item_code.Text.Replace("'", "''").Trim(),
                recv_item_name = txtrecv_item_name.Text.Replace("'", "''").Trim(),
            };

            if (!recv_item.recv_item_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_year = '" + recv_item.recv_item_year + "') ";
            }
            if (!recv_item.recv_item_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_code like '%" + recv_item.recv_item_code + "%') ";
            }
            if (!recv_item.recv_item_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_name like '%" + recv_item.recv_item_name + "%') ";
            }
            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  (c_active ='N') ";
            }

            try
            {
                if (!oRecv_item.SP_RECV_ITEM_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
            {
                oRecv_item.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
Ejemplo n.º 4
0
        private void BindGridView()
        {
            cRecv_item oRecv_item  = new cRecv_item();
            DataSet    ds          = new DataSet();
            string     strMessage  = string.Empty;
            string     strCriteria = string.Empty;
            var        recv_item   = new Recv_item();
            string     strScript   = string.Empty;

            recv_item.recv_item_year = ViewState["recv_item_year"].ToString();
            recv_item.recv_item_code = txtrecv_item_code.Text.Replace("'", "''").Trim();
            recv_item.recv_item_name = txtrecv_item_name.Text.Replace("'", "''").Trim();
            recv_item.recv_item_type = cboRecv_item_type.SelectedValue;;

            if (!recv_item.recv_item_year.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_year = '" + recv_item.recv_item_year + "') ";
            }
            if (!recv_item.recv_item_code.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_code = '" + recv_item.recv_item_code + "') ";
            }

            if (!recv_item.recv_item_name.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_name = '" + recv_item.recv_item_name + "') ";
            }

            if (!recv_item.recv_item_type.Equals(""))
            {
                strCriteria = strCriteria + "  And  (recv_item_type = '" + recv_item.recv_item_type + "') ";
            }

            if (ViewState["deduct_doc"] != null)
            {
                strCriteria = strCriteria + "  And  recv_item_code NOT IN (SELECT recv_item_code from Deduct_detail WHERE deduct_doc_no = '" + ViewState["deduct_doc"].ToString() + "') ";
            }

            try
            {
                if (oRecv_item.SP_RECV_ITEM_SEL(strCriteria, ref ds, ref strMessage))
                {
                    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
            {
                oRecv_item.Dispose();
                ds.Dispose();
            }
        }