Ejemplo n.º 1
0
        public void DeleteBestuur(int bestuurid)
        {
            Bestuur bestuur = ctx.Bestuur.Find(bestuurid);

            ctx.Bestuur.Remove(bestuur);
            ctx.SaveChanges();
        }
Ejemplo n.º 2
0
 public void ChangeBestuur(Bestuur bestuur)
 {
     begrotingrepo.UpdateBestuur(bestuur);
 }
Ejemplo n.º 3
0
 public Bestuur AddBestuur(Bestuur bestuur)
 {
     return(begrotingrepo.CreateBestuur(bestuur));
 }
Ejemplo n.º 4
0
        public void GetBegrotingenFromExcelViaStream(Stream fileStream)
        {
            GemeenteManager gemeenteMgr = new GemeenteManager(uowMgr);

            // Open het Excel document met read-only acces.
            using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileStream, false))
            {
                // Referentie maken naar het Workbook Part.
                WorkbookPart workbookPart = document.WorkbookPart;
                // Vind de eerste sheet en maak een referentie naar de worksheet.
                Sheet sheet = workbookPart.Workbook.Descendants <Sheet>().First();
                // Gooi een exception als de sheet niet wordt gevonden.
                if (sheet == null)
                {
                    throw new ArgumentException("De sheet met begrotingen werd niet gevonden!");
                }
                // Maak een referentie naar de Worksheet Part.
                WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id);

                int              i          = 2;
                string           cityString = "";
                List <Categorie> categories = GetAllCategorieën().ToList();
                do
                {
                    // CITY & BUDGET
                    string actionBudgetString = GetCellValue(worksheetPart, workbookPart, "O" + i);
                    double actionBudget;
                    Double.TryParse(actionBudgetString, out actionBudget);
                    cityString = GetCellValue(worksheetPart, workbookPart, "A" + i);
                    Gemeente city = gemeenteMgr.GetGemeente(cityString);
                    if (actionBudget != 0)
                    {
                        if (city != null)
                        {
                            if (city.BegrotingsTypes == null)
                            {
                                city.BegrotingsTypes = new List <BegrotingsType>();
                            }
                            int            year = Int32.Parse(GetCellValue(worksheetPart, workbookPart, "M" + i));
                            BegrotingsType begrotingsType;
                            if (year < DateTime.Now.Year)
                            {
                                begrotingsType = new Rekening(year);

                                //Alle categorieinformaties aanmaken
                                foreach (Categorie c in categories)
                                {
                                    begrotingsType.CategorieInformaties.Add(new CategorieInformatie {
                                        Categorie = c, Bedrag = 0
                                    });
                                }
                            }
                            else
                            {
                                begrotingsType = new Begroting(year);

                                //Alle categorieinformaties aanmaken
                                foreach (Categorie c in categories)
                                {
                                    begrotingsType.CategorieInformaties.Add(new CategorieInformatie {
                                        Categorie = c, Bedrag = 0
                                    });
                                }
                            }
                            if (!city.BegrotingsTypes.Exists(x => x.Jaartal.Equals(year)))
                            {
                                city.BegrotingsTypes.Add(begrotingsType);
                            }
                            else
                            {
                                begrotingsType = city.BegrotingsTypes.Find(x => x.Jaartal.Equals(year));
                            }

                            // MAAK ACTIES
                            if (begrotingsType != null)
                            {
                                //ACTIE
                                string actionName        = GetCellValue(worksheetPart, workbookPart, "D" + i);
                                string actionDescription = GetCellValue(worksheetPart, workbookPart, "E" + i);

                                Actie action = new Actie(actionName, actionDescription, actionBudget);
                                if (begrotingsType.Acties == null)
                                {
                                    begrotingsType.Acties = new List <Actie>();
                                }

                                // BESTUUR
                                string  bestuurString = GetCellValue(worksheetPart, workbookPart, "B" + i);
                                Bestuur bestuur;
                                if (bestuurString.Contains("OCMW"))
                                {
                                    bestuur = new Bestuur(bestuurString, BestuurType.OCMW);
                                }
                                else if (bestuurString.Equals(city.Naam))
                                {
                                    bestuur = new Bestuur(bestuurString, BestuurType.Gemeente);
                                }
                                else
                                {
                                    bestuur = new Bestuur(bestuurString, BestuurType.AutonomeGemeentebedrijven);
                                }
                                if (GetAllBesturen().ToList().Exists(x => bestuurString.Equals(x.Naam)))
                                {
                                    bestuur = GetAllBesturen().ToList().Find(x => bestuurString.Equals(x.Naam));
                                }
                                action.Bestuur = bestuur;

                                // CATEGORIE
                                string    categoryString = GetCellValue(worksheetPart, workbookPart, "H" + i);
                                Categorie categorie      = categories.Single(x => categoryString.Contains(x.Naam) && x.CategorieNiveau.Equals(CategorieNiveau.C));
                                action.Categorie = categorie;

                                // ADD ACTIE BIJ BUDGET
                                if (actionBudget > 0 && !begrotingsType.Acties.ToList().Exists(x => x.Naam.Equals(actionName)))
                                {
                                    begrotingsType.Acties.Add(action);
                                    // CATEGORYINFO
                                    if (action.Categorie != null)
                                    {
                                        // C
                                        CategorieInformatie infoC;

                                        infoC         = begrotingsType.CategorieInformaties.ToList().Find(x => x.Categorie.Naam.Equals(action.Categorie.Naam) && x.Categorie.CategorieNiveau == action.Categorie.CategorieNiveau);
                                        infoC.Bedrag += actionBudget;
                                        // B
                                        string    catBString = GetCellValue(worksheetPart, workbookPart, "G" + i);
                                        Categorie catB       = categories.Single(x => catBString.Contains(x.Naam) && x.CategorieNiveau == CategorieNiveau.B);
                                        if (catB == null)
                                        {
                                            throw new Exception();
                                        }
                                        CategorieInformatie infoB;
                                        infoB         = begrotingsType.CategorieInformaties.ToList().Find(x => x.Categorie.Naam.Equals(catB.Naam) && x.Categorie.CategorieNiveau == catB.CategorieNiveau);
                                        infoB.Bedrag += actionBudget;
                                        // A
                                        string    catAString = GetCellValue(worksheetPart, workbookPart, "F" + i);
                                        Categorie catA       = categories.Single(x => catAString.Contains(x.Naam) && x.CategorieNiveau == CategorieNiveau.A);
                                        if (catA == null)
                                        {
                                            throw new Exception();
                                        }
                                        CategorieInformatie infoA;
                                        infoA                  = begrotingsType.CategorieInformaties.ToList().Find(x => x.Categorie.Naam.Equals(catA.Naam) && x.Categorie.CategorieNiveau == catA.CategorieNiveau);
                                        infoA.Bedrag          += actionBudget;
                                        begrotingsType.Totaal += actionBudget;
                                    }
                                }
                            }

                            // UPDATE
                            gemeenteMgr.ChangeGemeente(city);
                        }
                    }
                    Console.WriteLine("Rij " + i + "ingelezen.");
                    i++;
                } while (cityString != null && !cityString.Equals(""));
            }
            uowMgr.Save();
        }
Ejemplo n.º 5
0
 public Bestuur CreateBestuur(Bestuur bestuur)
 {
     ctx.Bestuur.Add(bestuur);
     ctx.SaveChanges();
     return(bestuur);
 }
Ejemplo n.º 6
0
 public void UpdateBestuur(Bestuur bestuur)
 {
     ctx.Entry(bestuur).State = EntityState.Modified;
     ctx.SaveChanges();
 }