Пример #1
0
        /// <summary>
        /// Add project to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddProject_Click(object sender, EventArgs e)
        {
            var projectname = txtProjectName.Text;
            if (string.IsNullOrEmpty(_filePath) || string.IsNullOrEmpty(projectname))
            {
                MessageBox.Show("Eerst een plattegrond uploaden of projectnaam invullen");
                return;
            }
            var filename = Path.GetFileName(_filePath);

            // Making object project
            var project = new Project(0, projectname, "Files/" + filename);

            // INSERT PROJECT INTO DATABASE
            project = LogicCollection.ProjectLogic.Insert(project); 
            if (project != null)
            {
                var exists = Directory.Exists("Files");
                if (!exists)
                {
                    Directory.CreateDirectory("Files");
                }
                File.Copy(_filePath, "Files/" + filename);

                MessageBox.Show("Je hebt een project succesvol toegevoegd!");
                var startxUp = new StartUp();
                startxUp.RefreshList();
                Close();
            }
            else
            {
                MessageBox.Show("Er is iets misgegaan bij het toevoegen.");
            }
        }
Пример #2
0
        private void btnPrintOut_Click(object sender, EventArgs e)
        {
            var currentProject = (Project)lblProjecten.SelectedItem;
            var visits = LogicCollection.VisitLogic.GetAllVistsByPid(currentProject.ID);
            var listOfBirds = new List<Bird>();


            foreach(var visit in visits)
            {
                foreach (var observation in LogicCollection.ObservationLogic.GetByAllBid(visit.ID))
                {
                    var currentBird = LogicCollection.BirdLogic.GetById(observation.VID);
                    var currentObserationType = LogicCollection.ObservationTypeLogic.GetById(observation.WTID);
                    var currentDate = observation.Date;

                    var compareDateStart = new DateTime(currentDate.Year, currentBird.SpawnStart.Month, currentBird.SpawnStart.Day);
                    var compareDateEnd = new DateTime(currentDate.Year, currentBird.SpawnEnd.Month, currentBird.SpawnEnd.Day);

                    if (currentDate <= compareDateStart || currentDate >= compareDateEnd) continue;
                    switch (currentObserationType.Name)
                    {
                        case "VA":
                            var birdList = listOfBirds.Find(x => x.ID == currentBird.ID);
                            if (birdList == null)
                            {
                                currentBird.Score = currentBird.Score + 1;
                                listOfBirds.Add(currentBird);
                            }
                            else
                            {
                                birdList.Score = birdList.Score + 1;
                            }
                            break;
                        case "NI":
                            var birdListNI = listOfBirds.Find(x => x.ID == currentBird.ID);
                            if (birdListNI == null)
                            {
                                currentBird.Score = currentBird.Score + 3;
                                listOfBirds.Add(currentBird);
                            }
                            else
                            {
                                birdListNI.Score = birdListNI.Score + 3;
                            }
                            break;
                        default:
                            var birdListTI = listOfBirds.Find(x => x.ID == currentBird.ID);
                            if (birdListTI == null)
                            {
                                currentBird.Score = currentBird.Score + 2;
                                listOfBirds.Add(currentBird);
                            }
                            else
                            {
                                birdListTI.Score = birdListTI.Score + 2;
                            }
                            break;
                    }
                }
            }

            foreach (var bird in listOfBirds)
            {
                bird.Pairs = Convert.ToInt32(Math.Round(Convert.ToDecimal(bird.Score)/Convert.ToDecimal(bird.Points)));
            }

            if (rdbBreeding.Checked)
            {
                listOfBirds.Sort((x, y) => x.Pairs.CompareTo(y.Pairs));
            }else if (rdbBirdSort.Checked)
            {
                listOfBirds.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name));
            }
            else
            {
                MessageBox.Show("Uw moet een keuze maken om te sorteren.");
                return;
            }

            var counterName = txtCounterName.Text;
            if (string.IsNullOrEmpty(counterName))
            {
                MessageBox.Show("Naam is verplicht.");
                return;
            }

            // Writing to text bestand
            var earliestDate = visits.OrderBy(a => a.StartDate).First();
            var lastestDate = visits.OrderBy(a => a.EndDate).Last();

            var beginText = $@"Waargenomen broedparen per vogelsoort {Environment.NewLine}{Environment.NewLine}Gebied: {currentProject.Name} {Environment.NewLine}Datum eerste bezoek: {earliestDate.StartDate.ToShortDateString()}{Environment.NewLine}Datum laatste bezoek: {lastestDate.StartDate.ToShortDateString()}{Environment.NewLine}{Environment.NewLine}Geachte,{Environment.NewLine}Hieronder vindt u de waarnemingen gesorteerd op aantal broedgevallen, per vogelsoort.{Environment.NewLine}{Environment.NewLine}";
            var middleText = $@"Vogelsoort -  #broedgevallen{Environment.NewLine}";
            var endText = $@"{Environment.NewLine}Met vriendelijke groet,{Environment.NewLine}{counterName}";

            // WRITING XML FILE
            var t = DateTime.UtcNow - new DateTime(1970, 1, 1);
            var secondsSinceEpoch = (int)t.TotalSeconds;

            var filename = $@"Uitdraai_{secondsSinceEpoch}.txt";

            using (var file = new StreamWriter(filename))
            {
                try
                {
                    file.Write(beginText);
                    file.Write(middleText);
                    foreach (var line in listOfBirds.Select(bird => $@"{bird.Name} - {bird.Pairs}"))
                    {
                        file.WriteLine(line);
                    }
                    file.Write(endText);
                    file.Close();
                    MessageBox.Show("Uitdraai succesvol uitgevoerd.");

                    currentProject.Open = false;
                    LogicCollection.ProjectLogic.UpdateStatus(currentProject);

                    var startUp = new StartUp();
                    startUp.RefreshList();
                }
                catch (Exception x)
                {
                    MessageBox.Show("Error: " + x.Message);
                }
            }
        }