protected override string GetSalesMonth(DateTime exportDate, string filename) { string result = "\n" + filename + ": "; ProgressText += result; string tempDisplay = ProgressText; ProgressText += "Exporting..."; if ((SalesHistory == null) || (SalesHistory.Count() == 0)) return result + "No orders in sales history"; var orders = new List<SalesRecord>(); DateTime first = new DateTime(exportDate.Year, exportDate.Month, 1); DateTime last = first.AddMonths(1); //new DateTime(exportDate.Year, exportDate.Month, DateTime.DaysInMonth(exportDate.Year, exportDate.Month)); foreach (var order in SalesHistory) { string sDate = Client.GetValue(order, "OrderDate"); var orderDate = DateTime.Parse(sDate); if (DateTime.Compare(orderDate, first) < 0 || DateTime.Compare(orderDate, last) >= 0) continue; var o = new SalesRecord { ProductId = Client.GetValue(order, "ProductCode"), CustomerId = Client.GetValue(order, "CustomerId"), Quantity = Client.GetValue(order, "Quantity"), Date = orderDate.ToShortDateString() }; orders.Add(o); } ProgressText = tempDisplay + string.Format("{0}Uploading to server...", Environment.NewLine); result += m_boostService.WriteTable(m_alias, filename, orders); if (orders.Count == 0) result += "(no data)"; //still need an empty placeholder file uploaded, but nice to know return result; //final result should be in the format of "Filename: success/failure status" }
private List<_4_Tell.SalesRecord> SetSalesData(Stream Content) { List<SalesRecord> sales = null; try { StreamReader rdr = new StreamReader(Content); string sContent = rdr.ReadToEnd(); // string[] rows = sContent.Trim().Split(']'); string thisRow = String.Empty; foreach (string row in rows) { if (row.Length > 0) { thisRow = row; thisRow = thisRow.Replace("[", String.Empty); thisRow = thisRow.Replace("]", String.Empty); SalesRecord pr = new SalesRecord(); if (!row.StartsWith("[[") == true && !row.EndsWith("]]") == true) { // normal row string[] cols = thisRow.Split(','); pr.CustomerId = cols[0].Replace("\\", String.Empty).Replace("/", String.Empty).Replace('"', ' ').Trim(); pr.Date= cols[1].Replace("\\", String.Empty).Replace("/", String.Empty).Replace('"', ' ').Trim(); pr.ProductId= cols[2].Replace("\\", String.Empty).Replace("/", String.Empty).Replace('"', ' ').Trim(); pr.Quantity= cols[3].Replace("\\", String.Empty).Replace("/", String.Empty).Replace('"', ' ').Trim(); sales.Add(pr); } } } } catch (Exception e) { Console.WriteLine(e.Message); Console.Read(); } return sales; }