Пример #1
0
 private ImportLine addTrailer(ImportLine line)
 {
     line.Fields.Add(new ImportField
     {
         Field = "Field1",
         FieldStartPosition = 1,
         FieldLength        = 1
     });
     return(line);
 }
Пример #2
0
        static public ImportReturn PerformImport(RecordImport importStr, ImportLine importLineFunction, int headerRowCount = 1)
        {
            var importReturn = new ImportReturn();

            var lines = importStr.Data.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            var headerFound = 0;
            var line        = "";

            for (int i = 0; i < lines.Length; i++)
            {
                line += lines[i];

                var fields    = line.Split(new char[] { '\t' });
                var lastField = fields[fields.Length - 1];
                if (lastField.Length > 0 && lastField[0] == '"')
                {
                    if (lastField.Length == 1 || lastField[lastField.Length - 1] != '\"')
                    {
                        //last field is continued with next line, let's contiue
                        line += "\r\n";
                        continue;
                    }
                }

                if (headerFound < headerRowCount)
                {
                    headerFound++;
                    line = "";
                    continue;
                }

                //process line
                var msg = importLineFunction(fields);
                if (!string.IsNullOrEmpty(msg))
                {
                    importReturn.Data.Add(msg + " -- " + line);
                }

                line = ""; //reset line
            }

            if (importReturn.Data.Count > 0)
            {
                importReturn.Msg = "Errors are found in some lines";
            }
            else
            {
                importReturn.Msg = "Import success!";
            }

            return(importReturn);
        }
Пример #3
0
 private ImportLine addDetail(ImportLine line)
 {
     line.Fields.Add(new ImportField
     {
         Field = "Field1",
         FieldStartPosition = 1,
         FieldLength        = 1
     });
     line.Fields.Add(new ImportField
     {
         Field = "Field2",
         FieldStartPosition = 2,
         FieldLength        = 10
     });
     line.Fields.Add(new ImportField
     {
         Field = "Field3",
         FieldStartPosition = 12,
         FieldLength        = 50
     });
     return(line);
 }
Пример #4
0
        /// <summary>
        /// Creates and save import.
        /// </summary>
        /// <param name="api">The API.</param>
        /// <returns>Import.</returns>
        private static Import CreateAndSaveImport(Go api)
        {
            // Set up a journal for import
            Console.WriteLine("Creating Customer Invoice import");

            // Create the import "header"
            // The clue here is to set the Type to ImportType.OutgoingVoucher
            var import = new Import
            {
                Description = "Sample Customer Invoice Import",
                Type        = ImportType.OutgoingVoucher,
                Date        = DateTime.Now
            };

            // Add customer invoice lines
            Console.WriteLine("Adding customer invoice lines");

            //First we add a header line for the outgoing invoice
            //Note: Before importing Customer(s) and Product(s) on the import should be created through Api.Customer / Api.Product
            //All lines with the same DocumentNumber will be attached to one invoice/creditnote, there must be one and only one line with CustomerCode (this is identifying that this line is the header)
            var importLine1 = new ImportLine();

            importLine1.Amount         = 100.0m;
            importLine1.CurrencyAmount = importLine1.Amount;
            importLine1.CurrencyCode   = "NOK";
            importLine1.Description    = "test1";
            importLine1.DocumentDate   = DateTime.Now;
            importLine1.DocumentNumber = 1;
            importLine1.PostingDate    = DateTime.Now;

            //Add important Invoice head information
            importLine1.CustomerCode = 12345;
            importLine1.DueDate      = DateTime.Now.AddDays(14);
            importLine1.Cid          = "7123451002";
            importLine1.Reference    = "Reference here";
            importLine1.InvoiceNo    = "100";

            import.ImportLines.Add(importLine1);

            //Then we add a salesline on this customer invoice
            var importLine2 = new ImportLine();

            importLine2.AccountNumber  = 3000;
            importLine2.Amount         = -100.0m;
            importLine2.VatCode        = "3";
            importLine2.CurrencyAmount = importLine2.Amount;
            importLine2.Quantity       = 1;
            importLine2.CurrencyCode   = "NOK";
            importLine2.Description    = "test2";
            importLine2.DocumentDate   = DateTime.Now;
            importLine2.DocumentNumber = 1;
            importLine2.PostingDate    = DateTime.Now;
            importLine2.ProductCode    = "1";

            import.ImportLines.Add(importLine2);

            // Save the journal to the server. When this call has finished, the customer invoice import will
            // appear in the Journal Import list in PowerOffice Go.
            Console.WriteLine("Saving journal...");

            api.Import.Save(import);

            Console.WriteLine("Journal was saved and assign the Id: " + import.Id);
            return(import);
        }
Пример #5
0
 public ImportLine Add(ImportLine pt)
 {
     _unitOfWork.Repository <ImportLine>().Insert(pt);
     return(pt);
 }
Пример #6
0
 public void Update(ImportLine pt)
 {
     pt.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <ImportLine>().Update(pt);
 }
Пример #7
0
 public void Delete(ImportLine pt)
 {
     _unitOfWork.Repository <ImportLine>().Delete(pt);
 }
Пример #8
0
 public ImportLine Create(ImportLine pt)
 {
     pt.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <ImportLine>().Insert(pt);
     return(pt);
 }