private void Xoa_khoi_gio(string gio) { int ma_mon = int.Parse(Request["Ma_mon_an"].ToString()); Gio_hang_online gio_hang = new Gio_hang_online(); if (Session[gio] == null) { return; } else { gio_hang = (Gio_hang_online)Session[gio]; for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { Item_online mon_an = (Item_online)gio_hang.DsMonAn[i]; if (mon_an.Ma_item == ma_mon) { gio_hang.DsMonAn.RemoveAt(i); } } Tinh_gia_tri_gio_hang(ref gio_hang); Session[gio] = gio_hang; } Xuat_thong_tin_gio_hang(gio_hang); }
private void Cap_nhat_tien() { int ma_mon = int.Parse(Request["Ma_mon_an"].ToString()); Gio_hang_online gio_hang = new Gio_hang_online(); if (Session["Gio_hang"] == null) { return; } else { gio_hang = (Gio_hang_online)Session["Gio_hang"]; for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { Item_online mon_an = (Item_online)gio_hang.DsMonAn[i]; if (mon_an.Ma_item == ma_mon) { //gio_hang.DsMonAn.RemoveAt(i); mon_an.So_luong = int.Parse(Request["So_luong"].ToString()); gio_hang.DsMonAn[i] = mon_an; } } Tinh_gia_tri_gio_hang(ref gio_hang); //gio_hang.DsMonAn.Sort(); Session["Gio_hang"] = gio_hang; } Xuat_thong_tin_gio_hang(gio_hang); }
private void Thong_tin_chinh_gio_hang() { XL_THE Kq = new XL_THE("THONGTIN"); Gio_hang_online gio_hang = new Gio_hang_online(); if (Session["Gio_hang"] == null) { return; } else { gio_hang = (Gio_hang_online)Session["Gio_hang"]; int so_items = 0; for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { Item_online ma = (Item_online)gio_hang.DsMonAn[i]; so_items += ma.So_luong; } XL_THUOC_TINH Thuoc_tinh = new XL_THUOC_TINH("So_items", so_items.ToString()); Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("Tong_gia_tri", gio_hang.gia_tri.ToString()); Kq.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); XL_CHUOI.XuatXML(Response, Kq.Chuoi()); } }
private void Tinh_gia_tri_gio_hang(ref Gio_hang_online gio_hang) { decimal tong_gia_tri = 0; for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { Item_online mon_an_ol = (Item_online)gio_hang.DsMonAn[i]; tong_gia_tri += mon_an_ol.So_luong * mon_an_ol.Gia; } gio_hang.gia_tri = tong_gia_tri; }
private void Ghi_nhan_dat_hang() { ArrayList arr = new ArrayList(); int ma = int.Parse(Request["Ma"].ToString()); MonAnBUS monanBUS = new MonAnBUS(); if (Request["Loai"] == "0") { MonAnDTO MonAn = monanBUS.ChiTietMonAn(ma); Item_online mon_an = new Item_online(); mon_an.Ma_item = MonAn.Ma_mon; mon_an.Ten_item = MonAn.Ten_mon; mon_an.Hinh_anh_minh_hoa = MonAn.Hinh_anh_minh_hoa; mon_an.Gia = MonAn.Gia; mon_an.Loai_item = 0; mon_an.So_luong = int.Parse(Request["So_luong"].ToString()); Session["Item_online"] = mon_an; } else if (Request["Loai"] == "1") { ThucDonBUS thucdonBUS = new ThucDonBUS(); //ThucDonDTO ThucDon = thucdonBUS.ThongTinThucDon(ma); ThucDonDTO thuc_don = thucdonBUS.ChiTietThucDon(ma); Item_online mon_an = new Item_online(); mon_an.Ma_item = thuc_don.Ma_thuc_don; mon_an.Ten_item = thuc_don.Ten_thuc_don; mon_an.Hinh_anh_minh_hoa = thuc_don.Hinh_anh_minh_hoa; mon_an.Gia = thuc_don.Gia; mon_an.Loai_item = 1; mon_an.So_luong = int.Parse(Request["So_luong"].ToString()); Session["Item_online"] = mon_an; } else { ThucDonCaNhanBUS thucdonBUS = new ThucDonCaNhanBUS(); //ThucDonDTO ThucDon = thucdonBUS.ThongTinThucDon(ma); ThucDonCaNhanDTO thuc_don = thucdonBUS.ChiTietThucDonCaNhan(ma); Item_online mon_an = new Item_online(); mon_an.Ma_item = thuc_don.Ma_thuc_don_ca_nhan; mon_an.Ten_item = thuc_don.Ten_thuc_don; mon_an.Hinh_anh_minh_hoa = thuc_don.Hinh_anh; mon_an.Gia = thuc_don.Gia; mon_an.Loai_item = 1; mon_an.So_luong = int.Parse(Request["So_luong"].ToString()); Session["Item_online"] = mon_an; } }
private void Them_vao_gio_hang() { Gio_hang_online gio_hang = new Gio_hang_online(); bool flag = false; if (Session["Item_online"] == null) { if (Session["Gio_hang"] != null) { gio_hang = (Gio_hang_online)Session["Gio_hang"]; } Xuat_thong_tin_gio_hang(gio_hang); return; } Item_online mon_an = (Item_online)Session["Item_online"]; Session["Item_online"] = null; if (Session["Gio_hang"] == null) { gio_hang.username = ""; gio_hang.DsMonAn = new ArrayList(); gio_hang.DsMonAn.Add(mon_an); Tinh_gia_tri_gio_hang(ref gio_hang); Session["Gio_hang"] = gio_hang; } else { gio_hang = (Gio_hang_online)Session["Gio_hang"]; for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { Item_online ma = (Item_online)gio_hang.DsMonAn[i]; if (mon_an.Ma_item == ma.Ma_item) { ma.So_luong += mon_an.So_luong; gio_hang.DsMonAn[i] = ma; flag = true; } } if (flag == false) { gio_hang.DsMonAn.Add(mon_an); } Tinh_gia_tri_gio_hang(ref gio_hang); Session["Gio_hang"] = gio_hang; } Xuat_thong_tin_gio_hang(gio_hang); }
private void Xuat_thong_tin_gio_hang(Gio_hang_online gio_hang) { if (gio_hang.DsMonAn == null) { return; } XL_THE Kq = new XL_THE("DANH_SACH"); for (int i = 0; i < gio_hang.DsMonAn.Count; i++) { XL_THE Kq1 = new XL_THE("MonAn"); Item_online mon_an_ol = (Item_online)gio_hang.DsMonAn[i]; decimal gia_tri = gio_hang.gia_tri; int so_luong = mon_an_ol.So_luong; decimal Tong_gia_tri_mon_an = so_luong * mon_an_ol.Gia; XL_THUOC_TINH Thuoc_tinh = new XL_THUOC_TINH("Ma_mon", mon_an_ol.Ma_item.ToString()); Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("Ten_mon", mon_an_ol.Ten_item); Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("Hinh_anh_minh_hoa", mon_an_ol.Hinh_anh_minh_hoa); Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("Gia", mon_an_ol.Gia.ToString()); Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("So_luong", so_luong.ToString()); Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Thuoc_tinh = new XL_THUOC_TINH("Tong_gia_tri_mon_an", Tong_gia_tri_mon_an.ToString()); Kq1.Danh_sach_thuoc_tinh.Add(Thuoc_tinh); Kq.Danh_sach_the.Add(Kq1); } XL_THE Kq2 = new XL_THE("TongSoItem"); XL_THUOC_TINH Thuoc_tinh1 = new XL_THUOC_TINH("TongSoItem", gio_hang.DsMonAn.Count.ToString()); Kq2.Danh_sach_thuoc_tinh.Add(Thuoc_tinh1); Kq.Danh_sach_the.Add(Kq2); Kq2 = new XL_THE("TongGiaTri"); Thuoc_tinh1 = new XL_THUOC_TINH("TongGiaTri", gio_hang.gia_tri.ToString()); Kq2.Danh_sach_thuoc_tinh.Add(Thuoc_tinh1); Kq.Danh_sach_the.Add(Kq2); XL_CHUOI.XuatXML(Response, Kq.Chuoi()); }
protected void Dat_hang_guest() { DonHangDTO donhang = new DonHangDTO(); //Xac dinh tham so 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.Ngay_gio_giao_hang = DateTime.Parse(Request["Ngay_giao"].ToString()); donhang.Gia_tri = decimal.Parse(Request["Gia_tri"].ToString()); donhang.Da_dat_hang = 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"]; 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; } 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); } } 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; } the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("kq", "Dat hang thanh cong")); the.Danh_sach_thuoc_tinh.Add(new XL_THUOC_TINH("flag", "true")); XL_CHUOI.XuatChuoi(Response, the.Chuoi()); Session["Gio_hang"] = null; return; }
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; }