示例#1
0
 private static PayloadSegment ConvertRecord(CIFRecord record, CIFFile file, Country country, string id)
 {
     return segmentBuilder
         .BeginSegment()
             .AddCarnetNumber(record.CarnetNumber)
             .AddUpdateFlag("N")
             .AddProcessingDate(record.CreationDate)
             .AddCIFFilename(file.Name)
             .AddDateInCustomsLedger(record.DateInLedger)
             .AddReferenceInCustomsLedger(record.ReferenceInLedger)
             .AddCustomsOfficeReference(record.CustomsOfficeReference)
             .AddDischargeDate(record.DateOfDischarge)
             .AddDischargeReference(record.DischargeReference)
             .AddDischargeType(record.DischargeType)
             .AddVPN(record.VoletPageNumber)
             .AddDischargeStatus(record.DischargeStatus)
             .AddNumberOfPackages(record.NumberOfPackages)
             .AddComment(record.Comments)
             .AddInvoicedAssociationId(record.InvoicedAssociation.ID)
             .AddCountryCode(record.CountryISO)
             .AddSeriesType(record.SeriesType)
             .AddCarnetIndex(record.CarnetIndex)
         .EndSegment(country, id);
 }
示例#2
0
        static void Main(string[] args)
        {
            /*
            try
            {
                Console.WriteLine("Reading query 1.");
                new DevDBProvider().WithSqlReader(DBUtils.CURRENT_DB, "SELECT CT.C_C_CARNET_NUMBER, CT.C_C_STATE, CT.C_C_REASON FROM [CURRENT].DBO.CAR_CUR_CARNET_TABLE CT WITH(NOLOCK) WHERE CT.C_C_CARNET_NUMBER > 70320000", reader =>
                    {
                       return new QueryReader<Carnet>(new string[] { "C_C_CARNET_NUMBER", "C_C_STATE", "C_C_REASON" }, reader).Read();
                    }).Apply(c => Console.WriteLine(c));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();

            try
            {
                Console.WriteLine("Reading query 2.");
                new DevDBProvider().WithSqlReader(DBUtils.CURRENT_DB, "SELECT CT.C_C_CARNET_NUMBER, CT.C_C_STATE, CT.C_C_REASON FROM [CURRENT].DBO.CAR_CUR_CARNET_TABLE CT WITH(NOLOCK) WHERE CT.C_C_CARNET_NUMBER > 70320000", reader =>
                {
                    return new QueryReader<Carnet2>(new string[] { "C_C_CARNET_NUMBER", "C_C_STATE", "C_C_REASON" }, reader).Read();
                }).Apply(c => Console.WriteLine(c));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();

            return;
            */
            try
            {
                if (args.Length == 0) { return; }
                string cifName = args[0];

                CIFFile aFile = dbProvider.WithSqlReader(DBUtils.DISPATCH_DB, String.Format(@"select ToolsDB.dbo.GetCarnetNumberWithCheckDigit(c.D_C_CARNET_NUMBER) as CarnetNumber, h.D_H_CREATION_DATE, h.D_H_FILE_CUST_FILE, c.D_C_DATE_IN_LEDGER, c.D_C_REF_IN_LEDGER, c.D_C_REF_CUST_OFFICE, c.D_C_DATE_OF_DISCHARGE, D_C_REF_NUM_DISCHARGE, D_C_DISCHARGE_TYPE, c.D_C_SHEET_NUMBER, c.D_C_DISCHARGE_STATUS, c.D_C_NUM_PACKAGES, c.D_C_COMMENT, c.D_C_ASSOC_INVOICED, c.D_C_COUNTRY_ISO, c.D_C_SERIES_TYPE, c.D_C_CARNET_INDEX, ad.C_XST_ASSOCIATION_TXT, ad.C_XST_COUNTRY_ISO_CODE, c.D_C_CREATION_DATE
            from Dispatch.dbo.CAR_DISP_HEADERS h join Dispatch.dbo.CAR_DISP_CARNETS c on c.D_C_FILE_KEY = h.D_H_FILE_KEY join [Current].dbo.CAR_CUR_SYS_ASSOC_DETAILS ad on c.D_C_ASSOC_INVOICED = ad.C_XST_ASSOCIATION
            where h.D_H_FILE_CUST_FILE = '{0}'", cifName), reader =>
                {
                    DateTime processingDate = DateTime.Now;
                    string cifFilename = args[0];
                    IEnumerable<CIFRecord> records = new QueryReader<CIFRecord>(new string[] { "CarnetNumber", /*"D_H_CREATION_DATE", /*"D_H_FILE_CUST_FILE", */"D_C_DATE_IN_LEDGER", "D_C_REF_IN_LEDGER", "D_C_REF_CUST_OFFICE", "D_C_DATE_OF_DISCHARGE",
                        "D_C_REF_NUM_DISCHARGE", "D_C_DISCHARGE_TYPE", "D_C_SHEET_NUMBER", "D_C_DISCHARGE_STATUS", "D_C_NUM_PACKAGES", "D_C_COMMENT", "D_C_ASSOC_INVOICED", "D_C_COUNTRY_ISO", "D_C_SERIES_TYPE",
                        "D_C_CARNET_INDEX", /*"C_XST_ASSOCIATION_TXT", "C_XST_COUNTRY_ISO_CODE", */"D_C_CREATION_DATE" }, reader).Read();
                    // string carnetNumber, DateTime dateInLedger, string refInLedger, string customsOfficeReference, DateTime dateOfDischarge, string dischargeReference, string dischargeType, int vpn, string dischargeStatus, int numOfPacks, string comments, short invoicedAssociation, string countryISO, short seriesType, int carnetIndex, DateTime creationDate

                    /*
                     * System.String,        System.DateTime,       System.String,      System.String,                  System.DateTime,        System.String,              System.String,      System.Int32, System.String,        System.Int32, System.String,    System.Int16,               System.String,   System.Int16,      System.Int32, System.String, System.String, System.DateTime
                     * */
                    /*DateTime processingDate = DateTime.Now;
                    string cifFilename = args[0];

                    IEnumerable<CIFRecord> records = reader.ReadEachRow(read =>
                        {
                            CarnetNumber carnetNumber = read.GetString(carnetNumberIndex, string.Empty);
                            processingDate = read.GetDateTime(processingDateIndex, DateTime.Now);
                            cifFilename = read.GetString(cifFilenameIndex, cifFilename);
                            DateTime dateInLedger = read.GetDateTime(dateInLedgerIndex, DateTime.Now);
                            string refInLedger = read.GetString(refInLedgerIndex, string.Empty);
                            string customsOfficeReference = read.GetString(customsOfficeReferenceIndex, string.Empty);
                            DateTime dateOfDischarge = read.GetDateTime(dateOfDischargeIndex, DateTime.Now);
                            string dischargeRef = read.GetString(dischargeRefIndex, string.Empty);
                            string dischargeType = read.GetString(dischargeTypeIndex, string.Empty);
                            int vpn = read.GetInt(vpnIndex, -1);
                            string dischargeStatus = read.GetString(dischargeStatusIndex, string.Empty);
                            int packs = read.GetInt(packsIndex, -1);
                            string comments = read.GetString(commentsIndex, string.Empty);
                            short invoicedAssociationId = read.GetShort(invoicedAssociationIndex, -1);
                            Association invoicedAssociation = refs.GetAssociationById(invoicedAssociationId);
                            if (invoicedAssociation == null)
                            {
                                Console.Out.WriteLine("Invoiced association not found. Id=" + invoicedAssociationId.ToString());
                            }
                            else
                            {
                                if (invoicedAssociation.Country == null)
                                {
                                    Console.Out.WriteLine("Invoiced association country not found.");
                                }
                            }
                            string countryISO = read.GetString(countryISOIndex, string.Empty);
                            short seriesType = read.GetShort(seriesTypeIndex, -1);
                            int carnetIndex = read.GetInt(carnetIndexIndex, -1);
                            DateTime creationDate = read.GetDateTime(creationDateIndex);
                            CIFRecord record = new CIFRecord(carnetNumber, dateInLedger, refInLedger, customsOfficeReference, dateOfDischarge, dischargeRef, dischargeType, vpn, dischargeStatus, packs, comments, invoicedAssociation, countryISO, seriesType, carnetIndex, creationDate);
                            return record;
                        });*/
                    CIFFile file = new CIFFile(records, processingDate, cifFilename);
                    return file;
                });
                // Write the records back to a CXF file
                aFile.Records
                     .GroupBy(record => record.InvoicedAssociation, new Association.EqualityComparer())
                     .Apply(associationRecords => IOUtils.WithFileWriter(IOUtils.GetCurrentDirectory(), CXFFile.MakeFilename(associationRecords.Key as Association), writer =>
                     {
                         Country country = refs.GetCountryByCode("CHE");
                         writer.WriteLine(new CXFFileBuilder()
                             .BeginFile(country, "IRU")
                             .AddSegments(associationRecords.Select(record => ConvertRecord(record, aFile, country, "IRU")))
                             .EndFile()
                             .ToString());
                     }));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex);
            }
        }