private void BtnAddBook_Click(object sender, EventArgs e) { if (TxtBarcode.Text == "") { MessageBox.Show("Please enter missing fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBarcode.Text.Length <= 8) { MessageBox.Show("The Barcode's minimum accepted character length is 9.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBarcode.Text.Length == 11) { MessageBox.Show("The Barcode's character length must be 9, 10, 12 or 13 only.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookTitle.Text == "") { MessageBox.Show("Please enter missing fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookAuthor.Text == "") { MessageBox.Show("Please enter missing fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookCategory.Text == "") { MessageBox.Show("Please enter missing fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookPublisher.Text == "") { MessageBox.Show("Please enter missing fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var result = MessageBox.Show("Confirm adding new record?", "Add New Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { using (var con = new MySqlConnection(GetConnection())) { string command = $"INSERT INTO `lms.sad`.`tblbooks` (`Barcode`,`Book_Title`,`Book_Author`, `Book_Category`, `Publisher`) " + "VALUES " + $"('{TxtBarcode.Text}','{TxtBookTitle.Text}','{TxtBookAuthor.Text}','{TxtBookCategory.Text}','{TxtBookPublisher.Text}')"; con.Open(); using (var cmd = new MySqlCommand(command, con)) { cmd.CommandType = CommandType.Text; var i = cmd.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Successfully Added! Please check Book Records.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtBarcode.Clear(); TxtBookTitle.Clear(); TxtBookAuthor.Clear(); TxtBookCategory.Clear(); TxtBookPublisher.Clear(); } } con.Close(); } } } }
private void BtnClear_Click(object sender, EventArgs e) { TxtBookTitle.Clear(); TxtBookAuthor.Clear(); TxtBookCategory.Clear(); TxtBookPublisher.Clear(); TxtBarcode.Clear(); }
private void BtnUpdateBook_Click(object sender, EventArgs e) { if (TxtBookTitle.Text == "") { MessageBox.Show("Please fill empty fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookAuthor.Text == "") { MessageBox.Show("Please fill empty fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookCategory.Text == "") { MessageBox.Show("Please fill empty fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (TxtBookPublisher.Text == "") { MessageBox.Show("Please fill empty fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var result = MessageBox.Show("Confirm editing new record?", "Edit New Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { using (var con = new MySqlConnection(GetConnection())) { string command = $"UPDATE `lms.sad`.`tblbooks`" + $" SET " + $"`Book_Title`='{TxtBookTitle.Text}',`Book_Author`='{TxtBookAuthor.Text}',`Book_Category`='{TxtBookCategory.Text}',`Publisher`='{TxtBookPublisher.Text}'" + $" WHERE `Barcode`='{TxtBarcode.Text}'"; con.Open(); using (var cmd = new MySqlCommand(command, con)) { cmd.CommandType = CommandType.Text; var i = cmd.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Successfully Updated! Please refresh Book List to view entry!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtBookTitle.Clear(); TxtBookAuthor.Clear(); TxtBookCategory.Clear(); TxtBookPublisher.Clear(); TxtBarcode.Clear(); } } con.Close(); } } } }