Exemplo n.º 1
0
        public string AddPbcnetRecords(dbData3060 p_dbData3060, string delsystem, int leveranceid, int pbsfilesid)
        {
            int      antal;
            int      pbcnetrecords;
            DateTime transmisionsdato;
            int      idlev;
            string   filename;
            string   rec;

            pbcnetrecords = (from h in p_dbData3060.tblpbsfile
                             where h.pbsfilesid == pbsfilesid & (h.seqnr == 0 | h.seqnr == 9999)
                             select h).Count();

            if (pbcnetrecords == 0)
            {
                // Find antal records
                antal = (from h in p_dbData3060.tblpbsfile
                         where h.pbsfilesid == pbsfilesid & h.seqnr != 0 & h.seqnr != 9999
                         select h).Count();
                transmisionsdato = DateTime.Now;

                idlev = p_dbData3060.nextval("idlev");

                tblpbsfilename rec_pbsfiles = (from h in p_dbData3060.tblpbsfilename where h.id == pbsfilesid select h).First();

                rec = write00(delsystem, transmisionsdato, idlev, leveranceid);
                tblpbsfile rec_pbsfile = new tblpbsfile {
                    seqnr = 0, data = rec
                };
                rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);

                rec         = write90(delsystem, transmisionsdato, idlev, leveranceid, antal);
                rec_pbsfile = new tblpbsfile {
                    seqnr = 9999, data = rec
                };
                rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);

                p_dbData3060.SaveChanges();

                filename  = "D";
                filename += lpad(String.Format("{0:yyMMdd}", transmisionsdato), 6, '?');
                filename += lpad(idlev, 2, '0');
                filename += ".";
                filename += rpad(delsystem, 3, '_');
            }
            else
            {
                filename = "Unknown";
            }

            return(filename);
        }
Exemplo n.º 2
0
        public int ReadFraSFtp(dbData3060 p_dbData3060)
        {
            m_memPbsnetdir = new MemPbsnetdir(); //opret ny memPbsnetdir

            //  Iterate over the files.
            foreach (SftpFile fileObj in m_sftp.ListDirectory(m_rec_sftp.outbound))
            {
                if (fileObj.Name != "." && fileObj.Name != "..")
                {
                    recPbsnetdir rec = new recPbsnetdir
                    {
                        Type     = 8,
                        Path     = m_rec_sftp.outbound,
                        Filename = fileObj.Name,
                        Size     = (int)fileObj.Length,
                        Atime    = fileObj.LastAccessTime,
                        Mtime    = fileObj.LastWriteTime,
                        Gid      = fileObj.GroupId,
                        Uid      = fileObj.UserId,
                        Perm     = ""
                    };
                    m_memPbsnetdir.Add(rec);
                }
            }

            var leftqry_pbsnetdir =
                from h in m_memPbsnetdir
                //join d1 in p_dbData3060.Tblpbsfiles on new { h.Path, h.Filename } equals new { d1.Path, d1.Filename } into details
                //from d1 in details.DefaultIfEmpty(new Tblpbsfiles { Id = -1, Type = (int?)null, Path = null, Filename = null, Size = (int?)null, Atime = (DateTime?)null, Mtime = (DateTime?)null, Perm = null, Uid = (int?)null, Gid = (int?)null })
                //where d1.Path == null && d1.Filename == null
                select h;

            int AntalFiler = leftqry_pbsnetdir.Count();

            if (leftqry_pbsnetdir.Count() > 0)
            {
                foreach (var rec_pbsnetdir in leftqry_pbsnetdir)
                {
                    tblpbsfilename m_rec_pbsfiles = new tblpbsfilename
                    {
                        type     = rec_pbsnetdir.Type,
                        path     = rec_pbsnetdir.Path,
                        filename = rec_pbsnetdir.Filename,
                        size     = rec_pbsnetdir.Size,
                        atime    = rec_pbsnetdir.Atime,
                        mtime    = rec_pbsnetdir.Mtime,
                        perm     = rec_pbsnetdir.Perm,
                        uid      = rec_pbsnetdir.Uid,
                        gid      = rec_pbsnetdir.Gid
                    };
                    p_dbData3060.tblpbsfilename.Add(m_rec_pbsfiles);

                    //***********************************************************************
                    //  Open a file on the server:
                    string fullpath = rec_pbsnetdir.Path + "/" + rec_pbsnetdir.Filename;
                    int    numBytes = (int)rec_pbsnetdir.Size;

                    byte[]       b_data = new byte[numBytes];
                    MemoryStream stream = new MemoryStream(b_data, true);

                    Program.Log(string.Format("Start Download of {0}", fullpath));
                    m_sftp.DownloadFile(fullpath, stream);
                    Program.Log(string.Format("{0} Download Completed", fullpath));

                    sendAttachedFile(p_dbData3060, rec_pbsnetdir.Filename, b_data, false);
                    char[] c_data      = System.Text.Encoding.GetEncoding("windows-1252").GetString(b_data).ToCharArray();
                    string filecontens = new string(c_data);

                    string filecontens2 = filecontens.TrimEnd('\n');
                    string filecontens3 = filecontens2.TrimEnd('\r');
                    string filecontens4 = filecontens3.TrimEnd('\n');

                    string[] lines = filecontens4.Split('\n');
                    string   ln    = null;
                    int      seqnr = 0;
                    string   ln0_6;
                    for (int idx = 0; idx < lines.Count(); idx++)
                    {
                        ln = lines[idx].TrimEnd('\r');
                        try { ln0_6 = ln.Substring(0, 6); }
                        catch { ln0_6 = ""; }
                        if (((seqnr == 0) && !(ln0_6 == "PBCNET")) || (seqnr > 0))
                        {
                            seqnr++;
                        }
                        if (ln.Length > 0)
                        {
                            m_rec_pbsfile = new tblpbsfile
                            {
                                seqnr = seqnr,
                                data  = ln
                            };
                            m_rec_pbsfiles.tblpbsfile.Add(m_rec_pbsfile);
                        }
                    }

                    m_rec_pbsfiles.transmittime = DateTime.Now;
                    //var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString);
                    Program.Log(string.Format("Start Write {0} to SQL Database {1} on {2}", rec_pbsnetdir.Filename, "cb.InitialCatalog", "cb.DataSource"));
                    p_dbData3060.SaveChanges();
                    Program.Log(string.Format("{0} Write to SQL Database Completed", rec_pbsnetdir.Filename));
                }
            }
            p_dbData3060.SaveChanges();
            return(AntalFiler);
        }
