Exemplo n.º 1
0
        /// <summary>
        /// Texts the parser_ record read.
        /// </summary>
        /// <param name="CurrentLineNumber">The current line number.</param>
        /// <param name="lineText">The line text.</param>
        protected override void textFieldParser_RecordRead(int CurrentLineNumber, string lineText)
        {
            string type;
            string subType;

            if (!string.IsNullOrEmpty(lineText))
            {
                GetRowTypeAndSubType(lineText, out type, out subType);

                //check the type and subtype so we know what schema to set the parser to and which handlers to setup
                if (type == Stock_Code && subType == "A") //add
                {
                    CommanderProduct.SetCommanderProductMaintenanceAddSchema(textFieldParser.TextFields);
                }
                else if (type == Stock_Code && subType == "M") //modify
                {
                    CommanderProduct.SetCommanderProductMaintenanceModifySchema(textFieldParser.TextFields);
                }
                else if (type != Stock_Code && !((type == HeaderOrFooter && (subType == "F" || subType == "L"))))
                {
                    // Console.WriteLine(type);
                    //not sure what to do here?
                    //this was the wrong subscriber to process the message, allow the next subscriber to have a go
                }
            }
        }
        /// <summary>
        /// This fires when a product is successfully read from the message
        /// </summary>
        /// <param name="currentLineNumber">The current line number.</param>
        /// <param name="fields">The fields.</param>
        /// <param name="lineText">The line text.</param>
        private void RecordFound(ref int currentLineNumber, TextFieldCollection fields, string lineText)
        {
            string type;
            string subType;

            GetRowTypeAndSubType(lineText, out type, out subType);

            if (type == GetItemType() && subType == GetSubItemType()) //add
            {
                //get commander product by product code
                string productCode = fields["ProductCode"].Value.ToString().Trim();
                if (string.IsNullOrEmpty(site))
                {
                    site = fields["Site"].Value.ToString().Trim();
                }
                CommanderProduct commanderProduct = CommanderController.GetProduct(productCode);
                if (commanderProduct == null) //there is no matching HSPG product in our product list
                {
                    hspgItems.Add(lineText);
                }
                else
                {
                    tpcItems.Add(lineText);
                }
            }
            else if (type == HeaderOrFooter && subType == "L") //footer
            {
                footerLine = lineText;
            }
            else if (type == HeaderOrFooter && subType == "F") //header
            {
                headerLine = lineText;
            }
        }
        /// <summary>
        /// Saves the product.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <returns></returns>
        public static int SaveProduct(CommanderProduct product)
        {
            try
            {
                if (product.IsValid)
                {
                    // Save entity
                    product.Id = DataAccessProvider.Instance().SaveCommanderProduct(product);
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(product);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(product.Id);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Populates a commander product object from the item values held in the TextFieldCollection.
        /// </summary>
        /// <param name="fields">The fields.</param>
        /// <returns></returns>
        private CommanderProduct PopulateCommanderProduct(TextFieldCollection fields)
        {
            CommanderProduct commanderProduct = new CommanderProduct();

            PopulateProperties(fields, commanderProduct);
            commanderProduct.UpdatedBy = GetType().ToString();

            return(commanderProduct);
        }
        /// <summary>
        /// Gets the product.
        /// </summary>
        /// <param name="productCode">The product code.</param>
        /// <returns></returns>
        public static CommanderProduct GetProduct(string productCode)
        {
            CommanderProduct commanderProduct = null;

            try
            {
                commanderProduct =
                    CBO <CommanderProduct> .FillObject(DataAccessProvider.Instance().GetCommanderProduct(productCode));
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(commanderProduct);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="requestMessage">The request message.</param>
        /// <returns></returns>
        public override void ProcessRequest(RequestMessage requestMessage)
        {
            try
            {
                CommanderProduct.SetProductMaintenanceFileHeaderSchema(textFieldParser.TextFields);

                AddHandlers();

                base.ProcessRequest(requestMessage);
                //save the commander object and return the success of this process
                Status = SaveProducts(requestMessage);
            }
            catch (Exception ex)
            {
                // Store the exception
                LastError = ex;

                // Failed
                Status = SubscriberStatusEnum.Failed;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Saves the commander orders.
        /// </summary>
        /// <param name="requestMessage">The request message.</param>
        /// <returns></returns>
        private SubscriberStatusEnum SaveProducts(RequestMessage requestMessage)
        {
            foreach (CommanderProduct product in products)
            {
                if (product.IsUpdate)
                {
                    //this should be an update so check to see if this record already exists
                    CommanderProduct previousRecord = CommanderController.GetProduct(product.ProductCode);
                    if (previousRecord != null)
                    {
                        //the record did not exist so log an exception
                        ////log
                        //LogEntry logEntry=new  LogEntry();
                        //logEntry.Message = "blah";
                        //Logger.Write(logEntry);
                        // throw new Exception("This message has already been sent to the warehouse.");
                        return(SubscriberStatusEnum.Processed);
                    }

                    product.Id = previousRecord.Id;
                }

                //save salesOrder and lines
                try
                {
                    int savedId = CommanderController.SaveProduct(product);
                }

                catch (InValidBusinessObjectException ex)
                {
                    //log exception
                    return(SubscriberStatusEnum.Failed);
                }
            }

            return(SubscriberStatusEnum.Processed);
        }