コード例 #1
0
ファイル: ElementsWidth.cs プロジェクト: VahidN/PdfReport
        /// <summary>
        /// Tries to auto resize the specified table columns.
        /// </summary>
        /// <param name="table">pdf table</param>
        public static void AutoResizeTableColumns(this PdfGrid table)
        {
            if (table == null) return;
            var currentRowWidthsList = new List<float>();
            var previousRowWidthsList = new List<float>();

            foreach (var row in table.Rows)
            {
                currentRowWidthsList.Clear();
                currentRowWidthsList.AddRange(row.GetCells().Select(cell => cell.GetCellWidth()));

                if (!previousRowWidthsList.Any())
                {
                    previousRowWidthsList = new List<float>(currentRowWidthsList);
                }
                else
                {
                    for (int i = 0; i < previousRowWidthsList.Count; i++)
                    {
                        if (previousRowWidthsList[i] < currentRowWidthsList[i])
                            previousRowWidthsList[i] = currentRowWidthsList[i];
                    }
                }
            }

            if (previousRowWidthsList.Any())
                table.SetTotalWidth(previousRowWidthsList.ToArray());
        }
コード例 #2
0
ファイル: ReportesController.cs プロジェクト: ligues/isar_dev
        // GET: Tablero
        public ActionResult Tablero(string lvl, int? areaId)
        {
            ApplicationUser usuario = (ApplicationUser)db.Users.FirstOrDefault(item => item.UserName == User.Identity.Name);
            int periodId = (int)Session["SelectedPeriod"];
            Periodo period = db.Periodos.Find(periodId);
            int nivel;
            Area area;

            if (lvl == null)
            {
                nivel = usuario.UsuarioArea.Nivel.ID;
            }
            else
            {
                nivel = int.Parse(lvl);
            }
            // Area
            if (areaId == null)
            {
                if (usuario.TienePermiso(1)) // Administrador
                {
                    area = db.Areas.First();
                }
                else
                {
                    area = usuario.UsuarioArea;
                }
                areaId = area.ID;
            }
            else
            {
                area = db.Areas.FirstOrDefault(item => item.ID == areaId);
            }
            ViewBag.CurrentArea = area;
            // Areas
            if (usuario.TieneNivel(1) || usuario.TienePermiso(1))
            {
                ViewBag.Areas = db.Areas.Where(item => item.Nivel.ID == nivel).ToList();
            }
            else if (usuario.TieneNivel(2))
            {
                if (nivel == 2)
                {
                    ViewBag.Areas = db.Areas.Where(item => item.ID == usuario.UsuarioArea.ID).ToList();
                }
                else if (nivel == 3)
                {
                    List<Area> Areas = new List<Area>();
                    List<int> areasId = new List<int>();

                    Areas = db.Areas.Where(item => item.Nivel.ID == nivel && item.AreaPadre.ID == usuario.UsuarioArea.ID).ToList();
                    areasId = (from a in Areas
                               select a.ID).ToList();
                    Areas.AddRange(db.Areas.Where(item => item.Nivel.ID == nivel && areasId.Any(p => item.AreaPadre.ID == p)).ToList());
                    areasId = (from a in Areas
                               select a.ID).ToList();
                    Areas.AddRange(db.Areas.Where(item => item.Nivel.ID == nivel && areasId.Any(p => item.AreaPadre.ID == p)).ToList());
                    ViewBag.Areas = Areas.Distinct().OrderBy(item => item.ID);
                }
            }
            else if (usuario.TienePermiso(6))
            {
                List<Area> Areas = new List<Area>();

                Areas.Add(usuario.UsuarioArea);
                Areas.AddRange(usuario.UsuarioArea.AreasHijas.ToList());
                ViewBag.Areas = Areas.OrderBy(item => item.AreaPadre.ID);
            }
            lvl = nivel.ToString();
            ViewBag.usuario = usuario;
            ViewBag.Nivel = lvl;
            ViewBag.PeriodoSeleccionado = period;

               /* int _nivel = 3;

            if (usuario.TieneNivel(1))
            {
                _nivel = 1;
            }

            if (usuario.TieneNivel(2))
            {
                _nivel = 2;
            }

            if (usuario.TieneNivel(3))
            {
                _nivel = 3;
            }*/

            List<NivelOrganizacional> Niveles = new List<NivelOrganizacional>();

            NivelOrganizacional Nivel_01 = db.NivelesOrganizacionales.Find(1);
            Niveles.Add(Nivel_01);
            NivelOrganizacional Nivel_02 = db.NivelesOrganizacionales.Find(2);
            Niveles.Add(Nivel_02);
            NivelOrganizacional Nivel_03 = db.NivelesOrganizacionales.Find(3);
            Niveles.Add(Nivel_03);
            ViewBag.Niveles = Niveles;

            //if (usuario.TieneNivel(1) || usuario.TienePermiso(1))
            //{
            //    return View(db.Indicadores.Where(item => item.Tipo.Nivel.ID == nivel && item.Periodos.Any(p => p.ID == periodId)).ToList());
            //}
            //if ((usuario.TieneNivel(2) && nivel == 2) || (usuario.TieneNivel(3) && nivel == 3))
            //{
            //    return View(db.Indicadores.Where(item => item.Tipo.Nivel.ID == nivel && item.Area.ID == usuario.UsuarioArea.ID && item.Periodos.Any(p => p.ID == periodId)).ToList());
            //}
            //if ((usuario.TieneNivel(3) && usuario.TienePermiso(8) && nivel == 2) || (usuario.TieneNivel(2) && usuario.TienePermiso(5) && nivel == 1))
            //{
            //    return View(db.Indicadores.Where(item => item.Tipo.Nivel.ID == nivel && item.Area.ID == usuario.UsuarioArea.AreaPadre.ID && item.Periodos.Any(p => p.ID == periodId)).ToList());
            //}
            return View(db.Indicadores.Where(item => item.Area.ID == areaId && item.Periodos.Any(p => p.ID == periodId)).ToList());
        }
