Exemple #1
0
        private void ok_but_Click(object sender, EventArgs e)
        {
            Books cus = new Books
            {
                Title = title_tb.Text,
            };

            using (BestLibraryEntities db = new BestLibraryEntities())
            {
                if (this.Text == "Edit Books")
                {
                    var willEdit = db.Books
                                   .Where(c => c.Id == CurrIndex + 1)
                                   .FirstOrDefault();

                    willEdit.Title = cus.Title;


                    MessageBox.Show("Book has been edited!");
                }
                else
                {
                    db.Books.Add(cus);
                    MessageBox.Show("Book has been added!");
                }
                db.SaveChanges();
                this.Close();
            }
        }
Exemple #2
0
        private void ok_but_Click(object sender, EventArgs e)
        {
            Customers cus = new Customers
            {
                FirstName = firstName_tb.Text,
                LastName  = lastName_tb.Text,
                IsDebtor  = checkDebtor.Checked
            };

            using (BestLibraryEntities db = new BestLibraryEntities())
            {
                if (this.Text == "Edit Customer")
                {
                    var willEdit = db.Customers
                                   .Where(c => c.Id == CurrIndex + 1)
                                   .FirstOrDefault();

                    willEdit.FirstName = cus.FirstName;
                    willEdit.LastName  = cus.LastName;
                    willEdit.IsDebtor  = cus.IsDebtor;

                    MessageBox.Show("Customer has been edited!");
                }
                else
                {
                    db.Customers.Add(cus);
                    MessageBox.Show("Customer has been added!");
                }
                db.SaveChanges();
                this.Close();
            }
        }
Exemple #3
0
        private void delBut_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow.Index != -1)
            {
                DialogResult dr = MessageBox.Show("Are you sure you want to delete this Customer?", "Attention!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dr == DialogResult.Yes)
                {
                    using (BestLibraryEntities db = new BestLibraryEntities())
                    {
                        Customers toDelete = db.Customers.Where(c => c.Id == dataGridView1.CurrentRow.Index + 1).FirstOrDefault();
                        db.Customers.Remove(toDelete);
                        db.SaveChanges();
                        RefreshTables();
                    }
                }
            }
        }