Esempio n. 1
0
        private static ICollection <Tree> GetListTree(Range range)
        {
            List <Tree> trees = new List <Tree>();
            int         raw   = 19;

            while (!((range.Cells[raw, 1] as Range).Value2 is null))
            {
                using (var context = new ConstantTrialPlotsContext())
                {
                    var tree = new Tree()
                    {
                        IdPlot  = TrialPlot.Id,
                        Number  = (int)(range.Cells[raw, 1] as Range).Value2,
                        X       = (double)(range.Cells[raw, 2] as Range).Value2,
                        Y       = (double)(range.Cells[raw, 3] as Range).Value2,
                        IdBreed = context.Breed.ToList().FirstOrDefault(e => e.Cipher == (range.Cells[raw, 4] as Range).Value2).Id,
                    };

                    context.Tree.Add(tree);
                    context.SaveChanges();
                    var property = new TreeProperty
                    {
                        Age             = (int)(range.Cells[raw, 6] as Range).Value2,
                        DiametrNs       = (double)(range.Cells[raw, 7] as Range).Value2,
                        DiametrWe       = (double)(range.Cells[raw, 9] as Range).Value2,
                        Height          = (double)(range.Cells[raw, 10] as Range).Value2,
                        CrownDiametrNs  = (range.Cells[raw, 11] as Range).Value2 as double?,
                        CrownDiametrWe  = (range.Cells[raw, 12] as Range).Value2 as double?,
                        CrownLength     = (range.Cells[raw, 14] as Range).Value2 as double?,
                        IdCraft         = context.СraftСategory.ToList().FirstOrDefault(c => c.Chipher == ArabToRim((int?)(range.Cells[raw, 15] as Range).Value2)).Id,
                        IdSuitability   = context.TechnicalSuitability.ToList().FirstOrDefault(t => t.Chipher == (string)(range.Cells[raw, 16] as Range).Value2).Id,
                        IdTaxationYears = TaxationYear.Id,
                        IdTree          = tree.Id
                    };

                    context.TreeProperty.Add(property);
                    context.SaveChanges();
                }
                raw++;
            }
            return(trees);
        }
Esempio n. 2
0
 private static void BuildTrialPlot(TrialPlot plot)
 {
     using (var context = new ConstantTrialPlotsContext())
     {
         var check = context.TrialPlot.Where(p => p.Az == plot.Az && p.IdLeshos == plot.IdLeshos && p.Length == plot.Length && p.Number == plot.Number && p.Square == plot.Square && p.Weight == plot.Weight && p.X == plot.X && p.Y == plot.Y);
         if (check.FirstOrDefault() != null)
         {
             TrialPlot = check.FirstOrDefault();
         }
         else
         {
             context.TrialPlot.Add(plot);
             TrialPlot = plot;
         }
         context.SaveChanges();
     }
 }
Esempio n. 3
0
 private static void BuildLeshos(Leshos leshos)
 {
     using (var context = new ConstantTrialPlotsContext())
     {
         var check = context.Leshos.Where(l => l.Kvartal == leshos.Kvartal && l.Lesnichestvo == leshos.Lesnichestvo && l.Name == leshos.Name && l.Vydel == leshos.Vydel);
         if (check.FirstOrDefault() != null)
         {
             Leshos = check.FirstOrDefault();
         }
         else
         {
             context.Leshos.Add(leshos);
             Leshos = leshos;
         }
         context.SaveChanges();
     }
 }
Esempio n. 4
0
 private static void BuildSpravochniki()
 {
     using (var context = new ConstantTrialPlotsContext())
     {
         context.TechnicalSuitability.AddRange(techCategory.Where(tc => !context.TechnicalSuitability.Any(t => t.Chipher == tc.Chipher && t.Name == tc.Name)));
         context.СraftСategory.AddRange(craftCategory.Where(tc => !context.СraftСategory.Any(t => t.Chipher == tc.Chipher && t.Name == tc.Name)));
         context.Breed.AddRange(breedsCategory.Where(tc => !context.Breed.Any(t => t.Cipher == tc.Cipher && t.Name == tc.Name)));
         var checkYears = context.TaxationYear.Where(ty => ty.Year == TaxationYear.Year).FirstOrDefault();
         if (checkYears != null)
         {
             TaxationYear = context.TaxationYear.Where(ty => ty.Year == TaxationYear.Year).FirstOrDefault();
         }
         else
         {
             context.TaxationYear.Add(TaxationYear);
         }
         context.SaveChanges();
     }
 }