void ShowStaff() { listViewStaff.Items.Clear(); foreach (StaffSet staff in Program.RBS_Project.StaffSet) { DepartmentsSet departmentsSet = new DepartmentsSet(); foreach (DepartmentsSet departments in Program.RBS_Project.DepartmentsSet) { if (staff.Id_Department == departments.Id) { departmentsSet = departments; } } ListViewItem item = new ListViewItem(new string[] { staff.Id.ToString(), staff.LastName + " " + staff.FirstName + " " + staff.MiddleName, staff.Phone, staff.Email, staff.Position, departmentsSet.Name }); item.Tag = staff; listViewStaff.Items.Add(item); } listViewStaff.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
void Deductions(DepartmentsSet department) { int count = 0; foreach (StaffSet staff in Program.RBS_Project.StaffSet) { if (staff.Id_Department == department.Id) { count++; } } department.Count = count; }
private void buttonDelete_Click(object sender, EventArgs e) { try { if (listViewDepartments.SelectedItems.Count == 1) { DepartmentsSet departmentsSet = listViewDepartments.SelectedItems[0].Tag as DepartmentsSet; Program.RBS_Project.DepartmentsSet.Remove(departmentsSet); Program.RBS_Project.SaveChanges(); } textBoxName.Text = ""; comboBoxManager.SelectedItem = null; ShowDepartments(); } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void listViewDepartments_SelectedIndexChanged(object sender, EventArgs e) { if (listViewDepartments.SelectedItems.Count == 1) { DepartmentsSet departmentsSet = listViewDepartments.SelectedItems[0].Tag as DepartmentsSet; textBoxName.Text = departmentsSet.Name; if (departmentsSet.Manager != null) { comboBoxManager.SelectedIndex = comboBoxManager.FindString(departmentsSet.Id.ToString()); } } else { textBoxName.Text = ""; comboBoxManager.SelectedItem = null; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (textBoxName.Text != "") { DepartmentsSet departmentsSet = new DepartmentsSet(); departmentsSet.Name = textBoxName.Text; if (comboBoxManager.SelectedItem != null) { departmentsSet.Manager = comboBoxManager.SelectedItem.ToString(); } Program.RBS_Project.DepartmentsSet.Add(departmentsSet); Program.RBS_Project.SaveChanges(); ShowDepartments(); } else { MessageBox.Show("Заполните название отдела!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }