コード例 #1
0
 /// <summary>
 /// Inserts/Updates values in DataGridView when clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonInsUp_Click(object sender, EventArgs e)
 {
     try
     {
         commBuilder = new MySqlCommandBuilder(adapter);
         adapter.Update(dataSet);
     }
     catch (MySqlException ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         DBReader.connectionEnd(connection);
     }
     refreshTable();
 }
コード例 #2
0
 private void DataBaseNameSelector_Load(object sender, EventArgs e)
 {
     connection = DBReader.connectionCreatorWithNoDatabase();
     try
     {
         DBReader.connectionOpen(connection);
         comboBoxFill();
     }
     catch (MySqlException ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         DBReader.connectionEnd(connection);
     }
 }
コード例 #3
0
 /// <summary>
 /// Creates new MySql connection for selected database
 /// </summary>
 /// <param name="databaseName">Name of the current database</param>
 private void newConnection(string databaseName)
 {
     connection = DBReader.connectionCreator(databaseName);
     try
     {
         DBReader.connectionOpen(connection);
         entitiesToMenuStrip();
         comboBoxFill();
     }
     catch (MySqlException ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         DBReader.connectionEnd(connection);
     }
 }
コード例 #4
0
 /// <summary>
 /// Rotates players when clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonRightArrow_Click(object sender, EventArgs e)
 {
     playersID = new List <int>();
     try
     {
         DBReader.connectionOpen(connection);
         playersID = DBReader.selectAllPlayersID(connection, DBName);
         if (textBoxSelectedPlayer.Text == "For all")
         {
             buttonInsUp.Enabled        = false;
             currentID                  = 0;
             textBoxSelectedPlayer.Text = "Player " + playersID[0];
         }
         else if (textBoxSelectedPlayer.Text == "Player " + playersID[playersID.Count() - 1])
         {
             if (textBoxSelectedItem.Text != "")
             {
                 buttonInsUp.Enabled = true;
             }
             else
             {
                 buttonInsUp.Enabled = false;
             }
             currentID = -1;
             textBoxSelectedPlayer.Text = "For all";
         }
         else if (textBoxSelectedPlayer.Text.StartsWith("Player "))
         {
             buttonInsUp.Enabled = false;
             currentID++;
             textBoxSelectedPlayer.Text = "Player " + playersID[currentID];
         }
     }
     catch (MySqlException ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         DBReader.connectionEnd(connection);
     }
 }
コード例 #5
0
        /// <summary>
        /// Drops the base when clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDropTheBase_Click(object sender, EventArgs e)
        {
            var response = MessageBox.Show("Do you want to delete " + textBoxSelectedDatabase.Text + " session?", "Are you sure?", MessageBoxButtons.YesNo);
            {
                if (response == DialogResult.Yes)
                {
                    var response2 = MessageBox.Show("Are you sure?", "Are you sure?", MessageBoxButtons.YesNo);
                    {
                        if (response == DialogResult.Yes)
                        {
                            string commandText = "drop database " + DBName + ";";

                            MySqlCommand    dropCommand = new MySqlCommand(commandText, connection);
                            MySqlDataReader reader;

                            try
                            {
                                DBReader.connectionOpen(connection);
                                reader = dropCommand.ExecuteReader();
                                MessageBox.Show("Session was dropped!");
                                textBoxSelectedDatabase.Text = "";
                                textBoxSelectedItem.Text     = "";
                                tableEntity.DataSource       = null;
                                tableEntity.Refresh();
                                while (reader.Read())
                                {
                                }
                            }
                            catch (MySqlException ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                            finally
                            {
                                DBReader.connectionEnd(connection);
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Opens everything when EntityManager is loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EntityManager_Load(object sender, EventArgs e)
        {
            namesToTextBoxes();

            connection = DBReader.connectionCreator(DBName);
            try
            {
                DBReader.connectionOpen(connection);
                addNewRowEditor();
                placeRowEditors();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBReader.connectionEnd(connection);
            }
            doTheItemsExist();
        }
コード例 #7
0
        /// <summary>
        /// Updates values in table when clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            string           columnAndTextBoxValuesForUpdate = "";
            List <RowEditor> listOfRowEditors = new List <RowEditor>();
            List <string>    listOfColumns    = new List <string>();

            try
            {
                DBReader.connectionOpen(connection);
                listOfColumns = DBReader.selectAllColumnNames(connection, tableName);

                foreach (RowEditor editorControl in splitContainer.Panel2.Controls)
                {
                    listOfRowEditors.Add(editorControl);
                }

                for (int i = 0; i < listOfColumns.Count(); i++)
                {
                    columnAndTextBoxValuesForUpdate += DBReader.selectAllColumnNames(connection, tableName)[i] + "='" + listOfRowEditors[i].valueName + "',";
                }
                columnAndTextBoxValuesForUpdate = columnAndTextBoxValuesForUpdate.Remove(columnAndTextBoxValuesForUpdate.Length - 1);
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBReader.connectionEnd(connection);
            }


            string idValue = "";

            foreach (RowEditor editorControl in listOfRowEditors)
            {
                if (editorControl.labelName == "id_")
                {
                    idValue = editorControl.valueName;
                }
            }

            string          commandText   = "update " + tableName + " set " + columnAndTextBoxValuesForUpdate + " where id_ ='" + idValue + "' ;";
            MySqlCommand    updateCommand = new MySqlCommand(commandText, connection);
            MySqlDataReader reader;

            try
            {
                DBReader.connectionOpen(connection);
                reader = updateCommand.ExecuteReader();
                MessageBox.Show("Data was updated");
                while (reader.Read())
                {
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBReader.connectionEnd(connection);
            }
        }