Beispiel #1
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            SelectPdf.GlobalProperties.LicenseKey = "xu335vTz9+b19PL05vf+6Pbm9ffo9/To/////w== ";
            TTfileDict.Clear();
            sqlite_conn = SqLite.OpenSQLLiteConnection(sqlite_conn);
            sqlite_cmd  = sqlite_conn.CreateCommand();
            string commandstring = "SELECT * FROM BALLOTDETAILS  WHERE BALLOTID = " + BallotWindow.BallotId + " ORDER BY CANDIDATESLNO";

            sqlite_cmd.CommandText = commandstring;
            SQLiteDataReader oReader = sqlite_cmd.ExecuteReader();

            while (oReader.Read())
            {
                if (string.IsNullOrEmpty(oReader["CANDIDATEPHOTO"].ToString()))
                {
                    TTfileDict.Add(Convert.ToInt32(oReader["DETAILBALLOTID"]),
                                   new CandidateRecord()
                    {
                        BallotID         = Convert.ToInt32(oReader["BALLOTID"].ToString()),
                        CandidateNO      = Convert.ToInt32(oReader["CANDIDATESLNO"]),
                        CandidateNameENG = oReader["CANDIDATENAMEENG"].ToString(),
                        CandidateNameOL  = oReader["CANDIDATENAMEOL"].ToString(),
                        PartyNameENG     = oReader["PARTYAFFILIATIONENG"].ToString(),
                        PartyNameOL      = oReader["PARTYAFFILIATIONOL"].ToString(),
                        CandidatePhoto   = new byte[1],
                        ISNOTA           = Convert.ToInt32(oReader["ISNOTA"]),
                    });
                }

                else
                {
                    TTfileDict.Add(Convert.ToInt32(oReader["DETAILBALLOTID"]),
                                   new CandidateRecord()
                    {
                        BallotID         = Convert.ToInt32(oReader["BALLOTID"].ToString()),
                        CandidateNO      = Convert.ToInt32(oReader["CANDIDATESLNO"]),
                        CandidateNameENG = oReader["CANDIDATENAMEENG"].ToString(),
                        CandidateNameOL  = oReader["CANDIDATENAMEOL"].ToString(),
                        PartyNameENG     = oReader["PARTYAFFILIATIONENG"].ToString(),
                        PartyNameOL      = oReader["PARTYAFFILIATIONOL"].ToString(),
                        CandidatePhoto   = (byte[])oReader["CANDIDATEPHOTO"],
                        // CandidatePhoto = Convert.ToBase64String(oReader["CANDIDATEPHOTO"] as byte[]),
                        ISNOTA = Convert.ToInt32(oReader["ISNOTA"]),
                    });
                }
            }

            oReader.Close();
            sqlite_cmd.Dispose();
            SqLite.CloseSQLLiteConnection(sqlite_conn);

            if (TTfileDict.Values.Count == 0)
            {
                MessageBox.Show("No Candidate  Record Found...");

                return;
            }
            string str = "";
            List <CandidateRecord> candidateLists = new List <CandidateRecord>();

            candidateLists.Clear();
            foreach (KeyValuePair <int, CandidateRecord> candidate in TTfileDict)
            {
                candidateLists.Add(candidate.Value);
            }


            ballotCandidateList.Candidate = candidateLists;

            string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;
            string exeDir  = System.IO.Path.GetDirectoryName(exeFile);

            string Directorypath = Directory.GetCurrentDirectory() + "\\images";

            string base64String1 = ConvertImage(Directorypath + "\\eci-logo.png");
            string Imagesrc      = "data:image/jpg;base64," + base64String1;


            string base64String2 = null;
            string Imagesrc2     = null;

            //string Bordername = null;
            // var TemplateInstance=
            if (BallotWindow.strConstType == "Parliamentary")
            {
                base64String2 = ConvertImage(Directorypath + "\\PC.PNG");
                Imagesrc2     = "data:image/jpg;base64," + base64String2;
                BallotTemplatePC TemplateInstance = new BallotTemplatePC
                {
                    Session = new Dictionary <string, object>()
                };
                TemplateInstance.Session.Add("TTfileDict", ballotCandidateList);
                TemplateInstance.Session.Add("Imagesrc", Imagesrc);
                TemplateInstance.Session.Add("Imagesrc2", Imagesrc2);
                TemplateInstance.Session.Add("FontFamily", BallotWindow.selectedfont);
                TemplateInstance.Initialize();
                str = TemplateInstance.TransformText();
                // Bordername = "PC.PNG";
            }
            else
            {
                base64String2 = ConvertImage(Directorypath + "\\AC.PNG");
                Imagesrc2     = "data:image/jpg;base64," + base64String2;
                BallotTemplateAC TemplateInstanceAC = new BallotTemplateAC
                {
                    Session = new Dictionary <string, object>()
                };
                TemplateInstanceAC.Session.Add("TTfileDict", ballotCandidateList);
                TemplateInstanceAC.Session.Add("Imagesrc", Imagesrc);
                TemplateInstanceAC.Session.Add("Imagesrc2", Imagesrc2);
                TemplateInstanceAC.Session.Add("FontFamily", BallotWindow.selectedfont);
                TemplateInstanceAC.Initialize();
                str = TemplateInstanceAC.TransformText();
                // Bordername = "AC.PNG";
            }

            // ConvertHtmlToImage(str);



            /////////////////////////////////////////////////////////////////////////////////////////
            // Intentionally blank page tt file code
            string str1 = "";
            IntentionallyBlankPage TemplateInstance1 = new IntentionallyBlankPage();

            //TemplateInstance1.Session = new Dictionary<string, object>();
            //TemplateInstance1.Session.Add(Imagesrc, Imagesrc);
            //TemplateInstance1.Initialize();
            str1 = TemplateInstance1.TransformText();
            //////////////////////////////////////////////////////////////////////////////////////


            HtmlToPdf converter = new HtmlToPdf();
            string    fullPath  = System.IO.Path.Combine(exeDir, "..\\..\\HtmlEngine\\Select.Html.dep");
            string    filepath  = System.IO.Path.GetFileName(fullPath);

            GlobalProperties.HtmlEngineFullPath = filepath;
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(str);

            SelectPdf.PdfDocument doc1    = converter.ConvertHtmlString(str1);
            SelectPdf.PdfPage     pdfPage = doc1.Pages[0];
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                if (i % 2 == 1)
                {
                    doc.InsertPage(i, pdfPage);
                }
            }


            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                DefaultExt       = "pdf",
                Filter           = "Pdf File|*.pdf",
                Title            = "Save Ballot",
                FileName         = "Ballot",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            };


            if (saveFileDialog.ShowDialog() == true)
            {
                doc.Save(saveFileDialog.FileName);
                doc.Close();
                MessageBox.Show("File Saved...");
            }
            else
            {
                MessageBox.Show("File Not Saved...");
            }
        }
