private void btnSave_Click(object sender, EventArgs e)
        {
            btnNew.Enabled = true;
            label8.Visible = false;
            try
            {
                var count = lms.Book.Count(t => t.rfid == txtRfid.Text);
                if (count > 0)
                {
                    MessageBox.Show("This book has already registered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtRfid.Text = "";
                }
                else
                {
                    //int istock = Convert.ToInt32(txtStock.Text);
                    //Book book = new Book() { rfid = txtRfid.Text,name = txtName.Text, author = txtAuthor.Text, shelf = txtShelf.Text,stock = istock };
                    //lms.Book.Add(book);
                    //success();


                    bookBindingSource.EndEdit();
                    lms.SaveChangesAsync();
                    bookBindingSource.MoveLast();
                    MessageBox.Show("Transaction Complete ", "Register", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    panel.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bookBindingSource.ResetBindings(false);
            }
        }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            btnNew.Enabled     = true;
            lblWarning.Visible = false;


            try
            {
                studentBindingSource.EndEdit();
                lms.SaveChangesAsync();
                studentBindingSource.MoveLast();
                panel.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                studentBindingSource.ResetBindings(false);
            }
        }