コード例 #3
0
ファイル: ReportesController.cs プロジェクト: ligues/isar_dev
        // GET: Proyectos
        public ActionResult Proyectos(int? areaId, int? tipoId)
        {
            ApplicationUser usuario = (ApplicationUser)db.Users.FirstOrDefault(item => item.UserName == User.Identity.Name);
            int periodId = (int)Session["SelectedPeriod"];
            Periodo period = db.Periodos.Find(periodId);
            Area area;
            TipoProyecto tipo;

            if (areaId == null)
            {
                if (usuario.TienePermiso(26) && usuario.TieneNivel(2))
                {
                    area = db.Areas.Where(item => item.Nivel.ID == 3 && item.AreaPadre.ID == usuario.UsuarioArea.ID).First();
                }
                if (usuario.TienePermiso(1) || (usuario.TienePermiso(26) && (usuario.TieneNivel(1)))) // Administrador y Presidente
                {
                    area = db.Areas.Where(item => item.Nivel.ID == 3).First();
                }
                else if (usuario.TieneNivel(3) && usuario.TienePermiso(6))
                {
                    area = usuario.UsuarioArea;
                }
                else
                {
                    area = usuario.UsuarioArea;
                }
                areaId = area.ID;
            }
            else
            {
                area = db.Areas.Where(item => item.Nivel.ID == 3).FirstOrDefault(item => item.ID == areaId);
            }
            if (tipoId == null)
            {
                tipo = db.TipoProyecto.FirstOrDefault();
                tipoId = tipo.ID;
            }
            else
            {
                tipo = db.TipoProyecto.Find(tipoId);
            }
            ViewBag.CurrentTipo = tipo;
            ViewBag.CurrentArea = area;
            if (usuario.TienePermiso(26) && usuario.TieneNivel(2))
            {
                List<Area> Areas = new List<Area>();
                List<int> areasId = new List<int>();

                Areas = db.Areas.Where(item => item.Nivel.ID == 3 && item.AreaPadre.ID == usuario.UsuarioArea.ID).ToList();
                areasId = (from a in Areas
                           select a.ID).ToList();
                Areas.AddRange(db.Areas.Where(item => item.Nivel.ID == 3 && areasId.Any(p => item.AreaPadre.ID == p)).ToList());
                areasId = (from a in Areas
                           select a.ID).ToList();
                Areas.AddRange(db.Areas.Where(item => item.Nivel.ID == 3 && areasId.Any(p => item.AreaPadre.ID == p)).ToList());
                ViewBag.Areas = Areas.Distinct().OrderBy(item => item.ID);
            }
            if (usuario.TienePermiso(1) || (usuario.TienePermiso(26) && (usuario.TieneNivel(1)))) // Administrador y Presidente
            {
                ViewBag.Areas = db.Areas.Where(item => item.Nivel.ID == 3).ToList();
            }
            if (usuario.TienePermiso(6) && usuario.TieneNivel(3))
            {
                List<Area> Areas = new List<Area>();

                Areas.Add(usuario.UsuarioArea);
                Areas.AddRange(usuario.UsuarioArea.AreasHijas.ToList());
                ViewBag.Areas = Areas.OrderBy(item => item.AreaPadre.ID);
            }
            ViewBag.Tipos = db.TipoProyecto.ToList();
            ViewBag.usuario = usuario;
            ViewBag.PeriodoSeleccionado = period;
            return View(db.Proyectos.Where(item => item.Tipo.ID == tipoId && item.Area.ID == areaId && item.Periodos.Any(p => p.ID == periodId)).ToList());
        }
