private void AddingButton_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(AddName.Text) && !string.IsNullOrWhiteSpace(AddDescription.Text) && !string.IsNullOrWhiteSpace(AddPrice.Text) && !string.IsNullOrWhiteSpace(AddQuantity.Text))
     {
         try
         {
             string InsertQuery = "insert into items(ITEM_NAME,ITEM_PRICE,ITEM_DESCRIPTION,ITEM_QUANTATY) VALUES('" + AddName.Text + "','" + int.Parse(AddPrice.Text) + "','" + AddDescription.Text + "'," + int.Parse(AddQuantity.Text) + ")";
             connection.Open();
             MySqlCommand cmd = new MySqlCommand(InsertQuery, connection);
             cmd.ExecuteNonQuery();
         }
         catch (MySqlException ex)
         {
             MessageBox.Show(ex.ToString());
         }
         finally
         {
             connection.Close();
             MessageBox.Show("Successfully Added", "Success");
             AddName.Clear();
             AddDescription.Clear();
             AddPrice.Clear();
             AddQuantity.Clear();
         }
     }
     else
     {
         MessageBox.Show("incorrect input", "ERROR");
     }
 }
Exemple #2
0
        private void RefreshEverything()
        {
            // ----- Refresh most of the fields on the three main tabs.
            string        sqlText;
            SqlConnection linkToDB;
            SqlDataReader stateReader;

            // ----- Initialize.
            ActiveStateID = -1L;

            // ----- Open a database connection.
            linkToDB = General.OpenConnection();
            if (linkToDB == null)
            {
                return;
            }

            // ----- See if a custom state already exists.
            sqlText     = "SELECT * FROM StateRegion WHERE RegionType = 99";
            stateReader = General.OpenReader(sqlText, linkToDB);
            if ((stateReader != null) && (stateReader.HasRows == true))
            {
                // ----- Existing custom state record.
                stateReader.Read();
                ActiveStateID = (long)(int)stateReader["ID"];

                AddName.Text         = (string)stateReader["FullName"];
                AddAbbreviation.Text = (string)stateReader["Abbreviation"];
            }
            else
            {
                // ----- No custom state record.
                AddName.Clear();
                AddAbbreviation.Clear();
            }
            if (stateReader != null)
            {
                stateReader.Close();
            }

            // ----- Adjust the display.
            if (ActiveStateID == -1L)
            {
                // ----- Set up the display for a new entry.
                AddName.Enabled         = true;
                AddAbbreviation.Enabled = true;
                ActAdd.Enabled          = true;

                EditID.Text = "N/A";
                EditName.Clear();
                EditAbbreviation.Clear();
                EditName.Enabled         = false;
                EditAbbreviation.Enabled = false;
                ActEdit.Enabled          = false;

                DeleteID.Text           = "N/A";
                DeleteName.Text         = "N/A";
                DeleteAbbreviation.Text = "N/A";
                ActDelete.Enabled       = false;
            }
            else
            {
                // ----- Set up the display for an existing item.
                AddName.Enabled         = false;
                AddAbbreviation.Enabled = false;
                ActAdd.Enabled          = false;

                EditID.Text              = ActiveStateID.ToString();
                EditName.Text            = AddName.Text;
                EditAbbreviation.Text    = AddAbbreviation.Text;
                EditName.Enabled         = true;
                EditAbbreviation.Enabled = true;
                ActEdit.Enabled          = true;

                DeleteID.Text           = ActiveStateID.ToString();
                DeleteName.Text         = AddName.Text;
                DeleteAbbreviation.Text = AddAbbreviation.Text;
                ActDelete.Enabled       = true;
            }

            // ----- Refresh the SQL statement previews.
            RefreshAddPreview();
            RefreshEditPreview();
            RefreshDeletePreview();
        }