}//End public bool seEjecutoComando() public bool Conectar() { MySqlConnection mConnection = new MySqlConnection(MyConString); try { mConnection.Open(); } catch (Exception ex) { return false; } if (mConnection.Ping()) { //Command = Connection.CreateCommand(); return true; }//End if (Connection.Ping()) return false; }//End public void Conectar()
public void ConnectionTest() { DefaultConnectionString.Should().Not.Be.Empty(); using(var conn = new MySqlConnection(DefaultConnectionString)) { conn.Open(); conn.Ping().Should().Be.True(); } }
public DataBase() { MySqlConnectionStringBuilder _connectionSB = new MySqlConnectionStringBuilder(); _connectionSB.Server = "localhost"; _connectionSB.UserID = "server"; _connectionSB.Password = "******"; _connectionSB.Database = "KPITeamProject"; _connection = new MySqlConnection(_connectionSB.ConnectionString); try { _connection.Open(); if (!_connection.Ping()) Console.WriteLine("DataBase connection is failed"); _connection.Close(); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } }
public DataBase() { MySqlConnectionStringBuilder _connectionSB = new MySqlConnectionStringBuilder(); _connectionSB.Server = "localhost"; _connectionSB.UserID = "server"; _connectionSB.Password = "******"; _connectionSB.Database = "KPITeamProject"; _connection = new MySqlConnection(_connectionSB.ConnectionString); try { _connection.Open(); if (!_connection.Ping()) Console.WriteLine("DataBase connection is failed"); _connection.Close(); Log.WriteMessage("Ping and open connection was succeed", "Start connection"); } catch(Exception ex) { Log.WriteMessage(ex.Message, "Start connection"); } }
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 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); } }
private void submitDataButton_Click(object sender, EventArgs e) { submitDataButton.Enabled = false; if (Settings.Default.allowExportToTextFile) { //Write to TextFile if (saveFileDialog.ShowDialog() == DialogResult.OK) { var writer = new StreamWriter(saveFileDialog.FileName); writer.WriteLine("=========================================================="); writer.WriteLine("-===============+ Human Readable Portion +===============-"); writer.WriteLine("=========================================================="); writer.WriteLine("Time Created: " + Time.GetCurrentTime()); writer.WriteLine("Scouted By: " + Settings.Default.username); writer.WriteLine("Match #: " + Convert.ToString(matchNumber)); writer.WriteLine("Did the robot die?: " + Convert.ToBoolean(didRobotDie)); writer.WriteLine("Team Colour: " + teamColour); writer.WriteLine("Team Name: " + Program.selectedTeamName); writer.WriteLine("Team Number: " + Program.selectedTeamNumber); writer.WriteLine("#########################################################"); writer.WriteLine("Auto High: Goal: " + Convert.ToString(autoHighGoal) + " Miss: " + Convert.ToString(autoHighMiss)); writer.WriteLine("Auto Low: Goal: " + Convert.ToString(autoLowGoal) + " Miss: " + Convert.ToString(autoLowMiss)); writer.WriteLine("Controlled High: Goal: " + Convert.ToString(controlledHighGoal) + " Miss: " + Convert.ToString(controlledHighMiss)); writer.WriteLine("Controlled Low: Goal: " + Convert.ToString(controlledLowGoal) + " Miss: " + Convert.ToString(controlledLowMiss)); writer.WriteLine("Hot: Goal: " + Convert.ToString(hotGoal) + " Miss: " + Convert.ToString(hotMiss)); writer.WriteLine("3-Assist: Goal: " + Convert.ToString(tripleAssistGoal) + " Miss: " + Convert.ToString(tripleAssistMiss)); writer.WriteLine("Auto Pickup: Successful: " + Convert.ToString(autoBallPickup) + " Unsuccessful: " + Convert.ToString(autoBallPickupMiss)); writer.WriteLine("Controlled Pickup: Successful: " + Convert.ToString(controlledBallPickup) + " Unsuccessful: " + Convert.ToString(controlledBallPickupMiss)); writer.WriteLine("Pickup From Human: Successful: " + Convert.ToString(pickupFromHuman) + " Unsuccessful: " + Convert.ToString(pickupFromHumanMiss)); writer.WriteLine("Pass To Another Robot: Successful: " + Convert.ToString(passToOtherRobot) + " Unsuccessful: " + Convert.ToString(passToOtherRobotMiss)); writer.WriteLine("Truss Shot: Successful: " + Convert.ToString(successfulTruss) + " Unsuccessful: " + Convert.ToString(unsuccessfulTruss)); writer.WriteLine("Starting Location: X: " + Convert.ToString(xStarting) + " Y: " + Convert.ToString(yStarting)); writer.WriteLine("Driver Rating: " + driverRating); writer.WriteLine("Auto Movement: " + Convert.ToBoolean(autoMovement)); writer.WriteLine("Comments: " + Convert.ToString(comments)); writer.WriteLine("#########################################################"); writer.WriteLine("========================================================="); writer.WriteLine("-=============+ Computer Readable Portion +=============-"); writer.WriteLine("========================================================="); writer.WriteLine(Convert.ToString(Program.selectedTeamNumber)); writer.WriteLine(Convert.ToString(Program.selectedTeamName)); writer.WriteLine(Convert.ToString(teamColour)); writer.WriteLine(Convert.ToString(matchNumber)); writer.WriteLine(Convert.ToString(autoHighGoal)); writer.WriteLine(Convert.ToString(autoHighMiss)); writer.WriteLine(Convert.ToString(autoLowGoal)); writer.WriteLine(Convert.ToString(autoLowMiss)); writer.WriteLine(Convert.ToString(controlledHighGoal)); writer.WriteLine(Convert.ToString(controlledHighMiss)); writer.WriteLine(Convert.ToString(controlledLowGoal)); writer.WriteLine(Convert.ToString(controlledLowMiss)); writer.WriteLine(Convert.ToString(hotGoal)); writer.WriteLine(Convert.ToString(hotMiss)); writer.WriteLine(Convert.ToString(tripleAssistGoal)); writer.WriteLine(Convert.ToString(tripleAssistMiss)); writer.WriteLine(Convert.ToString(autoBallPickup)); writer.WriteLine(Convert.ToString(autoBallPickupMiss)); writer.WriteLine(Convert.ToString(controlledBallPickup)); writer.WriteLine(Convert.ToString(controlledBallPickupMiss)); writer.WriteLine(Convert.ToString(pickupFromHuman)); writer.WriteLine(Convert.ToString(pickupFromHumanMiss)); writer.WriteLine(Convert.ToString(passToOtherRobot)); writer.WriteLine(Convert.ToString(passToOtherRobotMiss)); writer.WriteLine(Convert.ToString(successfulTruss)); writer.WriteLine(Convert.ToString(unsuccessfulTruss)); writer.WriteLine(Convert.ToString(xStarting)); writer.WriteLine(Convert.ToString(yStarting)); writer.WriteLine(Convert.ToBoolean(didRobotDie)); writer.WriteLine(Convert.ToInt16(driverRating)); writer.WriteLine(Convert.ToBoolean(autoMovement)); writer.WriteLine(Convert.ToString(comments)); writer.WriteLine("END OF FILE"); writer.Close(); } } //MySQL Database //MySQL Database Connection Info string 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()) { Console.WriteLine("The connection to your database has been made successfully."); ConsoleWindow.WriteLine("The connection to your database has been made successfully."); } //Creating the MySQLCommand object MySqlCommand cmd = conn.CreateCommand(); if (tableCreated == false) { //Trying to create the table try { string createTable = String.Format( "CREATE TABLE `{0}` (`EntryID` int(11) NOT NULL DEFAULT '0',`TeamNumber` int(11) NOT NULL DEFAULT '0',`TeamName` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Default',`TeamColour` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Not Selected',`MatchNumber` int(11) NOT NULL DEFAULT '0',`AutoHighGoal` int(11) NOT NULL DEFAULT '0',`AutoHighMiss` int(11) NOT NULL DEFAULT '0',`AutoLowGoal` int(11) NOT NULL DEFAULT '0',`AutoLowMiss` int(11) NOT NULL DEFAULT '0',`ControlledHighGoal` int(11) NOT NULL DEFAULT '0',`ControlledHighMiss` int(11) NOT NULL DEFAULT '0',`ControlledLowGoal` int(11) NOT NULL DEFAULT '0',`ControlledLowMiss` int(11) NOT NULL DEFAULT '0',`HotGoals` int(11) NOT NULL DEFAULT '0',`HotGoalMiss` int(11) NOT NULL DEFAULT '0',`3AssistGoal` int(11) NOT NULL DEFAULT '0',`3AssistMiss` int(11) NOT NULL DEFAULT '0',`AutoBallPickup` int(11) NOT NULL DEFAULT '0',`AutoBallPickupMiss` int(11) NOT NULL DEFAULT '0',`ControlledBallPickup` int(11) NOT NULL DEFAULT '0',`ControlledBallPickupMiss` int(11) NOT NULL DEFAULT '0',`PickupFromHuman` int(11) NOT NULL DEFAULT '0',`MissedPickupFromHuman` int(11) NOT NULL DEFAULT '0',`PassToAnotherRobot` int(11) NOT NULL DEFAULT '0',`MissedPassToAnotherRobot` int(11) NOT NULL DEFAULT '0',`SuccessfulTruss` int(11) NOT NULL DEFAULT '0',`UnsuccessfulTruss` int(11) NOT NULL DEFAULT '0',`StartingX` int(11) NOT NULL DEFAULT '0',`StartingY` int(11) NOT NULL DEFAULT '0',`DidRobotDie` tinyint(4) NOT NULL DEFAULT '0',`DriverRating` int(11) NOT NULL DEFAULT '0',`AutoMovement` tinyint(4) NOT NULL DEFAULT '0',`Comments` varchar(300) COLLATE utf8_unicode_ci DEFAULT NULL,PRIMARY KEY (`EntryID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", Program.selectedEventName); cmd.CommandText = createTable; cmd.ExecuteNonQuery(); Console.WriteLine("The table: " + Program.selectedEventName + " has been created."); ConsoleWindow.WriteLine("The table: " + Program.selectedEventName + " has been created."); //end of creating the table } catch (MySqlException createException) { Console.WriteLine("If there is an error it is most likely because the table is already made."); Console.WriteLine("Errorcode: " + createException.ErrorCode); Console.WriteLine(createException.Message); 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); } tableCreated = true; } //Submit data into the database string insertDataString = String.Format( "Insert into {0} (EntryID,TeamNumber,TeamName,TeamColour,MatchNumber,AutoHighGoal,AutoHighMiss, AutoLowGoal, AutoLowMiss, ControlledHighGoal, ControlledHighMiss, ControlledLowGoal, ControlledLowMiss, HotGoals, HotGoalMiss, 3AssistGoal, 3AssistMiss, AutoBallPickup, AutoBallPickupMiss, ControlledBallPickup, ControlledBallPickupMiss, PickupFromHuman, MissedPickupFromHuman, PassToAnotherRobot, MissedPassToAnotherRobot, SuccessfulTruss, UnsuccessfulTruss, StartingX, StartingY, DidRobotDie, DriverRating, AutoMovement, Comments) values('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}');", Program.selectedEventName, (MySQLMethods.GetNumberOfRowsInATable() + 1), Program.selectedTeamNumber, Program.selectedTeamName, teamColour, matchNumber, autoHighGoal, autoHighMiss, autoLowGoal, autoLowMiss, controlledHighGoal, controlledHighMiss, controlledLowGoal, controlledLowMiss, hotGoal, hotMiss, tripleAssistGoal, tripleAssistMiss, autoBallPickup, autoBallPickupMiss, controlledBallPickup, controlledBallPickupMiss, pickupFromHuman, pickupFromHumanMiss, passToOtherRobot, passToOtherRobotMiss, successfulTruss, unsuccessfulTruss, xStarting, yStarting, didRobotDie, driverRating, Convert.ToInt16(autoMovement), comments); cmd.CommandText = insertDataString; cmd.ExecuteNonQuery(); Console.WriteLine("Data has been inserted into the database!"); ConsoleWindow.WriteLine("Data has been inserted into the database!"); //Closing the connection conn.Close(); cmd.Dispose(); } catch (MySqlException ex) { Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine(ex.Message); ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode); ConsoleWindow.WriteLine(ex.Message); } Notifications.ShowInformationMessage("You have successfully inserted your scouting data for Match #: " + matchNumber); //Clearing the values after you submit the data autoHighGoal = 0; autoHighMiss = 0; autoLowGoal = 0; autoLowMiss = 0; controlledHighGoal = 0; controlledHighMiss = 0; controlledLowGoal = 0; controlledLowMiss = 0; hotGoal = 0; hotMiss = 0; tripleAssistGoal = 0; tripleAssistMiss = 0; autoBallPickup = 0; autoBallPickupMiss = 0; controlledBallPickup = 0; controlledBallPickupMiss = 0; pickupFromHuman = 0; pickupFromHumanMiss = 0; passToOtherRobot = 0; passToOtherRobotMiss = 0; successfulTruss = 0; unsuccessfulTruss = 0; BlankPanel(); didRobotDie = 0; didRobotDieCheckBox.Checked = false; matchNumberUpDown.Value++; totalGoal = 0; totalMiss = 0; totalGoodControl = 0; totalMissControl = 0; xStarting = 0; yStarting = 0; startingLocationXYDisplay.Text = ("X: 0 Y: 0"); comments = (""); commentsTextBox.Text = ("Comments: Any other information that may be needed"); autoMovement = false; autonomousMovementCheckBox.Checked = false; driverRating = 0; driverRatingButton1.Enabled = true; driverRatingButton1.Checked = false; driverRatingButton2.Enabled = true; driverRatingButton2.Checked = false; driverRatingButton3.Enabled = true; driverRatingButton3.Checked = false; driverRatingButton4.Enabled = true; driverRatingButton4.Checked = false; UpdateLabels(); submitDataButton.Enabled = true; }
public void Open() { string connStr = "Server=" + _dbHost + ";Uid=" + _dbUser + ";Pwd=" + _dbPass + ";database=" + _dbName + ";Charset=utf8"; _conn = new MySqlConnection(connStr); MySqlCommand command = _conn.CreateCommand(); try { _conn.Open(); } catch (MySql.Data.MySqlClient.MySqlException ex) { switch (ex.Number) { case 0: Debug.WriteLine("無法連線到資料庫."); break; case 1045: Debug.WriteLine("使用者帳號或密碼錯誤,請再試一次."); break; } } Debug.WriteLine(_conn.Ping()); //command.CommandText = "Update user SET nickname='Admin' WHERE id = 0 "; //command.ExecuteNonQuery(); }
private void submitDataButton_Click(object sender, EventArgs e) { UpdateLabels(); if (Settings.Default.allowExportToTextFile) { //Write to TextFile 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 string 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()) { Console.WriteLine("The connection to your database has been made successfully."); ConsoleWindow.WriteLine("The connection to your database has been made successfully."); } //Creating the MySQLCommand object MySqlCommand cmd = conn.CreateCommand(); //Trying to create the table try { string 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(); Console.WriteLine("The table: " + Program.selectedEventName + " has been created."); ConsoleWindow.WriteLine("The table: " + Program.selectedEventName + " has been created."); //end of creating the table } catch (MySqlException createException) { Console.WriteLine("If there is an error it is most likely because the table is already made."); Console.WriteLine("Errorcode: " + createException.ErrorCode); Console.WriteLine(createException.Message); 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 string 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(); Console.WriteLine("Data has been inserted into the database!"); 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!"); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine(ex.Message); ConsoleWindow.WriteLine("Error Code: " + ex.ErrorCode); ConsoleWindow.WriteLine(ex.Message); } }
public void GetDataForTeam(int teamNumberLocal, int selection) { int numberOfMatches = 0; var AutoHighGoal = new List<double>(); var AutoHighMiss = new List<double>(); var AutoLowGoal = new List<double>(); var AutoLowMiss = new List<double>(); var ControlledHighGoal = new List<double>(); var ControlledHighMiss = new List<double>(); var ControlledLowGoal = new List<double>(); var ControlledLowMiss = new List<double>(); var HotGoal = new List<double>(); var HotMiss = new List<double>(); var TripleAssistGoal = new List<double>(); var TripleAssistMiss = new List<double>(); var AutoPickup = new List<double>(); var AutoPickupMiss = new List<double>(); var ControlledPickup = new List<double>(); var ControlledPickupMiss = new List<double>(); var PickupFromHuman = new List<double>(); var MissedPickupFromHuman = new List<double>(); var PassToAnotherRobot = new List<double>(); var MissedPassToAnotherRobot = new List<double>(); var SuccessfulTruss = new List<double>(); var UnSuccessfulTruss = new List<double>(); var DriverRating = new List<double>(); var RobotDied = new List<double>(); var AutoMovementGood = new List<double>(); var StartingX = new List<double>(); var StartingY = new List<double>(); try { var conn = new MySqlConnection(MySQLMethods.MakeMySqlConnectionString()); MySqlCommand cmd = conn.CreateCommand(); MySqlDataReader reader; cmd.CommandText = String.Format("SELECT * From {0} where TeamNumber={1}", Program.selectedEventName, teamNumberLocal); conn.Open(); if (conn.Ping()) { Console.WriteLine("Connected to the databse. Collecting and generating statistics now!"); ConsoleWindow.WriteLine("Connected to the databse. Collecting and generating statistics now!"); } reader = cmd.ExecuteReader(); while (reader.Read()) { numberOfMatches++; AutoHighGoal.Add(Convert.ToDouble(reader["AutoHighGoal"])); AutoHighMiss.Add(Convert.ToDouble(reader["AutoHighMiss"])); AutoLowGoal.Add(Convert.ToDouble(reader["AutoLowGoal"])); AutoLowMiss.Add(Convert.ToDouble(reader["AutoLowMiss"])); ControlledHighGoal.Add(Convert.ToDouble(reader["ControlledHighGoal"])); ControlledHighMiss.Add(Convert.ToDouble(reader["ControlledHighMiss"])); ControlledLowGoal.Add(Convert.ToDouble(reader["ControlledLowGoal"])); ControlledLowMiss.Add(Convert.ToDouble(reader["ControlledLowMiss"])); HotGoal.Add(Convert.ToDouble(reader["HotGoals"])); HotMiss.Add(Convert.ToDouble(reader["HotGoalMiss"])); TripleAssistGoal.Add(Convert.ToDouble(reader["3AssistGoal"])); TripleAssistMiss.Add(Convert.ToDouble(reader["3AssistMiss"])); AutoPickup.Add(Convert.ToDouble(reader["AutoBallPickup"])); AutoPickupMiss.Add(Convert.ToDouble(reader["AutoBallPickupMiss"])); ControlledPickup.Add(Convert.ToDouble(reader["ControlledBallPickup"])); ControlledPickupMiss.Add(Convert.ToDouble(reader["ControlledBallPickupMiss"])); PickupFromHuman.Add(Convert.ToDouble(reader["PickupFromHuman"])); MissedPickupFromHuman.Add(Convert.ToDouble(reader["MissedPickupFromHuman"])); PassToAnotherRobot.Add(Convert.ToDouble(reader["PassToAnotherRobot"])); MissedPassToAnotherRobot.Add(Convert.ToDouble(reader["MissedPassToAnotherRobot"])); SuccessfulTruss.Add(Convert.ToDouble(reader["SuccessfulTruss"])); UnSuccessfulTruss.Add(Convert.ToDouble(reader["UnsuccessfulTruss"])); DriverRating.Add(Convert.ToDouble(reader["DriverRating"])); if (Convert.ToInt32(reader["DidRobotDie"]) == 1) { RobotDied.Add(1); } if (Convert.ToInt32(reader["AutoMovement"].ToString()) == 1) { AutoMovementGood.Add(Convert.ToDouble(reader["AutoMovement"])); } StartingX.Add(Convert.ToDouble(reader["StartingX"])); StartingY.Add(Convert.ToDouble(reader["StartingY"])); } conn.Close(); } catch (MySqlException e) { Console.WriteLine("Error Code: " + e.ErrorCode); Console.WriteLine("Error Message: " + e.Message); ConsoleWindow.WriteLine("Error Code: " + e.ErrorCode); ConsoleWindow.WriteLine("Error Message: " + e.Message); Notifications.ErrorOccured("Looks like something went wrong. Check console for the error message"); } if (selection == 1) { try { _autoHighMean[0] = AutoHighGoal.Average(); _autoHighStandardDeviation[0] = CalculateStdDev(AutoHighGoal); _autoHighGoalSuccessRate[0] = AutoHighGoal.Sum()/(AutoHighGoal.Sum() + AutoHighMiss.Sum()); _autoLowMean[0] = AutoLowGoal.Average(); _autoLowStandardDeviation[0] = CalculateStdDev(AutoLowGoal); _autolowGoalSuccessRate[0] = AutoLowGoal.Sum()/(AutoLowGoal.Sum() + AutoLowMiss.Sum()); _autoMobilitySuccessRate[0] = AutoMovementGood.Sum()/(numberOfMatches); _driverRatingMean[0] = DriverRating.Average(); _driverRatingStandardDeviation[0] = CalculateStdDev(DriverRating); _controlledHighMean[0] = ControlledHighGoal.Average(); _controlledHighStandardDeviation[0] = CalculateStdDev(ControlledHighGoal); _controlledHighSuccessRate[0] = ControlledHighGoal.Sum()/ (ControlledHighGoal.Sum() + ControlledHighMiss.Sum()); _controlledLowMean[0] = ControlledLowGoal.Average(); _controlledLowStandardDeviation[0] = CalculateStdDev(ControlledLowGoal); _controlledLowSuccessRate[0] = ControlledLowGoal.Sum()/ (ControlledLowGoal.Sum() + ControlledLowMiss.Sum()); _hotGoalMean[0] = HotGoal.Average(); _hotGoalStandardDeviation[0] = CalculateStdDev(HotGoal); _hotGoalSuccessRate[0] = HotGoal.Sum()/(HotGoal.Sum() + HotMiss.Sum()); _pickupsMean[0] = (AutoPickup.Average()) + (ControlledPickup.Average()) + (PickupFromHuman.Average()); _pickupStandardDeviation[0] = CalculateStdDev(ControlledPickup); _pickupSuccessRate[0] = (AutoPickup.Sum() + ControlledPickup.Sum() + PickupFromHuman.Sum())/ (AutoPickup.Sum() + ControlledPickup.Sum() + PickupFromHuman.Sum() + AutoPickupMiss.Sum() + ControlledPickupMiss.Sum() + MissedPickupFromHuman.Sum()); _successfulTrussMean[0] = SuccessfulTruss.Average(); _trussStandardDeviation[0] = CalculateStdDev(SuccessfulTruss); _trussSuccessRate[0] = SuccessfulTruss.Sum()/(SuccessfulTruss.Sum() + UnSuccessfulTruss.Sum()); _survivability[0] = numberOfMatches/(numberOfMatches + RobotDied.Sum()); dataGridViewTeam1.Rows.Clear(); //Data Name, Mean, Standard Deviation, Successrate dataGridViewTeam1.Rows.Add("Autonomous High", _autoHighMean[0].ToString("#.##"), _autoHighStandardDeviation[0].ToString("#.##"), _autoHighGoalSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Autonomous Low", _autoLowMean[0].ToString("#.##"), _autoLowStandardDeviation[0].ToString("#.##"), _autolowGoalSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Autonomous Mobility", "N/A", "N/A", _autoMobilitySuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Driver Rating", _driverRatingMean[0].ToString("#.##"), _driverRatingStandardDeviation[0].ToString("#.##"), "N/A"); dataGridViewTeam1.Rows.Add("Controlled High", _controlledHighMean[0].ToString("#.##"), _controlledHighStandardDeviation[0].ToString("#.##"), _controlledHighSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Controlled Low", _controlledLowMean[0].ToString("#.##"), _controlledLowStandardDeviation[0].ToString("#.##"), _controlledLowSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Hot Goal", _hotGoalMean[0].ToString("#.##"), _hotGoalStandardDeviation[0].ToString("#.##"), _hotGoalSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Pickups", _pickupsMean[0].ToString("#.##"), _pickupStandardDeviation[0].ToString("#.##"), _pickupSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Truss", _successfulTrussMean[0].ToString("#.##"), _trussStandardDeviation[0].ToString("#.##"), _trussSuccessRate[0].ToString("P")); dataGridViewTeam1.Rows.Add("Survivability", "N/A", "N/A", _survivability[0].ToString("P")); } catch (Exception e) { dataGridViewTeam1.Rows.Clear(); team1Selected = false; Notifications.ErrorOccured("Looks like something went wrong. Check console for the error message"); Console.WriteLine("Error Message: " + e.Message); ConsoleWindow.WriteLine("Error Message: " + e.Message); } } else { if (selection == 2) { try { _autoHighMean[1] = AutoHighGoal.Average(); _autoHighStandardDeviation[1] = CalculateStdDev(AutoHighGoal); _autoHighGoalSuccessRate[1] = AutoHighGoal.Sum()/(AutoHighGoal.Sum() + AutoHighMiss.Sum()); _autoLowMean[1] = AutoLowGoal.Average(); _autoLowStandardDeviation[1] = CalculateStdDev(AutoLowGoal); _autolowGoalSuccessRate[1] = AutoLowGoal.Sum()/(AutoLowGoal.Sum() + AutoLowMiss.Sum()); _autoMobilitySuccessRate[1] = AutoMovementGood.Sum()/(numberOfMatches); _driverRatingMean[1] = DriverRating.Average(); _driverRatingStandardDeviation[1] = CalculateStdDev(DriverRating); _controlledHighMean[1] = ControlledHighGoal.Average(); _controlledHighStandardDeviation[1] = CalculateStdDev(ControlledHighGoal); _controlledHighSuccessRate[1] = ControlledHighGoal.Sum()/ (ControlledHighGoal.Sum() + ControlledHighMiss.Sum()); _controlledLowMean[1] = ControlledLowGoal.Average(); _controlledLowStandardDeviation[1] = CalculateStdDev(ControlledLowGoal); _controlledLowSuccessRate[1] = ControlledLowGoal.Sum()/ (ControlledLowGoal.Sum() + ControlledLowMiss.Sum()); _hotGoalMean[1] = HotGoal.Average(); _hotGoalStandardDeviation[1] = CalculateStdDev(HotGoal); _hotGoalSuccessRate[1] = HotGoal.Sum()/(HotGoal.Sum() + HotMiss.Sum()); _pickupsMean[1] = (AutoPickup.Average()) + (ControlledPickup.Average()) + (PickupFromHuman.Average()); _pickupStandardDeviation[1] = CalculateStdDev(ControlledPickup); _pickupSuccessRate[1] = (AutoPickup.Sum() + ControlledPickup.Sum() + PickupFromHuman.Sum())/ (AutoPickup.Sum() + ControlledPickup.Sum() + PickupFromHuman.Sum() + AutoPickupMiss.Sum() + ControlledPickupMiss.Sum() + MissedPickupFromHuman.Sum()); _successfulTrussMean[1] = SuccessfulTruss.Average(); _trussStandardDeviation[1] = CalculateStdDev(SuccessfulTruss); _trussSuccessRate[1] = SuccessfulTruss.Sum()/(SuccessfulTruss.Sum() + UnSuccessfulTruss.Sum()); _survivability[1] = numberOfMatches/(numberOfMatches + RobotDied.Sum()); dataGridViewTeam2.Rows.Clear(); //Data Name, Mean, Standard Deviation, Successrate dataGridViewTeam2.Rows.Add("Autonomous High", _autoHighMean[1].ToString("#.##"), _autoHighStandardDeviation[1].ToString("#.##"), _autoHighGoalSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Autonomous Low", _autoLowMean[1].ToString("#.##"), _autoLowStandardDeviation[1].ToString("#.##"), _autolowGoalSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Autonomous Mobility", "N/A", "N/A", _autoMobilitySuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Driver Rating", _driverRatingMean[1].ToString("#.##"), _driverRatingStandardDeviation[1].ToString("#.##"), "N/A"); dataGridViewTeam2.Rows.Add("Controlled High", _controlledHighMean[1].ToString("#.##"), _controlledHighStandardDeviation[1].ToString("#.##"), _controlledHighSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Controlled Low", _controlledLowMean[1].ToString("#.##"), _controlledLowStandardDeviation[1].ToString("#.##"), _controlledLowSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Hot Goal", _hotGoalMean[1].ToString("#.##"), _hotGoalStandardDeviation[1].ToString("#.##"), _hotGoalSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Pickups", _pickupsMean[1].ToString("#.##"), _pickupStandardDeviation[1].ToString("#.##"), _pickupSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Truss", _successfulTrussMean[1].ToString("#.##"), _trussStandardDeviation[1].ToString("#.##"), _trussSuccessRate[1].ToString("P")); dataGridViewTeam2.Rows.Add("Survivability", "N/A", "N/A", _survivability[1].ToString("P")); } catch (Exception e) { dataGridViewTeam2.Rows.Clear(); team2Selected = false; Notifications.ErrorOccured("Looks like something went wrong. Check console for the error message"); Console.WriteLine("Error Message: " + e.Message); ConsoleWindow.WriteLine("Error Message: " + e.Message); } } } }
public void PingUpdatesState() { MySqlConnection conn2 = new MySqlConnection(GetConnectionString(true)); conn2.Open(); KillConnection(conn2); Assert.IsFalse(conn2.Ping()); Assert.IsTrue(conn2.State == ConnectionState.Closed); conn2.Open(); conn2.Close(); }
public void updateTable(bool noChange = false) { Process plink = null; if (Properties.Settings.Default.SSHtunnel) { try { sqlconn.Server = @"127.0.0.1"; sqlconn.Port = uint.Parse(Properties.Settings.Default.SSHPort); ProcessStartInfo psi = new ProcessStartInfo(Properties.Settings.Default.plinkPath); psi.Arguments = "-ssh -l " + Properties.Settings.Default.SSHUser + " -L " + Properties.Settings.Default.port + ":localhost:" + Properties.Settings.Default.SSHPort + " -pw " + Properties.Settings.Default.SSHPass + " " + Properties.Settings.Default.server; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.UseShellExecute = false; psi.CreateNoWindow = true; plink = Process.Start(psi); } catch { debugOutput("SSH-Tunnel konnte nicht aufgebaut werden"); return; } } else { sqlconn.Server = Properties.Settings.Default.server; sqlconn.Port = Properties.Settings.Default.port; } sqlconn.UserID = Properties.Settings.Default.user; sqlconn.Password = Properties.Settings.Default.password; sqlconn.Database = Properties.Settings.Default.database; string table = Properties.Settings.Default.table; EntryTable.TableName = table; using (MySqlConnection connection = new MySqlConnection(sqlconn.ConnectionString)) { try { connection.Open(); if (!connection.Ping()) { throw new Exception("No Connection to Server. \r\n Connection: " + sqlconn.ConnectionString); } if (!noChange) { MySqlCommand del = new MySqlCommand(@"TRUNCATE TABLE " + sqlconn.Database + "." + table, connection); del.ExecuteNonQuery(); MySqlDataAdapter adapter = new MySqlDataAdapter(@"SELECT * FROM " + sqlconn.Database + "." + table, connection); MySqlCommandBuilder builder = new MySqlCommandBuilder(adapter); adapter.ContinueUpdateOnError = true; adapter.Update(EntryTable); } debugOutput("Successful", 1); } catch (Exception ex) { debugOutput(ex.Message.ToString()); //string tmp = ""; //if (plink != null) // tmp = plink.StandardOutput.ReadToEnd(); //debugOutput(ex.Message.ToString() + tmp); } } try { plink.StandardInput.WriteLine("exit"); plink.Kill(); plink.Dispose(); } catch { } if (!noChange) EntryTable.Clear(); }
private void SetUpConnection() { string conString = "SERVER=" + _configuration.database + ";" + "DATABASE=Computation;" + "UID=" + _configuration.user + ";PASSWORD="******";"; _sqlConnection = new MySqlConnection(conString); try { _sqlConnection.Open(); if (!_sqlConnection.Ping()) { MessageBox.Show("Die Verbindung zur Datenbank konnte nicht hergestellt werden", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); //Environment.Exit(-1); } } catch (Exception) { MessageBox.Show("Die Verbindung zur Datenbank konnte nicht hergestellt werden", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); //Environment.Exit(-1); } _sqlConnection.Close(); }