public void CreateOrder(TubesOrder order) { var transaction = connection.BeginTransaction(); //Register a new session var cmd = new SQLiteCommand(@" INSERT INTO orders ( districtId, tubeDiameter, tubesNumber, orderStatus, dateCreated, isDelivered) VALUES(@districtId, @tubeDiameter, @tubesNumber, @orderStatus, @dateCreated, @isDelivered)", connection); cmd.Parameters.AddWithValue("@districtId", order.districtId); cmd.Parameters.AddWithValue("@tubeDiameter", order.tubesDiameter); cmd.Parameters.AddWithValue("@tubesNumber", order.tubesNumber); cmd.Parameters.AddWithValue("@orderStatus", (int)order.orderStatus); cmd.Parameters.AddWithValue("@dateCreated", order.dateCreated); cmd.Parameters.AddWithValue("@isDelivered", order.deliveryStatus); cmd.ExecuteNonQuery(); transaction.Commit(); }
/// <summary> /// Возвращает список неотправленных на сервер сессий чтения /// </summary> public List<TubesOrder> GetUnshippedOrders() { var orders = new List<TubesOrder>(); var sessionCmd = new SQLiteCommand(@"SELECT * from orders where isDelivered <> " + (int)TubesOrder.DeliveryStatus.Shipped, connection); using (var reader = sessionCmd.ExecuteReader()) { while (reader.Read()) { var order = new TubesOrder { orderId = reader.GetInt32(0), trackId = reader.IsDBNull(1) ? null : (int?)reader.GetInt32(1), districtId = reader.GetInt32(2), tubesDiameter = reader.GetInt32(3), tubesNumber = reader.GetInt32(4), orderStatus = (TubesOrder.OrderStatus)reader.GetInt32(5), dateCreated = reader.GetString(6), deliveryStatus = (TubesOrder.DeliveryStatus)reader.GetInt32(7) }; orders.Add(order); } } return orders; }