public PdfPTable ArchiveSpin4(PdfPTable table, int deptID, string subdept, string dates, bool type)
        {
            List<test> all = new List<test>();
            PdfPCell cell = new PdfPCell();
            PdfPCell cell2 = new PdfPCell();
            PdfPCell cellName = new PdfPCell();
            PdfPCell cellMonday = new PdfPCell();
            PdfPCell cellTuesday = new PdfPCell();
            PdfPCell cellWednesday = new PdfPCell();
            PdfPCell cellThursday = new PdfPCell();
            PdfPCell cellfriday = new PdfPCell();
            PdfPCell cellsaturday = new PdfPCell();
            PdfPCell cellsunday = new PdfPCell();
            Array[] list = { };

            iTextSharp.text.Font georgia = FontFactory.GetFont("georgia", 14f);
            georgia.Color = iTextSharp.text.BaseColor.BLUE;
            iTextSharp.text.Font labels = FontFactory.GetFont("georgia", 14f);
            labels.Color = iTextSharp.text.BaseColor.WHITE;
            iTextSharp.text.Font Headers = FontFactory.GetFont("georgia", 18f);
            Headers.Color = iTextSharp.text.BaseColor.BLACK;
            List<test> concat = new List<test>();

            PdfPTable table2 = new PdfPTable(24);
            table.TotalWidth = 5000f;

            float[] widths = new float[] { 1300f, 1300, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f, 1300f };
            table.SetWidths(widths);
            DateTime week2 = Convert.ToDateTime(dates).AddDays(-7);
            DateTime week3 = Convert.ToDateTime(dates).AddDays(-14);
            DateTime week4 = Convert.ToDateTime(dates).AddDays(-21);
            DateTime week1 = Convert.ToDateTime(dates);
            List<test> listWeek1 = new List<test>();
            List<test> listWeek2 = new List<test>();
            List<test> listWeek3 = new List<test>();
            List<test> listWeek4 = new List<test>();
             List<test> potato = new List<test>();
            //  var init = Convert.ToInt32(deptID.ToString());
            int count = -7;
            
            for (int i = 0; i < 3; i++)
            {

                using (Anviz_Data_BaseEntities_test_jose dc = new Anviz_Data_BaseEntities_test_jose())
                {
                    //   all = (from e in dc).ToList();
                    if (type == true)
                    {
                        listWeek1 = (from e in dc.sp_matrix_weekdays(deptID, (week1.ToString("MM-dd-yyyy"))) select new test { Nombre = e.name, FechaEntradaMonday = e.Hora_de_LLegada_Lunes, FechaSalidaMonday = e.Hora_de_salida_Lunes, HorasMonday = e.Monday, FechaEntradaTuesday = e.Hora_de_LLegada_Martes, FechaSalidaTuesday = e.Hora_de_salida_Martes, HorasTuesday = e.Tuesday, FechaEntradaWendnsday = e.Hora_de_LLegada_Miercoles, FechaSalidaWendnsday = e.Hora_de_salida_Miercoles, HorasWendnsday = e.Wednsday, FechaEntradaThursday = e.Hora_de_LLegada_Jueves, FechaSalidaThursday = e.Hora_de_salida_Jueves, HorasThursday = e.Thursday, FechaEntradaFriday = e.Hora_de_LLegada_Viernes, FechaSalidaFriday = e.Hora_de_salida_Viernes, HorasFriday = e.Friday, FechaEntradaSaturday = e.Hora_de_LLegada_Sabado, FechaSalidaSaturday = e.Hora_de_salida_Sabado, HorasSaturday = e.Saturday, FechaEntradaSunday = e.Hora_de_LLegada_Domingo, FechaSalidaSunday = e.Hora_de_salida_Domingo, HorasSunday = e.Sunday }).ToList();
                        listWeek2 = (from e in dc.sp_matrix_weekdays(deptID, (week2.ToString("MM-dd-yyyy"))) select new test { Nombre = e.name, FechaEntradaMonday = e.Hora_de_LLegada_Lunes, FechaSalidaMonday = e.Hora_de_salida_Lunes, HorasMonday = e.Monday, FechaEntradaTuesday = e.Hora_de_LLegada_Martes, FechaSalidaTuesday = e.Hora_de_salida_Martes, HorasTuesday = e.Tuesday, FechaEntradaWendnsday = e.Hora_de_LLegada_Miercoles, FechaSalidaWendnsday = e.Hora_de_salida_Miercoles, HorasWendnsday = e.Wednsday, FechaEntradaThursday = e.Hora_de_LLegada_Jueves, FechaSalidaThursday = e.Hora_de_salida_Jueves, HorasThursday = e.Thursday, FechaEntradaFriday = e.Hora_de_LLegada_Viernes, FechaSalidaFriday = e.Hora_de_salida_Viernes, HorasFriday = e.Friday, FechaEntradaSaturday = e.Hora_de_LLegada_Sabado, FechaSalidaSaturday = e.Hora_de_salida_Sabado, HorasSaturday = e.Saturday, FechaEntradaSunday = e.Hora_de_LLegada_Domingo, FechaSalidaSunday = e.Hora_de_salida_Domingo, HorasSunday = e.Sunday }).ToList();
                        listWeek3 = (from e in dc.sp_matrix_weekdays(deptID, (week3.ToString("MM-dd-yyyy"))) select new test { Nombre = e.name, FechaEntradaMonday = e.Hora_de_LLegada_Lunes, FechaSalidaMonday = e.Hora_de_salida_Lunes, HorasMonday = e.Monday, FechaEntradaTuesday = e.Hora_de_LLegada_Martes, FechaSalidaTuesday = e.Hora_de_salida_Martes, HorasTuesday = e.Tuesday, FechaEntradaWendnsday = e.Hora_de_LLegada_Miercoles, FechaSalidaWendnsday = e.Hora_de_salida_Miercoles, HorasWendnsday = e.Wednsday, FechaEntradaThursday = e.Hora_de_LLegada_Jueves, FechaSalidaThursday = e.Hora_de_salida_Jueves, HorasThursday = e.Thursday, FechaEntradaFriday = e.Hora_de_LLegada_Viernes, FechaSalidaFriday = e.Hora_de_salida_Viernes, HorasFriday = e.Friday, FechaEntradaSaturday = e.Hora_de_LLegada_Sabado, FechaSalidaSaturday = e.Hora_de_salida_Sabado, HorasSaturday = e.Saturday, FechaEntradaSunday = e.Hora_de_LLegada_Domingo, FechaSalidaSunday = e.Hora_de_salida_Domingo, HorasSunday = e.Sunday }).ToList();
                        listWeek4 = (from e in dc.sp_matrix_weekdays(deptID, (week4.ToString("MM-dd-yyyy"))) select new test { Nombre = e.name, FechaEntradaMonday = e.Hora_de_LLegada_Lunes, FechaSalidaMonday = e.Hora_de_salida_Lunes, HorasMonday = e.Monday, FechaEntradaTuesday = e.Hora_de_LLegada_Martes, FechaSalidaTuesday = e.Hora_de_salida_Martes, HorasTuesday = e.Tuesday, FechaEntradaWendnsday = e.Hora_de_LLegada_Miercoles, FechaSalidaWendnsday = e.Hora_de_salida_Miercoles, HorasWendnsday = e.Wednsday, FechaEntradaThursday = e.Hora_de_LLegada_Jueves, FechaSalidaThursday = e.Hora_de_salida_Jueves, HorasThursday = e.Thursday, FechaEntradaFriday = e.Hora_de_LLegada_Viernes, FechaSalidaFriday = e.Hora_de_salida_Viernes, HorasFriday = e.Friday, FechaEntradaSaturday = e.Hora_de_LLegada_Sabado, FechaSalidaSaturday = e.Hora_de_salida_Sabado, HorasSaturday = e.Saturday, FechaEntradaSunday = e.Hora_de_LLegada_Domingo, FechaSalidaSunday = e.Hora_de_salida_Domingo, HorasSunday = e.Sunday }).ToList();
                        var y = week2.Year;
                        var Lr3 = listWeek1.Concat(listWeek2).Concat(listWeek3).Concat(listWeek4).ToList();

                        if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0) && DateTime.Today.Month==3)
                        {
                            DateTime week5 = Convert.ToDateTime(dates).AddDays(-28);
                            List<test> listWeek5 = (from e in dc.sp_matrix_weekdays(deptID, (week5.ToString("MM-dd-yyyy"))) select new test { Nombre = e.name, FechaEntradaMonday = e.Hora_de_LLegada_Lunes, FechaSalidaMonday = e.Hora_de_salida_Lunes, HorasMonday = e.Monday, FechaEntradaTuesday = e.Hora_de_LLegada_Martes, FechaSalidaTuesday = e.Hora_de_salida_Martes, HorasTuesday = e.Tuesday, FechaEntradaWendnsday = e.Hora_de_LLegada_Miercoles, FechaSalidaWendnsday = e.Hora_de_salida_Miercoles, HorasWendnsday = e.Wednsday, FechaEntradaThursday = e.Hora_de_LLegada_Jueves, FechaSalidaThursday = e.Hora_de_salida_Jueves, HorasThursday = e.Thursday, FechaEntradaFriday = e.Hora_de_LLegada_Viernes, FechaSalidaFriday = e.Hora_de_salida_Viernes, HorasFriday = e.Friday, FechaEntradaSaturday = e.Hora_de_LLegada_Sabado, FechaSalidaSaturday = e.Hora_de_salida_Sabado, HorasSaturday = e.Saturday, FechaEntradaSunday = e.Hora_de_LLegada_Domingo, FechaSalidaSunday = e.Hora_de_salida_Domingo, HorasSunday = e.Sunday }).ToList();
                            Lr3 = Lr3.Concat(listWeek5).ToList();
                        }


                                 foreach (var row in Lr3)
                                 {
                                     int index = potato.FindIndex(a => a.Nombre == row.Nombre);
                                     if (!(index >= 0))
                                     {
                                         potato.Add(row);

                                     }
                                     else
                                     {
                                         var tomato = potato[index];
                                         decimal? tempHoursi = (row.HorasMonday.Equals(null) ? 0:row.HorasMonday);
                                         decimal? tempHoursi2 =(row.HorasTuesday.Equals(null) ? 0:row.HorasTuesday) ;
                                         decimal? tempHoursi3 = (row.HorasWendnsday.Equals(null) ? 0 : row.HorasWendnsday);
                                         decimal? tempHoursi4 = (row.HorasThursday.Equals(null) ? 0:row.HorasThursday);
                                         decimal? tempHoursi5 = (row.HorasFriday.Equals(null) ? 0:row.HorasFriday);
                                         decimal? tempHoursi6 = (row.HorasSaturday.Equals(null) ? 0:row.HorasSaturday);
                                         decimal? tempHoursi7 = (row.HorasSunday.Equals(null) ? 0:row.HorasSunday);


                                         decimal? tempHours2 = (tomato.HorasMonday.Equals(null) ?0:tomato.HorasMonday) + tempHoursi;
                                         decimal? tempHours3 = (tomato.HorasTuesday.Equals(null) ?0:tomato.HorasTuesday)+ tempHoursi2;
                                         decimal? tempHours4 = (tomato.HorasWendnsday.Equals(null) ?0:tomato.HorasWendnsday) + tempHoursi3;
                                         decimal? tempHours5 = (tomato.HorasThursday.Equals(null) ?0:tomato.HorasThursday) + tempHoursi4;
                                         decimal? tempHours6 = (tomato.HorasFriday.Equals(null) ?0:tomato.HorasFriday) + tempHoursi5;
                                         decimal? tempHours7 = (tomato.HorasSaturday.Equals(null) ?0:tomato.HorasSaturday) + tempHoursi6;
                                         decimal? tempHours8 = (tomato.HorasSunday.Equals(null) ?0:tomato.HorasSunday) + tempHoursi7;


                                         tomato.HorasMonday = tempHours2;
                                         tomato.HorasTuesday = tempHours3;
                                          tomato.HorasWendnsday = tempHours4;
                                         tomato.HorasThursday = tempHours5;
                                         tomato.HorasFriday = tempHours6;
                                         tomato.HorasSaturday = tempHours7;
                                         tomato.HorasSunday = tempHours8;

                                         potato[index] = tomato;
                                     }


                                     all = potato;

                                 }
                
                        //    WorkingHoursPerDay = (from i in dc.sp_GetWorkingHoursPerDay(1, Convert.ToDateTime("08-13-2015").AddDays(w)) select new WorkingPerDay { Name = i.Name, HourInput = i.horaEntrada, HourOutput = i.horasalida, workingHours = Convert.ToInt32(i.horaTrabajada) }).ToList();
                        //     list[w] = WorkingHoursPerDay.ToList().ToArray();
                    }/*
                    else
                    {
                        all = (from e in dc.GetEmployes(deptID, dates) select new test { Nombre = e.name, FechaEntradaMonday = e.Hora_de_LLegada_Lunes, FechaSalidaMonday = e.Hora_de_salida_Lunes, HorasMonday = e.Monday, FechaEntradaTuesday = e.Hora_de_LLegada_Martes, FechaSalidaTuesday = e.Hora_de_salida_Martes, HorasTuesday = e.Tuesday, FechaEntradaWendnsday = e.Hora_de_LLegada_Miercoles, FechaSalidaWendnsday = e.Hora_de_salida_Miercoles, HorasWendnsday = e.Wednsday, FechaEntradaThursday = e.Hora_de_LLegada_Jueves, FechaSalidaThursday = e.Hora_de_salida_Jueves, HorasThursday = e.Thursday, FechaEntradaFriday = e.Hora_de_LLegada_Viernes, FechaSalidaFriday = e.Hora_de_salida_Viernes, HorasFriday = e.Friday, FechaEntradaSaturday = e.Hora_de_LLegada_Sabado, FechaSalidaSaturday = e.Hora_de_salida_Sabado, HorasSaturday = e.Saturday, FechaEntradaSunday = e.Hora_de_LLegada_Domingo, FechaSalidaSunday = e.Hora_de_salida_Domingo, HorasSunday = e.Sunday }).ToList();

                    }*/
            
                }
               
                DateTime datee = Convert.ToDateTime(dates);
                DateTime back = Convert.ToDateTime(datee.AddDays(-count));
                count = count - 7;
                dates = back.ToString();
           
            }

            DateTime date = Convert.ToDateTime(dates);

            //PdfPCell june = new PdfPCell(new Phrase("Cell 2",georgia));


            cell2 = new PdfPCell(new Phrase(subdept, Headers));
            cell2.HorizontalAlignment = Element.ALIGN_CENTER;
            cell2.BackgroundColor = new iTextSharp.text.BaseColor(245, 92, 24);
            cell2.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            cell2.Colspan = 24;
            table.AddCell(cell2);




            PdfPCell nombre = new PdfPCell(new Phrase("Name", labels));
            nombre.BackgroundColor = new iTextSharp.text.BaseColor(89, 89, 89);
            nombre.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            nombre.BorderWidthRight = 1;
            nombre.Rowspan = 2;
            nombre.Colspan = 2;
            nombre.HorizontalAlignment = 1;
            nombre.VerticalAlignment = 1;
            table.AddCell(nombre);

            PdfPCell june = new PdfPCell(new Phrase("Monday  " + "\n"));
            june.BorderWidthRight = 1;
            june.HorizontalAlignment = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.Colspan = 3;
            table.AddCell(june);
            june = new PdfPCell(new Phrase("Tuesday  " + "\n" ));
            june.BorderWidthRight = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.HorizontalAlignment = 1;
            june.Colspan = 3;
            table.AddCell(june);
            june = new PdfPCell(new Phrase("Wednesday  " + "\n"  ));
            june.BorderWidthRight = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.HorizontalAlignment = 1;
            june.Colspan = 3;
            table.AddCell(june);
            june = new PdfPCell(new Phrase("Thursday  " + "\n" ));
            june.BorderWidthRight = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.HorizontalAlignment = 1;
            june.Colspan = 3;
            table.AddCell(june);

            june = new PdfPCell(new Phrase("Friday   " + "\n" ));
            june.BorderWidthRight = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.HorizontalAlignment = 1;
            june.Colspan = 3;
            table.AddCell(june);


            june = new PdfPCell(new Phrase("Saturday  " + "\n" ));
            june.BorderWidthRight = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.HorizontalAlignment = 1;
            june.Colspan = 3;
            table.AddCell(june);
            june = new PdfPCell(new Phrase("Sunday   " + "\n" ));
            june.BorderWidthRight = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(247, 150, 70);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            june.HorizontalAlignment = 1;
            june.Colspan = 3;
            table.AddCell(june);

            june = new PdfPCell(new Phrase("Monthly Hours Worked", labels));
            june.BorderWidthRight = 1;
            june.Rowspan = 2;
            june.HorizontalAlignment = 1;
            june.BackgroundColor = new iTextSharp.text.BaseColor(89, 89, 89);
            june.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
            table.AddCell(june);




            PdfPCell In = new PdfPCell();
            PdfPCell OUT = new PdfPCell();
            PdfPCell second = new PdfPCell();

            for (var y = 0; y <= 6; y++)
            {
               
                second = new PdfPCell(new Phrase("Worked Hours", labels));
                second.BackgroundColor = new iTextSharp.text.BaseColor(89, 89, 89);
                second.BorderColor = new iTextSharp.text.BaseColor(0, 0, 0);
                second.BorderWidthRight = 1;
                second.HorizontalAlignment = 1;
                second.Colspan = 3;
                table.AddCell(second);


            }
        
            foreach (var item in all)
            {

                
                cellName.Phrase = new Phrase(item.Nombre);
                cellName.HorizontalAlignment = 1;
                cellName.Colspan = 2;
                cellName.BorderWidthRight = 1;
                table.AddCell(cellName);

                cellMonday = new PdfPCell(new Phrase((item.HorasMonday).ToString()));
                cellMonday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellMonday.BorderWidthRight = 1;
                cellMonday.HorizontalAlignment = 1;
                cellMonday.Colspan = 3;
                table.AddCell(cellMonday);


                cellTuesday = new PdfPCell(new Phrase((item.HorasTuesday).ToString()));
                cellTuesday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellTuesday.BorderWidthRight = 1;
                cellTuesday.HorizontalAlignment = 1;
                cellTuesday.Colspan = 3;
                table.AddCell(cellTuesday);

                cellWednesday = new PdfPCell(new Phrase((item.HorasWendnsday).ToString()));
                cellWednesday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellWednesday.BorderWidthRight = 1;
                cellWednesday.HorizontalAlignment = 1;
                cellWednesday.Colspan = 3;
                table.AddCell(cellWednesday);


                cellThursday = new PdfPCell(new Phrase((item.HorasThursday).ToString()));
                cellThursday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellThursday.BorderWidthRight = 1;
                cellThursday.HorizontalAlignment = 1;
                cellThursday.Colspan = 3;
                table.AddCell(cellThursday);

                cellfriday = new PdfPCell(new Phrase((item.HorasFriday).ToString()));
                cellfriday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellfriday.BorderWidthRight = 1;
                cellfriday.HorizontalAlignment = 1;
                cellfriday.Colspan = 3;
                table.AddCell(cellfriday);

                
                cellsaturday = new PdfPCell(new Phrase((item.HorasSaturday).ToString()));
                cellsaturday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellsaturday.BorderWidthRight = 1;
                cellsaturday.HorizontalAlignment = 1;
                cellsaturday.Colspan = 3;
                table.AddCell(cellsaturday);

                cellsunday = new PdfPCell(new Phrase((item.HorasSunday).ToString()));
                cellsunday.BackgroundColor = new iTextSharp.text.BaseColor(242, 242, 242);
                cellsunday.BorderWidthRight = 1;
                cellsunday.HorizontalAlignment = 1;
                cellsunday.Colspan = 3;
                table.AddCell(cellsunday);

                cell.Phrase = new Phrase(Convert.ToString(Convert.ToDecimal(item.HorasMonday) + Convert.ToDecimal(item.HorasTuesday) + Convert.ToDecimal(item.HorasWendnsday) + Convert.ToDecimal(item.HorasThursday) + Convert.ToDecimal(item.HorasFriday) + Convert.ToDecimal(item.HorasSaturday) + Convert.ToDecimal(item.HorasSunday)));
                cell.HorizontalAlignment = 1;

                table.AddCell(cell);

                //table.Rows.Add(cell);
                //                 

            }



            return table;
        }
Exemple #2
0
        /// <summary>
        /// Tries to find the PdfPCell's width, before rendering
        /// </summary>
        /// <param name="cell">pdf cell</param>
        /// <returns>its estimated width</returns>
        public static float GetCellWidth(this PdfPCell cell)
        {
            if (cell == null) return 0;

            var rulesWidth = new List<float>();
            var startWidth = cell.PaddingLeft + cell.PaddingRight + 1 + cell.BorderWidth;
            var cellWidth = startWidth;

            var compositeElements = cell.CompositeElements;
            if (compositeElements == null)
            {
                if (cell.Image != null)
                {
                    cellWidth += cell.Image.Width;
                }

                if (cell.Phrase != null)
                {
                    cellWidth += GetPhraseWidth(cell.Phrase);
                }

                if (cell.Table != null)
                {
                    cellWidth += cell.Table.TotalWidth;
                }

                return cellWidth;
            }

            foreach (var baseLevel in compositeElements)
            {
                if (baseLevel is Phrase)
                {
                    cellWidth += GetPhraseWidth((Phrase)baseLevel);
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth;
                }
                else if (baseLevel is List)
                {
                    cellWidth = getListWidth(rulesWidth, startWidth, cellWidth, baseLevel);
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth;
                }
                else if (baseLevel is PdfGrid)
                {
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth + ((PdfGrid)baseLevel).TotalWidth;
                    rulesWidth.Add(cellWidth);
                    cellWidth = startWidth;
                }
            }

            return rulesWidth.Concat(new[] { cellWidth }).Max();
        }