public Tuple <int> SendOrders(repositories.Order orders) { int counter = 0; SQLiteCommand command = new SQLiteCommand("SELECT * FROM order_list WHERE cancel_at IS NULL AND (dvizh_id = 0 OR dvizh_id IS NULL) ORDER BY id DESC", db.connection); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { entities.Order order = DataMapper.BuildOrder(reader); int dvizhid = SendOrder(order); if (dvizhid > 0) { orders.SaveDvizhIdWithSql(order, dvizhid); counter++; } } } reader.Close(); return(new Tuple <int>(counter)); }
public void SaveDvizhIdWithSql(entities.Order order, int dvizhId) { SQLiteCommand orderCommand = new SQLiteCommand("UPDATE order_list SET dvizh_id = @dvizh_id WHERE id = @id", db.connection); orderCommand.Parameters.AddWithValue("@dvizh_id", dvizhId); orderCommand.Parameters.AddWithValue("@id", order.GetId()); orderCommand.ExecuteNonQuery(); }
public bool FillOrders(repositories.Order orderRepository) { DateTime dt1 = DateTime.Now; SQLiteCommand command = new SQLiteCommand("SELECT * FROM order_list WHERE cancel_at IS NULL ORDER BY id DESC LIMIT 1000", db.connection); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { entities.Order order = BuildOrder(reader); orderRepository.Add(order); } } reader.Close(); foreach (entities.Order order in orderRepository.GetList()) { SQLiteCommand elementCommand = new SQLiteCommand("SELECT * FROM order_element_list WHERE order_id = " + order.GetId().ToString(), db.connection); SQLiteDataReader elementReader = elementCommand.ExecuteReader(); if (elementReader.HasRows) { while (elementReader.Read()) { string cancelAt; if (!elementReader.IsDBNull(6)) { cancelAt = elementReader.GetString(6); } else { cancelAt = ""; } entities.OrderElement element = new entities.OrderElement(elementReader.GetInt32(0), elementReader.GetInt32(1), elementReader.GetString(3), Convert.ToDouble(elementReader.GetDecimal(5)), elementReader.GetInt32(4), cancelAt); order.AddElement(element); } } elementReader.Close(); } return(true); }
//return dvizh_id public int SendOrder(entities.Order order) { string ids = ""; foreach (entities.OrderElement element in order.GetElements()) { ids += element.GetProductId().ToString() + "|" + element.GetCount() + "|" + element.GetPrice() + ";"; } string url = Properties.Settings.Default.protocol + "://" + Properties.Settings.Default.client + "." + Properties.Settings.Default.host + "/" + Properties.Settings.Default.csvRestPath + "/order" + Properties.Settings.Default.tokenPrefix + "token=" + Properties.Settings.Default.token + "&ids=" + ids + "&cost=" + order.GetTotal().ToString() + "&date=" + order.GetDate() + "&promocodeId=" + order.GetDiscountId().ToString() + "&cashierId=" + order.GetCashierId().ToString() + "&clientId=" + order.GetClientId().ToString(); //Clipboard.SetData(DataFormats.Text, (Object)url); try { string result = new WebClient().DownloadString(url); return(Convert.ToInt32(result)); } catch (System.Net.WebException e) { Console.WriteLine(e.Message); return(0); } }
public static List <Order> GenerateOrderList(List <Customer> customerList, List <OrderProductList> orderProductList) { List <Order> list = new List <Order>(); for (int i = 0; i < orderProductList.Count; i++) { DateTime randomDate = GetRandomDate(MIN_ORDER_DATE, MAX_ORDER_DATE); Customer customer = customerList[Rand.Next(customerList.Count)]; Order o = new entities.Order(customer, orderProductList[i], randomDate); list.Add(o); } var comparer = Comparer <Order> .Create((o1, o2) => o1.Date.CompareTo(o2.Date)); list.Sort(comparer); return(list); }
public void AddWithSql(entities.Order order) { Add(order); SQLiteCommand orderCommand; orderCommand = new SQLiteCommand("INSERT INTO order_list(dvizh_id, date, total, cashier_id, client_id, discount_id) VALUES(@dvizh_id, @date, @total, @cashier_id, @client_id, @discount_id)", db.connection); orderCommand.Parameters.AddWithValue("@dvizh_id", order.DvizhId); orderCommand.Parameters.AddWithValue("@date", order.Date); orderCommand.Parameters.AddWithValue("@cashier_id", order.cashierId); orderCommand.Parameters.AddWithValue("@client_id", order.clientId); orderCommand.Parameters.AddWithValue("@discount_id", order.discountId); orderCommand.Parameters.AddWithValue("@total", order.Total.ToString()); orderCommand.ExecuteNonQuery(); orderCommand.CommandText = "SELECT last_insert_rowid()"; Int64 LastRowID64 = (Int64)orderCommand.ExecuteScalar(); order.Id = (int)LastRowID64; foreach (entities.OrderElement element in order.GetElements()) { SQLiteCommand elementCommand = new SQLiteCommand("INSERT INTO order_element_list(order_id, product_id, product_name, count, price) values(@order_id, @product_id, @product_name, @count, @price)", db.connection); elementCommand.Parameters.AddWithValue("@order_id", order.GetId()); elementCommand.Parameters.AddWithValue("@product_id", element.GetProductId()); elementCommand.Parameters.AddWithValue("@product_name", element.GetProductName()); elementCommand.Parameters.AddWithValue("@count", element.GetCount()); elementCommand.Parameters.AddWithValue("@price", element.GetPrice().ToString()); elementCommand.ExecuteNonQuery(); } }
public void Delete(entities.Order order) { orders.Remove(order); }
public void Add(entities.Order order) { orders.Add(order); }