Ejemplo n.º 1
0
        //create insertstring for leaseorders
        private string GetLeaseOrderInsertString(Lease lease)
        {
            string insertLeaseOrder = $"insert into LeaseOrder (StartDate, EndDate, LeasePrice, ResourcesID, LeaseID, DeliveryStreet, DeliveryPostalCode, DeliveryCity, DeliveryPrice)\nvalues\n";

            for (int i = 0; i < lease.GetLeaseOrders().Count; i++)
            {
                LeaseOrder lo = lease.GetLeaseOrders()[i];
                if (i != 0)
                {
                    insertLeaseOrder += ", ";
                }
                insertLeaseOrder += $"('{lo.startDate.ToString("yyyy-MM-dd")}', '{lo.endDate.ToString("yyyy-MM-dd")}', {lo.leasePrice.ToString("G", new CultureInfo("en-US"))}," +
                                    $" {lo.resourceID}, {lease.leaseID}, '{lo.deliveryStreet.Replace("'", "''")}', {lo.deliveryPostalCode}, '{lo.deliveryCity.Replace("'", "''")}', {lo.deliveryPrice.ToString("G", new CultureInfo("en-US"))})";
            }
            return(insertLeaseOrder);
        }
Ejemplo n.º 2
0
        //inserts new Lease in database
        public string CreateLease(Lease lease)
        {
            string active = "1";

            if (lease.active == false)
            {
                active = "0";
            }

            string insertLease = $"insert into Lease (CreationDate, Active, DebtorID, BranchID, ContactFname, ContactLname, ContactPhone, Status) output inserted.LeaseID " +
                                 $"Values (CONVERT (date, CURRENT_TIMESTAMP), {active}, '{lease.debtorID}', {lease.branchID}, '{lease.contactFirstName.Replace("'", "''")}'," +
                                 $" '{lease.contactLastName.Replace("'", "''")}', '{lease.contactPhone.Replace("'", "''")}', '{lease.status}')";

            DataTable dataTable = DatabaseManager.ReadFromDatabase(insertLease);

            int leaseID = (int)dataTable.Rows[0][0];

            if (lease.GetLeaseOrders().Count > 0)
            {
                lease.SetLeaseID(leaseID);

                string insertLeaseOrder = GetLeaseOrderInsertString(lease);

                string isInsertSuccess = DatabaseManager.CreateUpdateDeleteInDatabase(insertLeaseOrder);

                return(leaseID.ToString() + ";" + isInsertSuccess);
            }
            else
            {
                return(leaseID.ToString() + ";Success");
            }
        }
Ejemplo n.º 3
0
        private void FillFormWithLease(DelpinCore.Lease lease)
        {
            string debtorID = lease.debtorID;

            if (debtorID.Length == 10)
            {
                personalRadioButton.Checked = true;
            }
            else
            {
                businessRadioButton.Checked = true;
            }

            debtorIDTextBox.Text = debtorID;
            GetDebtoryByID(debtorID);

            contactFirstName.Text = lease.contactFirstName;
            contactLastName.Text  = lease.contactLastName;
            contactPhone.Text     = lease.contactPhone;
            leaseNumber.Text      = lease.leaseID.ToString();

            if (lease.active == true)
            {
                AddOpenStatusesToComboBox();
                FillStatus(lease.status);
            }
            else
            {
                AddClosedStatusesToComboBox();
            }

            foreach (LeaseOrder leaseOrder in lease.GetLeaseOrders())
            {
                leaseOrders.Rows.Add();
                int lastRow = leaseOrders.Rows.GetLastRow(DataGridViewElementStates.Visible);
                leaseOrders.Rows[lastRow].Cells["ResurseID"].Value     = leaseOrder.resourceID;
                leaseOrders.Rows[lastRow].Cells["Resurse"].Value       = leaseOrder.modelName;
                leaseOrders.Rows[lastRow].Cells["Leveringsdato"].Value = leaseOrder.startDate.ToString("yyyy/MM/dd");
                leaseOrders.Rows[lastRow].Cells["Slutdato"].Value      = leaseOrder.endDate.ToString("yyyy/MM/dd");
                leaseOrders.Rows[lastRow].Cells["Dagspris"].Value      = leaseOrder.leasePrice.ToString("N2");
                leaseOrders.Rows[lastRow].Cells["Levering"].Value      = leaseOrder.deliveryPrice.ToString("N2");

                leaseOrders.Rows[lastRow].Cells["Gade"].Value     = leaseOrder.deliveryStreet;
                leaseOrders.Rows[lastRow].Cells["Postkode"].Value = leaseOrder.deliveryPostalCode.ToString();
                leaseOrders.Rows[lastRow].Cells["By"].Value       = leaseOrder.deliveryCity;
            }
        }
Ejemplo n.º 4
0
        private string UpdateLeaseOrdersOnLease(Lease lease)
        {
            string deleteLeaseOrders = $"delete from LeaseOrder where LeaseID = {lease.leaseID}";

            string isDeleteSuccess = DatabaseManager.CreateUpdateDeleteInDatabase(deleteLeaseOrders);

            if (isDeleteSuccess != "Success")
            {
                return(isDeleteSuccess);
            }

            if (lease.GetLeaseOrders().Count == 0)
            {
                return("Success");
            }

            string insertLeaseOrder = GetLeaseOrderInsertString(lease);

            string isInsertSuccess = DatabaseManager.CreateUpdateDeleteInDatabase(insertLeaseOrder);

            return(isInsertSuccess);
        }
