コード例 #1
0
ファイル: Form1.cs プロジェクト: zach-hunter/C-sharp
 private void ISBNTextBox_Enter(object sender, EventArgs e)
 {
     if (ISBNTextBox.Text.Equals("ISBN"))
     {
         ISBNTextBox.Clear();
     }
 }
コード例 #2
0
 /// <summary>
 /// Clears fields and sets necessary fields to prepare for
 /// save.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void NewBookButton_Click(object sender, EventArgs e)
 {
     AuthorTextBox.Clear();
     TitleTextBox.Clear();
     ISBNTextBox.Clear();
     PriceTextBox.Clear();
     BookSelectBox.Enabled = false;
     SaveButton.Enabled    = true;
     CancelButton.Enabled  = true;
 }
コード例 #3
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // Check for empty boxes.
            if (AuthorTextBox.Text == "" || TitleTextBox.Text == "" || ISBNTextBox.Text == "" || PriceTextBox.Text == "" ||
                !Regex.IsMatch(AuthorTextBox.Text, author) || !Regex.IsMatch(TitleTextBox.Text, title) || !Regex.IsMatch(ISBNTextBox.Text, isbn) ||
                !Regex.IsMatch(PriceTextBox.Text, price))
            {
                MessageBox.Show("Invalid Entry:\nAuthor must be First Last\nISBN must be digits only\nPrice must be $xxx.xx format");
                return;
            }

            // Display messagebox -> If user clicks no, cancel database update.
            if (MessageBox.Show("Confirm Update?", "", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            string          ConnectionString = "server=localhost;user=root;database=book store;password="******"Insert into books values(null,'{TitleTextBox.Text}','{AuthorTextBox.Text}','{ISBNTextBox.Text}','{PriceTextBox.Text}')";
                cmd.Connection  = DBConnect;
                cmd.ExecuteNonQuery();
                DBConnect.Close();

                AuthorTextBox.Clear();
                TitleTextBox.Clear();
                ISBNTextBox.Clear();
                PriceTextBox.Clear();

                // Call function to update the combobox with new book added.
                BookSelectComboBox_Click(sender, e);

                BookSelectBox.Enabled = true;
                SaveButton.Enabled    = false;
                MessageBox.Show("Book added to database.");
                return;
            }
            // Else update the currently selected book
            cmd.CommandText = $"Update books set title='{TitleTextBox.Text}', author='{AuthorTextBox.Text}',isbn='{ISBNTextBox.Text}',price='{PriceTextBox.Text}' where title='{BookSelectBox.Text}'";
            cmd.Connection  = DBConnect;
            cmd.ExecuteNonQuery();
            DBConnect.Close();
            MessageBox.Show("Book successfully updated.");
        }