Exemplo n.º 1
0
        public int GetOrderSummaryId(OrderSummary orSummary, SqlTransaction transaction)
        {
            using (SqlCommand cmd = new SqlCommand("SELECT OrderId FROM OrderSummary WHERE EmployeeId=@EmployeeId  AND DatePurches=@DatePurches AND TotalPrice=@TotalPrice AND CustomerId=@CustomerId  AND PaidMethod=@PaidMethod", conn, transaction))
            {
                cmd.Parameters.AddWithValue("@EmployeeId", orSummary.EmployeeId);
                cmd.Parameters.AddWithValue("@CustomerId", orSummary.CustomerId);
                cmd.Parameters.AddWithValue("@DatePurches", orSummary.DatePurches);
                cmd.Parameters.AddWithValue("@TotalPrice", orSummary.TotalPrice);


                cmd.Parameters.AddWithValue("@PaidMethod", orSummary.PaidMethod);


                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int id = reader.GetInt32(reader.GetOrdinal("OrderId"));
                            return(id);
                        }
                    }
                }
            }
            return(0);
        }
Exemplo n.º 2
0
        //*******************Transaction
        public bool Transaction_OrderSubmit(OrderSummary orderSum, int CashierId, int customerId)
        {
            SqlTransaction transaction = conn.BeginTransaction();

            try
            {
                AddOrderSummary(orderSum, transaction);                 //insert to OrderSummary Table

                int orderId = GetOrderSummaryId(orderSum, transaction); //get this new id after insert
                AddAllOrderItem(orderSum.Items, orderId, transaction);  //add list of orderitems
                foreach (OrderItem item in orderSum.Items)
                {
                    //for each product it must reduce QTY in stack
                    ReduceProductNumberInStack(item.ProductId, item.NumberOfUnit, transaction);
                }

                transaction.Commit();
                return(true);
            }
            catch (Exception ex) {
                string r = ex.Message;
                transaction.Rollback();
                return(false);
            }
        }
Exemplo n.º 3
0
        // <-- ******************* CRUD methods for ProductCategory ************************
        // <-- ******************* CRUD methods for OrderSummary   ************************

        public void AddOrderSummary(OrderSummary orSummary, SqlTransaction transaction)
        {
            using (SqlCommand cmd = new SqlCommand("INSERT INTO OrderSummary (EmployeeId,CustomerId,DatePurches,TotalPrice,Discount,Tax,TotalAndTax,PaidMethod,CheckNumber,CreditCardNumber,CardExprDate) VALUES (@EmployeeId,@CustomerId,@DatePurches,@TotalPrice,@Discount,@Tax,@TotalAndTax,@PaidMethod,@CheckNumber,@CreditCardNumber,@CardExprDate)", conn, transaction))
            {
                cmd.Parameters.AddWithValue("@EmployeeId", orSummary.EmployeeId);
                cmd.Parameters.AddWithValue("@CustomerId", orSummary.CustomerId);
                cmd.Parameters.AddWithValue("@DatePurches", orSummary.DatePurches);
                // cmd.Parameters.AddWithValue("@TotalPrice", orSummary.TotalPrice);
                cmd.Parameters.Add("@TotalPrice", SqlDbType.Money);
                cmd.Parameters["@TotalPrice"].Value = orSummary.TotalPrice;
                //  cmd.Parameters.AddWithValue("@Discount", orSummary.Discount);
                cmd.Parameters.Add("@Discount", SqlDbType.Money);
                cmd.Parameters["@Discount"].Value = orSummary.Discount;
                // cmd.Parameters.AddWithValue("@Tax", orSummary.Tax);
                cmd.Parameters.Add("@Tax", SqlDbType.Money);
                cmd.Parameters["@Tax"].Value = orSummary.Tax;
                //cmd.Parameters.AddWithValue("@TotalAndTax", orSummary.TotalAndTax);
                cmd.Parameters.Add("@TotalAndTax", SqlDbType.Money);
                cmd.Parameters["@TotalAndTax"].Value = orSummary.TotalAndTax;
                cmd.Parameters.AddWithValue("@PaidMethod", orSummary.PaidMethod);
                cmd.Parameters.AddWithValue("@CheckNumber", orSummary.CheckNumber);
                //  cmd.Parameters.AddWithValue("@CardExprDate", orSummary.CardExprDate);
                cmd.Parameters.AddWithValue("@CreditCardNumber", orSummary.CreditCardNumber);
                cmd.Parameters.AddWithValue("@CardExprDate", orSummary.CardExprDate);


                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 4
0
        private void btnSubmitOrder_Click(object sender, RoutedEventArgs e)
        {
            if (cmbPaymenthMethod.SelectedIndex == 0)
            {
                MessageBox.Show("please choose payment method");
                return;
            }
            if (cmbPaymenthMethod.SelectedItem.ToString() == PaymentMethod.CreditCard.ToString())
            {
                if (!HasCreditCardNumber(txtCardNumber.Text))
                {
                    MessageBox.Show("Card Number is invalid");
                    return;
                }
                if (txtSecurityCode.Text.Length < 3)
                {
                    MessageBox.Show("Security Number is invalid");
                    return;
                }
            }
            if (cmbPaymenthMethod.SelectedItem.ToString() == PaymentMethod.Cheque.ToString())
            {
                if (txtSecurityCode.Text.Length < 3)
                {
                    MessageBox.Show("Check Number is invalid");
                    return;
                }
            }


            OrderSummary orderSum = new OrderSummary();

            orderSum.Items            = orderItems;
            orderSum.EmployeeId       = cashierID;
            orderSum.CustomerId       = 1;
            orderSum.PaidMethod       = cmbPaymenthMethod.Text;
            orderSum.Tax              = Convert.ToDecimal(lblTotalTax.Content);
            orderSum.TotalAndTax      = Convert.ToDecimal(lblTotalAndTax.Content);
            orderSum.TotalPrice       = Convert.ToDecimal(lblTotal_Price.Content);
            orderSum.DatePurches      = DateTime.Now;
            orderSum.Discount         = Convert.ToDecimal(lblTotalDiscount.Content);
            orderSum.CheckNumber      = "";
            orderSum.CreditCardNumber = "";
            orderSum.CardExprDate     = "";
            if (db.Transaction_OrderSubmit(orderSum, cashierID, customerId))
            {
                Receipt receipt = new Receipt(orderItems, Convert.ToDecimal(lblTotal_Price.Content), Convert.ToDecimal(lblTotalAndTax.Content), Convert.ToDecimal(lblTotalDiscount.Content), Convert.ToDecimal(lblTotalTax.Content));
                this.Close();
                // Cashier.ResetDatagrids();
            }
            else
            {
                MessageBox.Show("This operation did n't be completed!!!,Try Again");
                this.Close();
            }
        }