public static int usp_user_restaurantBookedOrder(bookOrder _Bookorder)
        {
            int userid = 0;

            using (var connection = SQLConnection.GetOpenSQLConnection())
            {
                string sqlQuery = "usp_user_restaurantBookedOrder  @tablenumber,@bookitems,@quantity,@price";
                userid = connection.Query <int>(sqlQuery, new { tablenumber = _Bookorder.tablenumber, bookitems = _Bookorder.bookitems, quantity = _Bookorder.quantity, price = _Bookorder.price }).FirstOrDefault();
            }
            return(userid);
        }
        public HttpResponseMessage BookedOrder(bookOrder _ListAdd)
        {
            HttpResponseMessage response;

            try
            {
                if (string.IsNullOrWhiteSpace(_ListAdd.bookitems))
                {
                    response = Request.CreateResponse(HttpStatusCode.PreconditionFailed, "items can not be blank!");
                }
                else
                {
                    int new_user_id = RegistrationProcCall.usp_user_restaurantBookedOrder(_ListAdd);

                    response = Request.CreateResponse(HttpStatusCode.OK, new_user_id);
                }
            }
            catch (Exception)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError);
            }
            return(response);
        }
Пример #3
0
        private void buttonBookOrderAdd_Click(object sender, EventArgs e)
        {
            if (ValidateEmptyTextBox(3))
            {
                try
                {
                    projectEntities project = new projectEntities();
                    bookOrder       bOrder  = new bookOrder();
                    bOrder.CustomerOrderID = Convert.ToInt32(textBoxCustomerOrderID2.Text);
                    bOrder.BookID          = Convert.ToInt32(textBoxBookID.Text);
                    bOrder.OrderQuantity   = Convert.ToInt32(textBoxOrderQuantity.Text);

                    int checkBookID     = Convert.ToInt32(textBoxBookID.Text);
                    int customerOrderID = Convert.ToInt32(textBoxCustomerOrderID2.Text);
                    // Find Book
                    var checkBook = project.books.Find(checkBookID);

                    if (Convert.ToInt32(textBoxOrderQuantity.Text) <= checkBook.QOH)
                    {
                        project.bookOrders.Add(bOrder);

                        // Update the book qoh
                        int newBookQOH = checkBook.QOH - Convert.ToInt32(textBoxOrderQuantity.Text);
                        checkBook.QOH = newBookQOH;

                        // Check in invoice table id is exist or not
                        double unitPrice     = checkBook.UnitPrice;
                        int    orderQuantity = Convert.ToInt32(textBoxOrderQuantity.Text);
                        if (project.invoices.Any(x => x.InvoiceID == customerOrderID))
                        {
                            // update to invoice table
                            var updateInvoice = project.invoices.Find(customerOrderID);

                            double oldTotalPrice = updateInvoice.TotalPrice;
                            double newTotalPrice = oldTotalPrice + (unitPrice * orderQuantity);
                            MessageBox.Show(" newTotalPrice " + newTotalPrice + " customerOrderID " + customerOrderID);
                            updateInvoice.TotalPrice = newTotalPrice;
                        }
                        else
                        {
                            // insert to invoice table
                            invoice invoice = new invoice();
                            invoice.InvoiceID     = customerOrderID;
                            invoice.TotalPrice    = (unitPrice * orderQuantity);
                            invoice.TypeOfPayment = "None";
                            //DateTime date = new DateTime(1111, 11, 11);
                            //invoice.PaymentDate = date;
                            invoice.IsPaid = "n";
                            project.invoices.Add(invoice);
                        }


                        project.SaveChanges();
                        MessageBox.Show("Recored Inserted..");
                        this.DisplayBookOrder();
                        this.ClearTextBoxBO();
                    }
                    else
                    {
                        string msg = string.Format(" We only have {0} books for \n " +
                                                   " Book Id = {1} \n " +
                                                   " Book Name = {2} ",
                                                   checkBook.QOH, Convert.ToInt32(textBoxBookID.Text), checkBook.Title);
                        MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Recored Is Not Inserted..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //this.ClearTextBoxCO();
                }
            }
            else
            {
                MessageBox.Show("Please Enter Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }