Example #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;
            }
        }
Example #2
0
 public void Sua_DH(DonDH ddh)
 {
     string sql = "update DonDH set TinhTrang=@TinhTrang, TongTien=@TongTien where MaDonDH=@MaDonDH";
     SqlParameter madondh = new SqlParameter("@MaDonDH", ddh.MaDonDH);
     SqlParameter tinhtrang = new SqlParameter("@TinhTrang", ddh.TinhTrang);
     SqlParameter tongtien = new SqlParameter("@TongTien", ddh.TongTien);
     SqlDataProvider.ExecuteNonQuery(sql, CommandType.Text, madondh, tinhtrang, tongtien);
 }
Example #3
0
 public void Xoa(DonDH ddh)
 {
     string sql = "Delete DonDH where MaDonDH=@MaDonDH";
     SqlParameter madondh = new SqlParameter("@MaDonDH", ddh.MaDonDH);
     SqlDataProvider.ExecuteNonQuery(sql, CommandType.Text, madondh);
 }
Example #4
0
        public List<DonDH> TimKiem_TinhTrang(string tinhtrang)
        {
            List<DonDH> data = new List<DonDH>();
            string sql = "select * from DonDH where TinhTrang=@TinhTrang";
            SqlParameter tinh_trang = new SqlParameter("@TinhTrang", tinhtrang);
            SqlDataReader rd = SqlDataProvider.ExecuteQueryWithDataReader(sql, CommandType.Text, tinh_trang);
            DonDH ddh = new DonDH();
            if (rd.HasRows)
            {
                while (rd.Read())
                {
                    try
                    {
                        ddh = new DonDH()
                        {

                            MaDonDH = int.Parse(rd[0].ToString()),
                            Ten = rd[1].ToString(),
                            SDT = rd[2].ToString(),
                            Email = rd[3].ToString(),
                            DiaChi = rd[4].ToString(),
                            NgayDat = DateTime.Parse(rd[5].ToString()),
                            NgayGiao = DateTime.Parse(rd[6].ToString()),
                            GhiChu = rd[7].ToString(),
                            TinhTrang = rd[8].ToString(),
                            TongTien = int.Parse(rd[9].ToString()),
                            MaKhachHang = int.Parse(rd[10].ToString())
                        };
                    }
                    catch
                    {
                        ddh = new DonDH()
                        {

                            MaDonDH = int.Parse(rd[0].ToString()),
                            Ten = rd[1].ToString(),
                            SDT = rd[2].ToString(),
                            Email = rd[3].ToString(),
                            DiaChi = rd[4].ToString(),
                            NgayDat = DateTime.Parse(rd[5].ToString()),
                            NgayGiao = null,
                            GhiChu = null,
                            TinhTrang = null,
                            TongTien = int.Parse(rd[9].ToString()),
                            MaKhachHang = null
                        };
                    }
                    data.Add(ddh);
                }
            }
            return data;
        }
Example #5
0
        public List<DonDH> HienThiDonDH()
        {
            List<DonDH> data = new List<DonDH>();
            string sql = "select * from DonDH";
            SqlDataReader rd = SqlDataProvider.ExecuteQueryWithDataReader(sql, CommandType.Text);
            DonDH ddh = new DonDH();
            if (rd.HasRows)
            {
                while (rd.Read())
                {
                    if (ddh.TinhTrang != "" && ddh.MaKhachHang != null)
                    {
                        ddh = new DonDH()
                        {

                            MaDonDH = int.Parse(rd[0].ToString()),
                            Ten = rd[1].ToString(),
                            SDT = rd[2].ToString(),
                            Email = rd[3].ToString(),
                            DiaChi = rd[4].ToString(),
                            NgayDat = DateTime.Parse(rd[5].ToString()),
                            NgayGiao = DateTime.Parse(rd[6].ToString()),
                            GhiChu = rd[7].ToString(),
                            TinhTrang = rd[8].ToString(),
                            TongTien = int.Parse(rd[9].ToString()),
                            MaKhachHang = int.Parse(rd[10].ToString())
                        };

                    }
                    else
                    {
                        if (ddh.TinhTrang != "")
                        {
                            ddh = new DonDH()
                            {

                                MaDonDH = int.Parse(rd[0].ToString()),
                                Ten = rd[1].ToString(),
                                SDT = rd[2].ToString(),
                                Email = rd[3].ToString(),
                                DiaChi = rd[4].ToString(),
                                NgayDat = DateTime.Parse(rd[5].ToString()),
                                NgayGiao = null,
                                GhiChu = null,
                                TinhTrang = rd[8].ToString(),
                                TongTien = int.Parse(rd[9].ToString()),
                                MaKhachHang = null
                            };
                        }
                        else
                        {
                            ddh = new DonDH()
                            {

                                MaDonDH = int.Parse(rd[0].ToString()),
                                Ten = rd[1].ToString(),
                                SDT = rd[2].ToString(),
                                Email = rd[3].ToString(),
                                DiaChi = rd[4].ToString(),
                                NgayDat = DateTime.Parse(rd[5].ToString()),
                                NgayGiao = null,
                                GhiChu = null,
                                TinhTrang = null,
                                TongTien = int.Parse(rd[9].ToString()),
                                MaKhachHang = null
                            };
                        }
                    }

                    data.Add(ddh);
                }

            }
            return data;
        }