Exemple #1
0
        private void CheckDuplicatesButton_Click(object sender, RoutedEventArgs e)
        {
            using (FormMergedEntities ctx = new FormMergedEntities())
            {
                var recruits = ctx.Recruit
                               .Include("Squad")
                               .Where(r => !(r.Squad.V_VS.Equals("ВВ") || r.Squad.V_VS.Equals("ВВ МВД") || r.Squad.V_VS.Equals("МЧС") || r.Squad.V_VS.Equals("СССИ") || r.Squad.V_VS.Equals("ПП")))
                               .Where(r => r.N_KOM != "15" || r.SeasonYear == "2014" && r.SeasonNumber == "2")
                               .AsEnumerable()
                               .GroupBy(r => r.LN_SER + r.LN_NUM)
                               .Where(g => g.Count() > 1)
                               .SelectMany(g => g)
                               .Select(g => new DupToken(g))
                               .ToList();

                var window = new WindowWithGrid();
                window.PopulateListView(recruits);
                window.Show();
            }
        }
Exemple #2
0
        //private void FindDuplicates()
        //{

        //}

        private void FillExistingSeasons()
        {
            //using (EntityContextGeneral ctxg = new EntityContextGeneral())
            using (FormMergedEntities ctxg = new FormMergedEntities())
            {
                seasons = ctxg.Recruit
                          .AsEnumerable()
                          //.ToList()
                          .Distinct(seasonComparer)
                          //.Select(p => new Season(p))
                          .Select(p => new SeasonMSSQL(p))
                          .OrderByDescending(p => p.DateTime)
                          .ToList();

                Binding myBinding = new Binding()
                {
                    Source = seasons
                };

                SeasonsListView.SetBinding(ListView.ItemsSourceProperty, myBinding);
                seasonsBindingExpression = SeasonsListView.GetBindingExpression(ListView.ItemsSourceProperty);
            }
        }
