Exemplo n.º 1
0
        public OrderModel ToOrder(OrderDetails orderDetails) {
            OrderModel order = new OrderModel();

            order.CustomerID = this.CustomerID;
            order.OrderDate = this.OrderDate;

            order.OrderStatus = orderDetails.OrderStatus;
            order.OrderType = orderDetails.OrderType;
            order.OrderValue = orderDetails.OrderValue;
            return order;
        }
Exemplo n.º 2
0
 OrderModel SelectDuplicateOrder(string orderValue) {
     OrderModel order = null;
     using (SqlConnection connection = new SqlConnection(connectionString)) {
         string commandText = "SELECT TOP 1 * FROM Orders WHERE OrderValue=@orderValue";
         SqlCommand command = new SqlCommand(commandText);
         command.CommandType = CommandType.Text;
         command.Connection = connection;
         command.Parameters.AddWithValue("@orderValue", orderValue);
         connection.Open();
         using (SqlDataReader dataReader = command.ExecuteReader()) {
             while (dataReader.Read()) {
                 order = new OrderModel();
                 order.OrderID = Convert.ToInt64(dataReader["OrderID"]);
                 order.CustomerID = Convert.ToInt32(dataReader["CustomerID"]);
                 order.DateTimeAdded = Convert.ToDateTime(dataReader["DateTimeAdded"]);
                 order.DateTimeUpdated = Convert.ToDateTime(dataReader["DateTimeUpdated"]);
                 order.OrderDate = Convert.ToDateTime(dataReader["OrderDate"]);
                 order.OrderStatus = Convert.ToInt32(dataReader["OrderStatus"]);
                 order.OrderType = Convert.ToInt32(dataReader["OrderType"]);
                 order.OrderValue = dataReader["OrderValue"].ToString();
             }
         }
     }
     return order;
 }
Exemplo n.º 3
0
 void InsertOrderRecord(OrderModel order) {
     using (SqlConnection connection = new SqlConnection(connectionString)) {
         string commandText = "INSERT INTO Orders (CustomerID, OrderDate, OrderValue, OrderStatus, OrderType) VALUES (@CustomerID, @OrderDate, @OrderValue, @OrderStatus, @OrderType)";
         SqlCommand command = new SqlCommand(commandText);
         command.CommandType = CommandType.Text;
         command.Connection = connection;
         command.Parameters.AddWithValue("@CustomerID", order.CustomerID);
         command.Parameters.AddWithValue("@OrderDate", order.OrderDate);
         command.Parameters.AddWithValue("@OrderValue", order.OrderValue);
         command.Parameters.AddWithValue("@OrderStatus", order.OrderStatus);
         command.Parameters.AddWithValue("@OrderType", order.OrderType);
         connection.Open();
         command.ExecuteNonQuery();
     }
 }
 void LoadOrdersFromDB() {
     ordersFromDBRows.Clear();
     LinkedList<OrderModel> loadedList = new LinkedList<OrderModel>();
     if (CheckConnection()) {
         using (SqlConnection connection = new SqlConnection(connectionString)) {
             string commandText = "SELECT * FROM Orders";
             SqlCommand command = new SqlCommand(commandText);
             command.CommandType = CommandType.Text;
             command.Connection = connection;
             connection.Open();
             using (SqlDataReader dataReader = command.ExecuteReader()) {
                 while (dataReader.Read()) {
                     OrderModel order = new OrderModel();
                     order.OrderID = Convert.ToInt64(dataReader["OrderID"]);
                     order.CustomerID = Convert.ToInt32(dataReader["CustomerID"]);
                     order.DateTimeAdded = Convert.ToDateTime(dataReader["DateTimeAdded"]);
                     order.DateTimeUpdated = Convert.ToDateTime(dataReader["DateTimeUpdated"]);
                     order.OrderDate = Convert.ToDateTime(dataReader["OrderDate"]);
                     order.OrderStatus = Convert.ToInt32(dataReader["OrderStatus"]);
                     order.OrderType = Convert.ToInt32(dataReader["OrderType"]);
                     order.OrderValue = dataReader["OrderValue"].ToString();
                     loadedList.AddLast(order);
                 }
             }
         }
         ordersFromDBRows = loadedList;
         dgOrders.ItemsSource = loadedList;
     }
 }