private void DeleteCurrentWorkerButton_Click(object sender, EventArgs e) { if (WorkersDataGridView.SelectedRows.Count > 0) { if (MessageBox.Show("Вы уверены что хотите удалить работника?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { using (DBTTNEntities db = new DBTTNEntities()) { string tabNumber = WorkersDataGridView.SelectedRows[0].Cells[3].Value.ToString(); tbl_Kadrovii_Sostav ks = new tbl_Kadrovii_Sostav(); ks = db.tbl_Kadrovii_Sostav.Where(x => x.Tab_N_KS.Equals(tabNumber)).FirstOrDefault(); db.tbl_Kadrovii_Sostav.Remove(ks); WorkersDataGridView.Rows.Remove(WorkersDataGridView.SelectedRows[0]); db.SaveChanges(); } } } }
private void AddKadrviiSostRecord() { using (DBTTNEntities db = new DBTTNEntities()) { if (FirstNameTextBox.Text != "" && SecondNameTextBox.Text != "" && LastNameTextBox.Text != "" && TabNumberTextBox.Text != "" && DoljnostComboBox.SelectedItem.ToString() != "" && PartNumberComboBox.SelectedItem.ToString() != "") { try { string tabNumber = TabNumberTextBox.Text; tbl_Kadrovii_Sostav ks = new tbl_Kadrovii_Sostav(); //ks = db.tbl_Kadrovii_Sostav.Where(x => x.Tab_N_KS.Equals(tabNumber)).FirstOrDefault(); ks.Familiya_KS = FirstNameTextBox.Text; ks.Imya_KS = SecondNameTextBox.Text; ks.Otchestvo_KS = LastNameTextBox.Text; ks.Tab_N_KS = TabNumberTextBox.Text; ks.Dolgnost_KS = DoljnostComboBox.SelectedItem.ToString(); string pn = PartNumberComboBox.SelectedItem.ToString(); ks.Kod_ORM_KS = db.tbl_ORM.Where(x => x.Short_Name_ORM.Equals(pn)).Select(x => x.ID_ORM).FirstOrDefault(); db.tbl_Kadrovii_Sostav.Add(ks); db.SaveChanges(); WorkersDataGridView.Rows.Add(FirstNameTextBox.Text, SecondNameTextBox.Text, LastNameTextBox.Text, TabNumberTextBox.Text, DoljnostComboBox.SelectedItem.ToString(), PartNumberComboBox.SelectedItem.ToString()); ApplyButton.Visible = false; CancelButton.Visible = false; } catch (Exception e) { MessageBox.Show("Ошибка: " + e.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Одно из полей не заполнено. Пожалуйста, заполните ВСЕ поля для продолжения.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void EditKadrviiSostRecord() { using (DBTTNEntities db = new DBTTNEntities()) { //string tabNumber = TabNumberTextBox.Text; tbl_Kadrovii_Sostav ks = new tbl_Kadrovii_Sostav(); ks = db.tbl_Kadrovii_Sostav.Where(x => x.Tab_N_KS.Equals(tabNumberEditWorker)).FirstOrDefault(); ks.Familiya_KS = FirstNameTextBox.Text; ks.Imya_KS = SecondNameTextBox.Text; ks.Otchestvo_KS = LastNameTextBox.Text; ks.Tab_N_KS = TabNumberTextBox.Text; ks.Dolgnost_KS = DoljnostComboBox.SelectedItem.ToString(); string pn = PartNumberComboBox.SelectedItem.ToString(); ks.Kod_ORM_KS = db.tbl_ORM.Where(x => x.Short_Name_ORM.Equals(pn)).Select(x => x.ID_ORM).FirstOrDefault(); db.SaveChanges(); WorkersDataGridView.SelectedRows[0].Cells[0].Value = FirstNameTextBox.Text; WorkersDataGridView.SelectedRows[0].Cells[1].Value = SecondNameTextBox.Text; WorkersDataGridView.SelectedRows[0].Cells[2].Value = LastNameTextBox.Text; WorkersDataGridView.SelectedRows[0].Cells[3].Value = TabNumberTextBox.Text; WorkersDataGridView.SelectedRows[0].Cells[4].Value = DoljnostComboBox.SelectedItem; WorkersDataGridView.SelectedRows[0].Cells[5].Value = PartNumberComboBox.SelectedItem; } }