コード例 #4
0
        private PdfPCell AddDogDetails(Dogs d, List<DogClasses> dcList, Color altColor, bool topBorder )
        {
            Paragraph p = new Paragraph();
            Phrase ph = new Phrase();
            ph.Add(new Chunk(d.KCName, normalFont));
            ph.Add(Chunk.NEWLINE);
            var doginfo = d.KCNumber;
            if (!string.IsNullOrEmpty(d.DoB))
            {
                doginfo += ",";
                doginfo += d.DoB;
            }
            ph.Add(new Chunk(doginfo, normalFont));
            ph.Add(Chunk.NEWLINE);
            doginfo = d.Breed;
            if (doginfo.Length > 0) doginfo += ",";
            doginfo += "Grade " + Dogs.GetDogGrade(d.Grade);
            ph.Add(new Chunk(doginfo, normalFont));
            ph.Add(Chunk.NEWLINE);
            doginfo = "";
            doginfo += Dogs.GetDogHeight(d.Height);
            doginfo += ",";
            doginfo += Dogs.GetDogSexType(d.Sex);
            if (dcList.Any() && dcList.First().Lho == 1)
            {
                doginfo += ",LHO";
            }

            ph.Add(new Chunk(doginfo, normalFont));
            ph.Add(Chunk.NEWLINE);
            var cell = new PdfPCell(ph);
            cell.BorderWidth = 0;
            cell.BackgroundColor = altColor;
            if (topBorder)
            {
                cell.BorderColorTop = Color.BLACK;
                cell.BorderWidthTop = 1;
            }

            return cell;
        }
コード例 #5
0
 private void ScoreBoardColumnHeaders(ShowClasses showClass, PdfPTable callingListTbl, List<CallingListDto> callingList, float[] colWidths)
 {
     if (TeamPairsManager.isMultiDog(showClass.EntryType))
     {
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerHFont))) { BorderWidth = 0 });
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Team Name", headerHFont)))
         {
             BorderWidth = 0,
             Colspan = 2
         });
     }
     else
     {
         if (showClass.Lho == 1 || showClass.Lho == 2)
         {
             if (callingList.Any())
             {
                 var item = callingList.First();
                 var cnt = callingList.Count(x => x.Lho == item.Lho);
                 var title = $"{(item.Lho == 0 ? "Full Height " : "Lower Height")} ({cnt})";
                 callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont)))
                 {
                     BorderWidth = 0,
                     Colspan = colWidths.Length,
                     BackgroundColor = Color.LIGHT_GRAY,
                     HorizontalAlignment = Element.ALIGN_CENTER,
                     FixedHeight = 20,
                     BorderColorBottom = Color.BLACK,
                     BorderWidthBottom = 2
                 });
             }
             else
             {
                 var title = $"Dont Know (9999)";
                 callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont)))
                 {
                     BorderWidth = 0,
                     Colspan = colWidths.Length,
                     BackgroundColor = Color.LIGHT_GRAY,
                     HorizontalAlignment = Element.ALIGN_CENTER,
                     FixedHeight = 20,
                     BorderColorBottom = Color.BLACK,
                     BorderWidthBottom = 2
                 });
             }
         }
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerHFont))) { BorderWidth = 0 });
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Ring No", headerHFont))) {BorderWidth = 0});
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Handler", headerHFont))) { BorderWidth = 0 });
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Dog Name", headerHFont))) { BorderWidth = 0 });
     }
     callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Clears", headerHFont))) { BorderWidth = 0 });
     callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Faults", headerHFont))) { BorderWidth = 0 });
     callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Time", headerHFont))) { BorderWidth = 0 });
 }
