private async void metroTileAccept_Click(object sender, EventArgs e) { try { using (ApplicationDbContext context = new ApplicationDbContext()) { int pId = Int32.Parse(metroComboBoxPosition.SelectedValue.ToString()); sf.StaffTable(await context.Staffs.Include(p => p.Position).Where(p => p.PositionId == pId).ToListAsync()); sf.filter(); this.Close(); } } catch (Exception gg) { MessageBox.Show(gg.Message, "SWA", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void metroTileAccept_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(metroTextBoxSurname.Text)) { throw new Exception("Введите фамилию сотрудника"); } else if (String.IsNullOrEmpty(metroTextBoxFName.Text)) { throw new Exception("Введите имя сотрудника"); } else if (String.IsNullOrEmpty(metroTextBoxSName.Text)) { throw new Exception("Введите отчество сотрудника"); } else if (String.IsNullOrEmpty(metroComboBoxGender.Text)) { throw new Exception("Выберите пол сотрудника"); } else if (String.IsNullOrEmpty(metroTextBoxAdress.Text)) { throw new Exception("Введите адрес сотрудника"); } else if (String.IsNullOrEmpty(maskedTextBox1.Text)) { throw new Exception("Введите телефон сотрудника"); } using (ApplicationDbContext context = new ApplicationDbContext()) { staff.StafftSurName = metroTextBoxSurname.Text; staff.StaffFirstName = metroTextBoxFName.Text; staff.StaffSecondName = metroTextBoxSName.Text; staff.PositionId = Convert.ToInt32(metroComboBoxPosition.SelectedValue); staff.StaffBirthDate = dateTimePickerBirth.Value; staff.StaffGender = metroComboBoxGender.Text; staff.StaffAdress = metroTextBoxAdress.Text; staff.StaffTelephone = maskedTextBox1.Text; if (StaffId == 0) { context.Staffs.Add(staff); } else { context.Entry(staff).State = EntityState.Modified; } await context.SaveChangesAsync(); sf.StaffTable(await context.Staffs.Include(s => s.Position).ToListAsync()); } MessageBox.Show(MesAccept, "SWA", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception gg) { MessageBox.Show(gg.Message, "SWA", MessageBoxButtons.OK, MessageBoxIcon.Error); } }