コード例 #1
0
        public static response ExportDosarToPdfWithPdfForm(byte[] template_file_content, Models.Dosar dosar)
        {
            try
            {
                MemoryStream     ms         = new MemoryStream(template_file_content);
                string           fileName   = dosar.NR_DOSAR_CASCO.Replace('/', '_').Replace(' ', '_') + "_cerere.pdf";
                FileStream       fs         = File.Open(Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), FileMode.Create, FileAccess.ReadWrite);
                PdfFixedDocument poDocument = new PdfFixedDocument(ms);

                Models.SocietateAsigurare sCasco = (Models.SocietateAsigurare)dosar.GetSocietateCasco().Result;
                Models.SocietateAsigurare sRca   = (Models.SocietateAsigurare)dosar.GetSocietateRca().Result;
                Models.Asigurat           aCasco = (Models.Asigurat)dosar.GetAsiguratCasco().Result;
                Models.Asigurat           aRca   = (Models.Asigurat)dosar.GetAsiguratRca().Result;
                Models.Auto autoCasco            = (Models.Auto)dosar.GetAutoCasco().Result;
                Models.Auto autoRca = (Models.Auto)dosar.GetAutoRca().Result;

                poDocument.Form.Fields["FieldSocietateCasco"].Value           = sCasco.DENUMIRE;
                poDocument.Form.Fields["FieldAdresaSocietateCasco"].Value     = sCasco.ADRESA;
                poDocument.Form.Fields["FieldCUISocietateCasco"].Value        = sCasco.CUI;
                poDocument.Form.Fields["FieldContBancarSocietateCasco"].Value = sCasco.IBAN;
                poDocument.Form.Fields["FieldBancaSocietateCasco"].Value      = sCasco.BANCA;
                poDocument.Form.Fields["FieldSocietateRCA"].Value             = sRca.DENUMIRE;
                poDocument.Form.Fields["FieldAdresaSocietateRCA"].Value       = sRca.ADRESA;
                poDocument.Form.Fields["FieldNrDosarCasco"].Value             = dosar.NR_DOSAR_CASCO;
                poDocument.Form.Fields["FieldPolitaRCA"].Value     = dosar.NR_POLITA_RCA;
                poDocument.Form.Fields["FieldPolitaCasco"].Value   = dosar.NR_POLITA_CASCO;
                poDocument.Form.Fields["FieldAsiguratCasco"].Value = aCasco.DENUMIRE;
                poDocument.Form.Fields["FieldAsiguratRCA"].Value   = aRca.DENUMIRE;
                poDocument.Form.Fields["FieldNrAutoCasco"].Value   = autoCasco.NR_AUTO;
                poDocument.Form.Fields["FieldAutoCasco"].Value     = autoCasco.MARCA + " " + autoCasco.MODEL;
                poDocument.Form.Fields["FieldNrAutoRCA"].Value     = autoRca.NR_AUTO;
                poDocument.Form.Fields["FieldDataEveniment"].Value = Convert.ToDateTime(dosar.DATA_EVENIMENT).ToString("dd/MM/yyyy");
                poDocument.Form.Fields["FieldSuma"].Value          = dosar.VALOARE_DAUNA.ToString();

                string docs = "";
                Models.DocumentScanat[] dsj = (Models.DocumentScanat[])dosar.GetDocumente().Result;
                foreach (Models.DocumentScanat doc in dsj)
                {
                    docs = String.Format("- {1}\r\n{0}", docs, (doc.DETALII != "" && doc.DETALII != null ? doc.DETALII : doc.DENUMIRE_FISIER));
                }
                poDocument.Form.Fields["FieldDocumente"].Value = docs;

                poDocument.Form.FlattenFields();

                poDocument.Save(fs);
                fs.Flush();
                fs.Dispose();
                string toReturn = Path.Combine(CommonFunctions.GetPdfsFolder(), fileName);
                return(new response(true, toReturn, toReturn, null, null));
            }
            catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.Message, null, null, new System.Collections.Generic.List <Error>()
                {
                    new Error(exp)
                })); }
        }
