Example #1
0
        public string CreatePDF(string type = "", string file = "", BackgroundWorker bw = null, bool fileOverride = false)
        {
            try
            {
                string datoStr = (autoMode) ? datoStr = appConfig.dbTo.ToString("yyy-MM-dd") : pickerRankingDate.Value.ToString("yyy-MM-dd");
                string sourceFiles = "";
                string destinationFile = "";
                string graphStr1 = settingsPath + @"\rankingGrafOversikt.html";
                string graphStr2 = settingsPath + @"\rankingGrafButikk.html";
                string graphStr2b = settingsPath + @"\rankingGrafKnowHow.html";
                string graphStr3 = settingsPath + @"\rankingGrafData.html";
                string graphStr4 = settingsPath + @"\rankingGrafNettbrett.html";
                string graphStr5 = settingsPath + @"\rankingGrafAudioVideo.html";
                string graphStr6 = settingsPath + @"\rankingGrafTele.html";
                string newHash = appConfig.Avdeling + pickerRankingDate.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString();
                string newHashBudget = appConfig.Avdeling + pickerRankingDate.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString();
                string newHashStore = appConfig.Avdeling + pickerLagerDato.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString();
                string newHashService = appConfig.Avdeling + pickerServiceDato.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString();

                Log.n("Klargjør filer for konvertering..");
                processing.SetText = "Klargjør filer for konvertering..";

                if (!String.IsNullOrEmpty(type))
                {
                    if (type == "Vinnprodukter")
                    {
                        if (appConfig.pdfVisVinnprodukter)
                        {
                            BuildVinnRanking(true);
                            appConfig.strVinnprodukter = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                        }
                    }
                    else if (type == "FullBudget")
                    {
                        if (appConfig.budgetShowMda)
                        {
                            BuildBudget(BudgetCategory.MDA, appConfig.strBudgetMda, htmlBudgetMda);
                            appConfig.strBudgetMda = newHashBudget;
                            if (File.Exists(htmlBudgetMda))
                                sourceFiles += " \"" + settingsPath + "\\budsjettMda.html\" ";
                        }
                        else if (appConfig.budgetShowAudioVideo)
                        {
                            BuildBudget(BudgetCategory.AudioVideo, appConfig.strBudgetAv, htmlBudgetAudioVideo);
                            appConfig.strBudgetAv = newHashBudget;
                            if (File.Exists(htmlBudgetAudioVideo))
                                sourceFiles += " \"" + settingsPath + "\\budsjettAudioVideo.html\" ";
                        }
                        else if (appConfig.budgetShowSda)
                        {
                            BuildBudget(BudgetCategory.SDA, appConfig.strBudgetSda, htmlBudgetSda);
                            appConfig.strBudgetSda = newHashBudget;
                            if (File.Exists(htmlBudgetSda))
                                sourceFiles += " \"" + settingsPath + "\\budsjettSda.html\" ";
                        }
                        else if (appConfig.budgetShowTele)
                        {
                            BuildBudget(BudgetCategory.Tele, appConfig.strBudgetTele, htmlBudgetTele);
                            appConfig.strBudgetTele = newHashBudget;
                            if (File.Exists(htmlBudgetTele))
                                sourceFiles += " \"" + settingsPath + "\\budsjettTele.html\" ";
                        }
                        else if (appConfig.budgetShowData)
                        {
                            BuildBudget(BudgetCategory.Data, appConfig.strBudgetData, htmlBudgetData);
                            appConfig.strBudgetData = newHashBudget;
                            if (File.Exists(htmlBudgetData))
                                sourceFiles += " \"" + settingsPath + "\\budsjettData.html\" ";
                        }
                        else if (appConfig.budgetShowCross)
                        {
                            BuildBudget(BudgetCategory.Cross, appConfig.strBudgetCross, htmlBudgetCross);
                            appConfig.strBudgetCross = newHashBudget;
                            if (File.Exists(htmlBudgetCross))
                                sourceFiles += " \"" + settingsPath + "\\budsjettCross.html\" ";
                        }
                        else if (appConfig.budgetShowKasse)
                        {
                            BuildBudget(BudgetCategory.Kasse, appConfig.strBudgetKasse, htmlBudgetKasse);
                            appConfig.strBudgetKasse = newHashBudget;
                            if (File.Exists(htmlBudgetKasse))
                                sourceFiles += " \"" + settingsPath + "\\budsjettKasse.html\" ";
                        }
                        else if (appConfig.budgetShowAftersales)
                        {
                            BuildBudget(BudgetCategory.Aftersales, appConfig.strBudgetAftersales, htmlBudgetAftersales);
                            appConfig.strBudgetAftersales = newHashBudget;
                            if (File.Exists(htmlBudgetAftersales))
                                sourceFiles += " \"" + settingsPath + "\\budsjettAftersales.html\" ";
                        }
                        else if (appConfig.budgetShowMdasda)
                        {
                            BuildBudget(BudgetCategory.MDASDA, appConfig.strBudgetMdasda, htmlBudgetMdasda);
                            appConfig.strBudgetMdasda = newHashBudget;
                            if (File.Exists(htmlBudgetMdasda))
                                sourceFiles += " \"" + settingsPath + "\\budsjettMdaSda.html\" ";
                        }
                        if (String.IsNullOrEmpty(sourceFiles))
                        {
                            Log.n("Ingen budsjett er klar til eksportering til PDF. Opprett nye budsjett og/eller sjekk over budsjett innstillinger.", Color.Red);
                            return "";
                        }
                    }
                    else if (type == "KnowHow")
                    {
                        if (appConfig.pdfVisKnowHow)
                        {
                            BuildKnowHowRanking(true);
                            appConfig.strKnowHow = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingKnowHow.html\" ";
                            if (appConfig.graphKnowHow && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("KnowHow", true, bw);
                                sourceFiles += " \"" + graphStr2b + "\" ";
                            }
                        }
                        if (appConfig.pdfVisVinnprodukter)
                        {
                            BuildVinnRanking(true);
                            appConfig.strVinnprodukter = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                        }
                    }
                    else if (type == "Computer")
                    {
                        if (appConfig.pdfVisData)
                        {
                            BuildDataRanking(true, bw);
                            appConfig.strData = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingData.html\" ";
                            if (appConfig.graphData && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("Data", true, bw);
                                sourceFiles += " \"" + graphStr3 + "\" ";
                                ViewGraph("Nettbrett", true, bw);
                                sourceFiles += " \"" + graphStr4 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisVinnprodukter)
                        {
                            BuildVinnRanking(true);
                            appConfig.strVinnprodukter = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                        }
                    }
                    else if (type == "AudioVideo")
                    {
                        if (appConfig.pdfVisAudioVideo)
                        {
                            BuildAudioVideoRanking(true, bw);
                            appConfig.strAudioVideo = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingAudioVideo.html\" ";
                            if (appConfig.graphAudioVideo && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("AudioVideo", true, bw);
                                sourceFiles += " \"" + graphStr5 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisVinnprodukter)
                        {
                            BuildVinnRanking(true);
                            appConfig.strVinnprodukter = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                        }
                    }
                    else if (type == "Telecom")
                    {
                        if (appConfig.pdfVisTele)
                        {
                            BuildTeleRanking(true, bw);
                            appConfig.strTele = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingTele.html\" ";
                            if (appConfig.graphTele && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("Tele", true, bw);
                                sourceFiles += " \"" + graphStr6 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisVinnprodukter)
                        {
                            BuildVinnRanking(true);
                            appConfig.strVinnprodukter = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                        }
                    }
                    else if (type == "Cross")
                    {
                        if (appConfig.pdfVisKnowHow)
                        {
                            BuildKnowHowRanking(true);
                            appConfig.strKnowHow = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingKnowHow.html\" ";
                            if (appConfig.graphKnowHow && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("KnowHow", true, bw);
                                sourceFiles += " \"" + graphStr2b + "\" ";
                            }
                        }
                        if (appConfig.pdfVisData)
                        {
                            BuildDataRanking(true, bw);
                            appConfig.strData = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingData.html\" ";
                            if (appConfig.graphData && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("Data", true, bw);
                                sourceFiles += " \"" + graphStr3 + "\" ";
                                ViewGraph("Nettbrett", true, bw);
                                sourceFiles += " \"" + graphStr4 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisAudioVideo)
                        {
                            BuildAudioVideoRanking(true, bw);
                            appConfig.strAudioVideo = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingAudioVideo.html\" ";
                            if (appConfig.graphAudioVideo && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("AudioVideo", true, bw);
                                sourceFiles += " \"" + graphStr5 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisTele)
                        {
                            BuildTeleRanking(true, bw);
                            appConfig.strTele = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingTele.html\" ";
                            if (appConfig.graphTele && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("Tele", true, bw);
                                sourceFiles += " \"" + graphStr6 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisVinnprodukter)
                        {
                            BuildVinnRanking(true);
                            appConfig.strVinnprodukter = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                        }
                    }
                    else if (type == "Lister")
                    {
                        if (appConfig.pdfVisLister)
                        {
                            BuildListerRanking(true);
                            appConfig.strLister = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingLister.html\" ";
                        }
                    }
                    else if (type == "Full" || type == "FullUkestart")
                    {
                        if (appConfig.importSetting.StartsWith("Full"))
                        {
                            if (appConfig.pdfVisToppselgere)
                            {
                                BuildToppselgereRanking(true);
                                appConfig.strToppselgere = newHash;
                                sourceFiles += " \"" + settingsPath + "\\rankingToppselgere.html\" ";
                            }
                            if (appConfig.pdfVisOversikt && appConfig.importSetting.StartsWith("Full"))
                            {
                                BuildOversiktRanking(true, bw);
                                appConfig.strOversikt = newHash;
                                sourceFiles += " \"" + settingsPath + "\\rankingOversikt.html\" ";
                                if (appConfig.pdfExpandedGraphs && appConfig.graphOversikt && File.Exists(graphStr1))
                                {
                                    ViewGraph("Oversikt", true, bw);
                                    sourceFiles += " \"" + graphStr1 + "\" ";
                                }
                            }
                        }
                        if (appConfig.pdfVisButikk)
                        {
                            BuildButikkRanking(true, bw);
                            appConfig.strButikk = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingButikk.html\" ";
                            if (appConfig.pdfExpandedGraphs && appConfig.graphButikk)
                            {
                                ViewGraph("Butikk", true, bw);
                                sourceFiles += " \"" + graphStr2 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisKnowHow)
                        {
                            BuildKnowHowRanking(true);
                            appConfig.strKnowHow = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingKnowHow.html\" ";
                            if (appConfig.graphKnowHow && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("KnowHow", true, bw);
                                sourceFiles += " \"" + graphStr2b + "\" ";
                            }
                        }
                        if (appConfig.pdfVisData)
                        {
                            BuildDataRanking(true, bw);
                            appConfig.strData = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingData.html\" ";
                            if (appConfig.graphData && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("Data", true, bw);
                                sourceFiles += " \"" + graphStr3 + "\" ";
                                ViewGraph("Nettbrett", true, bw);
                                sourceFiles += " \"" + graphStr4 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisAudioVideo)
                        {
                            BuildAudioVideoRanking(true, bw);
                            appConfig.strAudioVideo = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingAudioVideo.html\" ";
                            if (appConfig.graphAudioVideo && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("AudioVideo", true, bw);
                                sourceFiles += " \"" + graphStr5 + "\" ";
                            }
                        }
                        if (appConfig.pdfVisTele)
                        {
                            BuildTeleRanking(true, bw);
                            appConfig.strTele = newHash;
                            sourceFiles += " \"" + settingsPath + "\\rankingTele.html\" ";
                            if (appConfig.graphTele && appConfig.pdfExpandedGraphs)
                            {
                                ViewGraph("Tele", true, bw);
                                sourceFiles += " \"" + graphStr6 + "\" ";
                            }
                        }
                        if (appConfig.importSetting.StartsWith("Full"))
                        {
                            if (appConfig.pdfVisLister)
                            {
                                BuildListerRanking(true);
                                appConfig.strLister = newHash;
                                sourceFiles += " \"" + settingsPath + "\\rankingLister.html\" ";
                            }
                            if (appConfig.pdfVisVinnprodukter)
                            {
                                BuildVinnRanking(true);
                                appConfig.strVinnprodukter = newHash;
                                sourceFiles += " \"" + settingsPath + "\\rankingVinnprodukter.html\" ";
                            }
                            if (appConfig.pdfVisTjenester)
                            {
                                BuildAvdTjenester(true);
                                appConfig.strTjenester = newHash;
                                sourceFiles += " \"" + settingsPath + "\\rankingAvdTjenester.html\" ";
                            }
                            if (appConfig.pdfVisSnittpriser)
                            {
                                BuildAvdSnittpriser(true);
                                appConfig.strSnittpriser = newHash;
                                sourceFiles += " \"" + settingsPath + "\\rankingAvdSnittpriser.html\" ";
                            }
                        }
                        if (!EmptyStoreDatabase())
                        {
                            if (appConfig.pdfVisObsolete)
                            {
                                BuildStoreStatus(true);
                                appConfig.strObsolete = newHashStore;
                                sourceFiles += " \"" + htmlStoreObsolete + "\" ";
                            }
                            if (appConfig.pdfVisObsoleteList)
                            {
                                BuildStoreObsoleteList(true);
                                appConfig.strObsoleteList = newHashStore;
                                sourceFiles += " \"" + htmlStoreObsoleteList + "\" ";
                            }
                            if (appConfig.pdfVisWeekly)
                            {
                                PageStoreWeekly page = new PageStoreWeekly(this, true, bw, webStore);
                                page.BuildPage_Overview("", appConfig.strLagerWeeklyOverview, htmlStoreWeeklyOverview, pickerLagerDato.Value);
                                appConfig.strLagerWeeklyOverview = newHashStore;
                                sourceFiles += " \"" + htmlStoreWeeklyOverview + "\" ";
                            }
                            if (appConfig.pdfVisPrisguide)
                            {
                                PageStorePrisguide page = new PageStorePrisguide(this, true, bw, webStore);
                                page.BuildPage_Overview("", appConfig.strLagerPrisguideOverview, htmlStorePrisguideOverview, pickerLagerDato.Value);
                                appConfig.strLagerPrisguideOverview = newHashStore;
                                sourceFiles += " \"" + htmlStorePrisguideOverview + "\" ";
                            }
                        }
                        if (appConfig.pdfVisService && service.dbServiceDatoFra.Date != service.dbServiceDatoTil.Date)
                        {
                            MakeServiceOversikt(true, bw);
                            appConfig.strServiceOversikt = newHashService;
                            sourceFiles += " \"" + htmlServiceOversikt + "\" ";
                        }
                    }
                    destinationFile = "\"" + System.IO.Path.GetTempPath() + "TjenesteRanking " + type + " " + appConfig.Avdeling + " " + datoStr + ".pdf\"";
                }
                else if (!String.IsNullOrEmpty(file))
                {
                    sourceFiles = file;
                    destinationFile = "\"" + settingsTemp + "\\KGSA " + appConfig.Avdeling + " " + currentPage() + " " + datoStr + ".pdf\"";
                }

                if (destinationFile != null)
                    filenamePDF = destinationFile.Substring(1, destinationFile.Length - 2);
                else
                {
                    Log.n("Feil oppstod under generering av PDF: Ingen destinasjon valgt.", Color.Red);
                    return "";
                }

                if (String.IsNullOrEmpty(sourceFiles))
                {
                    Log.n("Error: Har ikke data fra alle kategoriene til å lage en fullstendig rapport.", Color.Red);
                    return ""; // mangler filer
                }

                Log.n("Konverterer til PDF..");
                processing.SetText = "Konvertere til PDF..";

                if (fileOverride && filenamePDF.Length > 3)
                {
                    try
                    {
                        if (File.Exists(filenamePDF))
                            File.Delete(filenamePDF);
                    }
                    catch
                    {
                        Log.d("PDF (" + filenamePDF + ") er låst. Endrer filnavn..");
                        if (destinationFile.Length > 3)
                        {
                            Random r = new Random();
                            destinationFile = destinationFile.Substring(0, filenamePDF.Length - 3) + " " + r.Next(99) + ".pdf\"";
                            filenamePDF = destinationFile.Substring(1, destinationFile.Length - 2);
                        }
                    }
                }

                string options = " -B 15 -L 7 -R 7 -T 7 --zoom " + appConfig.pdfZoom + " ";
                if (type == "Full" && appConfig.pdfTableOfContent)
                    options = " --title \"KGSA Tjenesteranking " + datoStr + "\" -B 20 -L 7 -R 7 -T 7 --zoom " + appConfig.pdfZoom + " toc --toc-header-text \"KGSA Tjenesteranking " + datoStr + "\" --toc-header-text \" Innhold - KGSA Tjenesteranking\" ";

                if (appConfig.pdfLandscape)
                    options += "-O landscape ";

                Log.d("PDF generator: wkhtmltopdf " + options + sourceFiles + destinationFile);

                var wkhtmltopdf = new ProcessStartInfo();
                wkhtmltopdf.WindowStyle = ProcessWindowStyle.Hidden;
                wkhtmltopdf.FileName = filePDFwkhtmltopdf;
                wkhtmltopdf.Arguments = options + sourceFiles + destinationFile;
                wkhtmltopdf.WorkingDirectory = settingsPath;
                wkhtmltopdf.CreateNoWindow = true;
                wkhtmltopdf.UseShellExecute = false;

                Process D = Process.Start(wkhtmltopdf);

                D.WaitForExit(20000);

                if (!D.HasExited)
                {
                    Log.n("Error: PDF generatoren ble tidsavbrutt.", Color.Red);
                    return "";
                }

                int result = D.ExitCode;
                if (result != 0)
                {
                    Log.n("Error: PDF generator returnerte med feilkode " + result, Color.Red);
                    return "";
                }

                return filenamePDF;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                return "";
            }
        }
Example #2
0
 public void MakeStore(string katArg, bool bg = false, BackgroundWorker bw = null)
 {
     string newHash = appConfig.Avdeling + pickerLagerDato.Value.ToString() + RetrieveLinkerTimestamp().ToShortDateString();
     if (katArg == "Obsolete")
     {
         BuildStoreStatus();
         appConfig.strObsolete = newHash;
     }
     else if (katArg == "ObsoleteList")
     {
         BuildStoreObsoleteList();
         appConfig.strObsoleteList = newHash;
     }
     else if (katArg == "ObsoleteImports")
     {
         BuildStoreObsoleteImports();
         appConfig.strObsoleteImports = newHash;
     }
     else if (katArg.Equals("LagerUkeAnnonser"))
     {
         PageStoreWeekly page = new PageStoreWeekly(this, bg, bw, webStore);
         page.BuildPage_Report(katArg, appConfig.strLagerWeekly, htmlStoreWeekly, pickerLagerDato.Value);
         appConfig.strLagerWeekly = newHash;
     }
     else if (katArg.Equals("LagerUkeAnnonserOversikt"))
     {
         PageStoreWeekly page = new PageStoreWeekly(this, bg, bw, webStore);
         page.BuildPage_Overview(katArg, appConfig.strLagerWeeklyOverview, htmlStoreWeeklyOverview, pickerLagerDato.Value);
         appConfig.strLagerWeeklyOverview = newHash;
     }
     else if (katArg.Equals("LagerPrisguide"))
     {
         PageStorePrisguide page = new PageStorePrisguide(this, bg, bw, webStore);
         page.BuildPage_Report(katArg, appConfig.strLagerPrisguide, htmlStorePrisguide, pickerLagerDato.Value);
         appConfig.strLagerPrisguide = newHash;
     }
     else if (katArg.Equals("LagerPrisguideOversikt"))
     {
         PageStorePrisguide page = new PageStorePrisguide(this, bg, bw, webStore);
         page.BuildPage_Overview(katArg, appConfig.strLagerPrisguideOverview, htmlStorePrisguideOverview, pickerLagerDato.Value);
         appConfig.strLagerPrisguideOverview = newHash;
     }
     else
         Log.n("Ingen kategori valgt.");
 }