protected void btnThem_Click(object sender, EventArgs e) { if (txtname.Text == " " || txtprice.Text == "" || txtstime.Text == "" || txtdtime.Text == "" || DropDownListPlace.SelectedValue == null || DropDownListVehicle.SelectedValue == null || DropDownListHotel.SelectedValue == null || txtdetail.Text == "") { Response.Write("<script>alert('Bạn chưa nhập đầy đủ thông tin')</script>"); } else { dt.Name = txtname.Text; dt.Price = Int32.Parse(txtprice.Text); dt.StartTime = txtstime.Text; dt.Departure = txtdtime.Text; dt.Vehicle = Int32.Parse(DropDownListVehicle.SelectedValue); dt.Hotel = Int32.Parse(DropDownListHotel.SelectedValue); dt.Place = Int32.Parse(DropDownListPlace.SelectedValue); dt.Image = FileUpload1.FileName; dt.Detail = txtdetail.Text; t.ThemTour(dt.Name, dt.Price, dt.StartTime, dt.Departure, dt.Vehicle, dt.Hotel, dt.Place, dt.Image, dt.Detail); SaveFileUpLoad(); Response.Write("<script>alert('Thêm thành công')</script>"); Response.Redirect("viewtour.aspx"); } }
private void btn_Save_Click(object sender, EventArgs e) { bool isError = ThongBaoLoi(); TourBUS tourBus = new TourBUS(); switch (Onclicked) { #region Them Tour case 1: { if (!isError) { string maHT; HanhTrinhBUS hanhTrinhBus = new HanhTrinhBUS(); HanhTrinhDTO hanhTrinhDTO = hanhTrinhBus.TimHanhTrinh(int.Parse(cbo_NoiDi.SelectedValue.ToString()), int.Parse(cbo_NoiDen.SelectedValue.ToString())); //string maHT = new Random().Next(1, 10000).ToString(); if (hanhTrinhDTO == null) //Kiem tra thong tin Hanh Trinh da ton tai { DialogResult result = MessageBox.Show("Hành trình này chưa có sẵn", "Bạn có muốn tạo mới", MessageBoxButtons.YesNo); maHT = new Random().Next(1, 10000).ToString(); if (result == DialogResult.OK) //Them hanh trinh moi { hanhTrinhBus.ThemHanhTrinhMoi(new HanhTrinhDTO() { MaHanhTrinh = maHT, MaNoiDen = int.Parse(cbo_NoiDen.SelectedValue.ToString()), MaNoiDi = int.Parse(cbo_NoiDi.SelectedValue.ToString()) }); } } else { maHT = hanhTrinhDTO.MaHanhTrinh; } ThemTourDTO tourDTO = new ThemTourDTO() { //AnhDiaDiem=, MaHDV = int.Parse(cbo_HuongDanVien.SelectedValue.ToString()), MaKS = cbo_KhachSan.SelectedValue.ToString(), MaLoaiTour = cbo_LoaiTour.SelectedValue.ToString(), MaHanhTrinh = maHT, TourDTO = new TourDTO() { DiemDen = cbo_NoiDen.SelectedValue.ToString(), DiemDi = cbo_NoiDi.SelectedValue.ToString(), GiaNguoiLon = decimal.Parse(txt_GiaNguoiLon.Text), GiaTreEm = decimal.Parse(txt_GiaTreEm.Text), NgayKH = dateEdit_NgayKH.Value, NgayKT = dateEdit_NgayKT.Value, MaTour = new Random().Next(0, 10000).ToString(), TenTour = txt_TenTour.Text, LoaiTour = cbo_LoaiTour.SelectedValue.ToString(), } }; if (tourBus.TimTour(tourDTO.TourDTO.MaTour) != null) { MessageBox.Show(MessageBoxConstants.TRUNGKHOACHINH, "Mã tour này đã tồn tại"); } else { try { tourBus.ThemTour(tourDTO); MessageBox.Show(MessageBoxConstants.THEMTHANHCONG, "Thêm tour du lịch thành công"); gridControl_Tour.DataSource = tourBus.LoadTourToDataGridView(); } catch (Exception) { MessageBox.Show("Lỗi khóa ngoại", MessageBoxConstants.LOIKHOANGOAI); } } } else { MessageBox.Show(MessageBoxConstants.THIEUTHONGTIN, "Nhập lại thông tin"); } } break; #endregion #region Xoa tour case 3: { string maTour = gridView_Tour.GetFocusedRowCellValue("MaTour").ToString(); try { tourBus.XoaTour(maTour); MessageBox.Show(MessageBoxConstants.XOATHANHCONG, "Tour nay đã bị xóa đi"); gridControl_Tour.DataSource = tourBus.LoadTourToDataGridView(); } catch (Exception) { MessageBox.Show(MessageBoxConstants.LOITHAOTAC, "Xóa chỉ được đổi trạng thái"); } } break; #endregion #region Chinh sua Tour case 2: { string maHT; HanhTrinhBUS hanhTrinhBus = new HanhTrinhBUS(); HanhTrinhDTO hanhTrinhDTO = hanhTrinhBus.TimHanhTrinh(int.Parse(cbo_NoiDi.SelectedValue.ToString()), int.Parse(cbo_NoiDen.SelectedValue.ToString())); if (hanhTrinhDTO == null) //Kiem tra thong tin Hanh Trinh da ton tai { maHT = new Random().Next(1, 10000).ToString(); DialogResult result = MessageBox.Show("Hành trình này chưa có sẵn", "Bạn có muốn tạo mới", MessageBoxButtons.YesNo); if (result == DialogResult.OK) //Them hanh trinh moi { hanhTrinhBus.ThemHanhTrinhMoi(new HanhTrinhDTO() { MaHanhTrinh = maHT, MaNoiDen = int.Parse(cbo_NoiDen.SelectedValue.ToString()), MaNoiDi = int.Parse(cbo_NoiDi.SelectedValue.ToString()) }); } else { return; } } else { //maHT = new Random().Next(1, 10000).ToString(); maHT = hanhTrinhDTO.MaHanhTrinh; } string maTour = gridView_Tour.GetFocusedRowCellValue("MaTour").ToString(); ThemTourDTO tourDTO = new ThemTourDTO() { //AnhDiaDiem=, MaHDV = int.Parse(cbo_HuongDanVien.SelectedValue.ToString()), MaKS = cbo_KhachSan.SelectedValue.ToString(), MaLoaiTour = cbo_LoaiTour.SelectedValue.ToString(), MaHanhTrinh = maHT, TourDTO = new TourDTO() { DiemDen = cbo_NoiDen.SelectedValue.ToString(), DiemDi = cbo_NoiDi.SelectedValue.ToString(), GiaNguoiLon = decimal.Parse(txt_GiaNguoiLon.Text), GiaTreEm = decimal.Parse(txt_GiaTreEm.Text), NgayKH = dateEdit_NgayKH.Value, NgayKT = dateEdit_NgayKT.Value, MaTour = maTour } }; try { tourBus.ChinhSuaTour(tourDTO); MessageBox.Show(MessageBoxConstants.CHINHSUATHANHCONG, "Chỉnh sửa thông tin tour thành công"); gridControl_Tour.DataSource = tourBus.LoadTourToDataGridView(); } catch (Exception) { MessageBox.Show(MessageBoxConstants.LOITHAOTAC, "Chỉnh sửa thông tin tour không thành công, vui lòng thử lại"); } } break; #endregion default: break; } btn_Sua.Enabled = true; btnThem.Enabled = true; btn_Xoa.Enabled = true; }