コード例 #6
0
        private void BuildPDF(Dictionary<string, ISPage> pageMap, string baseRoom, Dictionary<string, int> chapterPageMap, bool fakeRun)
        {
            if (fakeRun)
            {
                ISPageHtmlParser.BuildAllISPages(pageMap, baseRoom, filePath).Wait();
            }
            //now that we have all the pages, we'll have to clean them up and decide on pages

            Dictionary<string, int> ISPageToPhysicalPageMap = new Dictionary<string, int>();

            int currentPage = 1;
            int currentChapter = 1;
            Random r = new Random(123456);
            List<string> pagesLeft = new List<string>(pageMap.Count);
            foreach (string x in pageMap.Keys)
            {
                pagesLeft.Add(x);
            }

            using (MemoryStream memStream = new MemoryStream())
            {
                Document pdfDoc = new Document();
                iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, memStream);
                HeaderFooter evnt = new HeaderFooter();
                if (fakeRun)
                {
                    evnt.pageByTitle = chapterPageMap;
                }
                else
                {
                    evnt.pageByTitle = new Dictionary<string, int>();
                }
                if (!fakeRun)
                {
                    writer.PageEvent = evnt;
                }

                pdfDoc.Open();
                pdfDoc.AddAuthor("test");
                pdfDoc.AddTitle("testTitle");

                while (pagesLeft.Any())
                {

                    string pageToAdd = pagesLeft.First();
                    if (currentPage > 1)
                    {
                        pagesLeft.Skip(r.Next(pagesLeft.Count)).First();
                    }
                    pagesLeft.Remove(pageToAdd);

                    if (fakeRun)
                    {
                        chapterPageMap.Add(pageToAdd, writer.PageNumber + 1);
                    }

                    ISPageToPhysicalPageMap.Add(pageToAdd, currentPage);

                    var chapter = GetPDFPage(pageMap[pageToAdd], int.Parse(pageToAdd), chapterPageMap);
                    pdfDoc.Add(chapter);

                    int actualPageLength = fakeRun ? 1 : chapterPageMap[pageToAdd];

                    currentPage += actualPageLength;
                    currentChapter++;
                }

                pdfDoc.Close();
                writer.Close();

                if (!fakeRun)
                {
                    File.WriteAllBytes(Path.Combine(filePath, fileName), memStream.GetBuffer());
                }
            }
        }
コード例 #7
0
ファイル: Parser.cs プロジェクト: kamalm87/WebScaleFileManage
 private Dictionary<string,object> CreateBookMark(KeyValuePair<string,BookMark> bookMark)
 {
     var bm = new Dictionary<string, object>();
     bm["Action"] = "GoTo";
     bm["Title"] = bookMark.Key;
     bm["Page"] = string.Format("{0} XYZ 0 0 0", bookMark.Value.Page);
     if(bookMark.Value.Children != null)
     {
         List<Dictionary<string, object>> kids = new List<Dictionary<string, object>>();
         foreach(var kvp in bookMark.Value.Children)
         {
             kids.Add(CreateBookMark(kvp));
         }
         if (kids.Any())
         {
             bm["children"] = kids;
         }
     }
     return bm;
 }
コード例 #8
0
 public String demographicfield(int fieldID,int pollID,String [] items)
 {
     var result = "";
     var poll = pollRepository.GetPollByID(pollID);
     List<string> values = new List<string>();
     IList<ParticipantFieldValue> valued = participantRepository.GetParticipantFieldByID(fieldID).fieldValues.Where(valu => (!valu.value.Equals(""))).ToList();
     if (poll.isGroup) valued = valued.Where(v => v.groupd != null).ToList();
     else valued = valued.Where(v => v.participant != null).ToList();
     values = (from v in valued select v.value).Distinct().ToList();
     bool num = true;
     int number;
     if (values.Any(v => (!int.TryParse(v, out number)))) num = false;
     if (num == false)
     {
         values.Sort((x, y) => string.Compare(x, y));
         foreach (String value in values)
         {
             if (items != null && items.Contains(value))
                 result = result + "<label><input type=\"checkbox\" name=\"items\" checked=\"yes\" value=\"" + value + "\"/>" + value + "</label><br />";
             else result = result + "<label><input type=\"checkbox\" name=\"items\" value=\"" + value + "\"/>" + value + "</label><br />";
         }
     }
     else
     {
         List<int> intvalues = values.ConvertAll<int>(delegate(String i) { return int.Parse(i); });
         intvalues.Sort();
         foreach (int value in intvalues)
         {
             if (items != null && items.Contains(value.ToString()))
                 result = result + "<label><input type=\"checkbox\" name=\"items\" checked=\"yes\" value=\"" + value + "\"/>" + value + "</label><br />";
             else result = result + "<label><input type=\"checkbox\" name=\"items\" value=\"" + value + "\"/>" + value + "</label><br />";
         }
     }
     return result;
 }