コード例 #2
0
        //public static PdfFlowTextContent GeneratePdfContent(List<string> pdfText, Models.Dosar dosar)
        public static PdfFormattedContent GeneratePdfContent(List <string> pdfText, Models.Dosar dosar)
        {
            Models.SocietateAsigurare sCasco = (Models.SocietateAsigurare)dosar.GetSocietateCasco().Result;
            Models.SocietateAsigurare sRca   = (Models.SocietateAsigurare)dosar.GetSocietateRca().Result;
            Models.Asigurat           aCasco = (Models.Asigurat)dosar.GetAsiguratCasco().Result;
            Models.Asigurat           aRca   = (Models.Asigurat)dosar.GetAsiguratRca().Result;
            Models.Auto autoCasco            = (Models.Auto)dosar.GetAutoCasco().Result;
            Models.Auto autoRca = (Models.Auto)dosar.GetAutoRca().Result;

            Dictionary <string, string> field_names = new Dictionary <string, string>();

            field_names.Add("{{NR_SCA}}", dosar.NR_SCA == null || dosar.NR_SCA.Trim() == "" ? "_________" : dosar.NR_SCA);
            field_names.Add("{{DATA_SCA}}", dosar.DATA_SCA == null ? "____________" : Convert.ToDateTime(dosar.DATA_SCA).Year.ToString());
            field_names.Add("{{NR_DOSAR_CASCO}}", dosar.NR_DOSAR_CASCO == null || dosar.NR_DOSAR_CASCO.Trim() == "" ? "_________________" : dosar.NR_DOSAR_CASCO);
            field_names.Add("{{VALOARE_DAUNA}}", dosar.VALOARE_DAUNA.ToString().Trim() == "" ? "___________" : dosar.VALOARE_DAUNA.ToString());
            field_names.Add("{{NR_POLITA_CASCO}}", dosar.NR_POLITA_CASCO == null || dosar.NR_POLITA_CASCO.Trim() == "" ? "_________________" : dosar.NR_POLITA_CASCO);
            field_names.Add("{{NR_POLITA_RCA}}", dosar.NR_POLITA_RCA == null || dosar.NR_POLITA_RCA.Trim() == "" ? "_________________" : dosar.NR_POLITA_RCA);
            field_names.Add("{{DATA_EVENIMENT}}", dosar.DATA_EVENIMENT == null ? "___________" : Convert.ToDateTime(dosar.DATA_EVENIMENT).ToString("dd/MM/yyyy"));

            field_names.Add("{{SOCIETATE_CASCO}}", sCasco.DENUMIRE == null || sCasco.DENUMIRE.Trim() == "" ? "__________________________________" : sCasco.DENUMIRE);
            field_names.Add("{{ADRESA_SOCIETATE_CASCO}}", sCasco.ADRESA == null || sCasco.ADRESA.Trim() == "" ? "___________________________________________________" : sCasco.ADRESA);
            field_names.Add("{{NR_REG_COM_SOCIETATE_CASCO}}", sCasco.NR_REG_COM == null || sCasco.NR_REG_COM.Trim() == "" ? "_______________" : sCasco.NR_REG_COM.ToUpper());
            field_names.Add("{{CUI_SOCIETATE_CASCO}}", sCasco.CUI == null || sCasco.CUI.Trim() == "" ? "______________" : sCasco.CUI.ToUpper());
            field_names.Add("{{IBAN_SOCIETATE_CASCO}}", sCasco.IBAN == null || sCasco.IBAN.Trim() == "" ? "__________________________________________" : sCasco.IBAN.ToUpper());
            field_names.Add("{{BANCA_SOCIETATE_CASCO}}", sCasco.BANCA == null || sCasco.BANCA.Trim() == "" ? "____________________________________" : sCasco.BANCA.ToUpper());

            field_names.Add("{{SOCIETATE_RCA}}", sRca.DENUMIRE == null || sRca.DENUMIRE.Trim() == "" ? "_________________________________" : sRca.DENUMIRE);
            field_names.Add("{{ADRESA_SOCIETATE_RCA}}", sRca.ADRESA == null || sRca.ADRESA.Trim() == "" ? "___________________________________________________" : sRca.ADRESA);
            field_names.Add("{{ASIGURAT_CASCO}}", aCasco.DENUMIRE == null || aCasco.DENUMIRE.Trim() == "" ? "__________________________________" : aCasco.DENUMIRE);
            field_names.Add("{{ASIGURAT_RCA}}", aRca.DENUMIRE == null || aRca.DENUMIRE.Trim() == "" ? "__________________________________" : aRca.DENUMIRE);

            field_names.Add("{{NR_AUTO_CASCO}}", autoCasco.NR_AUTO == null || autoCasco.NR_AUTO.Trim() == "" ? "____________" : autoCasco.NR_AUTO.ToUpper());
            field_names.Add("{{MARCA_AUTO_CASCO}}", autoCasco.MARCA == null || autoCasco.MARCA.Trim() == "" ? "______________" : autoCasco.MARCA.ToUpper());
            field_names.Add("{{NR_AUTO_RCA}}", autoRca.NR_AUTO == null || autoRca.NR_AUTO.Trim() == "" ? "____________" : autoRca.NR_AUTO.ToUpper());
            field_names.Add("{{PROPRIETAR_AUTO_RCA}}", "_______________________");

            field_names.Add("{{NORMA}}", dosar.DATA_EVENIMENT < new DateTime(2015, 1, 1) ? Articole.articole[0].Ordin : dosar.DATA_EVENIMENT >= new DateTime(2015, 1, 1) && dosar.DATA_EVENIMENT <= new DateTime(2016, 12, 22) ? Articole.articole[1].Ordin : Articole.articole[2].Ordin);
            field_names.Add("{{ARTICOL_PLATA}}", dosar.DATA_EVENIMENT < new DateTime(2015, 1, 1) ? Articole.articole[0].ArticolPlata : dosar.DATA_EVENIMENT >= new DateTime(2015, 1, 1) && dosar.DATA_EVENIMENT <= new DateTime(2016, 12, 22) ? Articole.articole[1].ArticolPlata : Articole.articole[2].ArticolPlata);
            field_names.Add("{{ARTICOL_OBIECTIUNI}}", dosar.DATA_EVENIMENT < new DateTime(2015, 1, 1) ? Articole.articole[0].ArticolObiectiuni : dosar.DATA_EVENIMENT >= new DateTime(2015, 1, 1) && dosar.DATA_EVENIMENT <= new DateTime(2016, 12, 22) ? Articole.articole[1].ArticolObiectiuni : Articole.articole[2].ArticolObiectiuni);
            field_names.Add("{{TERMEN}}", dosar.DATA_EVENIMENT < new DateTime(2015, 1, 1) ? Articole.articole[0].NrZile : dosar.DATA_EVENIMENT >= new DateTime(2015, 1, 1) && dosar.DATA_EVENIMENT <= new DateTime(2016, 12, 22) ? Articole.articole[1].NrZile : Articole.articole[2].NrZile);
            field_names.Add("{{CAZ}}", dosar.CAZ == null || dosar.CAZ.Trim() == "" ? "_____" : dosar.CAZ);
            field_names.Add("{{DATA}}", DateTime.Now.ToString("dd/MM/yyyy"));


            string docs = "";

            //pentru insiruirea in opis a tuturor documentelor, negrupate pe tip

            /*
             * Models.DocumentScanat[] dsj = (Models.DocumentScanat[])dosar.GetDocumente().Result;
             * foreach (Models.DocumentScanat doc in dsj)
             * {
             *  Models.Nomenclator tip_document = (Models.Nomenclator)doc.GetTipDocument().Result;
             *  //docs = String.Format("- {1}\r\n{0}", docs, (doc.DETALII != "" && doc.DETALII != null ? doc.DETALII : doc.DENUMIRE_FISIER));
             *  docs = String.Format("- {1}\r\n{0}", docs, tip_document.DENUMIRE + " " + (doc.DETALII != "" && doc.DETALII != null ? doc.DETALII : ""));
             * }
             */
            object[] DocumenteTipuri = (object[])dosar.GetDocumenteTipuri().Result;
            foreach (object[] documentTip in DocumenteTipuri)
            {
                docs = String.Format("{0}\r\n- {1}{2}", docs, documentTip[1].ToString(), Convert.ToInt32(documentTip[2]) > 1 ? " (" + documentTip[2].ToString() + " file)" : "");
            }

            field_names.Add("{{DOCUMENTE}}", docs);


            PdfUnicodeTrueTypeFont boldFont    = new PdfUnicodeTrueTypeFont(new FileStream(Path.Combine(AppContext.BaseDirectory, "Content", "arialbold.ttf"), FileMode.Open, FileAccess.Read, FileShare.Read), 12, true);
            PdfUnicodeTrueTypeFont regularFont = new PdfUnicodeTrueTypeFont(new FileStream(Path.Combine(AppContext.BaseDirectory, "Content", "arial.ttf"), FileMode.Open, FileAccess.Read, FileShare.Read), 12, true);

            PdfFormattedContent pfc = new PdfFormattedContent();

            foreach (string s in pdfText)
            {
                PdfFormattedParagraph pfp = new PdfFormattedParagraph();
                pfp.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple;
                pfp.LineSpacing     = 1.3;
                pfp.SpacingAfter    = 15;

                if (s.IndexOf("{{NR_SCA}}") > -1)
                {
                    pfp.HorizontalAlign = PdfStringHorizontalAlign.Right;
                }
                else if (s.IndexOf("CERERE DE DESPAGUBIRE") > -1)
                {
                    pfp.HorizontalAlign = PdfStringHorizontalAlign.Center;
                }
                else
                {
                    pfp.HorizontalAlign = PdfStringHorizontalAlign.Justified;
                    if (s.IndexOf("Catre") < 0 && s.IndexOf("{{DOCUMENTE}}") < 0 && s.IndexOf("$$") < 0)
                    {
                        pfp.FirstLineIndent = 30;
                    }
                    if (s.IndexOf("{{DOCUMENTE}}") > -1 || s.IndexOf("$$") > -1)
                    {
                        pfp.LeftIndentation = 50;
                    }
                }

                List <string> splitters = new List <string>();
                foreach (KeyValuePair <string, string> field in field_names)
                {
                    if (s.IndexOf(field.Key) > -1)
                    {
                        splitters.Add(field.Key);
                    }
                }
                string[] sBlocks = null;
                if (splitters.Count > 0)
                {
                    sBlocks = s.Split(splitters.ToArray(), StringSplitOptions.None);
                }
                else
                {
                    sBlocks = new string[] { s }
                };

                int splitter_count = 0;
                for (int i = 0; i < sBlocks.Length; i++)
                {
                    try
                    {
                        PdfFormattedTextBlock b1 = new PdfFormattedTextBlock(sBlocks[i].Replace("$$", "\r\n"), sBlocks[i].IndexOf("CERERE DE DESPAGUBIRE") > -1 ? boldFont : regularFont);
                        pfp.Blocks.Add(b1);
                        string theFuckingWrightSplitter = "";
                        //if (splitter_count < splitters.Count)
                        {
                            foreach (string splitter in splitters)
                            {
                                if (s.IndexOf(sBlocks[i] + splitter) > -1)
                                {
                                    theFuckingWrightSplitter = splitter;
                                    splitter_count++;
                                    splitters.Remove(splitter);
                                    break;
                                }
                            }
                            //PdfFormattedTextBlock b2 = new PdfFormattedTextBlock(field_names[splitters[i]], boldFont);
                            PdfFormattedTextBlock b2 = new PdfFormattedTextBlock(field_names[theFuckingWrightSplitter], boldFont);
                            pfp.Blocks.Add(b2);
                        }
                    }
                    catch { }
                }
                pfc.Paragraphs.Add(pfp);
            }
            //pfc.SplitByBox(485, 742);
            //PdfFlowTextContent pftc = new PdfFlowTextContent(pfc);
            //return pftc;
            return(pfc);
        }