Пример #1
0
 private void CloseSubdivision()
 {
     if (dateTimePicker2.Value < NewdSubDivivsion.CreateDate || dateTimePicker2.Value > DateTime.Now)
     {
         MessageBox.Show("Не корректная дата закрытия");
         return;
     }
     using (DBConteiner db = new DBConteiner())
     {
         try
         {
             SubDivName_txtBox.Enabled = false;
             SubDivision CloseSubdiv = db.SubDivisions.Where(o => o.SubDivisionId == NewdSubDivivsion.SubDivisionId).FirstOrDefault();
             if (CloseSubdiv != null)
             {
                 db.Entry(CloseSubdiv).State = EntityState.Modified;
                 CloseSubdiv.CollapsDate     = dateTimePicker2.Value;
                 CloseSubdiv.WorkStatus      = false;
                 //here we change the status of parent subdivision in all of subdivision which have a parent subdivision
                 //that we close now. New status of these subdivision is "No patent sabdivision"
                 List <SubDivision> subDivisions = db.SubDivisions.Where(e => e.ParentIdent == NewdSubDivivsion.SubDivisionId).ToList();
                 if (subDivisions != null)
                 {
                     foreach (SubDivision sub in subDivisions)
                     {
                         db.Entry(sub).State = EntityState.Modified;
                         sub.ParentIdent     = 1;
                     }
                 }
                 db.SaveChanges();
                 NewdSubDivivsion.WorkStatus = false;//for corret showing infomation by label4 (Work ort Don't work)
                 PreviosDataLoad();
                 SetDefaultControls();
                 MessageBox.Show("Подразделение закрыто");
             }
         }
         catch (ArgumentNullException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (OverflowException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             MessageBox.Show(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Пример #2
0
        private void EditSubdiv()
        {
            using (DBConteiner db = new DBConteiner())
            {
                try
                {
                    Library lib = new Library();
                    if (!lib.NewSubDivValidstion(SelectedSubDivivsion))
                    {
                        return;
                    }

                    SubDivision tmp = db.SubDivisions.Where(o => o.SubDivisionId == NewdSubDivivsion.SubDivisionId).FirstOrDefault();

                    if (tmp != null)
                    {
                        db.Entry(tmp).State = EntityState.Modified;

                        tmp.SubDivName   = SubDivName_txtBox.Text;
                        tmp.ParentIdent  = SelectedSubDivivsion.SubDivisionId;
                        tmp.ParentSubdiv = db.SubDivisions.Where(e => e.SubDivisionId == SelectedSubDivivsion.SubDivisionId).FirstOrDefault();
                        tmp.CreateDate   = dateTimePicker1.Value;
                        tmp.CollapsDate  = dateTimePicker2.Value;

                        db.SaveChanges();
                        editSave         = true;
                        NewdSubDivivsion = SelectedSubDivivsion;
                        PreviosDataLoad();
                        SetDefaultControls();
                        MessageBox.Show("Данные о подразделении изменены");
                    }
                }
                catch (ArgumentNullException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (OverflowException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #3
0
        private void SaveNewEmployeeData()
        {
            using (DBConteiner db = new DBConteiner())
            {
                try
                {
                    // db.Entry(TransferSubDivision).State = EntityState.Modified;

                    if (editEmployee)
                    {
                        SelectedEmployee = db.Employees.Where(e => e.EmployeeId == SelectedEmployee.EmployeeId).FirstOrDefault();
                    }
                    //else
                    //    db.Employees.Attach(SelectedEmployee);



                    SelectedEmployee.EmpName       = textBox_Name.Text;
                    SelectedEmployee.EmpSurName    = textBox_Surname.Text;
                    SelectedEmployee.EmpPatronimic = textBox_Patronimic.Text;
                    if (radioButton_male.Checked)
                    {
                        SelectedEmployee.Sex = true;
                    }
                    if (radioButton_female.Checked)
                    {
                        SelectedEmployee.Sex = false;
                    }
                    SelectedEmployee.DateBirth     = dateTimePicker_BirthDate.Value;
                    SelectedEmployee.BirthPlace    = richTextBox_BirthPlace.Text;
                    SelectedEmployee.INN           = textBox_INN.Text;
                    SelectedEmployee.TabNumber     = textBox_TabNumber.Text;
                    SelectedEmployee.StartDateWork = dateTimePicker_StartDateWork.Value;
                    if (checkBox_Fired.Checked)
                    {
                        SelectedEmployee.FireDate   = dateTimePicker_FireDate.Value;
                        SelectedEmployee.FireReason = richTextBox1.Text;
                    }



                    //кастыли, которые не также не работают, но если их применить, то получаем
                    //дублирование название подразделения в БД. Что говорит о том, что нужно как-то умудриться
                    //подифицировать это подразделение.. Пока - хз как. Т.к. связ подразделения и сотрудника у нас
                    //посрдедством n - n, и с какого-то хера из подразделения не видно сотрудника, хотя и все
                    //нужные поля  - публичные . жопа кароч
                    //db.Configuration.AutoDetectChangesEnabled = false;
                    //db.Configuration.ValidateOnSaveEnabled = false;


                    if (editEmployee)
                    {
                        db.Entry(SelectedEmployee).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Employees.Add(SelectedEmployee);
                    }



                    db.SaveChanges();

                    EmployeeSubDivs empSabDiv = new EmployeeSubDivs();
                    empSabDiv.Employee     = SelectedEmployee;
                    empSabDiv.SubDivision  = TransferSubDivision;
                    empSabDiv.Position     = textBox_EmpPosition.Text;
                    empSabDiv.TransferDate = dateTimePicker_StartDateWork.Value;


                    db.EmployeeSubDivisions.Add(empSabDiv);

                    db.SaveChanges();

                    MessageBox.Show("Данные сохранены");
                }
                catch (ArgumentNullException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (OverflowException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }