//Getting the number of rows in the table
        public int CountRowsInDatabase()
        {
            var numberOfRows = 0;

            try
            {
                var mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
                var conn = new MySqlConnection {
                    ConnectionString = mySqlConnectionString
                };

                using (var cmd = new MySqlCommand("SELECT COUNT(*) FROM " + Program.selectedEventName, conn))
                {
                    conn.Open();
                    numberOfRows = int.Parse(cmd.ExecuteScalar().ToString());
                    conn.Close();
                    return(numberOfRows);
                }
            }
            catch (MySqlException ex)
            {
                ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode);
                ConsoleWindow.WriteLine(ex.Message);
            }

            return(numberOfRows);
        }
Esempio n. 2
0
        private void testConnectionToDatabaseButton_Click(object sender, EventArgs e)
        {
            try
            {
                string mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
                var    conn = new MySqlConnection {
                    ConnectionString = mySqlConnectionString
                };

                conn.Open();

                if (conn.Ping())
                {
                    Console.WriteLine("You have successfully connected to your database!");
                    ConsoleWindow.WriteLine("You have successfully connected to your database!");
                    connectionDisplay.BackColor = Color.Chartreuse;
                    connectionDisplay.Text      = ("Successfully Connected to Database.");
                    try
                    {
                        MySQLMethods.InitializeDatabases();
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine("Error Message: " + exception.Message);
                        ConsoleWindow.WriteLine("Error Message: " + exception.Message);
                    }
                }
                else
                {
                    Console.WriteLine("You have unsuccessfully connected to your database!");
                    ConsoleWindow.WriteLine("You have unsuccessfully connected to your database!");
                    connectionDisplay.BackColor = Color.Red;
                    connectionDisplay.Text      = ("Connection to Database Failed.");
                }

                conn.Close();
            }
            catch (MySqlException ex)
            {
                connectionDisplay.BackColor = Color.Red;
                connectionDisplay.Text      = ("Connection to Database Failed.");
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Message " + ex.Message);
                ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode);
                ConsoleWindow.WriteLine("Error Message " + ex.Message);
            }
        }
        private void submitDataButton_Click(object sender, EventArgs e)
        {
            UpdateLabels();

            if (Settings.Default.allowExportToTextFile)
            {
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    var writer = new StreamWriter(saveFileDialog.FileName);
                    writer.WriteLine("Time Created: " + Time.GetCurrentTime());
                    writer.WriteLine("FRC_Scouting_V2 Match #: " + Convert.ToString(matchNumber));
                    writer.WriteLine("Did the robot die?: " + didRobotDie);
                    writer.WriteLine("===============================================");
                    writer.WriteLine("Team Name: " + Convert.ToString(Program.selectedTeamName));
                    writer.WriteLine("Team Number: " + Convert.ToString(Program.selectedTeamNumber));
                    writer.WriteLine("Team Color During Match: " + teamColour);
                    writer.WriteLine("===============================================");
                    writer.WriteLine();
                    writer.WriteLine("Points Scored");
                    writer.WriteLine("Auto High Tally: " + Convert.ToString(autoHighTally));
                    writer.WriteLine("Auto Low Tally: " + Convert.ToString(autoLowTally));
                    writer.WriteLine("Manually Controlled High Tally: " + Convert.ToString(controlledHighTally));
                    writer.WriteLine("Manually Controlled Low Tally: " + Convert.ToString(controlledLowTally));
                    writer.WriteLine("Hot Goals Scored: " + Convert.ToString(hotGoalTally));
                    writer.WriteLine("===============================================");
                    writer.WriteLine("Ball Control");
                    writer.WriteLine("Autonomous Ball Pickups: " + Convert.ToString(autoPickupTally));
                    writer.WriteLine("Controlled Ball Pickups: " + Convert.ToString(controlledPickupTally));
                    writer.WriteLine("Missed Pickups/Loads: " + Convert.ToString(missedPickupsTally));
                    writer.WriteLine("===============================================");
                    writer.WriteLine("Comments");
                    writer.WriteLine(Convert.ToString(comments));
                    writer.WriteLine("===============================================");
                    writer.WriteLine("Starting Location");
                    writer.WriteLine("X Starting Location: " + Convert.ToString(xStarting));
                    writer.WriteLine("Y Starting Location: " + Convert.ToString(yStarting));
                    writer.WriteLine("===============================================");
                    writer.WriteLine("END OF FILE");
                    writer.Close();
                }
            }

            //MySQL Database
            //MySQL Database Connection Info
            var mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();

            try
            {
                //Creating the connection to the database and opening the connection
                var conn = new MySqlConnection {
                    ConnectionString = mySqlConnectionString
                };
                conn.Open();

                //Checking if the connection is successful
                if (conn.Ping())
                {
                    ConsoleWindow.WriteLine("The connection to your database has been made successfully.");
                }

                //Creating the MySQLCommand object
                var cmd = conn.CreateCommand();

                //Trying to create the table
                try
                {
                    var createTable =
                        string.Format(
                            "CREATE TABLE `{0}` (`EntryID` int(11) NOT NULL,`TeamName` varchar(45) NOT NULL DEFAULT 'Default', `TeamNumber` int(11) NOT NULL DEFAULT '0',`TeamColour` varchar(45) NOT NULL DEFAULT 'Default',`MatchNumber` int(11) NOT NULL DEFAULT '0',`AutoHighTally` int(11) NOT NULL DEFAULT '0',`AutoLowTally` int(11) NOT NULL DEFAULT '0',`ControlledHighTally` int(11) NOT NULL DEFAULT '0',`ControlledLowTally` int(11) NOT NULL DEFAULT '0',`HotGoalTally` int(11) NOT NULL DEFAULT '0',`AutoPickup` int(11) NOT NULL DEFAULT '0',`ControlledPickup` int(11) NOT NULL DEFAULT '0',`MissedPickups` int(11) NOT NULL DEFAULT '0',`StartingLocationX` int(11) NOT NULL DEFAULT '0',`StartingLocationY` int(11) NOT NULL DEFAULT '0',`Comments` varchar(45) DEFAULT 'No Comment',`DidRobotDie` tinyint(4) NOT NULL DEFAULT '0',PRIMARY KEY (`EntryID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8",
                            Program.selectedEventName);
                    cmd.CommandText = createTable;
                    cmd.ExecuteNonQuery();
                    ConsoleWindow.WriteLine("The table: " + Program.selectedEventName + " has been created.");
                    //end of creating the table
                }
                catch (MySqlException createException)
                {
                    ConsoleWindow.WriteLine("If there is an error it is most likely because the table is already made.");
                    ConsoleWindow.WriteLine("Errorcode: " + createException.ErrorCode);
                    ConsoleWindow.WriteLine(createException.Message);
                }

                //Submit data into the database
                var insertDataString =
                    string.Format(
                        "Insert into {0} (EntryID,TeamName,TeamNumber,TeamColour,MatchNumber,AutoHighTally,AutoLowTally,ControlledHigHTally,ControlledLowTally,HotGoalTally,AutoPickup,ControlledPickup,MissedPickups,StartingLocationX,StartingLocationY,Comments,DidRobotDie) values('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}');",
                        Program.selectedEventName, CountRowsInDatabase() + 1,
                        Program.selectedTeamName,
                        Program.selectedTeamNumber, teamColour, matchNumber, autoHighTally, autoLowTally,
                        controlledHighTally, controlledLowTally, hotGoalTally, autoPickupTally, controlledPickupTally,
                        missedPickupsTally, xStarting, yStarting, comments, didRobotDieINT);

                cmd.CommandText = insertDataString;
                cmd.ExecuteNonQuery();

                ConsoleWindow.WriteLine("Data has been inserted into the database!");
                contextDisplayLabel.Text = "Your data has been inserted into the database!";

                //Closing the connection
                conn.Close();
                cmd.Dispose();
            }
            catch (MySqlException ex)
            {
                contextDisplayLabel.Text = "An error has occured!";
                ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode);
                ConsoleWindow.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
 private void initializeDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MySQLMethods.InitializeDatabases();
 }
Esempio n. 5
0
        private void MainSettings_Load(object sender, EventArgs e)
        {
            if (Settings.Default.clickToEmptyTextBoxes)
            {
                clickEmptyTextBoxChecker.Checked = true;
            }
            else
            {
                if (Settings.Default.clickToEmptyTextBoxes == false)
                {
                    clickEmptyTextBoxChecker.Checked = false;
                }
            }

            if (Settings.Default.minimizeHomeWentEventLoads)
            {
                minimizeHomeCheckbox.Checked = true;
            }
            else
            {
                if (Settings.Default.minimizeHomeWentEventLoads == false)
                {
                    minimizeHomeCheckbox.Checked = false;
                }
            }

            if (Settings.Default.clearConsoleOnToggle)
            {
                clearConsoleOnToggleCheckBox.Checked = true;
            }
            else
            {
                if (Settings.Default.clearConsoleOnToggle == false)
                {
                    clearConsoleOnToggleCheckBox.Checked = false;
                }
            }

            if (Settings.Default.allowExportToTextFile)
            {
                allowExportToTextFileCheckBox.Checked = true;
            }
            else
            {
                if (Settings.Default.allowExportToTextFile == false)
                {
                    allowExportToTextFileCheckBox.Checked = false;
                }
            }

            if (Settings.Default.showQuestionButtons)
            {
                showQuestionButtonsCheckBox.Checked = true;
            }
            else
            {
                if (Settings.Default.showQuestionButtons == false)
                {
                    showQuestionButtonsCheckBox.Checked = false;
                }
            }

            if (Settings.Default.colourTeamComparisonStatistics)
            {
                colourTeamComparisonStatisticsCheckBox.Checked = true;
            }
            else
            {
                if (Settings.Default.colourTeamComparisonStatistics == false)
                {
                    colourTeamComparisonStatisticsCheckBox.Checked = false;
                }
            }

            teamComparisonEqualValueColourDisplay.BackColor = Settings.Default.teamComparisonEqualValueColour;
            usernameTextBox.Text         = Settings.Default.username;
            databaseIPTextBox.Text       = Settings.Default.databaseIP;
            databasePortTextBox.Text     = Settings.Default.databasePort;
            databaseUsernameTextBox.Text = Settings.Default.databaseUsername;
            databasePasswordTextBox.Text = Security.DeCryptString(Settings.Default.databasePassword);
            databaseNameTextBox.Text     = Settings.Default.databaseName;

            try
            {
                string mySqlConnectionString = MySQLMethods.MakeMySqlConnectionString();
                var    conn = new MySqlConnection {
                    ConnectionString = mySqlConnectionString
                };

                conn.Open();

                if (conn.Ping())
                {
                    Console.WriteLine("You have successfully connected to your database!");
                    ConsoleWindow.WriteLine("You have successfully connected to your database!");
                    connectionDisplay.BackColor = Color.Chartreuse;
                    connectionDisplay.Text      = ("Successfully Connected to Database.");
                }
                else
                {
                    Console.WriteLine("You have unsuccessfully connected to your database!");
                    ConsoleWindow.WriteLine("You have unsuccessfully connected to your database!");
                    connectionDisplay.BackColor = Color.Red;
                    connectionDisplay.Text      = ("Connection to Database Failed.");
                }

                conn.Close();
            }
            catch (MySqlException ex)
            {
                connectionDisplay.BackColor = Color.Red;
                connectionDisplay.Text      = ("Connection to Database Failed.");
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Message " + ex.Message);
                ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode);
                ConsoleWindow.WriteLine("Error Message " + ex.Message);
            }
        }