private void btAdd_Click(object sender, EventArgs e) { fAddStaff f = new fAddStaff(); f.ActivebtnAdd(); f.ShowDialog(); List <Staff> staffs = StaffDAL.Instance.GetListStaff(); bool setcolor = true; if (this.flowLayoutPanelStaff.Controls.Count < staffs.Count) { foreach (Staff staff in staffs) { int count = staffs.IndexOf(staff); if (staffs.IndexOf(staff) + 1 == staffs.Count) { StaffItem staffItem = new StaffItem(staff.ID, staff.Name, staff.Image, staff.BirthDate, staff.Position, staff.UserName, staff.OverTime, staff.Fault, staff.SalaryReceived, staff.Sex, staff.CMND, staff.PhoneNumber, staff.Address, setcolor); staffItem.onEdit += Item_OnEdit; staffItem.onDel += StaffItem_onDel; staffItem.onOverTimeValueChanged += StaffItem_onOverTimeValueChanged; staffItem.onFaultChanged += StaffItem_onFaultChanged; staffItem.Tag = staff; flowLayoutPanelStaff.Controls.Add(staffItem); staffItems.Add(staffItem); sizeChange(); } } } this.SetBackGround(); }
private void Item_OnEdit(object sender, EventArgs args) { int id = ((sender as StaffItem).Tag as Staff).ID; Staff staff = StaffDAL.Instance.GetStaffById(id); string name = staff.Name; DateTime birthDate = staff.BirthDate; string pos = staff.Position; string phonenumber = staff.PhoneNumber; string username = staff.UserName; byte[] image = staff.Image; string address = staff.Address; bool sex = staff.Sex; string cmnd = staff.CMND; string phoneNumber = staff.PhoneNumber; fAddStaff frm = new fAddStaff(id, name, image, birthDate, pos, phonenumber, username, cmnd, sex, address); frm.ActivebtnEdit(); frm.UpdatelbNameForm("Sửa thông tin nhân viên"); frm.ShowDialog(); (sender as StaffItem).UpdateStaffItem(id); }