public bool ThemDonHangDinhKy(DonHangDinhKyDTO donhangdk) { SqlConnection cnn = Connect(); SqlCommand cmd = new SqlCommand("spThemDonHangDinhKy", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@madonhangkinhky", SqlDbType.Int); cmd.Parameters.Add("@loaidinhky", SqlDbType.NVarChar); cmd.Parameters.Add("@ngaybatdau", SqlDbType.DateTime); cmd.Parameters.Add("@ngayketthuc", SqlDbType.DateTime); cmd.Parameters.Add("@ngaygiao", SqlDbType.VarChar); cmd.Parameters.Add("@thugiao", SqlDbType.VarChar); cmd.Parameters.Add("@giogiao", SqlDbType.DateTime); cmd.Parameters.Add("@tinhtrang", SqlDbType.Bit); cmd.Parameters["@madonhangkinhky"].Value = donhangdk.Ma_don_hang; cmd.Parameters["@loaidinhky"].Value = donhangdk.Loai_dinh_ky; cmd.Parameters["@ngaybatdau"].Value = donhangdk.Ngay_bat_dau; cmd.Parameters["@ngayketthuc"].Value = donhangdk.Ngay_ket_thuc; cmd.Parameters["@ngaygiao"].Value = donhangdk.Ngay_giao; cmd.Parameters["@thugiao"].Value = donhangdk.Thu_giao; cmd.Parameters["@giogiao"].Value = donhangdk.Gio_giao; cmd.Parameters["@tinhtrang"].Value = donhangdk.Tinh_trang; try { cmd.ExecuteNonQuery(); } catch (SqlException ex) { Disconnect(); throw ex; } Disconnect(); return(true); }
protected void Dat_hang_customer() { DonHangDTO donhang = new DonHangDTO(); DonHangDinhKyDTO donhangdk = new DonHangDinhKyDTO(); //Xac dinh tham so viewKhachHangDTO vkhDto = (viewKhachHangDTO)Session["khachhang"]; donhang.Ma_khach_hang = vkhDto.Ma_nguoi_dung; donhang.Ngay_gio_lap = DateTime.Parse(Request["Ngay_lap"].ToString()); donhang.Dia_chi_nhan = Request["Dia_chi_nhan"]; donhang.Nguoi_nhan = Request["Nguoi_nhan"]; donhang.Hinh_thuc_khuyen_mai = int.Parse(Request["HTKM"].ToString()); donhang.Tien_khuyen_mai = decimal.Parse(Request["Tien_khuyen_mai"].ToString()); donhang.Gia_tri = decimal.Parse(Request["Gia_tri"].ToString()); donhang.Ma_hinh_thuc_thanh_toan = int.Parse(Request["HTTT"].ToString()); int loaiyeucau = int.Parse(Request["Loai_yeu_cau"].ToString()); if (loaiyeucau == 0 || loaiyeucau == 1) //lưu or đặt hàng bình thường { donhang.Loai_don_dat_hang = 0; //don hang binh thuong donhang.Ngay_gio_giao_hang = DateTime.Parse(Request["Ngay_giao"].ToString()); if (loaiyeucau == 0) { donhang.Da_dat_hang = false; } else { donhang.Da_dat_hang = true; } } else if (loaiyeucau == 2 || loaiyeucau == 3) //lưu or đặt hàng định kỳ { donhang.Loai_don_dat_hang = 1; //đơn hàng định kỳ if (loaiyeucau == 2) { donhang.Da_dat_hang = false; } else { donhang.Da_dat_hang = true; } donhangdk.Loai_dinh_ky = Request["Loai_dk"].ToString(); donhangdk.Ngay_bat_dau = DateTime.Parse(Request["Ngay_bd"].ToString()); donhangdk.Ngay_ket_thuc = DateTime.Parse(Request["Ngay_kt"].ToString()); if (donhangdk.Loai_dinh_ky == "Hang Tuan") { donhangdk.Thu_giao = Request["Thoi_gian_giao"].ToString(); } else if (donhangdk.Loai_dinh_ky == "Hang Thang") { donhangdk.Ngay_giao = Request["Thoi_gian_giao"].ToString(); } donhangdk.Gio_giao = DateTime.Parse(Request["Gio_giao"].ToString()); donhangdk.Tinh_trang = true; } donhang.Da_thanh_toan = false; donhang.Da_giao_hang = false; donhang.Tien_thue = decimal.Parse(Request["Tien_thue"].ToString()); int madonhang; Gio_hang_online gio_hang = (Gio_hang_online)Session["Gio_hang"]; Gio_hang_online gio_qua_tang = new Gio_hang_online(); if (Session["Gio_qua_tang"] != null) { gio_qua_tang = (Gio_hang_online)Session["Gio_qua_tang"]; } XL_THE the = new XL_THE("goc"); XL_THUOC_TINH thuoc_tinh; try { madonhang = (new DonHangBUS()).ThemDonHang(donhang); } catch (Exception ex) { the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("kq", "Dat hang loi")); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "false")); string chuoi = the.Chuoi(); XL_CHUOI.XuatChuoi(Response, chuoi); return; } //lưu or đặt hàng định kỳ if (donhang.Loai_don_dat_hang == 1) { donhangdk.Ma_don_hang = madonhang; try { (new DonHangDinhKyBUS()).ThemDonHangDinhKy(donhangdk); } catch (Exception ex) { (new DonHangDinhKyBUS()).XoaDonHang(madonhang); //rollback the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("kq", "Dat hang dinh ky loi")); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "false")); string chuoi = the.Chuoi(); XL_CHUOI.XuatChuoi(Response, chuoi); return; } } try { CTDonHangDTO ctdonhang = new CTDonHangDTO(); CTDonHangBUS ctdhBUS = new CTDonHangBUS(); TagBUS tagbus = new TagBUS(); for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { Item_online item = (Item_online)gio_hang.DsMonAn[i]; ctdonhang.Ma_don_hang = madonhang; ctdonhang.Ma_item = item.Ma_item; ctdonhang.So_luong = item.So_luong; ctdonhang.Thanh_tien = item.So_luong * item.Gia; ctdonhang.Loai_item = item.Loai_item; ctdonhang.La_qua_tang = false; ctdhBUS.ThemChiTietDonHang(ctdonhang); tagbus.CapNhatDoUuTien(ctdonhang.Ma_item, ctdonhang.Loai_item); } if (gio_qua_tang.DsMonAn != null) { for (int i = 0; i < gio_qua_tang.DsMonAn.Count; i++) { Item_online item = (Item_online)gio_qua_tang.DsMonAn[i]; ctdonhang.Ma_don_hang = madonhang; ctdonhang.Ma_item = item.Ma_item; ctdonhang.So_luong = item.So_luong; ctdonhang.Thanh_tien = item.So_luong * item.Gia; ctdonhang.Loai_item = item.Loai_item; ctdonhang.La_qua_tang = true; ctdhBUS.ThemChiTietDonHang(ctdonhang); } } int diemmoi = (new DonHangBUS()).CapNhatDiemKMTheoQuiDinh(donhang.Ma_khach_hang, vkhDto.Diem_khuyen_mai, donhang.Gia_tri, donhang.Tien_khuyen_mai); vkhDto.Diem_khuyen_mai = diemmoi; } catch (Exception ex) { if (donhang.Loai_don_dat_hang == 1) { (new DonHangDinhKyBUS()).XoaDonHangDinhKy(madonhang); //rollback } else { (new DonHangBUS()).XoaDonHang(madonhang); //rollback } (new KhachHangBUS()).CapNhatDiemKhuyenMai(donhang.Ma_khach_hang, vkhDto.Diem_khuyen_mai); //rollback the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("kq", "Dat hang loi")); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "false")); string chuoi = the.Chuoi(); XL_CHUOI.XuatChuoi(Response, chuoi); return; } //neu ko fai chon luu dh if (donhang.Da_dat_hang == true) { // Dat hang thanh cong + chon thanh toan = the tin dung -> tien hanh thanh toan int Thanh_toan = int.Parse(Request["Thanh_toan"].ToString()); if (Thanh_toan == 1) { WS_CardSystem.CardDTO cardDto1 = new WS_CardSystem.CardDTO(); //Neu su dung the khac int The_khac = int.Parse(Request["The_khac"].ToString()); ThanhToanTheTinDungDTO thett = new ThanhToanTheTinDungDTO(); if (The_khac == 1) { thett.Ma_don_hang = madonhang; //don hang vua them thett.Ma_loai_the = int.Parse(Request["Ma_loai_the"].ToString()); thett.So_the = Request["So_the"].ToString(); thett.Ngay_het_han = DateTime.Parse(Request["Ngay_hh"].ToString()); //them vao csdl the su dung try { (new ThanhToanTheTinDungBUS()).ThemThanhToanTheTinDung(thett); } catch (Exception ex) { if (donhang.Loai_don_dat_hang == 1) { (new DonHangDinhKyBUS()).XoaDonHangDinhKy(madonhang); //rollback } else { (new DonHangBUS()).XoaDonHang(madonhang); //rollback } (new KhachHangBUS()).CapNhatDiemKhuyenMai(donhang.Ma_khach_hang, vkhDto.Diem_khuyen_mai); //rollback the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("kq", "Dat hang loi")); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "false")); string chuoi = the.Chuoi(); XL_CHUOI.XuatChuoi(Response, chuoi); return; } //The khac cardDto1.Code = thett.So_the; string tenloaithe = Request["Ten_loai_the"].ToString(); cardDto1.Type = tenloaithe; } else { //the mac dinh cardDto1.Code = vkhDto.So_the; cardDto1.Type = vkhDto.Ten_loai_the; } //thanh toan bool kq = ThanhToan(donhang.Gia_tri, the, cardDto1); if (kq == true) { (new DonHangBUS()).CapNhatTrangThaiDaThanhToan(madonhang, true); } else { (new ThanhToanTheTinDungBUS()).XoaThanhToanTheTinDung(thett.Ma_don_hang); if (donhang.Loai_don_dat_hang == 1) { (new DonHangDinhKyBUS()).XoaDonHangDinhKy(madonhang); //rollback } else { (new DonHangBUS()).XoaDonHang(madonhang); //rollback } (new KhachHangBUS()).CapNhatDiemKhuyenMai(donhang.Ma_khach_hang, vkhDto.Diem_khuyen_mai); //rollback the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("kq", "Thanh toan loi, dat hang khong thanh cong \n Vui long kiem tra lai the su dung")); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "false")); string chuoi = the.Chuoi(); XL_CHUOI.XuatChuoi(Response, chuoi); return; } } thuoc_tinh = new XL_THUOC_TINH("kq", "Dat hang thanh cong"); } else { Session["madonhangluu"] = madonhang; //luu lại mã đh để trh khách hàng chọn đặt mua sau đó thuoc_tinh = new XL_THUOC_TINH("kq", "Luu don hang thanh cong"); } the.Danh_sach_thuoc_tinh.Add(thuoc_tinh); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "true")); XL_CHUOI.XuatChuoi(Response, the.Chuoi()); Session["Gio_qua_tang"] = null; Session["Gio_hang"] = null; Session["FormDatHangDinhKy"] = null; Session["FormDatHang"] = null; return; }
private void LayThongTinDonHang() { DonHangBUS bus = new DonHangBUS(); int maDonHang = int.Parse(Request["MaDonHang"]); DonHangDTO dhDTO = bus.LayThongTinDonHang(maDonHang); XL_THE kq = new XL_THE("DonHang"); NguoiDungBUS ndBUS = new NguoiDungBUS(); NguoiDungDTO ndDTO = ndBUS.ThongTinNguoiDung(dhDTO.Ma_khach_hang); XL_THUOC_TINH Thuoc_tinh = new XL_THUOC_TINH("TenKhachHang", ndDTO.Ho_ten); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayGioLap", dhDTO.Ngay_gio_lap.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("DiaChiNhan", dhDTO.Dia_chi_nhan.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NguoiNhan", dhDTO.Nguoi_nhan); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); HinhThucKhuyenMaiBUS htkmBus = new HinhThucKhuyenMaiBUS(); HinhThucKhuyenMaiDTO htkmDto = htkmBus.ThongTinHTKM(dhDTO.Hinh_thuc_khuyen_mai); string tenHinhThucKhuyenMai = "Không có"; if (htkmDto != null) { tenHinhThucKhuyenMai = htkmDto.Ten_hinh_thuc_khuyen_mai; } Thuoc_tinh = new XL_THUOC_TINH("HinhThucKhuyenMai", tenHinhThucKhuyenMai); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("TienKhuyenMai", dhDTO.Tien_khuyen_mai.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("GiaTri", dhDTO.Gia_tri.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("TienThue", dhDTO.Tien_thue.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); string loai = dhDTO.Ngay_gio_giao_hang.ToString(); string ngayGioGiaoHang = "chưa có"; if (dhDTO.Loai_don_dat_hang == 1) { loai = "5"; // " (Đơn hàng định kỳ)"; } else if (dhDTO.Da_dat_hang == false && dhDTO.Da_thanh_toan == false && dhDTO.Da_giao_hang == false) { loai = "0"; //"Đã lưu"; } else if (dhDTO.Da_dat_hang == true && dhDTO.Da_thanh_toan == false && dhDTO.Da_giao_hang == false) { loai = "1"; //"Đã đặt hàng nhưng chưa thanh toán"; } else if (dhDTO.Da_dat_hang == true && dhDTO.Da_thanh_toan == true && dhDTO.Da_giao_hang == false) { loai = "2"; //"Đã thanh toán nhưng chưa giao hàng"; } else if (dhDTO.Da_dat_hang == true && dhDTO.Da_thanh_toan == true && dhDTO.Da_giao_hang == true) { loai = "3"; //Đã hoàn tất"; ngayGioGiaoHang = dhDTO.Ngay_gio_giao_hang.ToString(); } else { loai = "4"; //Trong ngày (đã đặt hàng)"; } if (loai == "5") { DonHangDinhKyBUS dhdkBus = new DonHangDinhKyBUS(); DonHangDinhKyDTO dhdk = dhdkBus.LayThongTinDonHangDinhKy(dhDTO.Ma_don_hang); Thuoc_tinh = new XL_THUOC_TINH("LoaiDinhKy", dhdk.Loai_dinh_ky); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayBatDau", dhdk.Ngay_bat_dau.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayKetThuc", dhdk.Ngay_ket_thuc.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); string thoiDiem = ""; if (dhdk.Loai_dinh_ky.ToUpper().Trim() == "Tuần") { thoiDiem = dhdk.Thu_giao; } else { thoiDiem = dhdk.Ngay_giao; } Thuoc_tinh = new XL_THUOC_TINH("ThoiDiemGiao", thoiDiem); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("GioGiao", dhdk.Gio_giao.ToString()); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("TinhTrang", dhdk.Tinh_trang ? "1" : "0"); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); } Thuoc_tinh = new XL_THUOC_TINH("loai", loai); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayGioGiaoHang", ngayGioGiaoHang); kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); XL_CHUOI.XuatXML(Response, kq.Chuoi()); }
public bool ThemDonHangDinhKy(DonHangDinhKyDTO donhangdk) { return(dhdkDAO.ThemDonHangDinhKy(donhangdk)); }
private void LayDanhSachDonHang(int request) { DonHangBUS bus = new DonHangBUS(); DonHangDinhKyBUS dhdkBUS = new DonHangDinhKyBUS(); XemDanhSachDonHang[] arrFuncXemDanhSach = new XemDanhSachDonHang[] { bus.DanhSachDonHangDaLuu, bus.DanhSachDonHangDaDatChuaThanhToan, bus.DanhSachDonHangDaThanhToanChuaGiao, bus.DanhSachDonHangDaHoanTat, bus.DanhSachDonHangTrongNgay, dhdkBUS.DanhSachDonHangDinhKy }; TongDonHang[] arrFuncTongDonHang = new TongDonHang[] { bus.TongDonHangDaLuu, bus.TongDonHangDaDatChuaThanhToan, bus.TongDonHangDaThanhToanChuaGiao, bus.TongDonHangDaHoanTat, bus.TongDonHangTrongNgay, bus.TongDonHangDinhKy }; int maKhachHang = (int)Session["MaNguoiDung"]; // Xử lý request int pageSize = 10; if (Request["results"] != null) { pageSize = int.Parse((string)Request["results"]); } int pageNum = 1; if (Request["startIndex"] != null) { pageNum = (int.Parse((string)Request["startIndex"]) / pageSize) + 1; } // Lấy danh sách đơn hàng DonHangDTO[] kq = arrFuncXemDanhSach[request](maKhachHang, pageNum, pageSize); int tongDonHang = arrFuncTongDonHang[request](maKhachHang); XL_THE Kq = new XL_THE("DANH_SACH"); XL_THUOC_TINH Thuoc_tinh = new XL_THUOC_TINH("totalRecords", tongDonHang.ToString()); Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); foreach (DonHangDTO dto in kq) { XL_THE the = new XL_THE("DonHang"); Thuoc_tinh = new XL_THUOC_TINH("MaDonHang", dto.Ma_don_hang.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayGioLap", dto.Ngay_gio_lap.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("DiaChiNhan", dto.Dia_chi_nhan); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NguoiNhan", dto.Nguoi_nhan); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayGioGiaoHang", dto.Ngay_gio_giao_hang.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("GiaTri", dto.Gia_tri.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); if (request == 5) // đơn hàng định kỳ { DonHangDinhKyDTO dhdk = (DonHangDinhKyDTO)dto; Thuoc_tinh = new XL_THUOC_TINH("LoaiDinhKy", dhdk.Loai_dinh_ky); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayBatDau", dhdk.Ngay_bat_dau.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayKetThuc", dhdk.Ngay_ket_thuc.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("NgayGiao", dhdk.Ngay_giao.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("ThuGiao", dhdk.Thu_giao.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("GioGiao", dhdk.Gio_giao.ToString()); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("TinhTrang", dhdk.Tinh_trang ? "1" : "0"); the.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); } Kq.Danh_sach_the.Add(the); } XL_CHUOI.XuatXML(Response, Kq.Chuoi()); }