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; } }
private void button4_Click(object sender, EventArgs e) { int numberTTN = Convert.ToInt32(NumberTTNTextBox.Text); int alreadyExistMovementNumber = db.tbl_Movement_History.Where(x => x.Movement_History_Number == numberTTN).Count(); if (alreadyExistMovementNumber > 0) { if (ITSSenderComboBox.SelectedText != "" && KustSenderComboBox.SelectedText != "" && KustNumbertextBox.Text != "" && SenderComboBox.SelectedText != "" && DriverComboBox.SelectedText != "" && DriverListSerialtextBox.Text != "" && ObjectsMovementGridView.RowCount > 0) { string senderKadrSostName = SenderComboBox.SelectedItem.ToString().Split(' ').First(); string senderPermicionKadrSostName = SenderAllowedComboBox.SelectedItem.ToString().Split(' ').First(); string receverRequestKadrSostName = RequestedReceverComboBox.SelectedItem.ToString().Split(' ').First(); string driverKadrSostName = DriverComboBox.SelectedItem.ToString().Split(' ').First(); db.tbl_Movement_History.Add(new tbl_Movement_History { Data_Movement_History = DateTime.Now, Kod_Sender_ORM = db.tbl_ORM.Where(x => x.Short_Name_ORM.Equals((string)ITSSenderComboBox.SelectedItem)).Select(x => x.ID_ORM).FirstOrDefault(), Kod_Sender_Kadr_Sost = db.tbl_Kadrovii_Sostav.Where(x => x.Familiya_KS.Equals(senderKadrSostName)).Select(x => x.ID_KS).FirstOrDefault(), Kod_Sender_Permision_Kadr_Sost = db.tbl_Kadrovii_Sostav.Where(x => x.Familiya_KS.Equals(senderPermicionKadrSostName)).Select(x => x.ID_KS).FirstOrDefault(), Kod_Recever_ORM = db.tbl_ORM.Where(x => x.Short_Name_ORM.Equals((string)ITSReceverComboBox.SelectedItem)).Select(x => x.ID_ORM).FirstOrDefault(), Kod_Recever_Request_Kadr_Sost = db.tbl_Kadrovii_Sostav.Where(x => x.Familiya_KS.Equals(receverRequestKadrSostName)).Select(x => x.ID_KS).FirstOrDefault(), Kod_Driver_Kadr_Sost = db.tbl_Kadrovii_Sostav.Where(x => x.Familiya_KS.Equals(driverKadrSostName)).Select(x => x.ID_KS).FirstOrDefault(), Kod_Driver_Movement_List = Convert.ToInt32(DriverListSerialtextBox.Text), Movement_History_Number = numberTTN }); int i = 0; List <tbl_Movement_History_Details> liMovDet = new List <tbl_Movement_History_Details>(); while (ObjectsMovementGridView.Rows.Count > i) { int kodModulName = 0; string nonExistInDictionaryModulName = null; string modul = ObjectsMovementGridView.Rows[i].Cells[0].Value.ToString(); if (db.tbl_Modul_Name.Where(x => x.Short_Name_Modul_Name.Equals(modul)).Count() > 0) { kodModulName = db.tbl_Modul_Name.Where(x => x.Short_Name_Modul_Name.Equals(modul)).Select(x => x.ID_Modul_Name).FirstOrDefault(); nonExistInDictionaryModulName = null; } else { kodModulName = 0; nonExistInDictionaryModulName = modul; } string edIzmer = ObjectsMovementGridView.Rows[i].Cells[3].Value.ToString(); string package = ObjectsMovementGridView.Rows[i].Cells[4].Value.ToString(); int countModul = (int)ObjectsMovementGridView.Rows[i].Cells[2].Value; float weightModul = (float)ObjectsMovementGridView.Rows[i].Cells[5].Value; string wayToGetWeight = ObjectsMovementGridView.Rows[i].Cells[5].Value.ToString(); liMovDet.Add(new tbl_Movement_History_Details { Kod_Movement_History = numberTTN, Kod_Modul_Name = kodModulName, Modul_Name_IF_Definition_Not_Exist_In_Dictionary = nonExistInDictionaryModulName, Kod_Ed_Izmer = db.tbl_Spiski.Where(x => x.Value_Spiski.Equals(edIzmer)).Select(x => x.ID_Spiski).FirstOrDefault(), Kod_Package = db.tbl_Spiski.Where(x => x.Value_Spiski.Equals(package)).Select(x => x.ID_Spiski).FirstOrDefault(), Count_Modul = countModul, Weight_Modul = weightModul, Kod_Way_To_Get_Weight = wayToGetWeight }); i++; } db.SaveChanges(); } else { MessageBox.Show("Один или несколько пунектов не заполнены!", "Ошибка!!!"); } } else { MessageBox.Show("ТТН с таким номером уже существует. Введите другой номер.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }