Пример #1
0
        public bool DatHang(string ten, string sdt, string email, string diachi, string total, string id, List<CartItem> cart)
        {
            try
            {
                if (id != null)
                {
                    DonDH don = new DonDH()
                    {
                        Ten = ten,
                        SDT = sdt,
                        Email = email,
                        DiaChi = diachi,
                        NgayDat = DateTime.Now,
                        TongTien = int.Parse(total),
                        MaKhachHang = int.Parse(id)
                    };
                    db.DonDHs.Add(don);
                }
                else
                {
                    DonDH don = new DonDH()
                    {
                        Ten = ten,
                        SDT = sdt,
                        Email = email,
                        DiaChi = diachi,
                        NgayDat = DateTime.Now,
                        TongTien = int.Parse(total)
                    };
                    db.DonDHs.Add(don);
                }
                db.SaveChanges();

                foreach (var item in cart)
                {
                    CT_DonDH ct = new CT_DonDH()
                    {
                        MaDonDH = db.DonDHs.Max(x => x.MaDonDH),
                        SP_ID = item.Product.SP_ID,
                        DonGiaDat = (int)item.Product.DonGia,
                        SoLuongDat = item.Quantity
                    };
                    db.CT_DonDH.Add(ct);

                    TonKho ton = new TonKho()
                    {
                        SP_ID = item.Product.SP_ID,
                        ThoiGian = DateTime.Now,
                        SoLuongTon = tonkho.TimTheoSPID(item.Product.SP_ID).SoLuongTon - item.Quantity
                    };
                    db.TonKhoes.Add(ton);
                }
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
Пример #2
0
        public List<CT_DonDH> HienThiCT_DonDH(CT_DonDH ct)
        {
            List<CT_DonDH> data = new List<CT_DonDH>();

            string sql = "select MaDonDH,sp.SP_ID,DonGiaDat,SoLuongDat from CT_DonDH ct, SanPham sp where ct.SP_ID=sp.SP_ID and MaDonDH=@MaDonDH";
            SqlParameter madondh = new SqlParameter("@MaDonDH", ct.MaDonDH);
            SqlDataReader rd = SqlDataProvider.ExecuteQueryWithDataReader(sql, CommandType.Text, madondh);
            if (rd.HasRows)
            {
                while (rd.Read())
                {
                    ct = new CT_DonDH()
                    {
                        MaDonDH = int.Parse(rd[0].ToString()),
                        SP_ID = int.Parse(rd[1].ToString()),
                        DonGiaDat = int.Parse(rd[2].ToString()),
                        SoLuongDat = int.Parse(rd[3].ToString()),

                    };
                    data.Add(ct);
                }
            }
            return data;
        }
Пример #3
0
 public void Xoa(CT_DonDH ct)
 {
     string sql = "Delete CT_DonDH where MaDonDH=@MaDonDH";
     SqlParameter madondh = new SqlParameter("@MaDonDH", ct.MaDonDH);
     SqlDataProvider.ExecuteNonQuery(sql, CommandType.Text, madondh);
 }