示例#1
0
        public Sprzedaz parsujstrSprzedaz(string linia)
        {
            string id_s, nip, adres, nr, tab_s, data, netto_s, vat_s;

            int[]   tabOfIDs;
            int     id;
            decimal netto, vat;

            //MessageBox.Show(linia);

            id_s  = linia.Substring(0, linia.IndexOf(','));
            linia = linia.Substring((linia.IndexOf(',') + 1), linia.Length - (linia.IndexOf(',') + 1));
            Int32.TryParse(id_s, out id);

            nip   = linia.Substring(0, linia.IndexOf(','));
            linia = linia.Substring((linia.IndexOf(',') + 1), linia.Length - (linia.IndexOf(',') + 1));

            adres = linia.Substring(0, linia.IndexOf(','));
            linia = linia.Substring((linia.IndexOf(',') + 1), linia.Length - (linia.IndexOf(',') + 1));

            nr    = linia.Substring(0, linia.IndexOf(','));
            linia = linia.Substring((linia.IndexOf(',') + 1), linia.Length - (linia.IndexOf(',') + 1));

            tab_s = linia.Substring(0, linia.IndexOf('}'));
            linia = linia.Substring((linia.IndexOf('}') + 1), linia.Length - (linia.IndexOf('}') + 1));

            tabOfIDs = parsujStrIntTab(tab_s);

            data  = linia.Substring(0, linia.IndexOf(','));
            linia = linia.Substring((linia.IndexOf(',') + 1), linia.Length - (linia.IndexOf(',') + 1));

            netto_s = linia.Substring(0, linia.IndexOf(','));
            linia   = linia.Substring((linia.IndexOf(',') + 1), linia.Length - (linia.IndexOf(',') + 1));

            vat_s = linia.Substring(0, (linia.Length - 1));

            netto_s = zamiana(netto_s, '.', ',');
            vat_s   = zamiana(vat_s, '.', ',');
            try
            {
                netto = Convert.ToDecimal(netto_s);
                vat   = Convert.ToDecimal(vat_s);
            }
            catch (FormatException)
            {
                string msg;
                msg = "Blad parsowania stringow ";
                MessageBox.Show(msg);
                netto = 0;
                vat   = 0;
            }

            Sprzedaz temp = new Sprzedaz(id, nip, adres, nr, tabOfIDs, data, netto, vat);

            return(temp);
        }
示例#2
0
        //Obsluga transakcji

        public void utworzTransakcje(Controler controler)
        {
            int      counter = controler.Transkacje.Count;
            DateTime data    = DateTime.UtcNow.ToLocalTime();
            string   nr_fak  = "0/0/0";

            nr_fak = data.ToString("yyyy") + '/' + data.ToString("MM") + '/' + counter.ToString();
            string czas = data.ToString("dd-MM-yyyy HH:mm:ss");

            controler.Klienci.TryGetValue(controler.KlientID, out Klient linia);
            Sprzedaz nowyRekordSprzedazy = new Sprzedaz(
                controler.KlientID,
                linia.NIP,
                linia.adres,
                //"0/0/0",
                nr_fak,
                controler.KoszykList.ToArray(),
                //"03:06:2019",
                czas,
                controler.KoszykSuma,
                controler.koszykPodatek
                );


            controler.Transkacje.Add(counter, nowyRekordSprzedazy);
            string pdf = pdfh.createFaktura(nowyRekordSprzedazy, controler);

            kh.wyczyscKoszyk(controler);

            //Process myProcess = new Process();
            //myProcess.StartInfo.FileName = "acroRd32.exe"; //not the full application path
            pdf = AppDomain.CurrentDomain.BaseDirectory + pdf;
            //pdf = "/A "  + pdf;
            //myProcess.StartInfo.Arguments = pdf;
            //myProcess.Start();
            System.Diagnostics.Process.Start(pdf);
        }
示例#3
0
        public string createFaktura(Sprzedaz nowyRekordSprzedazy, Controler controler)
        {
            var    exportFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string nazwa        = nowyRekordSprzedazy.nr_dok.Replace('/', '_');
            var    exportFile   = System.IO.Path.Combine(fakturyPath + nazwa + ".pdf");

            controler.Klienci.TryGetValue(controler.KlientID, out Klient klient);

            try
            {
                using (var writer = new PdfWriter(exportFile))
                {
                    using (var pdf = new PdfDocument(writer))
                    {
                        var       doc       = new Document(pdf);;
                        ImageData imageData = ImageDataFactory.Create("LOGO.png");
                        Image     image     = new Image(imageData).ScaleAbsolute(100, 100).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.RIGHT);

                        doc.Add(image);
                        var naglowek = new Paragraph("Faktura " + nowyRekordSprzedazy.nr_dok).SetRelativePosition(200, 0, 200, 0);
                        doc.Add(naglowek);
                        doc.Add(new Paragraph("Kupujacy:" + klient.nazwa));
                        doc.Add(new Paragraph("Adres:" + klient.adres));
                        doc.Add(new Paragraph("NIP/REGON:" + klient.NIP));
                        doc.Add(new Paragraph("Data:" + nowyRekordSprzedazy.data));

                        var table = new Table(new float[] { 2, 6, 4, 4 });
                        table.SetWidth(UnitValue.CreatePercentValue(100));
                        table.AddHeaderCell(new Cell().Add(new Paragraph("Nr")));
                        table.AddHeaderCell(new Cell().Add(new Paragraph("Produkt")));
                        table.AddHeaderCell(new Cell().Add(new Paragraph("Cena")));
                        table.AddHeaderCell(new Cell().Add(new Paragraph("Vat")));

                        int numerator = 1;
                        foreach (int id_prod in nowyRekordSprzedazy.tabIDs)
                        {
                            controler.Asortyment.TryGetValue(id_prod, out Przedmiot rzecz);

                            table.AddCell(new Cell().Add(new Paragraph(numerator.ToString())));
                            table.AddCell(new Cell().Add(new Paragraph(rzecz.nazwa)));
                            table.AddCell(new Cell().Add(new Paragraph(rzecz.cena.ToString())));
                            table.AddCell(new Cell().Add(new Paragraph((rzecz.cena * rzecz.VAT / 100).ToString())));
                            numerator++;
                        }

                        table.AddCell(new Cell().Add(new Paragraph("")));
                        table.AddCell(new Cell().Add(new Paragraph("")));
                        table.AddCell(new Cell().Add(new Paragraph(nowyRekordSprzedazy.kwotaNetto + "zl")));
                        table.AddCell(new Cell().Add(new Paragraph(nowyRekordSprzedazy.podatekVat + "zl")));

                        doc.Add(table);

                        doc.Add(new Paragraph("Kwota netto:" + nowyRekordSprzedazy.kwotaNetto + "zl").SetRelativePosition(400, 0, 0, 0));
                        doc.Add(new Paragraph("Podatek:" + nowyRekordSprzedazy.podatekVat + "zl").SetRelativePosition(400, 0, 0, 0));
                        doc.Add(new Paragraph("PDF created with itext7 under AGPL license").SetFixedPosition(0, 0, 300));

                        doc.Close();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Blad tworzenia pdf'a " + e.ToString());
            }
            return(exportFile);
        }