public CSVFile(FileItem file) { File = file; }
public Invoice(Invoice copy) : this() { this.id = copy.id; this.BillingCity = copy.BillingCity; this.BillingCompany = copy.BillingCompany; this.BillingCountry = copy.BillingCountry; this.BillingCountryName = copy.BillingCountryName; this.BillingName = copy.BillingName; this.BillingPhoneNumber = copy.BillingPhoneNumber; this.BillingState = copy.BillingState; this.BillingStateName = copy.BillingStateName; this.BillingStreet = copy.BillingStreet; this.BillingZip = copy.BillingZip; this.icoNumber = copy.icoNumber; this.dicNumber = copy.dicNumber; // this.company = copy.company; this.Cancelled = copy.Cancelled; this.Country = copy.Country; this.CustomerEmail = copy.CustomerEmail; this.CustomerName = copy.CustomerName; this.Equipped = copy.Equipped; //this.Icon = copy.Icon; //this.InvoiceItems = copy.InvoiceItems; foreach (var item in copy.InvoiceItems) this.InvoiceItems.Add(new InvoiceItem(item, this)); // nakopirovanie poloziek bez parovania this.InvoiceStatus = copy.InvoiceStatus; this.OrderDate = copy.OrderDate; this.OrderDiscount = copy.OrderDiscount; this.OrderDue = copy.OrderDue; this.OrderGrandTotal = copy.OrderGrandTotal; this.OrderNumber = copy.OrderNumber; this.OrderPaid = copy.OrderPaid; this.OrderPaymentMethod = copy.OrderPaymentMethod; this.OrderPurchasedFrom = copy.OrderPurchasedFrom; this.OrderRefunded = copy.OrderRefunded; this.OrderShipping = copy.OrderShipping; this.OrderShippingMethod = copy.OrderShippingMethod; this.OrderStatus = copy.OrderStatus; this.OrderSubtotal = copy.OrderSubtotal; this.OrderTax = copy.OrderTax; this.ShippingCity = copy.ShippingCity; this.ShippingCompany = copy.ShippingCompany; this.ShippingCountry = copy.ShippingCountry; this.ShippingCountryName = copy.ShippingCountryName; this.ShippingName = copy.ShippingName; this.ShippingPhoneNumber = copy.ShippingPhoneNumber; this.ShippingState = copy.ShippingState; this.ShippingStateName = copy.ShippingStateName; this.ShippingStreet = copy.ShippingStreet; this.ShippingZip = copy.ShippingZip; this.TotQtyOrdered = copy.TotQtyOrdered; this.fromFile = copy.fromFile; // this.TestValues = copy.TestValues; }
internal StockEntity decodeMessage(string messageBody, FileItem file) { var lines = messageBody.Split(Environment.NewLine.ToCharArray()).Where(s => s != null && s.Trim().Length > 0).ToArray(); var positionQTY = 5; if (lines.Contains("\tConfirmation Note\t ")) positionQTY = 4; var order = new StockEntity(); List<StockItem> items = new List<StockItem>(); file.ProdCount = 0; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (line.Contains(productCode)) { StockItem item = new StockItem(); item.ProductCode = line.Substring(line.IndexOf(':') + 1).Trim(); line = lines[i - positionQTY];//i - 5 item.Ord_Qty = int.Parse(line.Trim()); line = lines[i - 4]; item.Disp_Qty = int.Parse(line.Trim()); line = lines[i - 3]; item.Description = line.Trim(); line = lines[i - 2]; item.Price = Common.GetPrice(line); line = lines[i - 1]; item.Total = Common.GetPrice(line); item.Currency = line.Substring(0, 1); item.FromFile = file; file.ProdCount++; if (item.State == StockItemState.PermanentStorage) item.Sklad = "02"; else if (item.State == StockItemState.Waiting) item.Sklad = Properties.Settings.Default.Storage; items.Add(item); } if (line.Trim() == delivery || line.Trim() == deliveryText) { StockItem item = new StockItem(); line = lines[i + 1]; line = line.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); item.Price = Common.GetPrice(line); item.Total = item.Price; item.Currency = line.Substring(0, 1); item.Description = deliveryText; item.Disp_Qty = 1; item.Ord_Qty = 1; item.ProductCode = item.Description; item.FromFile = file; file.Delivery += item.Price; //file.ProdCount++; //items.Add(item); // doprava nebude polozka ale spojena so suborom } if (line.Contains(orderRef)) { line = lines[i + 1]; order.OrderReference = line.Trim(); } if (line.Contains(ourRef)) { line = lines[i + 1]; order.OurReference = line.Trim(); } } DecomposeMultipleItems(items); order.Items = items.ToArray(); return order; }
internal StockEntity decodeMessage2(string messageBody, FileItem file) { var lines = messageBody.Split(Environment.NewLine.ToCharArray()).Where(s => s != null && s.Trim().Length > 0).ToList(); var order = new StockEntity(); List<StockItem> items = new List<StockItem>(); file.ProdCount = 0; var found = lines.FirstOrDefault(l => l.Contains(orderRef.ToLower())); if (found != null) order.OrderReference = order.OurReference = found.Substring(found.Trim().LastIndexOf(' ')).Trim(); var start = lines.FirstOrDefault(l => l.Contains("Processed Qty")); if (start == null) return null; var istart = lines.FindIndex(s => s == start); for (int i = istart + 1; i < lines.Count; i += 5) { if (lines[i].Trim().StartsWith("Total") || lines[i].Trim().StartsWith("Grand Total")) break; StockItem item = new StockItem(); item.Ord_Qty = int.Parse(lines[i].Trim()); item.Disp_Qty = item.Ord_Qty; item.Description = lines[i + 1].Trim();// +" " + lines[i + 2].Trim(); item.Price = Common.GetPrice(lines[i + 3].Trim()); item.Total = Common.GetPrice(lines[i + 4].Trim()); item.Currency = "€"; item.FromFile = file; item.ProductCode = lines[i + 2].Substring(lines[i + 2].Trim().LastIndexOf(' ')); file.ProdCount++; if (item.State == StockItemState.PermanentStorage) item.Sklad = "02"; else if (item.State == StockItemState.Waiting) item.Sklad = Properties.Settings.Default.Storage; items.Add(item); } DecomposeMultipleItems(items); order.Items = items.ToArray(); return order; }
void OrderdateChanged(FileItem file) { var ds = GetProductsDS(); if (ds == null) return; var list = ds.Where(oi => oi.FromFile == file).ToList(); foreach (var item in list) { item.OrderDate = file.OrderDate; } RefreshTab(); }
void RateChanged(FileItem file) { double kurz = file.ExchRate; if (!double.IsNaN(kurz)) { var ds = GetProductsDS(); if (ds == null) return; var list = ds.Where(oi => oi.FromFile == file).ToList(); foreach (var item in list) { item.PriceEURnoTax = Math.Round(item.Price * kurz, 2); item.TotalEUR = Math.Round(item.Total * kurz, 2); item.PriceWithDeliveryEUR = Math.Round(item.PriceWithDelivery * kurz, 2); } RefreshTab(); } else { log("Exchange rate is not a number!"); MessageBox.Show(this, "Exchange rate is not a number!", "Error"); } }
private StockEntity decodeMandMMessage(string messageBody, FileItem file) { try { var order = new StockEntity(); List<StockItem> items = new List<StockItem>(); var lines = messageBody.Split(Environment.NewLine.ToCharArray()).Where(s => s != null && s.Trim().Length > 0).ToList(); // cislo objednavky var orderNum = lines.Where(s => s.Contains("order confirmation number")).FirstOrDefault(); if (!string.IsNullOrEmpty(orderNum)) { var from = orderNum.IndexOf(':') + 1; order.OrderReference = orderNum.Substring(from).Trim(); order.OurReference = order.OrderReference; } var start = lines.IndexOf("Items for delivery: "); var stop = false; var i = start + 1; file.ProdCount = 0; file.Currency = "GBP"; var delivery = (lines.FirstOrDefault(l => l.Trim().StartsWith("Standard Delivery")) ?? "£0.00").Trim(); file.Delivery = Common.GetPrice(delivery.Substring(delivery.LastIndexOf('£') + 1)); if (double.IsNaN(file.Delivery)) file.Delivery = 0; while (!stop || i >= lines.Count) { var hypl_qty = lines[i++]; if (hypl_qty.ToLower().Trim().StartsWith("total items")) break; var props = lines[i++]; StockItem item = new StockItem(); var si = hypl_qty.LastIndexOf('"') + 1; var ei = hypl_qty.LastIndexOf("Qty."); item.Description = hypl_qty.Substring(si, ei - si).Trim(); var di = hypl_qty.IndexOf("details/") + 8; var edi = hypl_qty.IndexOf('/', di); item.ProductCode = hypl_qty.Substring(di, edi - di); item.Ord_Qty = Convert.ToInt32(hypl_qty.Substring(ei + 5).Trim()); item.Disp_Qty = item.Ord_Qty; var prop = props.Split('\t'); item.Size = prop[0].Substring(6); item.Total = Convert.ToDouble(Common.CleanPrice(prop[2].Trim('£'))); item.Price = item.Total / item.Ord_Qty; item.Currency = "GBP"; item.FromFile = file; while (lines[i].Trim().StartsWith("_") && lines[i].Trim().EndsWith("_")) i++; //= 2; // 2 riadky ______ file.ProdCount++; if (item.State == StockItemState.PermanentStorage) item.Sklad = "02"; else if (item.State == StockItemState.Waiting) item.Sklad = Properties.Settings.Default.Storage; items.Add(item); } DecomposeMultipleItems(items); order.Items = items.ToArray(); return order; } catch (System.Exception ex) { MessageBox.Show(this, ex.ToString(), "Error"); } return null; }
/// <summary> /// Deprecated.. /// </summary> /// <param name="messageBody"></param> /// <param name="file"></param> /// <returns></returns> private StockEntity decodeMandMMessageOld(string messageBody, FileItem file) { try { var order = new StockEntity(); List<StockItem> items = new List<StockItem>(); var lines = messageBody.Split(Environment.NewLine.ToCharArray()).Where(s => s != null && s.Trim().Length > 0).ToArray(); // cislo objednavky var orderNum = lines.Where(s => s.Contains("order confirmation number")).FirstOrDefault(); if (!string.IsNullOrEmpty(orderNum)) { var from = orderNum.IndexOf(':') + 1; order.OrderReference = orderNum.Substring(from).Trim(); order.OurReference = order.OrderReference; } var relevant = lines.Where(s => s.ToCharArray().Count(c => c == '\t') == 5).ToList(); file.ProdCount = 0; for (int i = 0; i < relevant.Count; i++) { string line = relevant[i]; if (line.ToLower().StartsWith("item")) continue; var cols = line.Split('\t'); StockItem item = new StockItem(); item.Description = cols[0]; item.ProductCode = item.Description.Split(' ')[0].Trim(); item.Size = cols[1].Trim(); item.Ord_Qty = int.Parse(cols[2].Trim()); item.Disp_Qty = item.Ord_Qty; item.Price = Common.GetPrice(cols[3]); item.Total = Common.GetPrice(cols[4]); item.Currency = cols[3].Substring(0, 1); item.FromFile = file; file.ProdCount++; if (item.State == StockItemState.PermanentStorage) item.Sklad = "02"; else if (item.State == StockItemState.Waiting) item.Sklad = Properties.Settings.Default.Storage; items.Add(item); } DecomposeMultipleItems(items); order.Items = items.ToArray(); return order; } catch (System.Exception ex) { MessageBox.Show(this, ex.ToString(), "Error"); } return null; }
private StockEntity decodeGTLMessage(string messageBody, FileItem file) { try { var order = new StockEntity(); List<StockItem> items = new List<StockItem>(); var lines = messageBody.Split(Environment.NewLine.ToCharArray()).Where(s => s != null && s.Trim().Length > 0).ToArray(); // cislo objednavky var orderNum = lines.Where(s => s.ToUpper().Contains("ORDER NUMBER:")).FirstOrDefault(); if (!string.IsNullOrEmpty(orderNum)) { var from = orderNum.IndexOf(':') + 1; order.OrderReference = orderNum.Substring(from).Trim(); order.OurReference = order.OrderReference; } var relevant = lines.Where(s => s.ToCharArray().Count(c => c == '\t') == 5).ToList(); file.ProdCount = 0; for (int i = 0; i < relevant.Count; i++) { string line = relevant[i]; if (line.ToLower().StartsWith("item")) continue; var cols = line.Split('\t'); StockItem item = new StockItem(); item.Description = cols[0]; item.Description = item.Description.Remove(0, item.Description.IndexOf(" ") + 1); item.ProductCode = item.Description; //item.ProductCode = item.ProductCode.Remove(0,item.ProductCode.IndexOf(" ")+1);//odstranime prve slovo Mens,Womens.. aby sa dalo porovnať s náazvom v csv item.Ord_Qty = int.Parse(cols[1].Trim()); item.Disp_Qty = item.Ord_Qty; item.Price = Common.GetPrice(cols[4]); item.Total = Common.GetPrice(cols[4]) / item.Ord_Qty; // suma deleno pocet = jednotkova cena item.Currency = "EUR"; item.FromFile = file; item.Size = cols[2].Trim(); file.ProdCount++; if (item.State == StockItemState.PermanentStorage) item.Sklad = "02"; else if (item.State == StockItemState.Waiting) item.Sklad = Properties.Settings.Default.Storage; items.Add(item); } DecomposeMultipleItems(items); order.Items = items.ToArray(); return order; } catch (System.Exception ex) { MessageBox.Show(this, ex.ToString(), "Error"); } return null; }
private StockEntity decode5PoundsMessage(string messageBody, FileItem file) { try { var order = new StockEntity(); List<StockItem> items = new List<StockItem>(); var lines = messageBody.Split(Environment.NewLine.ToCharArray()).Where(s => s != null && s.Trim().Length > 0).ToArray(); // cislo objednavky var orderNum = lines.Where(s => s.ToUpper().Contains("ORDER NUMBER:")).FirstOrDefault(); if (!string.IsNullOrEmpty(orderNum)) { var from = orderNum.IndexOf(':') + 1; order.OrderReference = orderNum.Substring(from).Trim(); order.OurReference = order.OrderReference; } // order date var orderDate = lines.Where(s => s.ToUpper().Contains("DATE ORDERED:")).FirstOrDefault(); var start = lines.Where(s => s.Contains("Item") && s.Contains("Qty") && s.Contains("Price") && s.Contains("Total")).FirstOrDefault(); var end = lines.Where(s => s.Trim() == "Billing Address").FirstOrDefault(); if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end)) return order; var istart = lines.ToList().FindIndex(s => s == start); var iend= lines.ToList().FindIndex(s => s == end); file.ProdCount = 0; var offset = 5; for (int i = istart + 1; i < iend; i += offset) { if (i + 4 > iend) break; string[] tmp; StockItem item = new StockItem(); offset = 0; // description tmp = lines[i + offset].Split(new string[] { "\\n" }, StringSplitOptions.None); item.Description = tmp[1].Split('\t')[0]; item.ProductCode = item.Description; offset++; for (int j = 0; j < 3; j++) { if (lines[i + offset].Contains("Size:")) { // size tmp = lines[i + offset].Split(':'); item.Size = tmp[1].Trim(); offset++; } else if (lines[i + offset].Contains("Style Number:")) { // product code /*tmp = lines[i + offset].Split(':'); item.ProductCode = tmp[1].Trim();*/ offset++; } else if (lines[i + offset].Contains("Colour(s):")) { // color tmp = lines[i + offset].Split(':'); item.Color = tmp[1].Trim(); offset++; } } // qauntity tmp = lines[i + offset].Split(new string[] { "\\n" }, StringSplitOptions.None); item.Ord_Qty = 1; try { item.Ord_Qty = Convert.ToInt32(tmp[3].Split('\t')[1].Trim()); } catch (System.Exception) { } item.Disp_Qty = item.Ord_Qty; offset++; item.Total = 5; item.Price = item.Total * item.Ord_Qty; item.Currency = "GBP"; //item.OrderDate = orderDate; item.FromFile = file; if (item.State == StockItemState.PermanentStorage) item.Sklad = "02"; else if (item.State == StockItemState.Waiting) item.Sklad = Properties.Settings.Default.Storage; items.Add(item); file.ProdCount++; } DecomposeMultipleItems(items); order.Items = items.ToArray(); return order; } catch (System.Exception ex) { MessageBox.Show(this, ex.ToString(), "Error"); } return null; }
internal StockEntity ProcessMessage(FileItem file) { StockEntity order = null; try { MailItem item = (MailItem)outlook.CreateItemFromTemplate(file.FullFileName, Type.Missing); if (file.Type == MSG_TYPE.SPORTS_DIRECT) { try { order = decodeMessage(item.Body, file); } catch (System.Exception) { try { order = decodeMessage2(item.Body, file); } catch(System.Exception ex) { MessageBox.Show("Spravu sportsdirect sa nepoadrilo nacitat! " + ex.Message); } } } else if (file.Type == MSG_TYPE.MANDM_DIRECT) order = decodeMandMMessage(item.Body, file); else if (file.Type == MSG_TYPE.GETTHELABEL) order = decodeGTLMessage(item.Body, file); else if (file.Type == MSG_TYPE.FIVE_POUNDS) order = decode5PoundsMessage(item.Body, file); file.OrderNumber = order.OrderReference; } catch (System.Exception ex) { log(ex.Message); return order; } return order; }
internal StockEntity ProcessCSVX(FileItem file) { if (file == null) return null; StockEntity ret = new StockEntity(); try { string fileContent = File.ReadAllText(file.FullFileName); var lines = fileContent.Split(Environment.NewLine.ToCharArray()); var orderItems = new List<StockItem>(); foreach (var line in lines) { if (line == null || line.Trim().Length == 0) continue; var split = line.Split(';'); StockItem newItem = new StockItem(); newItem.ProductCode = split[0]; newItem.Description = split[1]; newItem.Ord_Qty = int.Parse(split[2]); newItem.Disp_Qty = int.Parse(split[3]); newItem.Price = double.Parse(split[4]); newItem.Total = double.Parse(split[5]); newItem.Currency = split[6]; newItem.FromFile = file; orderItems.Add(newItem); } ret.Items = orderItems.ToArray(); } catch (System.Exception ex) { log(ex.Message); return null; } return ret; }
internal CSVFile ProcessCSV(FileItem fromFile) { CSVFile ret = new CSVFile(fromFile); try { string fileContent = File.ReadAllText(fromFile.FullFileName); var lines = fileContent.Split(Environment.NewLine.ToCharArray()); var csvContent = new List<CSVFileItem>(); for (int i = 1; i < lines.Count(); i++) { if (lines[i].Trim().Length == 0) continue; CSVFileItem item = new CSVFileItem(lines[i]); csvContent.Add(item); } ret.Items = csvContent.ToArray(); } catch (System.Exception ex) { log(ex.Message); return null; } return ret; }