Example #1
0
        public async void done(object sender, EventArgs e)
        {
            displayActivityIndicator();

            await Task.Run(() => {
                FileHandler fileHandler = new FileHandler();
                fileHandler.updateStoredEventsFile();
                fileHandler.updateMyEventsFile();

                Device.BeginInvokeOnMainThread(() => {
                    mainPage.populateGrid();
                    Navigation.PopModalAsync();
                });
            });
        }
        public void addEvent(object sender, EventArgs e)
        {
            if (entryName.Text == null)
            {
                this.DisplayAlert("Error", "Event name cannot be empty", "Ok");
                return;
            }
            for (int i = 0; i < GlobalVariables.myEvents.Count; i++)
            {
                if (string.Compare(GlobalVariables.myEvents[i].getName(), entryName.Text, true) == 0)
                {
                    this.DisplayAlert("Error", "An event with that name already exists", "Ok");
                    return;
                }
            }
            for (int i = 0; i < GlobalVariables.storedEvents.Count; i++)
            {
                if (string.Compare(GlobalVariables.storedEvents[i].getName(), entryName.Text, true) == 0)
                {
                    this.DisplayAlert("Error", "An event with that name already exists", "Ok");
                    return;
                }
            }
            Event newEvent = new Event(entryName.Text, datePicked.Date);

            newEvent.setOneTimeEvent(oneTimeEvent);
            GlobalVariables.resetEvent(newEvent);
            GlobalVariables.myEvents.Add(newEvent);

            //save event to file
            try {
                FileHandler fileHandler = new FileHandler();
                fileHandler.appendEventToFile(newEvent);
            } catch (Exception ex) {
                Debug.WriteLine("Exception caught!");
                Debug.WriteLine(ex.Message);
            }
            mainPage.populateGrid();
            Navigation.PopModalAsync();
        }
        public async void addEvent(object sender, EventArgs e)
        {
            if (entryName.Text == null)
            {
                await this.DisplayAlert("Error", "Event name cannot be empty.", "Ok");

                return;
            }

            //remove white space on ends
            while (entryName.Text.Length > 0 && entryName.Text[0] == ' ')
            {
                entryName.Text = entryName.Text.Substring(1);
            }
            while (entryName.Text.Length > 0 && entryName.Text[entryName.Text.Length - 1] == ' ')
            {
                entryName.Text = entryName.Text.Substring(0, entryName.Text.Length - 1);
            }

            if (entryName.Text.Length == 0)
            {
                await this.DisplayAlert("Error", "Event name cannot be empty.", "Ok");

                return;
            }
            for (int i = 0; i < GlobalVariables.myEvents.Count; i++)
            {
                if (string.Compare(GlobalVariables.myEvents[i].getName(), entryName.Text, true) == 0)
                {
                    await this.DisplayAlert("Error", "An event with that name already exists.", "Ok");

                    return;
                }
            }
            for (int i = 0; i < GlobalVariables.storedEvents.Count; i++)
            {
                if (string.Compare(GlobalVariables.storedEvents[i].getName(), entryName.Text, true) == 0)
                {
                    await this.DisplayAlert("Error", "An event with that name already exists.", "Ok");

                    return;
                }
            }

            displayActivityIndicator();

            await Task.Run(() => {
                DateTime eventDate = new DateTime(datePicked.Date.Year, datePicked.Date.Month, datePicked.Date.Day, timePicked.Time.Hours, timePicked.Time.Minutes, 0);
                Event newEvent     = new Event(entryName.Text, eventDate);
                newEvent.setAllDayEvent(allDayEvent);
                newEvent.setOneTimeEvent(oneTimeEvent);
                GlobalVariables.resetEvent(newEvent);
                GlobalVariables.myEvents.Add(newEvent);

                //save event to file
                FileHandler fileHandler = new FileHandler();
                fileHandler.appendEventToFile(newEvent);

                Device.BeginInvokeOnMainThread(() => {
                    mainPage.refreshGrid();
                    mainPage.populateGrid();
                    Navigation.PopModalAsync();
                });
            });
        }