public static void FillMilitaryDistrict(FirebirdFilePath dbFile)
        {
            List <V_OKRUG> entities;

            using (Old2014_1Context ctxFB = new Old2014_1Context(dbFile.ConnectionString))
            {
                entities = ctxFB.V_OKRUG.ToList();
            }

            using (BrandNewContext ctxg = new BrandNewContext())
            {
                foreach (var entity in entities)
                {
                    if (!ctxg.MilitaryDistrict.Any(e => e.Name.Equals(entity.NAME)))
                    {
                        ctxg.MilitaryDistrict.AddObject(new MilitaryDistrict()
                        {
                            Name = entity.NAME
                        });
                    }
                }

                ctxg.SaveChanges();
            }
        }
        public static void FillBadRegistry(FirebirdFilePath dbFile)
        {
            List <NA_UCHETE> entities;

            using (Old2014_1Context ctxFB = new Old2014_1Context(dbFile.ConnectionString))
            {
                entities = ctxFB.NA_UCHETE.ToList();
            }

            using (BrandNewContext ctxg = new BrandNewContext())
            {
                foreach (var entity in entities)
                {
                    if (!ctxg.BadRegistry.Any(e => e.Name.Equals(entity.NAME)))
                    {
                        ctxg.BadRegistry.AddObject(new BadRegistry()
                        {
                            Name = entity.NAME
                        });
                    }
                }

                ctxg.SaveChanges();
            }
        }
        private void FillMilitaryForces(FirebirdFilePath dbFile)
        {
            List <VID_VS> entities;

            using (Old2014_1Context ctxFB = new Old2014_1Context(dbFile.ConnectionString))
            {
                entities = ctxFB.VID_VS.ToList();
            }

            using (BrandNewContext ctxg = new BrandNewContext())
            {
                foreach (var entity in entities)
                {
                    if (!ctxg.MilitaryForces.Any(mf => mf.Name.Equals(entity.NAME)))
                    {
                        ctxg.MilitaryForces.AddObject(new MilitaryForces()
                        {
                            Name = entity.NAME
                        });
                    }
                }

                ctxg.SaveChanges();
            }
        }
        public static void FillSeason(FirebirdFilePath dbFile)
        {
            using (BrandNewContext ctxg = new BrandNewContext())
            {
                if (!ctxg.Season.Any(e => e.Year == dbFile.Year && e.Number == dbFile.Number))
                {
                    ctxg.Season.AddObject(new Season()
                    {
                        Year = dbFile.Year, Number = dbFile.Number
                    });
                }

                ctxg.SaveChanges();
            }
        }
        public static void FillDepartment(FirebirdFilePath dbFile)
        {
            List <RVK> entities;

            using (Old2014_1Context ctxFB = new Old2014_1Context(dbFile.ConnectionString))
            {
                entities = ctxFB.RVK.ToList();
            }

            using (BrandNewContext ctxg = new BrandNewContext())
            {
                Season season = ctxg.Season.FirstOrDefault(s => s.Number == dbFile.Number && s.Year == dbFile.Year);
                if (season == default(Season))
                {
                    season = new Season()
                    {
                        Number = dbFile.Number, Year = dbFile.Year
                    };
                }

                foreach (var entity in entities)
                {
                    if (!ctxg.Department.Any(e => e.NameShort == entity.NAME &&
                                             e.Season.Year == dbFile.Year &&
                                             e.Season.Number == dbFile.Number))
                    {
                        ctxg.Department.AddObject(new Department()
                        {
                            NameShort = entity.NAME, NameFull = entity.NAME_S, Season = season
                        });
                    }
                }

                ctxg.SaveChanges();
            }
        }
        public static void FillCompetency()
        {
            using (BrandNewContext ctxg = new BrandNewContext())
            {
                if (ctxg.Competency.Count() < 1)
                {
                    ctxg.Competency.AddObject(new Competency()
                    {
                        Name = "I"
                    });
                    ctxg.Competency.AddObject(new Competency()
                    {
                        Name = "II"
                    });
                    ctxg.Competency.AddObject(new Competency()
                    {
                        Name = "III"
                    });
                    //ctxg.Competency.AddObject(new Competency() { Name = "IV" });

                    ctxg.SaveChanges();
                }
            }
        }
        public static void FillMilitaryTitle()
        {
            using (BrandNewContext ctxg = new BrandNewContext())
            {
                if (ctxg.MilitaryTitle.Count() < 1)
                {
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 1,
                        Land   = "рядовой",
                        Marine = "матрос"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 2,
                        Land   = "ефрейтор",
                        Marine = "ст. матрос"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 3,
                        Land   = "мл. сержант",
                        Marine = "старшина 2 ст."
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 4,
                        Land   = "сержант",
                        Marine = "старшина 1 ст."
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 5,
                        Land   = "ст. сержант",
                        Marine = "главный старшина"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 5,
                        Land   = "старшина",
                        Marine = "главный корабельный старшина"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 6,
                        Land   = "прапорщик",
                        Marine = "мичман"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 7,
                        Land   = "ст. прапорщик",
                        Marine = "ст. мичман"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 8,
                        Land   = "мл. лейтенант",
                        Marine = "мл. лейтенант"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 9,
                        Land   = "лейтенант",
                        Marine = "лейтенант"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 10,
                        Land   = "ст. лейтенант",
                        Marine = "ст. лейтенант"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 11,
                        Land   = "капитан",
                        Marine = "капитан-лейтенант"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 12,
                        Land   = "майор",
                        Marine = "капитан 3 ранга"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 13,
                        Land   = "подполковник",
                        Marine = "капитан 2 ранга"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 14,
                        Land   = "полковник",
                        Marine = "капитан 1 ранга"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 15,
                        Land   = "генерал-майор",
                        Marine = "контр-адмирал"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 16,
                        Land   = "генерал-лейтенант",
                        Marine = "вице-адмирал"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 17,
                        Land   = "генерал-полковник",
                        Marine = "адмирал"
                    });
                    ctxg.MilitaryTitle.AddObject(new MilitaryTitle()
                    {
                        Rank   = 18,
                        Land   = "генерал армии",
                        Marine = "адмирал флота"
                    });

                    ctxg.SaveChanges();
                }
            }
        }
        public static void FillChosenRecruit(FirebirdFilePath dbFile)
        {
            List <KN_P> entities;

            using (Old2014_1Context ctxFB = new Old2014_1Context(dbFile.ConnectionString))
            {
                entities = ctxFB.KN_P.ToList();
            }

            using (BrandNewContext ctxg = new BrandNewContext())
            {
                foreach (var entity in entities)
                {
                    DateTime birthDate;
                    DateTime.TryParse(entity.D_ROD, out birthDate);

                    #region debugshit

                    /*
                     * List<ChosenRecruit> a1 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a2 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a3 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a4 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a5 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a51 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a52 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a53 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a6 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a7 = new List<ChosenRecruit>();
                     * List<ChosenRecruit> a8 = new List<ChosenRecruit>();
                     * try
                     * {
                     *  a1 = ctxg.ChosenRecruit.Where(e => e.LastName == entity.FAM).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a2 = a1.Where(e => e.FirstName == entity.IM).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a3 = a2.Where(e => e.MiddleName == entity.OTCH).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a4 = a3.Where(e => e.BirthDate.Value.Year == birthDate.Year).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a51 = a4.Where(e => e.Department_ID.HasValue).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a52 = a4.Where(e => string.IsNullOrEmpty(entity.RVK)).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * //try
                     * //{
                     * //    a53 = a4.Where(e => e.Department.NameShort == entity.RVK).ToList();
                     * //}
                     * //catch
                     * //{
                     * //}
                     * try
                     * {
                     *  a5 = a4.Where(e => !e.Department_ID.HasValue && string.IsNullOrEmpty(entity.RVK) ||
                     *      e.Department_ID.HasValue && e.Department.NameShort == entity.RVK).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a6 = a5.Where(e => e.Destination == entity.KUDA).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a7 = a6.Where(e => string.IsNullOrEmpty(e.Patron) && string.IsNullOrEmpty(entity.KTO) || e.Patron == entity.KTO).ToList();
                     * }
                     * catch
                     * {
                     * }
                     * try
                     * {
                     *  a8 = a7.Where(e => e.Season.Year == dbFile.Year && e.Season.Number == dbFile.Number).ToList();
                     * }
                     * catch (Exception)
                     * {
                     * }
                     */
                    #endregion

                    //if (!ctxg.ChosenRecruit.Any(e => e.Equals(entity, dbFile.Number, dbFile.Year)))
                    if (!ctxg.ChosenRecruit.Any(e =>
                                                (string.IsNullOrEmpty(e.LastName) && string.IsNullOrEmpty(entity.FAM) || e.LastName == entity.FAM) &&
                                                (string.IsNullOrEmpty(e.FirstName) && string.IsNullOrEmpty(entity.IM) || e.FirstName == entity.IM) &&
                                                (string.IsNullOrEmpty(e.MiddleName) && string.IsNullOrEmpty(entity.OTCH) || e.MiddleName == entity.OTCH) &&
                                                (!e.BirthDate.HasValue && birthDate == null || e.BirthDate.Value.Year == birthDate.Year) &&
                                                (!e.Department_ID.HasValue && string.IsNullOrEmpty(entity.RVK) || e.Department_ID.HasValue && e.Department.NameShort == entity.RVK) &&
                                                (string.IsNullOrEmpty(e.Destination) && string.IsNullOrEmpty(entity.KUDA) || e.Destination == entity.KUDA) &&
                                                (string.IsNullOrEmpty(e.Patron) && string.IsNullOrEmpty(entity.KTO) || e.Patron == entity.KTO) &&
                                                e.Season.Year == dbFile.Year && e.Season.Number == dbFile.Number
                                                ))
                    {
                        Season season = ctxg.Season.FirstOrDefault(s => s.Number == dbFile.Number && s.Year == dbFile.Year);
                        if (season == default(Season))
                        {
                            season = new Season()
                            {
                                Number = dbFile.Number, Year = dbFile.Year
                            };
                        }

                        Department dept = ctxg.Department.FirstOrDefault(d => d.NameShort.Equals(entity.RVK) &&
                                                                         d.Season.Year == dbFile.Year && d.Season.Number == dbFile.Number);
                        if (dept == default(Department))
                        {
                            //dept = new Department() { NameShort = entity.RVK };
                        }

                        ctxg.ChosenRecruit.AddObject(new ChosenRecruit()
                        {
                            LastName    = entity.FAM,
                            FirstName   = entity.IM,
                            MiddleName  = entity.OTCH,
                            BirthDate   = birthDate,
                            Department  = dept,
                            Destination = entity.KUDA,
                            Patron      = entity.KTO,
                            Season      = season
                        });
                    }
                    //else
                    //{
                    //    var a = 0;
                    //}
                }

                ctxg.SaveChanges();
            }
        }