private void controls_BindData(KhachHang _cus) { txtCode.Text = _cus.ID; txtName.Text = _cus.Ten; txtFirstName.Text = _cus.Ho; txtAddress.Text = _cus.DiaChi; txtPhone.Text = _cus.SoDT; txtAccount.Text = _cus.SoTaiKhoan; if (_cus.GTinh) { rdMale.Checked = true; } else { rdFemale.Checked = true; } int i = 0; foreach (var item in cbbCountries.Items) { if (item.ToString().ToUpper() == _cus.QuocGia.ToUpper()) { cbbCountries.SelectedIndex = i; break; } i++; } cbbCity.SelectedIndex = 0; if (cbbCity.Enabled) { i = 0; foreach (var item in cbbCity.Items) { if (item.ToString().ToUpper() == _cus.ThanhPho.ToUpper()) { cbbCity.SelectedIndex = i; break; } i++; } } List <DatCho> temp = ListOrd.Find(Code); //Lấy danh sách đặt chỗ đang mở cua khach hang hien taij listOrder = ListTrips.Find(temp, 1); lvTripsOrders_Load(listOrder); dtpBirth.Value = _cus.NgaySinh; }
private void btnRequireOrder_Click(object sender, EventArgs e) { if (ListCus.Single(txtCode.Text) != null) { if (listOrder.Count > 0) { //Tao ra danh sach dat cho List <DatCho> temp = new List <DatCho>(); DatCho t = new DatCho(); foreach (Chuyen item in listOrder) { t.MChuyen = item.MChuyen; t.MKHang = txtCode.Text; temp.Add(t); } //Tim danh sach dat cho da ton tai va co trang thai chuyen di la dang cho List <Chuyen> oldTrip = ListTrips.Find(ListOrd.Find(Code), 1);//Tim ds chuyen dang mo cua ds dat cho cua khach hang //Tao ds dat cho cua khach hang da ton tai va trang thai dang mo List <DatCho> old = new List <DatCho>(); foreach (Chuyen item in oldTrip) { DatCho tp = new DatCho(); tp.MKHang = txtCode.Text; tp.MChuyen = item.MChuyen; old.Add(tp); } // So sanh voi temp de lay ra nhung cai them moi va nhung cai can xoa di List <DatCho> nw = new List <DatCho>(); //danh sach can them moi List <DatCho> dl = new List <DatCho>(); //danh sach can xoa di foreach (DatCho i in temp) { bool s = true; foreach (DatCho j in old) { if (i.MChuyen == j.MChuyen)//da ton tai, bo qua { s = false; break; } } if (s) { nw.Add(i);//Chua ton tai nen them duoc } } foreach (DatCho i in old) { bool r = true; foreach (DatCho j in temp) { if (i.MChuyen == j.MChuyen) { r = false; break; } } if (r)//co trong cai cu nhung khong co trong cai moi nen xoa di { dl.Add(i); } } // duong nhien ca hai old va temp deu la danh sach dat cho cua chuyen dang mo // Thuc hien xoa tren old va add tren nw la OK foreach (DatCho i in nw) { if (ListOrd.Add(i)) { MessageBox.Show(String.Format("You have add the trip which has code {0}!", i.MChuyen), "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(String.Format("You had been faile the trip which has code {0}!", i.MChuyen), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } foreach (DatCho i in dl) { if (ListOrd.Delete(i)) { MessageBox.Show(String.Format("You have delete the trip which has code {0}!", i.MChuyen), "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(String.Format("You had been faile the trip which has code {0}!", i.MChuyen), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } btnRequireOrder.Enabled = false; } else { MessageBox.Show("You have not add the trips! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("You have not add this customer! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }