public static bool AddOrder(OrderClass order, List <Order_Products> products)
        {
            SqlConnection connection      = CompanyDB_Class.GetConnection();
            string        insertStatement =
                "INSERT INTO orders " +
                "( date, subtotal, tax, total, status_order_id, client_id) " +
                "VALUES ( @date, @subtotal, @tax, @total, @status_order_id, @client_id)";
            SqlCommand insertCommand = new SqlCommand(insertStatement, connection);

            insertCommand.Parameters.AddWithValue("@date", order.dateOrder);
            insertCommand.Parameters.AddWithValue("@subtotal", order.subtotalOrders);
            insertCommand.Parameters.AddWithValue("@tax", order.taxOrder);
            insertCommand.Parameters.AddWithValue("@total", order.totalOrder);
            insertCommand.Parameters.AddWithValue("@status_order_id", order.statusOrderId);
            insertCommand.Parameters.AddWithValue("@client_id", order.client_id);

            try
            {
                connection.Open();
                int count = insertCommand.ExecuteNonQuery();
                if (count > 0)
                {
                    connection.Close();

                    int order_id = Order_Products();     //  method 1

                    Insers_Products(products, order_id); // method 2

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Пример #2
0
        private void btnPrintOrder_Click(object sender, EventArgs e)
        {
            OrderClass reportOrder = new OrderClass();

            if (lstOrder.SelectedItems.Count > 0)
            {
                ListViewItem item = lstOrder.SelectedItems[0];
                reportOrder.idOrders       = Convert.ToInt32(item.SubItems[0].Text);
                reportOrder.dateOrder      = Convert.ToDateTime(item.SubItems[1].Text);
                reportOrder.subtotalOrders = Convert.ToDecimal(item.SubItems[2].Text);
                reportOrder.taxOrder       = Convert.ToDecimal(item.SubItems[3].Text);
                reportOrder.totalOrder     = Convert.ToDecimal(item.SubItems[4].Text);
                reportOrder.statusOrderId  = Convert.ToInt32(item.SubItems[5].Text);
                PrintOrder printOrder = new PrintOrder(reportOrder, reportOrder.idOrders);
                printOrder.Show();
            }
            else
            {
                MessageBox.Show("Please select an order ");
            }
        }
Пример #3
0
        private void btnAddOrder_Click(object sender, EventArgs e)
        {
            AddOrder addOrderClick = new AddOrder();
            var      result        = addOrderClick.ShowDialog();

            if (result == DialogResult.OK)
            {
                OrderClass            orderClass = addOrderClick.getOrder;
                List <Order_Products> products   = addOrderClick.getProducts;
                bool returnedResult = OrderDB_Class.AddOrder(orderClass, products);
                if (returnedResult)
                {
                    FillListViewOrders();
                    MessageBox.Show("Order added");
                }
                else
                {
                    MessageBox.Show("Error");
                }
            }
        }
        public static List <OrderClass> GetOrders()
        {
            SqlConnection connection = CompanyDB_Class.GetConnection();
            string        selectStatement
                = "SELECT id, date, subtotal, tax, total, status_order_id, client_id "
                  + "FROM orders";
            SqlCommand selectcommand =
                new SqlCommand(selectStatement, connection);

            try
            {
                connection.Open();
                SqlDataReader custReader =
                    selectcommand.ExecuteReader();

                List <OrderClass> orders = new List <OrderClass>();
                while (custReader.Read())
                {
                    OrderClass order = new OrderClass();
                    order.idOrders       = (int)custReader["id"];
                    order.dateOrder      = Convert.ToDateTime(custReader["date"]);
                    order.subtotalOrders = Convert.ToDecimal(custReader["subtotal"]);
                    order.taxOrder       = Convert.ToDecimal(custReader["tax"]);
                    order.totalOrder     = Convert.ToDecimal(custReader["total"]);
                    order.statusOrderId  = Convert.ToInt32(custReader["status_order_id"]);
                    order.client_id      = Convert.ToInt32(custReader["client_id"]);
                    orders.Add(order);
                }
                custReader.Close();
                return(orders);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
        public static bool ChangeStatusOrder(OrderClass order)
        {
            SqlConnection connection      = CompanyDB_Class.GetConnection();
            string        updateStatement =
                "UPDATE  orders SET " +
                "status_order_id = @status_order_id " +
                " WHERE id = @id ";
            SqlCommand updateCommand =
                new SqlCommand(updateStatement, connection);

            updateCommand.Parameters.AddWithValue(
                "@id", order.idOrders);
            updateCommand.Parameters.AddWithValue(
                "@status_order_id", order.statusOrderId);
            try
            {
                connection.Open();
                int count = updateCommand.ExecuteNonQuery();
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Пример #6
0
 public PrintOrder(OrderClass order, int order_id)
 {
     orderID = order_id;
     orders  = order;
     InitializeComponent();
 }