Ejemplo n.º 5
0
        public string MakePDF(Lease lease, Business business)
        {
            // Her bruges classen pdfDocument.
            PdfDocument document = new PdfDocument();

            // Her laver jeg et pdf dokument og kalder det Faktura
            document.Info.Title = "Faktura";

            // Her laves en side
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Opret skrift størelse og sill
            XFont companyAndDebtor = new XFont("Calibri", 10, XFontStyle.Regular);
            XFont fakture          = new XFont("Calibri", 20, XFontStyle.Bold);
            XFont smallHeadLine    = new XFont("Calibri", 10, XFontStyle.Bold);
            XFont priceFat         = new XFont("Calibri", 10, XFontStyle.Bold);

            // Draw the text. Dette er hvad der skal være på teksten, og hvor det skal være. Der kan laves lige så mange som man vil
            //Kunde Oplysninger------------------------------------------------------------------------------------------------------------------------------

            gfx.DrawString($"{business.companyName}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -270, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString($"{business.street}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -260, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString($"{business.postalCode} {business.city}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -250, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString($"Kunde Nr: {lease.debtorID}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -230, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //FAKTURA---------------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("FAKTURA", fakture, XBrushes.Black,
                           new XRect(80, -170, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Billede af Delpin----------------------------------------------------------------------------------------------------------------------------
            var image = DelpinCore.Properties.Resources.Delpinlogo;

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);

            XImage xImage = XImage.FromStream(stream);

            gfx.DrawImage(xImage, 405, 35);

            //Firma informationer----------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("Nordvesthavnsvej 60 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -300, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("6400 Sønderborg ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -290, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Tlf 74 48 88 88 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -280, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //BankOplysninger------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("Bank ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -250, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Reg. Nr:9735 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -240, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Konto Nr:4571973602842330 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -230, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Fakture Nr dato og betalings dato------------------------------------------------------------------------------------------------------------
            gfx.DrawString($"Faktura Nr.{lease.leaseID} ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -180, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString($"{lease.dateCreated.ToShortDateString()} ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -170, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Headlines Resurce Antal Pris Beløb-----------------------------------------------------------------------------------------------------------
            gfx.DrawString("Vare ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -130, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString("Antal Dage ", smallHeadLine, XBrushes.Black,
                           new XRect(0, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("Daglig Lejepris ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("Levering ", smallHeadLine, XBrushes.Black,
                           new XRect(150, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("Beløb ", smallHeadLine, XBrushes.Black,
                           new XRect(-60, -130, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Navn på vare antal pris beløb-------------------------------------------------------------------------------------------------------------
            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -125, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Her oprettes en variabel som sættes til 0
            int lineSpace = 0;

            for (int i = 0; i < lease.GetLeaseOrders().Count; i++)
            {
                //Her bliver Variablen sat til 15. så hver gange der bliver kørt GetLeaseOrders(tilføjet en ny vare linje bliver der pludset 15 til y aksens position)
                lineSpace = 15 * i;

                gfx.DrawString($"{lease.GetLeaseOrders()[i].modelName}", companyAndDebtor, XBrushes.Black,
                               new XRect(80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString($"{lease.GetLeaseOrders()[i].GetDaysRented()}", companyAndDebtor, XBrushes.Black,
                               new XRect(0, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                gfx.DrawString($"Kr. {lease.GetLeaseOrders()[i].leasePrice} ", companyAndDebtor, XBrushes.Black,
                               new XRect(80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                gfx.DrawString($"Kr. {lease.GetLeaseOrders()[i].deliveryPrice}", companyAndDebtor, XBrushes.Black,
                               new XRect(150, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                gfx.DrawString($"Kr. {lease.GetLeaseOrders()[i].GetTotalPrice()}", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);
            }

            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -100 + lineSpace, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Hvis det er erhvers person
            if (business.CVR.Length == 8)
            {
                gfx.DrawString("Total: ", priceFat, XBrushes.Black,
                               new XRect(400, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString($"Kr. {lease.GetTotalPrice()} ", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                               new XRect(400, -15 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            //Hvis det er Privat person
            else
            {
                gfx.DrawString("Netto: ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Moms (25%): ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Total: ", priceFat, XBrushes.Black,
                               new XRect(400, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString($"Kr. {lease.GetTotalPrice()} ", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString($"Kr. {Moms(lease.GetTotalPrice())} ", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString($"Kr. {endPrice(Moms(lease.GetTotalPrice()), lease.GetTotalPrice())} ", priceFat, XBrushes.Black,
                               new XRect(-60, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                               new XRect(400, 15 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            //Her Laves navnet på filen
            string filename = $"Faktura{lease.leaseID}.pdf";

            try
            {
                //Dette er til at gemme pdf
                document.Save(filename);
            }
            catch (Exception)
            {
                return("Filen kan ikke gemmes");
            }

            //Dette er til at vise PDF
            Process.Start(filename);
            return("Success");
        }