private void btnAdd_Click(object sender, EventArgs e) { if (TestPrice()) { if (listGuideChoose == null || listGuideChoose.Count == 0) { MessageBox.Show("You do not choose the Guiders!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); btnAdd.Enabled = false; return; } DialogResult dlg = MessageBox.Show("Are you adding this trip?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == System.Windows.Forms.DialogResult.Yes) { Chuyen ch = controls_Load(); int _MT = (cbbTours.SelectedItem as Tour).ID; int _MC = Chuyen.Add(ch); if (_MC > 0) { PhanCongHDV pc; List <PhanCongHDV> listPC = new List <PhanCongHDV>(); foreach (HuongDanVien item in listGuideChoose) { pc = new PhanCongHDV(); pc.MChuyen = _MC; pc.MTour = _MT; pc.MHDV = item.ID; if (!PhanCongHDV.Add(pc)) { DialogResult dl = MessageBox.Show(String.Format("Division had been failse with the guide has code: {0} and name: {1} {2}! Are you wanting to continue?", item.ID, item.Ho, item.Ten), "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dl == System.Windows.Forms.DialogResult.No) { return; } } } MessageBox.Show("Adding is successful!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); int index = cbbTours.SelectedIndex; cbbTours.SelectedIndex = -1; cbbTours.SelectedIndex = index; this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBox.Show("Adding had been failse!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void cbbTours_SelectedIndexChanged(object sender, EventArgs e) { if (cbbTours.SelectedIndex > -1) { Tour t = cbbTours.SelectedItem as Tour; listGuideNoChoose = HuongDanVien.FindBy_MTour_NotBusy(t.ID); if (MChuyen == 0) { listGuideChoose = new List <HuongDanVien>(); lvGuidesChosed.Items.Clear(); } else { //Load ds huong dan vien duoc phan cong len listGuideChoose = HuongDanVien.FindByMChuyen(MChuyen); lvGuidesChosed_Load(listGuideChoose); //Chuyen thanh tour khac if (current != null && (cbbTours.SelectedItem as Tour).ID != current.MTour) { DialogResult dlg = MessageBox.Show("Program remove all guides had been chose! Are you wanting repair this trip?", "Wraning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlg == System.Windows.Forms.DialogResult.Yes) { PhanCongHDV.DeletePhanCong(MChuyen); lvGuidesChosed.Items.Clear(); listGuideChoose = new List <HuongDanVien>(); listGuideNoChoose = HuongDanVien.FindBy_MTour_NotBusy((cbbTours.SelectedItem as Tour).ID); lvGuidesNoChoose_Load(listGuideNoChoose); //btnAdd.Enabled = false; //btnUpdate.Enabled = false; } else { int count = cbbTours.Items.Count; for (int i = 0; i < count; i++) { if ((cbbTours.Items[i] as Tour).ID == current.MTour) { cbbTours.SelectedIndex = i; break; } } } } } lvGuidesNoChoose_Load(listGuideNoChoose); //Thoong ke tinh gia listPrice = Chuyen.FindByMTour(t.ID); } }