Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        public void ProcessAsaFile(string filePath)
        {
            string recordType;
            int    recordCount = 0;
            List <AsaJobRecord>      AsaJobRecordList      = new List <AsaJobRecord>();
            List <AsaCustomerRecord> AsaCustomerRecordList = new List <AsaCustomerRecord>();
            List <AsaInvoiceRecord>  AsaInvoiceRecordList  = new List <AsaInvoiceRecord>();

            logger.Info("File path for Asa File is " + filePath);

            logger.Info("TEST - Wait 10 seconds before processing file");

            Thread.Sleep(10000);

            try
            {
                using (StreamReader streamReader = File.OpenText(filePath))
                {
                    string flatFileLine = String.Empty;
                    while ((flatFileLine = streamReader.ReadLine()) != null)
                    {
                        recordType = flatFileLine.Substring(0, AsaConstants.RECORD_TYPE_LENGTH);

                        switch (recordType)
                        {
                        case AsaConstants.JOB_RECORD_TYPE:
                            AsaJobRecord asaJobRecord = ProcessJobRecord(flatFileLine);
                            logger.Info("Job Record for Job: " + asaJobRecord.Job);
                            AsaJobRecordList.Add(asaJobRecord);
                            break;

                        case AsaConstants.CUSTOMER_RECORD_TYPE:
                            AsaCustomerRecord asaCustomerRecord = ProcessCustomerRecord(flatFileLine);
                            logger.Info("Customer Record for account: " + asaCustomerRecord.CustomerNumber);
                            AsaCustomerRecordList.Add(asaCustomerRecord);
                            break;

                        case AsaConstants.INVOICE_RECORD_TYPE:
                            AsaInvoiceRecord asaInvoiceRecord = ProcessInvoiceRecord(flatFileLine);
                            logger.Info("Invoice Record for invoice: " + asaInvoiceRecord.OEInvoiceNo);
                            AsaInvoiceRecordList.Add(asaInvoiceRecord);
                            break;

                        default:
                            logger.Info("Encountered Default case - Record type not defined or invalid");
                            break;
                        }
                        recordCount++;
                    }

                    logger.Info("Job record count: " + AsaJobRecordList.Count.ToString());
                    logger.Info("Customer record count: " + AsaCustomerRecordList.Count.ToString());
                    logger.Info("Invoice record count: " + AsaInvoiceRecordList.Count.ToString());
                    logger.Info("Total records processed: " + recordCount.ToString());
                    //Check for job records to process
                    if (AsaJobRecordList.Count > 0)
                    {
                        foreach (AsaJobRecord jobRecord in AsaJobRecordList)
                        {
                            logger.Info("Insert job record -> " + jobRecord.Job);
                            ABLEController.ABLEJobTableInsert(jobRecord.CustomerNumber, jobRecord.Job, jobRecord.AbleLotId,
                                                              jobRecord.AbleDateExpected, jobRecord.AbleTruckRoute, jobRecord.AbleShippingDay, jobRecord.WorkOrderNumber);
                        }
                    }
                    //Check for customer records to process
                    if (AsaCustomerRecordList.Count > 0)
                    {
                        foreach (AsaCustomerRecord customerRecord in AsaCustomerRecordList)
                        {
                            //Insert customer record
                            if (customerRecord.StatusFlag == "A")
                            {
                                logger.Info("Insert customer record -> " + customerRecord.CustomerNumber);
                                ABLEController.ABLEAccountTableInsert(customerRecord.CustomerNumber, customerRecord.CustomerName,
                                                                      customerRecord.GetAddress(), customerRecord.CustomerContactName,
                                                                      customerRecord.GetPhoneNumber(), customerRecord.BinderID);
                            }
                            //Update customer record
                            else if (customerRecord.StatusFlag == "C")
                            {
                                logger.Info("Update customer record -> " + customerRecord.CustomerNumber);
                                ABLEController.ABLEAccountTableUpdate(customerRecord.CustomerNumber, customerRecord.CustomerName,
                                                                      customerRecord.GetAddress(), customerRecord.CustomerContactName,
                                                                      customerRecord.GetPhoneNumber(), customerRecord.BinderID);
                            }
                            //Delete customer record
                            else if (customerRecord.StatusFlag == "D")
                            {
                                logger.Info("Delete customer record -> " + customerRecord.CustomerNumber);
                                ABLEController.ABLEAccountTableDelete(customerRecord.CustomerNumber);
                            }
                        }
                    }
                    //Check for invoice records to process
                    if (AsaInvoiceRecordList.Count > 0)
                    {
                        foreach (AsaInvoiceRecord invoiceRecord in AsaInvoiceRecordList)
                        {
                            logger.Info("Insert Invoice record -> " + invoiceRecord.OEInvoiceNo);
                            //HAS MULTIPLE departments for each account string department = ABLEController.ABLEGetDepartmentForAccount(invoiceRecord.CustomerAccountNumber);

                            ABLEController.ABLEBillingTableInsert(invoiceRecord.CustomerAccountNumber, invoiceRecord.AbleLotID,
                                                                  invoiceRecord.InvoiceAmount, invoiceRecord.InvoiceAmount, "");
                        }
                    }
                }
                logger.Info("Done Processing Asa File " + filePath);
            }
            catch (Exception ex)
            {
                logger.Info("ProcessAsaFile exception --> " + ex.Message + "Stack Trace " + ex.StackTrace);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="flatFileRecord"></param>
        /// <returns></returns>
        private AsaInvoiceRecord ProcessInvoiceRecord(string flatFileRecord)
        {
            int lineIndex       = 0;
            int customerAccount = 0;
            int lotId           = 0;
            int jobId           = 0;

            AsaInvoiceRecord asaInvoiceRecord = new AsaInvoiceRecord();

            lineIndex = AsaConstants.RECORD_TYPE_LENGTH;
            asaInvoiceRecord.CustomerAccountNumber = flatFileRecord.Substring(lineIndex, AsaConstants.CUSTOMER_ACCOUNT_NUMBER_LENGTH).TrimEnd();

            //Remove leading zeros from string by converting to integer
            if (Int32.TryParse(asaInvoiceRecord.CustomerAccountNumber, out customerAccount))
            {
                logger.Debug("ProcessInvoiceRecord Customer Account is " + customerAccount);
                asaInvoiceRecord.CustomerAccountNumber = customerAccount.ToString();
            }
            else
            {
                logger.Debug("ProcessInvoiceRecord Customer Account could not be parsed");
                asaInvoiceRecord.CustomerAccountNumber = "0";
            }

            lineIndex += AsaConstants.CUSTOMER_ACCOUNT_NUMBER_LENGTH;
            asaInvoiceRecord.StatusFlag = flatFileRecord.Substring(lineIndex, AsaConstants.STATUS_FLAG_LENGTH).TrimEnd();
            lineIndex += AsaConstants.STATUS_FLAG_LENGTH;
            asaInvoiceRecord.AbleLotID = flatFileRecord.Substring(lineIndex, AsaConstants.ABLE_LOT_ID_LENGTH).TrimEnd();

            //Remove leading zeros from string by converting to integer
            if (Int32.TryParse(asaInvoiceRecord.AbleLotID, out lotId))
            {
                logger.Debug("ProcessInvoiceRecord: lot id is " + lotId);
                asaInvoiceRecord.AbleLotID = lotId.ToString();
            }
            else
            {
                logger.Debug("ProcessInvoiceRecord: lot id could not be parsed");
                asaInvoiceRecord.AbleLotID = "0";
            }

            lineIndex += AsaConstants.ABLE_LOT_ID_LENGTH;
            asaInvoiceRecord.OEInvoiceNo = flatFileRecord.Substring(lineIndex, AsaConstants.INVOICE_NUMBER_LENGTH).TrimEnd();
            lineIndex += AsaConstants.INVOICE_NUMBER_LENGTH;
            asaInvoiceRecord.InvoiceAmount = flatFileRecord.Substring(lineIndex, AsaConstants.INVOICE_AMOUNT_LENGTH).TrimEnd();
            lineIndex += AsaConstants.INVOICE_AMOUNT_LENGTH;
            asaInvoiceRecord.JobNumber = flatFileRecord.Substring(lineIndex, AsaConstants.JOB_NUMBER_LENGTH).TrimEnd();

            //Remove leading zeros from string by converting to integer
            if (Int32.TryParse(asaInvoiceRecord.JobNumber, out jobId))
            {
                logger.Debug("ProcessInvoiceRecord: Job Id is " + jobId);
                asaInvoiceRecord.JobNumber = jobId.ToString();
            }
            else
            {
                logger.Debug("ProcessInvoiceRecord: Job Id could not be parsed");
                asaInvoiceRecord.JobNumber = "0";
            }

            lineIndex += AsaConstants.JOB_NUMBER_LENGTH;
            asaInvoiceRecord.CustomerType = flatFileRecord.Substring(lineIndex, AsaConstants.CUSTOMER_TYPE_LENGTH).TrimEnd();
            lineIndex += AsaConstants.CUSTOMER_TYPE_LENGTH;
            asaInvoiceRecord.TotalOrderQty = flatFileRecord.Substring(lineIndex, AsaConstants.TOTAL_ORDER_QTY_LENGTH).TrimEnd();
            lineIndex += AsaConstants.TOTAL_ORDER_QTY_LENGTH;
            asaInvoiceRecord.TaxAmount = flatFileRecord.Substring(lineIndex, AsaConstants.TAX_AMOUNT_LENGTH).TrimEnd();
            lineIndex += AsaConstants.TAX_AMOUNT_LENGTH;
            asaInvoiceRecord.FreightAmount = flatFileRecord.Substring(lineIndex, AsaConstants.FREIGHT_AMOUNT_LENGTH).TrimEnd();

            return(asaInvoiceRecord);
        }