public DTOKhoSP LaySoLuongKhoSP(int ma)
        {
            ketnoi.TaoKetNoi();
            DTOKhoSP dtoDH = null;
            try
            {
                string lenh = "Select * from KhoSP k, SanPham sp, LoaiSP l where k.MaSP=sp.MaSP and sp.MaLoai=l.MaLoai and k.MaSP=@ma";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@ma", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters["@ma"].Value = ma;

                DataTable bang = new DataTable();
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                DataRow dong = bang.Rows[0];
                dtoDH = new DTOKhoSP(dong);
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dtoDH;
        }
        public List<DTOKhoSP> LayDSKhoSP()
        {
            List<DTOKhoSP> ds = new List<DTOKhoSP>();

            string lenh = "Select * from KhoSP k, SanPham sp, LoaiSP l where sp.MaLoai=l.MaLoai and k.MaSP=sp.MaSP";

            ketnoi.TaoKetNoi();
            DataTable bang = new DataTable();
            try
            {
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
                //dong bo lenh ket noi voi du lieu trong database
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                foreach (DataRow dongDL in bang.Rows)
                {
                    DTOKhoSP dtoct = new DTOKhoSP(dongDL);
                    ds.Add(dtoct);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ds;
        }
        public bool CapNhatSLKhoSP(DTOKhoSP dtoKho)
        {
            bool ketqua = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = "update KhoSP set Soluong = @sl where MaSP=@ma";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@ma", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters.Add("@sl", SqlDbType.Int);

                ketnoi.LenhKetNoi.Parameters["@ma"].Value = dtoKho.MaSP;
                ketnoi.LenhKetNoi.Parameters["@sl"].Value = dtoKho.Soluong;

                if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
                    ketqua = true;
            }
            catch (Exception)
            {

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ketqua;
        }
        protected void btnThemSP_Click(object sender, EventArgs e)
        {


            XemDSKho.Visible = true;
            DTOXuLyPhieuGiao dtoct = new DTOXuLyPhieuGiao();
            // DTODonDatHang dtoDH = new DTODonDatHang();

            dtoct.MaDH = lbMaDH.Text;
            DTOSanPham dtoSP = new DTOSanPham();
            dtoct.MaSP = int.Parse(ddTP.SelectedValue);
            // dtoSP.TenSP = ddTP.SelectedItem.ToString();

            //dtoct.dtoSP = dtoSP;
            //dtoct.dtoDH = dtoDH;

            //dtoSP.TenSP = ddTP.SelectedValue;
            dtoct.SoLuong = int.Parse(txtSoLuong.Text);

            dtoct.ThanhTien = int.Parse(lbgia.Text) * int.Parse(txtSoLuong.Text);


            //BLLXuLyDonHang bll = new BLLXuLyDonHang();
            //bll.ThemChiTietDH(dtoct);


            DTOKhoSP dtokho = new DTOKhoSP();
            dtokho.MaSP = int.Parse(ddTP.SelectedValue);
            dtokho.Soluong = int.Parse(lbSLKho.Text) - int.Parse(txtSoLuong.Text);
            DAO_Entity dao = new DAO_Entity();
            dao.CapNhatSLKhoSP(dtokho);

          


            DAO_Entity daokh = new DAO_Entity();
            daokh.ThemPhieuGiaoHang(dtoct);
            Response.Redirect(Request.RawUrl);

        }