Ejemplo n.º 1
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.º 2
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();
            }
        }