private void btnEdit_Click(object sender, EventArgs e) { if (BangTour.SelectedRows.Count > 0) { if (txtMa.Text != "" && txtTen.Text != "" && txtDacDiem.Text != "" && cbbLoai.Text != "") { if (ValadateTen(txtTen.Text)) { MessageBox.Show("Tên tác giả tại sao lại chứa kí tự lạ hả!!!", "Thông báo"); txtTen.Text = ""; txtTen.Focus(); } else if (ValadateTen(txtMa.Text)) { MessageBox.Show("Mã đọc giả tại sao lại chứa kí tự lạ hả!!!", "Thông báo"); txtMa.Text = ""; txtMa.Focus(); } else if (ValadateTen(txtDacDiem.Text)) { MessageBox.Show("Mã đọc giả tại sao lại chứa kí tự lạ hả!!!", "Thông báo"); txtDacDiem.Text = ""; txtDacDiem.Focus(); } else { DataGridViewRow row = BangTour.SelectedRows[0]; string ma = row.Cells[0].Value.ToString(); TourDTO sDTO = new TourDTO(ma, txtTen.Text, cbbLoai.Text); // Sửa if (bus.suaTour(sDTO)) { MessageBox.Show("Sửa thành công"); BangTour.DataSource = bus.getTour(); // refresh datagridview } else { MessageBox.Show("Sửa ko thành công"); } } } else { MessageBox.Show("Xin hãy nhập đầy đủ"); } } else { MessageBox.Show("Hãy chọn tác giả muốn sửa"); } }
private void Save_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) { TourBUS tour = new TourBUS(); 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); foreach (ListViewItem item in listView1.Items) { if (item.Selected) { if (tour.suaTour(t) == 1) { MessageBox.Show("Lưu thành công!", "Thông báo"); item.Text = textBox_matour.Text; item.SubItems[1].Text = textBox_tentour.Text; item.SubItems[2].Text = textBox_thongtintour.Text; item.SubItems[3].Text = textBox_giatour.Text; } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); Dispose(); } } } } }
private void Save_Click(object sender, EventArgs e) { if (TestInput() == true) { TourBUS tour = new TourBUS(); TourDTO t = new TourDTO(); foreach (ListViewItem item in listView_dstour.Items) { if (item.Selected) { t.MaTour = int.Parse(item.SubItems[0].Text); 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); if (tour.suaTour(t) == 1) { MessageBox.Show("Lưu thành công!", "Thông báo"); ChiTietTourBUS ctt = new ChiTietTourBUS(); ctt.xoaChiTiet(int.Parse(item.SubItems[0].Text)); 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 = int.Parse(item.SubItems[0].Text); ct.MaDiaDiem = ma; ChiTietTourBUS chitiet = new ChiTietTourBUS(); chitiet.themChiTiet(ct); } item.SubItems[1].Text = textBox_tentour.Text; item.SubItems[2].Text = textBox_thongtintour.Text; item.SubItems[3].Text = textBox_giatour.Text; } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); Dispose(); } } } } } }