private void SynchWithWebsite() { //Get latest web order in database: lock (fileStore) { int lastWebOrder = 0; int holeIndex = 0; bool go = true; List <string> keys = fileStore.Keys; //Will not work. while (go) { if (knownHoleStarts.Contains(lastWebOrder)) { lastWebOrder = knownHoleEnds[holeIndex]; holeIndex++; } Order2 order = fileStore[OrderConverters.GetWebOrderNumber(lastWebOrder + 1)]; if (order == null) { break; } if (order.WebOrder) //Should always be true... TODO: Better error handling... { lastWebOrder = Math.Max(order.WebId ?? 0, lastWebOrder); } } WebOrder webOrder = WebApiConnector.GetWebOrderByNumber(lastWebOrder + 1); Order2 newOrder; while (webOrder != null) { if (webOrder == null) { break; } newOrder = OrderConverters.ConvertWebOrderToDbOrder(webOrder); fileStore[newOrder.OrderNumber] = newOrder; webOrder = WebApiConnector.GetWebOrderByNumber(webOrder.Id + 1); } } isSynchedWithWeb = true; }
private async Task OnSaveAsync(object sender, EventArgs e) { var path = _fileDialogs.SaveFileDialog("Lista_zamowien_w_przedziale_cenowym"); if (path == "" || path == string.Empty) // Canceled dialog { return; } try { var flatOrders = OrderConverters.FlattenOrder(_orders).ToList(); Application.UseWaitCursor = true; await OrdersWriter.SaveToCsvAsync(flatOrders, path); Application.UseWaitCursor = false; } catch (Exception) { Application.UseWaitCursor = false; MessageBox.Show("Błąd w trakcie zapisu. Spróbuj ponownie."); } }
public Order2 GetNextPaidOrder() { if (!isSynchedWithWeb) { SynchWithWebsite(); } lock (fileStore) { Order2 order = null; //= fileStore[OrderConverters.GetWebOrderNumber(4)]; int lastWebOrder = 0; int holeIndex = 0; while (true) { if (knownHoleStarts.Contains(lastWebOrder)) { lastWebOrder = knownHoleEnds[holeIndex]; holeIndex++; } order = fileStore[OrderConverters.GetWebOrderNumber(lastWebOrder + 1)]; lastWebOrder++; if (order == null) { break; } if (order.OrderPaid != null && order.OrderSent == false) { return(order); } } } return(null); }