Example #1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (txtTitle.Text == "" || txtAuthor.Text == "" || txtISBN.Text == "" || txtPublisher.Text == "" || txtPrice.Text == "" || txtLanguage.Text == "" || txtLanguage.Text == "" || txtLanguage.Text == "" || txtLanguage.Text == "" || txtYear.Text == "" || txtCopies.Text == "" || cboGenre.Text == "" || cboMediaType.Text == "" || cboSubject.Text == "")
            {
                txtTitle.Focus();
                MyMessageBox.ShowMessage("Please don't leave blank spaces! Add 'NA' for blank spaces instead.", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    if (MyMessageBox.ShowMessage("Are you sure you want to add " + txtTitle.Text + "?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //open connection to the database
                        cn.Open();
                        //command to be executed on the database
                        cm = new SqlCommand("INSERT INTO tblBook (bookTitle, bookISBN, subject, genre, mediaType, language, author, publisher, price, pubYear, allCopies, availableCopies)  VALUES (@booktitle, @bookisbn, @subject, @genre, @mediatype, @language, @author, @publisher, @price, @year, @allcopies, @available)", cn);
                        //set parameters value
                        cm.Parameters.AddWithValue("@bookisbn", txtISBN.Text);
                        cm.Parameters.AddWithValue("@booktitle", txtTitle.Text);
                        cm.Parameters.AddWithValue("@allcopies", txtCopies.Text);
                        cm.Parameters.AddWithValue("@available", txtCopies.Text);
                        cm.Parameters.AddWithValue("@subject", cboSubject.Text);
                        cm.Parameters.AddWithValue("@genre", cboGenre.Text);
                        cm.Parameters.AddWithValue("@mediatype", cboMediaType.Text);
                        cm.Parameters.AddWithValue("@language", txtLanguage.Text);
                        cm.Parameters.AddWithValue("@author", txtAuthor.Text);
                        cm.Parameters.AddWithValue("@publisher", txtPublisher.Text);
                        cm.Parameters.AddWithValue("@price", txtPrice.Text);
                        cm.Parameters.AddWithValue("@year", txtYear.Text);
                        //ask db to execute query
                        cm.ExecuteNonQuery();
                        //close connection
                        cn.Close();
                        Logs();

                        popupNotifier.ContentText = txtTitle.Text + " has been successfully added!";
                        popupNotifier.Popup();
                        Clear();
                        frmlist.LoadRecords();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
        private void BtnAddCopies_Click(object sender, EventArgs e)
        {
            try
            {
                if (MyMessageBox.ShowMessage("Are you sure you want to add new copies?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    cn.Open();
                    cm = new SqlCommand("UPDATE tblBook SET allCopies = allcopies + @addCopy, availableCopies = availableCopies + @addAvailCopy WHERE bookTitle = @bookTitle", cn);
                    cm.Parameters.AddWithValue("@addCopy", txtCopies.Text);
                    cm.Parameters.AddWithValue("@addAvailCopy", txtCopies.Text);
                    cm.Parameters.AddWithValue("@bookTitle", lblBookTitle.Text);
                    cm.ExecuteNonQuery();
                    cn.Close();
                    Logs();

                    frm.gunaDataGridView1.Rows.Clear();
                    frm.LoadRecords();
                    this.Close();

                    popupNotifier.ContentText = "Copies successfully added!";
                    popupNotifier.Popup();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }