Beispiel #1
0
        private void doConvertDetail(StreamReader reader, ref int CountLine,
                                     ref IList <PaymentConversionLine> ListDetail, ref PaymentConversionLine oHeader,
                                     ref StringBuilder StandardFile)
        {
            string strLine = null;

            //parse next line detail
            while ((strLine = reader.ReadLine()) != null)
            {
                CountLine++;
                //ignore line is BLANK
                if (string.IsNullOrEmpty(strLine))
                {
                    continue;
                }

                PaymentConversionLine oTestLineDetail = new PaymentConversionLine(CountLine, strLine);
                if (oTestLineDetail.IsLineDetail())
                {
                    if (oTestLineDetail.HasErrors)
                    {
                        this.ListErrors.Add(oTestLineDetail.ErrorMessage);
                    }
                    else
                    {
                        ListDetail.Add(oTestLineDetail);
                    }
                }
                else if (oTestLineDetail.IsLinePayeeID())
                {
                    if (oTestLineDetail.HasErrors)
                    {
                        this.ListErrors.Add(oTestLineDetail.ErrorMessage);
                    }
                    else
                    {
                        oHeader.PayeeID = oTestLineDetail.PayeeID;
                        if (string.IsNullOrEmpty(oHeader.PayeeID))
                        {
                            this.ListErrorVendor.Add(string.Format(ERROR_LINE_FIELD_VENDOR, CountLine, "Payee ID"));
                            oHeader.IsErrortVendor = true;
                        }
                    }

                    //Line payment date
                    string strLinePaymentDate = reader.ReadLine();
                    CountLine++;
                    PaymentConversionLine oTestLinePaymentDatePaymentAmount = new PaymentConversionLine(CountLine, strLinePaymentDate);
                    if (oTestLinePaymentDatePaymentAmount.IsLinePaymentDatePaymentAmount())
                    {
                        if (oTestLinePaymentDatePaymentAmount.HasErrors)
                        {
                            this.ListErrors.Add(oTestLinePaymentDatePaymentAmount.ErrorMessage);
                        }
                        else
                        {
                            oHeader.PaymentDate   = oTestLinePaymentDatePaymentAmount.PaymentDate;
                            oHeader.PaymentAmount = oTestLinePaymentDatePaymentAmount.PaymentAmount;
                        }
                    }

                    //parse vendor address
                    this.doConvertVendor(reader, ref CountLine, ref oHeader);

                    //build standard file
                    StandardFile.AppendLine(oHeader.GetHeaderDataLine());
                    if (ListDetail != null && ListDetail.Count > 0)
                    {
                        foreach (PaymentConversionLine oDetailData in ListDetail)
                        {
                            StandardFile.AppendLine(oDetailData.GetDetailDataLine());
                        }
                        //reset variable
                        ListDetail = null;
                    }

                    if (!oHeader.IsErrortVendor)
                    {
                        if (!string.IsNullOrEmpty(oHeader.Address1) || !string.IsNullOrEmpty(oHeader.City) || !string.IsNullOrEmpty(oHeader.StateProvince) || !string.IsNullOrEmpty(oHeader.PostalCode))
                        {
                            this.ListVendorAddress.Add(oHeader.ToVendorAddress);
                        }
                    }
                    ListVendors.Add(oHeader);
                    oHeader = null;
                    break;//end of detail line
                }
            } //whilte loop detail
        }
