コード例 #1
0
        private void buttonSearchOL_Click(object sender, EventArgs e)
        {
            //OrderLineBook ol = dbEntities.OrderLineBooks.Find(Convert.ToInt32(maskedTextBoxSearchOLID.Text));
            //if (ol != null)
            //{
            //    textBoxOLID.Text =  ol.OlBooksId.ToString();
            //    comboBoxOrderID.Text = ol.OrderId.ToString();
            //    comboBoxBookID.Text = ol.BookId.ToString();
            //    textBoxOrderLineQuantity.Text = ol.OlQuantity.ToString();
            //}


            //Solution using LINQ
            int idSearch = Convert.ToInt32(maskedTextBoxSearchOLID.Text);

            OrderLineBook search = (from num in dbEntities.OrderLineBooks
                                    where num.OlBooksId == idSearch
                                    select num).Single <OrderLineBook>();

            if (search != null)
            {
                textBoxOLID.Text              = search.OlBooksId.ToString();
                comboBoxOrderID.Text          = search.OrderId.ToString();
                comboBoxBookID.Text           = search.BookId.ToString();
                textBoxOrderLineQuantity.Text = search.OlQuantity.ToString();
            }
            else
            {
                MessageBox.Show("Order line ID not found");
            }
        }
コード例 #2
0
        private void buttonDeleteOL_Click(object sender, EventArgs e)
        {
            OrderLineBook ol = dbEntities.OrderLineBooks.Find(Convert.ToInt32(textBoxOLID.Text));

            dbEntities.OrderLineBooks.Remove(ol);
            dbEntities.SaveChanges();
            MessageBox.Show("The order line was deleted.");
        }
コード例 #3
0
        private void buttonUpdateOL_Click(object sender, EventArgs e)
        {
            OrderLineBook ol = dbEntities.OrderLineBooks.Find(Convert.ToInt32(textBoxOLID.Text));

            ol.OrderId    = Convert.ToInt32(comboBoxOrderID.Text);
            ol.BookId     = Convert.ToInt32(comboBoxBookID.Text);
            ol.OlQuantity = Convert.ToInt32(textBoxOrderLineQuantity.Text);
            dbEntities.SaveChanges();

            MessageBox.Show("The order line was modified");
        }
コード例 #4
0
        private void buttonSaveOL_Click(object sender, EventArgs e)
        {
            OrderLineBook bookOrder = new OrderLineBook();

            bookOrder.OrderId    = Convert.ToInt32(comboBoxOrderID.Text);
            bookOrder.BookId     = Convert.ToInt32(comboBoxBookID.Text);
            bookOrder.OlQuantity = Convert.ToInt32(textBoxOrderLineQuantity.Text);
            dbEntities.OrderLineBooks.Add(bookOrder);
            dbEntities.SaveChanges();

            MessageBox.Show("The order line was saved");
        }