Exemplo n.º 3
0
        public int ReadFromLocalFile(dbData3060 p_dbData3060, string FilePath)
        {
            FileInfo file;

            try
            {
                file = new FileInfo(FilePath);
                if (!(file.Exists))
                {
                    return(0);
                }
            }
            catch (Exception)
            {
                return(0);
            }

            //***********************************************************************
            //  Open a local file:
            string fullpath = file.FullName;
            int    numBytes = (int)file.Length;

            byte[] b_data = new byte[numBytes];

            Program.Log(string.Format("Start Reading of {0}", fullpath));
            using (FileStream ts = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
            {
                ts.Read(b_data, 0, numBytes);
            }
            Program.Log(string.Format("{0} Reading Completed", fullpath));

            sendAttachedFile(p_dbData3060, file.Name, b_data, false);
            char[] c_data      = System.Text.Encoding.GetEncoding("windows-1252").GetString(b_data).ToCharArray();
            string filecontens = new string(c_data);

            string filecontens2 = filecontens.TrimEnd('\n');
            string filecontens3 = filecontens2.TrimEnd('\r');
            string filecontens4 = filecontens3.TrimEnd('\n');

            string[] lines = filecontens4.Split('\n');
            string   ln    = null;
            int      seqnr = 0;
            string   ln0_6;

            tblpbsfilename m_rec_pbsfiles = new tblpbsfilename
            {
                type     = 8,
                path     = file.Directory.FullName,
                filename = file.Name,
                size     = (int)file.Length,
                atime    = file.LastAccessTime,
                mtime    = file.LastWriteTime
            };

            p_dbData3060.tblpbsfilename.Add(m_rec_pbsfiles);
            for (int idx = 0; idx < lines.Count(); idx++)
            {
                ln = lines[idx].TrimEnd('\r');
                try { ln0_6 = ln.Substring(0, 6); }
                catch { ln0_6 = ""; }
                if (((seqnr == 0) && !(ln0_6 == "PBCNET")) || (seqnr > 0))
                {
                    seqnr++;
                }
                if (ln.Length > 0)
                {
                    m_rec_pbsfile = new tblpbsfile
                    {
                        seqnr = seqnr,
                        data  = ln
                    };
                    m_rec_pbsfiles.tblpbsfile.Add(m_rec_pbsfile);
                }
            }

            m_rec_pbsfiles.transmittime = DateTime.Now;
            //var cb = new SqlConnectionStringBuilder(p_dbData3060.Connection.ConnectionString);
            Program.Log(string.Format("Start Write {0} to SQL Database {1} on {2}", file.Name, "cb.InitialCatalog", "cb.DataSource"));
            p_dbData3060.SaveChanges();
            Program.Log(string.Format("{0} Write to SQL Database Completed", file.Name));
            return(1);
        }
Exemplo n.º 4
0
        public void krdfaktura_overfoersel_action(dbData3060 p_dbData3060, int lobnr)
        {
            string   rec;
            int      seq = 0;
            int      wleveranceid;
            DateTime wdispositionsdato;
            int      whour;
            int      wbankdage;

            // Betalingsoplysninger
            int belobint;

            // Tællere
            int antalos5;        // Antal OS5: Antal foranstående OS5 records
            int belobos5;        // Beløb: Nettobeløb i OS5 records

            int antalsek;        // Antal sektioner i leverancen
            int antalos5tot;     // Antal OS5: Antal foranstående OS5 records
            int belobos5tot;     // Beløb: Nettobeløb i OS5 records

            whour = DateTime.Now.Hour;
            if (whour > 17)
            {
                wbankdage = 3;
            }
            else
            {
                wbankdage = 2;
            }
            wdispositionsdato = clsOverfoersel.bankdageplus(DateTime.Now, wbankdage);

            antalos5 = 0;
            belobos5 = 0;

            antalsek    = 0;
            antalos5tot = 0;
            belobos5tot = 0;



            {
                var antal = (from c in p_dbData3060.tbltilpbs
                             where c.id == lobnr
                             select c).Count();
                if (antal == 0)
                {
                    throw new Exception("101 - Der er ingen PBS forsendelse for id: " + lobnr);
                }
            }
            {
                var antal = (from c in p_dbData3060.tbltilpbs
                             where c.id == lobnr && c.pbsforsendelseid != null
                             select c).Count();
                if (antal > 0)
                {
                    throw new Exception("102 - Pbsforsendelse for id: " + lobnr + " er allerede sendt");
                }
            }
            {
                var antal = (from c in p_dbData3060.tbloverforsel
                             where c.tilpbsid == lobnr
                             select c).Count();
                if (antal == 0)
                {
                    throw new Exception("103 - Der er ingen pbs transaktioner for tilpbsid: " + lobnr);
                }
            }

            var rsttil = (from c in p_dbData3060.tbltilpbs
                          where c.id == lobnr
                          select c).First();

            if (rsttil.udtrukket == null)
            {
                rsttil.udtrukket = DateTime.Now;
            }
            if (rsttil.bilagdato == null)
            {
                rsttil.bilagdato = rsttil.udtrukket;
            }
            if (rsttil.delsystem == null)
            {
                rsttil.delsystem = "OS1";
            }
            if (rsttil.leverancetype != null)
            {
                rsttil.leverancetype = null;
            }
            p_dbData3060.SaveChanges();


            wleveranceid = p_dbData3060.nextval("leveranceid");
            tblpbsforsendelse rec_pbsforsendelse = new tblpbsforsendelse
            {
                delsystem     = rsttil.delsystem,
                leverancetype = rsttil.leverancetype,
                oprettetaf    = "Udb",
                oprettet      = DateTime.Now,
                leveranceid   = wleveranceid
            };

            p_dbData3060.tblpbsforsendelse.Add(rec_pbsforsendelse);
            rec_pbsforsendelse.tbltilpbs.Add(rsttil);

            tblpbsfilename rec_pbsfiles = new tblpbsfilename();

            rec_pbsforsendelse.tblpbsfilename.Add(rec_pbsfiles);

            tblkreditor krd = (from k in p_dbData3060.tblkreditor
                               where k.delsystem == rsttil.delsystem
                               select k).First();


            // -- Leverance Start - OS1
            // - rstkrd.Datalevnr - Dataleverandørnr.: Dataleverandørens SE-nummer
            // - wleveranceid     - Leveranceidentifikation: Løbenummer efter eget valg
            rec = writeOS1(krd.datalevnr, wleveranceid);
            tblpbsfile rec_pbsfile = new tblpbsfile {
                seqnr = ++seq, data = rec
            };

            rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);

            var qrydeb = from h in p_dbData3060.tbloverforsel
                         where h.tilpbsid == lobnr
                         select h;

            // Start loop over betalinger i tbloverforsel
            int testantal = qrydeb.Count();

            foreach (tbloverforsel rec_overfoersel in qrydeb)
            {
                DateTime Betalingsdato = (rec_overfoersel.betalingsdato == null) ? wdispositionsdato : (DateTime)rec_overfoersel.betalingsdato;
                if (Betalingsdato < wdispositionsdato)
                {
                    Betalingsdato = wdispositionsdato;
                }
                rec_overfoersel.betalingsdato = Betalingsdato; //opdater aktuel betalingsdato

                // Sektion start – (OS2)
                antalos5 = 0;
                belobos5 = 0;

                // -- OS2
                // - Betalingsdato  - Dispositionsdato
                // - krd.regnr      - Reg.nr.: Overførselsregistreringsnummer
                // - krd.kontonr    - Kontonr.: Overførselskontonummer
                // - krd.datalevnr  - Dataleverandørnr.: Dataleverandørens SE-nummer
                rec         = writeOS2(Betalingsdato, krd.regnr, krd.kontonr, krd.datalevnr);
                rec_pbsfile = new tblpbsfile {
                    seqnr = ++seq, data = rec
                };
                rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);

                ++antalsek;

                // -- Forfald betaling
                if (rec_overfoersel.advisbelob > 0)
                {
                    belobint    = (int)(rec_overfoersel.advisbelob * ((decimal)100));
                    belobos5    = belobos5 + belobint;
                    belobos5tot = belobos5tot + belobint;
                }
                else
                {
                    belobint = 0;
                }

                // -- OS5
                // - debinfo.bankregnr   - Betalingsmodtager registreringsnummer
                // - debinfo.bankkontonr - Betalingsmodtager kontonummer
                // - belobint            - Beløb: Beløb i øre uden fortegn
                // - Betalingsdato       - Dispositionsdato
                // - krd.regnr           - Reg.nr.: Overførselsregistreringsnummer
                // - krd.kontonr         - Kontonr.: Overførselskontonummer
                // - deb.advistekst      - Tekst på Betalingsmodtagers kontoudtog
                // - deb.SFakID          - Ref til betalingsmodtager til eget brug
                rec         = writeOS5(rec_overfoersel.bankregnr, rec_overfoersel.bankkontonr, belobint, Betalingsdato, krd.regnr, krd.kontonr, rec_overfoersel.advistekst, (int)rec_overfoersel.SFakID);
                rec_pbsfile = new tblpbsfile {
                    seqnr = ++seq, data = rec
                };
                rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);

                antalos5++;
                antalos5tot++;


                // -- Sektion s**t – (OS8)
                // - OS8
                // - antalos5          - Antal 042: Antal foranstående 042 records
                // - belobos5          - Beløb: Nettobeløb i 042 records
                // - Betalingsdato     - Dispositionsdato
                // - krd.regnr         - Reg.nr.: Overførselsregistreringsnummer
                // - krd.kontonr       - Kontonr.: Overførselskontonummer
                // - krd.datalevnr     - Dataleverandørnr.: Dataleverandørens SE-nummer
                rec         = writeOS8(antalos5, belobos5, Betalingsdato, krd.regnr, krd.kontonr, krd.datalevnr);
                rec_pbsfile = new tblpbsfile {
                    seqnr = ++seq, data = rec
                };
                rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);
            }

            // -- Leverance s**t - (OS9)

            // --OS9
            // - antalos5tot    - Antal 042: Antal foranstående 042 records
            // - belobos5tot    - Beløb: Nettobeløb i 042 records
            // - krd.datalevnr  - Dataleverandørnr.: Dataleverandørens SE-nummer
            rec         = writeOS9(antalos5tot, belobos5tot, krd.datalevnr);
            rec_pbsfile = new tblpbsfile {
                seqnr = ++seq, data = rec
            };
            rec_pbsfiles.tblpbsfile.Add(rec_pbsfile);

            rsttil.udtrukket = DateTime.Now;
            rsttil.leverancespecifikation = wleveranceid.ToString();
            p_dbData3060.SaveChanges();
        }