Beispiel #2
0
        public StringBuilder doConvert(byte[] fileInput)
        {
            //clear the variable Errors
            this.ListErrors      = new List <string>();
            this.ListErrorVendor = new List <string>();
            ListVendorAddress    = new List <VendorInfomation>();

            //stanadard file
            StringBuilder StandardFile = new StringBuilder();

            StandardFile.AppendLine(this.GetHeader());
            StandardFile.AppendLine(this.GetHeaderDetail());

            //count line
            int CountLine = 0;
            //input string line
            string strLine = null;

            using (MemoryStream stream = new MemoryStream(fileInput))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    //IList<string> ListPaymentNumber = new List<string>();
                    IList <string> ListPayeeId = new List <string>();
                    IList <PaymentConversionLine> ListDetail = null;
                    PaymentConversionLine         oHeader    = null;
                    while ((strLine = reader.ReadLine()) != null)
                    {
                        //count line;
                        CountLine++;
                        //ignore line is BLANK
                        if (string.IsNullOrEmpty(strLine))
                        {
                            continue;
                        }

                        PaymentConversionLine oTestHeader = new PaymentConversionLine(CountLine, strLine);
                        if (oTestHeader.IsLinePaymentNumber())
                        {
                            //initialize header & detail
                            if (oHeader == null)
                            {
                                oHeader = new PaymentConversionLine();
                            }
                            if (ListDetail == null)
                            {
                                ListDetail = new List <PaymentConversionLine>();
                            }

                            if (oTestHeader.HasErrors)
                            {
                                this.ListErrors.Add(oTestHeader.ErrorMessage);
                            }
                            else
                            {
                                oHeader.PaymentNumber = oTestHeader.PaymentNumber;
                            }

                            //next line is header overflow or not
                            strLine = reader.ReadLine();
                            CountLine++;
                            PaymentConversionLine oTestLine = new PaymentConversionLine(CountLine, strLine);

                            if (oTestLine.IsLinePayeeID())
                            {
                                if (oTestLine.HasErrors)
                                {
                                    this.ListErrors.Add(oTestLine.ErrorMessage);
                                }
                                else
                                {
                                    oHeader.PayeeID = oTestLine.PayeeID;
                                    if (string.IsNullOrEmpty(oHeader.PayeeID))
                                    {
                                        this.ListErrorVendor.Add(string.Format(ERROR_LINE_FIELD_VENDOR, CountLine, "Payee ID"));
                                        oHeader.IsErrortVendor = true;
                                    }
                                }

                                //Line payment date
                                string strLinePaymentDate = reader.ReadLine();
                                CountLine++;
                                PaymentConversionLine oTestLinePaymentDatePaymentAmount = new PaymentConversionLine(CountLine, strLinePaymentDate);
                                if (oTestLinePaymentDatePaymentAmount.IsLinePaymentDatePaymentAmount())
                                {
                                    if (oTestLinePaymentDatePaymentAmount.HasErrors)
                                    {
                                        this.ListErrors.Add(oTestLinePaymentDatePaymentAmount.ErrorMessage);
                                    }
                                    else
                                    {
                                        oHeader.PaymentDate   = oTestLinePaymentDatePaymentAmount.PaymentDate;
                                        oHeader.PaymentAmount = oTestLinePaymentDatePaymentAmount.PaymentAmount;
                                    }
                                }

                                //parse vendor address
                                this.doConvertVendor(reader, ref CountLine, ref oHeader);

                                //build standard file
                                StandardFile.AppendLine(oHeader.GetHeaderDataLine());
                                if (ListDetail != null && ListDetail.Count > 0)
                                {
                                    foreach (PaymentConversionLine oDetailData in ListDetail)
                                    {
                                        StandardFile.AppendLine(oDetailData.GetDetailDataLine());
                                    }
                                    //reset variable
                                    ListDetail = null;
                                }

                                if (!oHeader.IsErrortVendor)
                                {
                                    if (!string.IsNullOrEmpty(oHeader.Address1) || !string.IsNullOrEmpty(oHeader.City) || !string.IsNullOrEmpty(oHeader.StateProvince) || !string.IsNullOrEmpty(oHeader.PostalCode))
                                    {
                                        this.ListVendorAddress.Add(oHeader.ToVendorAddress);
                                    }
                                }
                                ListVendors.Add(oHeader);
                                oHeader = null;
                            }
                            else if (oTestLine.IsLineOverflow())
                            {
                                this.doConvertDetail(reader, ref CountLine, ref ListDetail, ref oHeader, ref StandardFile);
                            }
                            else if (oTestLine.IsLineDetail())
                            {
                                if (oTestLine.HasErrors)
                                {
                                    this.ListErrors.Add(oTestLine.ErrorMessage);
                                }
                                else
                                {
                                    ListDetail.Add(oTestLine);
                                }
                                this.doConvertDetail(reader, ref CountLine, ref ListDetail, ref oHeader, ref StandardFile);
                            } //if (oLineTest.IsLineOverflow())
                        }     //if (oTestHeader.IsLinePaymentNumber() && !ListPaymentNumber.Contains(oTestHeader.PaymentNumber))

                        //TODO List Vendor Address in DB
                    } //loop while
                }
            }

            #region add/update vendor from payment file
            //update vendor
            var error  = string.Empty;
            var module = new CreateVendorsFromPayments(ListVendors);
            if (!module.ProcessCreateVendors(out error))
            {
                throw new Exception(error);
            }
            #endregion

            #region Added logic for Adding Vendor Address information from Data File for Check payments.
            //LOGGER.Info("Begin: Logic for Adding Vendor Address information from Data File for Check payments....");
            //DataSet dsVendor = new DataSet();
            //int BatchSize = 500;
            //int j = 0;
            //DataTable newdbVendor = ListVendorAddress.AsDataTable();

            //#region validate
            //List<string> lstErr = ValidateLogiCreateVendor(ref newdbVendor);
            //#endregion
            //if (newdbVendor.Rows.Count > 0)
            //{
            //    DataTable new_tableSmallVendor = newdbVendor.Clone();
            //    if (newdbVendor.Rows.Count <= BatchSize)
            //    {

            //        new_tableSmallVendor = newdbVendor.Copy();
            //        dsVendor.Tables.Add(new_tableSmallVendor);

            //    }
            //    else
            //    {
            //        for (int i = 0; i < newdbVendor.Rows.Count; i++)
            //        {
            //            new_tableSmallVendor.NewRow();
            //            new_tableSmallVendor.ImportRow(newdbVendor.Rows[i]);
            //            if ((i + 1) == newdbVendor.Rows.Count)
            //            {

            //                dsVendor.Tables.Add(new_tableSmallVendor.Copy());
            //                new_tableSmallVendor.Rows.Clear();
            //            }
            //            else if (++j == BatchSize)
            //            {
            //                dsVendor.Tables.Add(new_tableSmallVendor.Copy());
            //                new_tableSmallVendor.Rows.Clear();
            //                j = 0;
            //            }
            //        }
            //    }


            //    string ResultReturn = string.Empty;
            //    Parallel.For(0, dsVendor.Tables.Count, index =>
            //    {
            //        ResultReturn = CreateVendor(dsVendor.Tables[index]);
            //        if (ResultReturn.Length > 0)
            //        {
            //            lstErr.Add(ResultReturn);
            //        }
            //    });
            //    LOGGER.Info("End: Logic for Adding Vendor Address information from Data File for Check payments....");
            //}
            #endregion

            return(StandardFile);
        }