public FrmStaff() { InitializeComponent(); CmbStaffRole.SelectedIndex = 0; Staff = null; staffs = StaffDao.QueryAll(); hasUpdated = false; //foreach (EtStaff staff in staffs) // DgvStaffData.Rows.Add(new object[] { // staff.StaffID, // staff.StaffName, // staff.StaffPhone, // staff.Role // }); }
private void BtnStaffCancel_Click(object sender, EventArgs e) { DgvStaffData.Rows.Clear(); staffs = StaffDao.QueryAll(); foreach (EtStaff staff in staffs) { DgvStaffData.Rows.Add(new object[] { staff.StaffID, staff.StaffName, staff.StaffPhone, staff.Role }); } hasUpdated = false; }
//private void CmbStaffRole_SelectedIndexChanged(object sender, EventArgs e) { // if (CmbStaffRole.SelectedIndex == 0) // staffs = StaffDao.QueryAll(); // else // staffs = StaffDao.QueryByRole(CmbStaffRole.SelectedIndex-1); // DgvStaffData.Rows.Clear(); // foreach (EtStaff staff in staffs) // DgvStaffData.Rows.Add(new object[] { // staff.StaffID, // staff.StaffName, // staff.StaffPhone, // staff.Role // }); // TxtStaffSearch.Text = ""; //} private void BtnStaffSearch_Click(object sender, EventArgs e) { List <EtStaff> list1, list2; int index = CmbStaffRole.SelectedIndex; if (0 == index) { list1 = StaffDao.QueryAll(); } else { list1 = StaffDao.QueryByRole(index - 1); } string idOrName = TxtStaffSearch.Text; if ("".Equals(idOrName)) { staffs = list1; } else { string RegexStr = "^[0-9]+$"; if (Regex.IsMatch(idOrName, RegexStr)) { list2 = StaffDao.QueryByStaffID(int.Parse(idOrName)); } else { list2 = StaffDao.QueryByStaffName(idOrName); } staffs = list1.Intersect(list2, new MyCompare()).ToList(); } DgvStaffData.Rows.Clear(); foreach (EtStaff staff in staffs) { DgvStaffData.Rows.Add(new object[] { staff.StaffID, staff.StaffName, staff.StaffPhone, staff.Role }); } }