Пример #1
0
        /**
         * This page will simply reset the database and all matches. Games will remain.
         * */
        public SettingsPage()
        {
            InitializeComponent();
            database = App.Database;
            Title    = "Settings";

            Button btnReset = new Button {
                Text = "Reset"
            };
            Label lblreset = new Label {
                Text = "Press to reset"
            };

            //Main layout for the reset button
            StackLayout mainLayout = new StackLayout
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Children          = { lblreset, btnReset }
            };

            btnReset.Clicked += (sender, e) =>
            {
                // Call clear tables function in database
                database.clearTables();
                // Go back to main screen after reset
                Navigation.PopToRootAsync();
            };

            Content = mainLayout;
        }
        public OpponentCell()
        {
            database = App.Database;

            // Display Opponents first name, last name, and phone number on main page
            var firstName = new Label();

            firstName.SetBinding(Label.TextProperty, "oFirstName");

            var lastName = new Label();

            lastName.SetBinding(Label.TextProperty, "oLastName");

            var phone = new Label();

            phone.SetBinding(Label.TextProperty, "oPhone");


            // Adding menu item for long click or swipe
            MenuItem menuItem = new MenuItem
            {
                Text          = "Delete Opponent?",
                IsDestructive = true
            };

            menuItem.Clicked += (sender, e) =>
            {
                // Get the parent's ListView
                ListView parent = (ListView)this.Parent;
                // Remove all matches and opponents
                database.DeleteAllMatches((this.BindingContext as Opponents).ID);
                database.DeleteOpponent(this.BindingContext as Opponents);
                //Update ItemsSource list
                parent.ItemsSource = database.GetAllOpponents();
            };

            ContextActions.Add(menuItem);
            // Place names side-by-side
            var nameStack = new StackLayout
            {
                Spacing     = 4,
                Orientation = StackOrientation.Horizontal,
                Children    = { firstName, lastName }
            };

            // Define what the content will look like
            View = new StackLayout
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Orientation       = StackOrientation.Horizontal,
                Spacing           = 25,
                Padding           = 10,
                Children          = { nameStack, phone }
            };
        }
        /**
         *  This page will display all games and how many times they've been played.
         *  When a match has been deleted, it will update the Games page as well.
         * */
        public DisplayGamesPage()
        {
            InitializeComponent();
            database = App.Database;
            Title    = "Previous";
            ListView gameList = new ListView
            {
                ItemsSource  = database.GetAllGames(),
                RowHeight    = 100,
                ItemTemplate = new DataTemplate(typeof(gameCell))
            };

            Content = gameList;
        }
        /**
         *  Displaying the game name, description, rating and number of matches
         * */
        public gameCell()
        {
            database = App.Database;

            Label gameName = new Label {
                FontAttributes = FontAttributes.Bold
            };

            gameName.SetBinding(Label.TextProperty, "gName");

            Label gameDescription = new Label();

            gameDescription.SetBinding(Label.TextProperty, "gDescription");

            Label gameRating = new Label();

            gameRating.SetBinding(Label.TextProperty, "gRating");

            Label numMatches = new Label {
                Text = "# Matches: "
            };

            totalGames = new Label();

            StackLayout numMatchLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    = { numMatches, totalGames }
            };


            StackLayout descRatingLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    = { gameDescription, gameRating }
            };

            View = new StackLayout
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Spacing           = 10,
                Padding           = new Thickness(25, 5, 0, 15),
                Children          = { gameName, descRatingLayout, numMatchLayout }
            };
        }
        /**
         * Main start page. This page will display current opponents in the database
         * by first name, last name, and phone number
         * */
        public StartPage()
        {
            InitializeComponent();
            database = App.Database;

            // Set Title
            Title = "Opponents";

            // Use all opponents list for source in ListView
            opplistView = new ListView
            {
                ItemsSource  = database.GetAllOpponents(),
                RowHeight    = 50,
                ItemTemplate = new DataTemplate(typeof(OpponentCell))
            };

            // When Opponent gets tapped
            opplistView.ItemTapped += (sender, e) =>
            {
                opplistView.SelectedItem = null;
                // Go to matches page
                Navigation.PushAsync(new NewMatchesPage(e.Item as Opponents));
            };

            // Add "Add new Opponent Button"
            Button btnNewOpponent = new Button {
                Text = "Add New Opponent"
            };

            btnNewOpponent.Clicked += (sender, e) =>
            {
                Navigation.PushAsync(new NewOpponentPage());
            };

            // Main StackView layout
            StackLayout mainLayout = new StackLayout
            {
                Padding  = new Thickness(0, 0, 0, 25),
                Children = { opplistView, btnNewOpponent }
            };


            Content = mainLayout;
        }
Пример #6
0
        /**
         * Display option for the match cell and how it will be displayed on page
         * */
        public matchCell()
        {
            database = App.Database;

            lblFullName = new Label {
                FontAttributes = FontAttributes.Bold
            };

            Label lblDate = new Label {
                FontSize = 12
            };

            lblDate.SetBinding(Label.TextProperty, "mDate", stringFormat: "{0:D}");

            lblGameName = new Label {
                FontSize = 12
            };
            // Menu item to be able to delete a match
            MenuItem menuItem = new MenuItem
            {
                Text          = "Delete Match?",
                IsDestructive = true
            };

            menuItem.Clicked += (sender, e) =>
            {
                // Get parent's list to remove item
                ListView parent = (ListView)this.Parent;
                // Remove item from database
                database.DeleteMatch(this.BindingContext as Matches);
                // Update list
                parent.ItemsSource = database.GetAllMatches();
            };

            ContextActions.Add(menuItem);

            View = new StackLayout
            {
                Spacing  = 2,
                Padding  = 5,
                Children = { lblFullName, lblDate, lblGameName }
            };
        }
Пример #7
0
        /**
         * This page will display current matches and add ability to add a new match
         * */
        public NewMatchesPage(Opponents opponent)
        {
            InitializeComponent();
            database = App.Database;
            Title    = "Opponents";

            // Layout for top items
            StackLayout topLayout = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            // Add matches to listview
            ListView matchListView = new ListView
            {
                ItemsSource = database.GetMatchesByID(opponent.ID),
                //ItemsSource = matchList,
                RowHeight     = 75,
                ItemTemplate  = new DataTemplate(typeof(matchCell)),
                HeightRequest = 750
            };


            // Add to top layout
            topLayout.Children.Add(matchListView);

            /////////// Table Section Below /////////////////////
            StackLayout tableLayout = new StackLayout {
                VerticalOptions = LayoutOptions.Center
            };
            TableView tableView = new TableView {
                Intent = TableIntent.Form
            };

            tableView.HeightRequest = 700;

            // Cells go in sections, sections in root
            DatePicker dPicker = new DatePicker {
                Date = DateTime.Now, Format = "D"
            };

            ViewCell vDate = new ViewCell();

            vDate.View = dPicker;

            // Comments section
            EntryCell eComments = new EntryCell {
                Label = "Comment: "
            };
            // Picker for Game selection
            Picker pGame = new Picker
            {
                ItemsSource        = database.GetAllGames(),
                ItemDisplayBinding = new Binding("gName"),
                Title = "Game:"
            };
            // Picker must be placed in ViewCell
            ViewCell vPicker = new ViewCell();

            vPicker.View = pGame;
            SwitchCell sWin = new SwitchCell {
                Text = "Win?"
            };

            TableSection tableSection = new TableSection("Add Match")
            {
                vDate, eComments, vPicker, sWin
            };

            tableView.Root = new TableRoot {
                tableSection
            };
            tableLayout.Children.Add(tableView);

            // Create button to add matches
            Button btnAdd = new Button {
                Text = "Add", HorizontalOptions = LayoutOptions.Center
            };

            btnAdd.Clicked += (sender, e) =>
            {
                // Check to make sure that we're updating an item already in database
                if (currentMatch != null)
                {
                    currentMatch.mDate     = dPicker.Date;
                    currentMatch.mComments = eComments.Text;
                    currentMatch.mWin      = sWin.On;
                    currentMatch.mGameID   = ((Games)pGame.SelectedItem).gID;
                    // Update match
                    database.SaveMatch(currentMatch);
                    // Update list
                    matchListView.ItemsSource = database.GetMatchesByID(currentMatch.opponent_id);

                    currentMatch = null;
                }
                else
                {
                    // Create new match to save
                    Matches newMatch = new Matches
                    {
                        mDate       = dPicker.Date,
                        mComments   = eComments.Text,
                        mGameID     = ((Games)pGame.SelectedItem).gID,
                        opponent_id = opponent.ID,
                        mWin        = sWin.On
                    };
                    // Save new match to database
                    database.SaveMatch(newMatch);
                    // Update list
                    matchListView.ItemsSource = database.GetMatchesByID(newMatch.opponent_id);
                }
            };

            matchListView.ItemTapped += (sender, e) =>
            {
                matchListView.SelectedItem = null;
                // Set current item equal to the object which was tapped
                // Used to be able to know if we need to update, or create new match
                currentMatch   = (Matches)e.Item;
                dPicker.Date   = currentMatch.mDate;
                eComments.Text = currentMatch.mComments;
                // Index needs to be offset by one, since picker and database do not
                // start at the same numbers. One start at 0 and the other other 1.
                pGame.SelectedIndex = currentMatch.mGameID - 1;
                sWin.On             = currentMatch.mWin;
            };

            // Create main layout
            StackLayout mainLayout = new StackLayout
            {
                Children = { topLayout, tableLayout, btnAdd }
            };

            Content = mainLayout;
        }
