Beispiel #1
0
        public static Document ImportDAT(string fileName)
        {
            var orders = new List <OrderHeader>();

            string          line;
            OrderHeader     orderHeader     = null;
            OrderLineHeader orderLineHeader = null;

            // Read the file and parse it line by line.
            var enc = Encoding.GetEncoding(1252);

            using (var file = new StreamReader(fileName, enc))
                while ((line = file.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line) || line.Length < 3)
                    {
                        continue;
                    }
                    var lineType = line.Substring(0, 3);

                    // If the line starts with SOH
                    if (lineType.Equals(OrderHeaderLineType))
                    {
                        orderHeader = ParseHeaderString(line);
                        orders.Add(orderHeader);
                        continue;
                    }

                    if (orderHeader == null)
                    {
                        throw new Exception("The file is in the incorrect format.", new Exception("SOH Header line not included before SOD or LTD lines."));
                    }

                    // If the line starts with SOD
                    if (lineType.Equals(OrderLineHeaderLineType))
                    {
                        orderLineHeader = ParseOrderLineHeaderString(line);
                        orderHeader.OrderLineHeaders.Add(orderLineHeader);

                        continue;
                    }

                    if (orderLineHeader == null)
                    {
                        throw new Exception("The file is in the incorrect format.", new Exception("SOD Header line not included before LTD lines."));
                    }

                    // If the line starts with LTD
                    if (lineType.Equals(OrderLineItemLineType))
                    {
                        var templateDetail = ParseOrderLineString(line);
                        orderLineHeader.OrderLineTemplateDetails.Add(templateDetail);
                        continue;
                    }
                }

            return(new Document {
                OrderHeader = orders
            });
        }
Beispiel #2
0
        private static OrderLineHeader ParseOrderLineHeaderString(string orderString)
        {
            var fields = orderString.Split('þ');

            var orderLineType = fields[0]; // should be SOD;

            if (!orderLineType.Equals(OrderLineHeaderLineType))
            {
                throw new Exception("That is not an order line header string!");
            }

            var result = new OrderLineHeader();

            if (!fields.Any())
            {
                return(result);
            }

            result.OrderLineTemplateDetails = new List <LineTemplateDetail>();

            if (fields.Length > 1)
            {
                result.RequiredDeliveryDate = fields[1];
            }

            if (fields.Length > 2)
            {
                result.QTY = fields[2];
            }

            if (fields.Length > 3)
            {
                result.SellingPrice = fields[3];
            }

            if (fields.Length > 4)
            {
                result.Description = fields[4];
            }

            if (fields.Length > 5)
            {
                result.SKU = fields[5];
            }

            if (fields.Length > 6)
            {
                result.SODShipComp = fields[6];
            }

            if (fields.Length > 7)
            {
                result.CatalogCode = fields[7];
            }

            if (fields.Length > 8)
            {
                result.DeliveryRemarks = fields[8];
            }

            if (fields.Length > 9)
            {
                result.TaxFlag = fields[9];
            }

            if (fields.Length > 10)
            {
                result.SkipAllocationFlag = fields[10];
            }

            if (fields.Length > 11)
            {
                result.ListPrice = fields[11];
            }

            if (fields.Length > 12)
            {
                result.SODCommissionFlag = fields[12];
            }

            if (fields.Length > 13)
            {
                result.SODCommissionCode = fields[13];
            }

            if (fields.Length > 14)
            {
                result.ItemsTerms = fields[14];
            }

            if (fields.Length > 15)
            {
                result.MgtNumber = fields[15];
            }

            if (fields.Length > 16)
            {
                result.OptionOne = fields[16];
            }

            if (fields.Length > 17)
            {
                result.OptionTwo = fields[17];
            }

            if (fields.Length > 18)
            {
                result.OptionThree = fields[18];
            }

            if (fields.Length > 19)
            {
                result.OptionFour = fields[19];
            }

            if (fields.Length > 20)
            {
                result.OptionFive = fields[20];
            }

            return(result);
        }
Beispiel #3
0
        public static FlexOrder.OrderLineHeader ToFlexOrder(this OrderLineHeader line)
        {
            if (line.OrderLineTemplateDetails.Any(s => s.SKU != line.SKU))
            {
                throw new Exception(
                          "Invalid file. Some order line details do not match the sku for the main order header record.");
            }

            // we currently do not support formulas or ranges.
            if (line.OrderLineTemplateDetails.Any() && line.Quantity != line.OrderLineTemplateDetails.Count)
            {
                throw new Exception("Order line details do not match order quantity.");
            }

            #region User Defined Fields

            var fields = new FlexOrder.UserDefinedFields {
                Fields = new List <FlexOrder.UserDefinedField>()
            };

            if (!string.IsNullOrWhiteSpace(line.RequiredDeliveryDate))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "RequiredDeliveryDate", Value = line.RequiredDeliveryDate
                });
            }

            if (!string.IsNullOrWhiteSpace(line.SellingPrice))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "SellingPrice", Value = line.SellingPrice
                });
            }

            if (!string.IsNullOrWhiteSpace(line.SODShipComp))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "SODShipComp", Value = line.SODShipComp
                });
            }

            if (!string.IsNullOrWhiteSpace(line.CatalogCode))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "CatalogCode", Value = line.CatalogCode
                });
            }

            if (!string.IsNullOrWhiteSpace(line.DeliveryRemarks))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "DeliveryRemarks", Value = line.DeliveryRemarks
                });
            }

            if (!string.IsNullOrWhiteSpace(line.TaxFlag))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "TaxFlag", Value = line.TaxFlag
                });
            }

            if (!string.IsNullOrWhiteSpace(line.SkipAllocationFlag))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "SkipAllocationFlag", Value = line.SkipAllocationFlag
                });
            }

            if (!string.IsNullOrWhiteSpace(line.ListPrice))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "ListPrice", Value = line.ListPrice
                });
            }

            if (!string.IsNullOrWhiteSpace(line.SODCommissionFlag))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "SODCommissionFlag", Value = line.SODCommissionFlag
                });
            }

            if (!string.IsNullOrWhiteSpace(line.SODCommissionCode))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "SODCommissionCode", Value = line.SODCommissionCode
                });
            }

            if (!string.IsNullOrWhiteSpace(line.ItemsTerms))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "ItemsTerms", Value = line.ItemsTerms
                });
            }

            if (!string.IsNullOrWhiteSpace(line.MgtNumber))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "MgtNumber", Value = line.MgtNumber
                });
            }

            if (!string.IsNullOrWhiteSpace(line.OptionOne))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "OptionOne", Value = line.OptionOne
                });
            }

            if (!string.IsNullOrWhiteSpace(line.OptionTwo))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "OptionTwo", Value = line.OptionTwo
                });
            }

            if (!string.IsNullOrWhiteSpace(line.OptionThree))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "OptionThree", Value = line.OptionThree
                });
            }

            if (!string.IsNullOrWhiteSpace(line.OptionFour))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "OptionFour", Value = line.OptionFour
                });
            }

            if (!string.IsNullOrWhiteSpace(line.OptionFive))
            {
                fields.Fields.Add(new FlexOrder.UserDefinedField {
                    Key = "OptionFive", Value = line.OptionFive
                });
            }

            #endregion

            var result = new FlexOrder.OrderLineHeader
            {
                SkuName  = line.SKU,
                Quantity = line.Quantity,
                OrderLineMarkingDetail = line.OrderLineTemplateDetails.Select(d => d.ToFlexOrder()).ToList(),
                UserDefinedFields      = fields,
            };

            return(result);
        }