private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (var logic = new NomenclaturesLogic())
            {
                this.department = logic.UN_Departments.GetById(this.id_selectedDepartment);

                if (this.id_structurePosition == 0)
                {
                    this.structurePosition               = new HR_StructurePositions();
                    this.structurePosition.IsActive      = true;
                    this.structurePosition.Code          = department.Code;
                    this.structurePosition.id_department = this.id_selectedDepartment;
                    this.structurePosition.ActiveFrom    = DateTime.Now;
                }
                else
                {
                    this.structurePosition = logic.HR_StructurePositions.GetById(this.id_structurePosition);
                }

                var comboBoxLogic = new ComboBoxLogic();
                this.cmbPosition.ItemsSource = comboBoxLogic.ReadGlobalPositions(this.structurePosition.id_globalPosition);
                if (this.structurePosition.id_globalPosition != 0)
                {
                    this.cmbPositionTypes.ItemsSource = comboBoxLogic.ReadPositionTypes(this.structurePosition.HR_GlobalPositions.id_positionType);
                }
                else
                {
                    this.cmbPositionTypes.ItemsSource = comboBoxLogic.ReadPositionTypes();
                }
            }
            this.DataContext = this.structurePosition;
        }
        private void btnImportPersonsAndPositions_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            if (opf.ShowDialog().Value == true)
            {
                Excel.Worksheet xlsheet;
                Excel.Workbook  xlwkbook;

                xlwkbook = (Excel.Workbook)System.Runtime.InteropServices.Marshal.BindToMoniker(opf.FileName);
                xlsheet  = (Excel.Worksheet)xlwkbook.ActiveSheet;

                Excel.Range oRng;

                int id_currentDepartment = 0;
                int id_parentDepartment  = 0;


                for (int i = 1; i < 12; i++)
                {
                    using (var logic = new NomenclaturesLogic())
                    {
                        string gstr;
                        if (id_currentDepartment == 0)
                        {
                            gstr = this.GetRangeValue(i, 1, xlsheet);
                            if (gstr == "")
                            {
                                continue;
                            }
                            if (gstr == "1000")
                            {
                                gstr = this.GetRangeValue(i, 2, xlsheet);

                                id_currentDepartment = logic.GetDepartmentByName(gstr).id_department;
                                id_parentDepartment  = id_currentDepartment;
                                continue;
                            }
                            else if (gstr == "999")
                            {
                                gstr = this.GetRangeValue(i, 2, xlsheet);
                                id_currentDepartment = logic.GetDepartmentShiftByName(gstr, id_currentDepartment).id_department;
                                continue;
                            }
                        }
                        else
                        {
                            gstr = this.GetRangeValue(i, 1, xlsheet);
                            if (gstr == "")
                            {
                                continue;
                            }
                            #region parse department
                            if (gstr == "1000")
                            {
                                gstr = this.GetRangeValue(i, 2, xlsheet);
                                id_currentDepartment = logic.GetDepartmentByName(gstr).id_department;
                                id_parentDepartment  = id_currentDepartment;
                                continue;
                            }
                            else if (gstr == "999")
                            {
                                gstr = this.GetRangeValue(i, 2, xlsheet);
                                id_currentDepartment = logic.GetDepartmentShiftByName(gstr, id_parentDepartment).id_department;
                                continue;
                            }
                            #endregion
                            else
                            {
                                gstr = this.GetRangeValue(i, 2, xlsheet);


                                HR_StructurePositions spos = null;

                                UN_Persons     per = new UN_Persons();
                                HR_Contracts   con = new HR_Contracts();
                                HR_Assignments ass = new HR_Assignments();

                                spos = logic.FindStructurePositionByName(gstr, id_currentDepartment);
                                if (spos == null)
                                {
                                    spos = new HR_StructurePositions();
                                    spos.id_globalPosition = logic.GetGlobalPositionByName(gstr).id_globalPosition;
                                    spos.id_department     = id_currentDepartment;
                                    spos.IsActive          = true;
                                    spos.ActiveFrom        = DateTime.Now;
                                    spos.StaffCount        = 1;
                                    logic.HR_StructurePositions.Add(spos);
                                }

                                gstr     = this.GetRangeValue(i, 3, xlsheet);
                                per.Name = gstr;

                                con.UN_Persons = per;

                                ass.HR_StructurePositions = spos;
                                ass.AdditionalHolidays    = 0;
                                ass.NumberHolidays        = 20;
                                ass.HR_Contracts          = con;
                                ass.IsActive = true;
                                ass.IsAdditionalAssignment = false;

                                logic.UN_Persons.Add(per);

                                logic.HR_Contracts.Add(con);
                                logic.HR_Assignments.Add(ass);

                                logic.Save();

                                spos.Order = spos.id_structurePosition;
                                logic.Save();
                            }
                        }
                    }
                }
            }
        }