예제 #1
0
        // Loc Danh Sach Phieu Xuat Hang
        public List <PhieuXuatHang> LocDanhSachPhieuXuatHang(PhieuXuatHang px)
        {
            try
            {
                OpenConnection();
                List <PhieuXuatHang> pxlist     = new List <PhieuXuatHang>();
                SqlCommand           sqlCommand = new SqlCommand();
                sqlCommand.CommandType = CommandType.Text;
                SqlDataReader sqlReader = null;
                DataTable     dt        = new DataTable();

                if (px.Search == "Mã Phiếu Xuất")
                {
                    sqlCommand.CommandText = "SELECT MAPX FROM dbo.PHIEUXUAT";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();

                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        PhieuXuatHang pxh = new PhieuXuatHang();
                        pxh.MaPx = int.Parse(dt.Rows[i][0].ToString());

                        pxlist.Add(pxh);
                    }
                }
                else if (px.Search == "Mã Nhân Viên")
                {
                    sqlCommand.CommandText = "SELECT DISTINCT(MANV) FROM dbo.PHIEUXUAT";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();

                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        PhieuXuatHang pxh = new PhieuXuatHang();
                        pxh.MaNv = int.Parse(dt.Rows[i][0].ToString());

                        pxlist.Add(pxh);
                    }
                }
                else if (px.Search == "Mã Khách Hàng")
                {
                    sqlCommand.CommandText = "SELECT DISTINCT(MAKH) FROM dbo.PHIEUXUAT";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();
                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        PhieuXuatHang pxh = new PhieuXuatHang();
                        pxh.MaKh = int.Parse(dt.Rows[i][0].ToString());

                        pxlist.Add(pxh);
                    }
                }
                else if (px.Search == "Mã Sản Phẩm")
                {
                    sqlCommand.CommandText = "SELECT DISTINCT(MASP) FROM dbo.CTPX";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();
                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        PhieuXuatHang pxh = new PhieuXuatHang();
                        pxh.MaSp = int.Parse(dt.Rows[i][0].ToString());

                        pxlist.Add(pxh);
                    }
                }

                sqlReader.Close();
                return(pxlist);
            }
            catch
            {
                throw;
            }
            finally
            {
                CloseConnection();
            }
        }