private void btnAddTour_Click(object sender, EventArgs e) { if (Tour.FindByName(txtName.Text).Count > 0) { MessageBox.Show("This tour had been exited!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (lvDestination.Items.Count == 0) { MessageBox.Show("Do not choose the destinations!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult dlg = MessageBox.Show("Do you want to adding this tour?", "Question!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == System.Windows.Forms.DialogResult.No) { return; } int affected = Tour.Add(controls_Load()); if (affected > 0) { //Thêm danh sách điểm đến //Gán mã tour cho danh sách điểm đến foreach (DiemDen item in listDes) { item.MTour = affected; } DiemDen.Add(listDes); listDes = new List <DiemDen>(); listScenic = new List <DiemDL>(); lvDestination.Items.Clear(); txtName.Text = ""; txtStartPlace.Text = ""; tvtours_Load(Tour.All()); MessageBox.Show("Adding is successful!", "Message!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.DialogResult = System.Windows.Forms.DialogResult.OK; } }
private void btnUpdateTour_Click(object sender, EventArgs e) { Tour exited = Tour.Single(ID); Tour newToour = controls_Load(); if (exited.TenTour != newToour.TenTour) { if (Tour.FindByName(txtName.Text).Count > 0) { MessageBox.Show("This tour had been exited!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (lvDestination.Items.Count == 0) { MessageBox.Show("Do not choose the destinations!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult dlg = MessageBox.Show("Do you want to update this tour?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == System.Windows.Forms.DialogResult.Yes) { Tour.Update(newToour); DiemDen.DeleteByMTour(ID); //Gán mã tour cho danh sách điểm đến foreach (DiemDen item in listDes) { item.MTour = ID; } DiemDen.Add(listDes); tvtours_Load(Tour.All()); MessageBox.Show("Updating had been successful!", "Message!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; } }