Exemple #3
0
        /// <summary>
        /// Without try/catches
        /// </summary>
        private void MergeUnsafely()
        {
            isProcessRunning = true;
            //ProgressBar.IsIndeterminate = true;

            string singleDBConnectionString = ConfigurationManager
                                              .ConnectionStrings["EntityContextSingle"]
                                              .ConnectionString;

            string oldPair = Regex.Match(singleDBConnectionString, @"(?:database=).+?(?=;)").Value;
            string connectionStringSelected = singleDBConnectionString.Replace(oldPair, "database=" + selectedFile.InternalPath);

            using (EntityContextSingle ctxs = new EntityContextSingle(connectionStringSelected))
            {
                //using (EntityContextGeneral ctxg = new EntityContextGeneral())
                using (FormMergedEntities ctxg = new FormMergedEntities())
                {
                    int countPriz = ctxs.PRIZ.Count();
                    int countKom  = ctxs.kom.Count();
                    if (countPriz == 0 && countKom == 0)
                    {
                        MessageBox.Show("Отсутствуют записи в таблицах призывников и команд данного сезона");
                        ctxg.Dispose();
                        ctxs.Dispose();
                        return;
                    }


                    var komGeneralToDelete = ctxg.Squad
                                             .Where(p => p.SeasonYear.Equals(year) &&
                                                    p.SeasonNumber.Equals(number))
                                             .ToList();
                    int deleteCount = komGeneralToDelete.Count();
                    for (int i = 0; i < deleteCount; i++)
                    {
                        ctxg.DeleteObject(komGeneralToDelete[i]);

                        //if (i % progressBarUpdateRate == 0)
                        //{
                        //    ProgressBar.Dispatcher.BeginInvoke(
                        //        new DoubleParameterDelegate(UpdateProgress),
                        //        (double)(50 + 50 * (deleteCount - i) / deleteCount));
                        //}
                        //if (commitBufferSize != 0 && i % commitBufferSize == 0)
                        //{
                        //    ctxg.SaveChanges();
                        //}
                    }
                    ctxg.SaveChanges();

                    var prizGeneralToDelete = ctxg.Recruit
                                              .Where(p => p.SeasonYear.Equals(year) &&
                                                     p.SeasonNumber.Equals(number))
                                              .ToList();
                    deleteCount = prizGeneralToDelete.Count();
                    for (int i = 0; i < deleteCount; i++)
                    {
                        ctxg.DeleteObject(prizGeneralToDelete[i]);

                        //if (i % progressBarUpdateRate == 0)
                        //{
                        //    ProgressBar.Dispatcher.BeginInvoke(
                        //        new DoubleParameterDelegate(UpdateProgress),
                        //        (double)(50 * (deleteCount - i) / deleteCount));
                        //}
                        //if (commitBufferSize != 0 && i % commitBufferSize == 0)
                        //{
                        //    ctxg.SaveChanges();
                        //}
                    }
                    ctxg.SaveChanges();

                    DateTime date = DateTime.Now.Date;
                    TimeSpan time = DateTime.Now.TimeOfDay;

                    //if (deleteCount == 0)
                    //{
                    //    Season seasonToAdd = new Season(
                    //        year, number, date.Add(time));
                    //    seasons.Add(seasonToAdd);
                    //}
                    if (seasons.Any(s => s.Year.Equals(year) && s.Number.Equals(number)))
                    {
                        //Season seasonOld = seasons.First(s => s.Year.Equals(year) && s.Number.Equals(number));
                        SeasonMSSQL seasonOld = seasons.First(s => s.Year.Equals(year) && s.Number.Equals(number));
                        seasonOld.DateTime = date.Add(time);
                    }
                    seasons = seasons
                              .OrderByDescending(s => s.DateTime)
                              .ToList();
                    SeasonsListView.Dispatcher.BeginInvoke(
                        new Action(UpdateSeasonsSource));


                    int id = 0;
                    if (ctxg.Squad.Count() > 0)
                    {
                        id = ctxg.Squad.Max(p => p.ID);
                    }
                    IEnumerable <FormDatabasesMerge.EntityDataModel.SingleDatabaseModel.kom> komEntities =
                        ctxs.kom.OrderBy(p => p.ID).AsEnumerable();
                    current = 0;
                    foreach (var kom in komEntities)
                    {
                        current++;

                        //var komGeneral = DataConverter.FromSinglekom(
                        var komGeneral = DataConverterMSSQL.FromSinglekom(
                            kom, id + current, year, number, date, time);
                        ctxg.AddToSquad(komGeneral);

                        //if (current % progressBarUpdateRate == 0)
                        //{
                        //    ProgressBar.Dispatcher.BeginInvoke(
                        //        new DoubleParameterDelegate(UpdateProgress),
                        //        (double)(50 * current / countKom));
                        //}
                        //if (commitBufferSize != 0 && current % commitBufferSize == 0)
                        //{
                        //    ctxg.SaveChanges();
                        //}
                    }

                    //ctxg.SaveChanges(false);
                    //ctxg.AcceptAllChanges();
                    ctxg.SaveChanges();


                    id = 0;
                    if (ctxg.Recruit.Count() > 0)
                    {
                        id = ctxg.Recruit.Max(p => p.ID);
                    }
                    IEnumerable <FormDatabasesMerge.EntityDataModel.SingleDatabaseModel.PRIZ> prizEntities =
                        ctxs.PRIZ.OrderBy(p => p.ID).AsEnumerable();
                    current = 0;
                    foreach (var priz in prizEntities)
                    {
                        current++;

                        var kom = ctxg.Squad.First(k =>
                                                   k.N_KOM == priz.N_KOM &&
                                                   k.SeasonYear.Equals(year) &&
                                                   k.SeasonNumber.Equals(number));
                        var prizGeneral = DataConverterMSSQL.FromSinglePRIZ(
                            priz, id + current, kom, year, number, date, time);
                        ctxg.AddToRecruit(prizGeneral);

                        //if (current % progressBarUpdateRate == 0)
                        //{
                        //    ProgressBar.Dispatcher.BeginInvoke(
                        //        new DoubleParameterDelegate(UpdateProgress),
                        //        (double)(50 + 50 * current / countPriz));
                        //}
                        //if (commitBufferSize != 0 && current % commitBufferSize == 0)
                        //{
                        //    ctxg.SaveChanges();
                        //}
                    }

                    //ctxg.SaveChanges(false);
                    //ctxg.AcceptAllChanges();
                    ctxg.SaveChanges();


                    ProgressBar.Dispatcher.BeginInvoke(new Action(CompleteProgress));
                }
            }
        }