Пример #8
0
        /**
         *  This page will handle adding a new opponent to the database
         * */
        public NewOpponentPage()
        {
            InitializeComponent();
            Title    = "Opponents";
            database = App.Database;

            // Main layout to add components to when finished
            StackLayout mainLayout = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            StackLayout tableLayout = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center
            };

            TableView tableView = new TableView {
                Intent = TableIntent.Form
            };

            // Cells have to go in sections and sections in Root
            EntryCell eFirstName = new EntryCell {
                Label = "First Name: "
            };
            EntryCell eLastName = new EntryCell {
                Label = "Last Name: "
            };
            EntryCell eAddress = new EntryCell {
                Label = "Address: "
            };
            EntryCell ePhone = new EntryCell {
                Label = "Phone: "
            };
            EntryCell eEmail = new EntryCell {
                Label = "Email: "
            };

            TableSection section = new TableSection("Add New Opponent")
            {
                eFirstName, eLastName, eAddress, ePhone, eEmail
            };

            // Root
            tableView.Root = new TableRoot {
                section
            };

            // Add to table layout
            tableLayout.Children.Add(tableView);

            Button btnSave = new Button {
                Text = "Save"
            };

            btnSave.Clicked += (sender, e) =>
            {
                // Create new opponent to be saved in database
                Opponents newOpp = new Opponents
                {
                    oFirstName = eFirstName.Text,
                    oLastName  = eLastName.Text,
                    oAddress   = eAddress.Text,
                    oPhone     = ePhone.Text,
                    oEmail     = eEmail.Text
                };
                // Persiste new opponent to database
                database.SaveOpponent(newOpp);
                // Reset string fields to empty
                eFirstName.Text = string.Empty;
                eLastName.Text  = string.Empty;
                eAddress.Text   = string.Empty;
                ePhone.Text     = string.Empty;
                eEmail.Text     = string.Empty;
            };
            // Add to main layout
            mainLayout.Children.Add(tableLayout);
            mainLayout.Children.Add(btnSave);

            Content = mainLayout;
        }