Beispiel #2
0
        //Select.PDF.Core - deprecated (for this program) due to cost restraints
        public SelectPdf.PdfDocument ConvertToPdf(ArrayList translationInput, int caseNumber, int evidenceNumber)
        {
            SelectPdf.PdfDocument doc   = new SelectPdf.PdfDocument();
            SelectPdf.PdfPage     page  = doc.AddPage();
            SelectPdf.PdfPage     page2 = doc.AddPage();
            SelectPdf.PdfPage     page3 = doc.AddPage();

            PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);

            font.Size = 15;

            PdfRenderingResult result;

            PdfTextElement text = new PdfTextElement(50, 50, "Cipher Translations", font);

            result = page.Add(text);

            int i = 0;

            foreach (string str in translationInput)    //if statements are a temporary code that would be changed with a paid subscription for Select.PDF
            {
                i++;
                PdfTextElement elem;// = new PdfTextElement(0, result.PdfPageLastRectangle.Bottom + 30, i + ": " + str, font);
                if (i <= 10)
                {
                    elem   = new PdfTextElement(0, result.PdfPageLastRectangle.Bottom + 30, i + ": " + str, font);
                    result = page.Add(elem);
                }
                else if (i <= 20)
                {
                    if (i == 11)
                    {
                        result = page2.Add(text);
                    }
                    elem   = new PdfTextElement(0, result.PdfPageLastRectangle.Bottom + 30, i + ": " + str, font);
                    result = page2.Add(elem);
                }
                else if (i < 30)
                {
                    if (i == 21)
                    {
                        result = page3.Add(text);
                    }
                    elem   = new PdfTextElement(0, result.PdfPageLastRectangle.Bottom + 30, i + ": " + str, font);
                    result = page3.Add(elem);
                }
            }
            string name = "CsNum" + caseNumber + ".EviNum" + evidenceNumber + ".pdf";

            doc.Save(name);
            //string pathToSave = @"src\CipherStoreTemp";
            //FileStream stream = System.IO.File.Create(pathToSave);
            doc.Close();

            return(doc);

            //Additional features Below

            //// instantiate a html to pdf converter object
            //HtmlToPdf converter = new HtmlToPdf();

            //// create a new pdf document converting an url
            //PdfDocument doc = converter.ConvertUrl(TxtUrl.Text);

            //// get conversion result (contains document info from the web page)
            //HtmlToPdfResult result = converter.ConversionResult;

            //// set the document properties
            //doc.DocumentInformation.Title = result.WebPageInformation.Title;
            //doc.DocumentInformation.Subject = result.WebPageInformation.Description;
            //doc.DocumentInformation.Keywords = result.WebPageInformation.Keywords;

            //doc.DocumentInformation.Author = "Select.Pdf Samples";
            //doc.DocumentInformation.CreationDate = DateTime.Now;

            //// save pdf document
            //doc.Save(Response, false, "Sample.pdf");

            //// close pdf document
            //doc.Close();
        }