private void btnAdd_Click(object sender, EventArgs e) { if (cbbLoai.GetItemText(cbbLoai.SelectedItem) != "" && txtDacDiem.Text != "" && txtMa.Text != "" && txtTen.Text != "") { String maLoai = cbbLoai.GetItemText(cbbLoai.SelectedItem); TourDTO DTO = new TourDTO(txtMa.Text, txtTen.Text, maLoai); if (bus.themTour(DTO)) { MessageBox.Show("Thêm thành công"); BangTour.DataSource = bus.getTour(); // refresh datagridview } else { MessageBox.Show("Thêm ko thành công"); } } else { MessageBox.Show("Xin hãy nhập đầy đủ"); } }
private void Add1_Click(object sender, EventArgs e) { if (TestInput() == true) { TourDTO t = new TourDTO(); t.TenTour = textBox_tentour.Text; t.ThongTinTour = textBox_thongtintour.Text; string str = textBox_giatour.Text; if (str.Contains("₫")) { while (str.IndexOf("₫") != -1) { str = str.Remove(str.IndexOf("₫"), 1); } } if (str.Contains(" ")) { while (str.IndexOf(" ") != -1) { str = str.Remove(str.IndexOf(" "), 1); } } if (str.Contains(".")) { while (str.IndexOf(".") != -1) { str = str.Remove(str.IndexOf("."), 1); } } Regex regex = new Regex(@"^\d+$"); if (!regex.IsMatch(str)) { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { t.GiaTour = int.Parse(str); TourBUS tour = new TourBUS(); int kq = tour.themTour(t); if (kq != 0) { MessageBox.Show("Thêm thành công!", "Thông báo"); ListViewItem item = new ListViewItem(new String[] { textBox_matour.Text = kq.ToString(), textBox_tentour.Text, textBox_thongtintour.Text, textBox_giatour.Text }); this.listView_dstour.Items.AddRange(new ListViewItem[] { item }); foreach (ListViewItem item1 in listView_dd.Items) { DiaDiemBUS dd = new DiaDiemBUS(); int ma = dd.search_madd(item1.SubItems[0].Text); ChiTietTourDTO ct = new ChiTietTourDTO(); ct.MaTour = kq; ct.MaDiaDiem = ma; ChiTietTourBUS chitiet = new ChiTietTourBUS(); chitiet.themChiTiet(ct); } textBox_tentour.Text = ""; textBox_thongtintour.Text = ""; textBox_giatour.Text = ""; listView_dd.Items.Clear(); } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); Dispose(); } } } }
private void Add1_Click(object sender, EventArgs e) { int k = 0; if (textBox_matour.Text == "") { k = 1; errorProvider1.SetError(textBox_matour, "Mã tour không được để trống!"); } if (textBox_tentour.Text == "") { k = 1; errorProvider1.SetError(textBox_tentour, "Tên tour không được để trống!"); } if (textBox_thongtintour.Text == "") { k = 1; errorProvider1.SetError(textBox_thongtintour, "Thông tin tour không được để trống!"); } if (textBox_giatour.Text == "") { k = 1; errorProvider1.SetError(textBox_giatour, "Giá tour không được để trống!"); } if (k == 0) { TourDTO t = new TourDTO(); t.MaTour = int.Parse(textBox_matour.Text); t.TenTour = textBox_tentour.Text; t.ThongTinTour = textBox_thongtintour.Text; t.GiaTour = int.Parse(textBox_giatour.Text); TourBUS tour = new TourBUS(); int kq = tour.themTour(t); if (kq == t.MaTour) { MessageBox.Show("Mã tour đã tồn tại.", "Thông báo"); } else if (kq == 1) { MessageBox.Show("Thêm thành công!", "Thông báo"); ListViewItem item = new ListViewItem(new String[] { textBox_matour.Text, textBox_tentour.Text, textBox_thongtintour.Text, textBox_giatour.Text }); this.listView1.Items.AddRange(new ListViewItem[] { item }); textBox_matour.Text = ""; textBox_tentour.Text = ""; textBox_thongtintour.Text = ""; textBox_giatour.Text = ""; } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); Dispose(); } } }