Example #1
0
        private static DownloadPdf getWiredUpDownloadPdf(EventHandler <LibraryBook> completedAction)
        {
            var downloadPdf = new DownloadPdf();

            downloadPdf.Begin += (_, __) => wireUpEvents(downloadPdf);

            if (completedAction != null)
            {
                downloadPdf.Completed += completedAction;
            }

            return(downloadPdf);
        }
Example #2
0
        public IActionResult CreatePDF([FromBody] DownloadPdf data)
        {
            CommonResponse commonResponse = new CommonResponse();
            var            globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
                Out           = @"D:\DMS\Employee_Report.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(data),
                WebSettings    = { DefaultEncoding = "utf -8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "Styles.css") },
                HeaderSettings = { FontName = "Georgia", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Georgia", FontSize = 9, Line = true, Center = "Shiftwise Employee Details" }
            };

            var pdf = new HtmlToPdfDocument
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            converter.Convert(pdf);
            commonResponse.isStatus = true;
            commonResponse.response = appSettings.ImageUrl + "Employee_Report.pdf";
            //var file = converter.Convert(pdf);
            //return File(file, "application/pdf","Employee.pdf");
            return(Ok(commonResponse));
        }
        public static string GetHTMLString(DownloadPdf data)
        {
            CommonFunction commonFunction = new CommonFunction();
            var            employees      = commonFunction.GetEmployeeDetails(data);

            var sb = new StringBuilder();

            sb.Append(@"
                <html>
                    <head></head>
                    <body>
                        <div class='header'><h1> Shiftwise Employee Details</h1></div>
                        <table align='center'>
                            <tr>
                                <th> Employee Name</th>
                                <th> Employee Id </th>
                                <th> Cell </th>
                                <th> SubCell </th>
                                <th> DepartMent </th>
                                <th> Designation </th>
                                <th> Shift </th>
                                <th> FromDate </th>
                                <th> ToDate </th>
                                <th> Machines </th>
                            </tr>");

            foreach (var item in employees)
            {
                //sb.AppendFormat(@"
                //<tr>
                //    <td>{0}</td>
                //    <td>{1}</td>
                //    <td>{2}</td>
                //    <td>{3}</td>
                //    <td>{4}</td>
                //    <td>{5}</td>
                //    <td>{6}</td>
                //    <td>{7}</td>
                //</tr>", item.employeeName, item.Cell, item.subCell, item.department, item.designation, item.shift, item.fromDate, item.toDate);

                sb.Append("<tr>");
                sb.Append("<td>" + item.employeeName + "</td>");
                sb.Append("<td>" + item.employeeNo + "</td>");
                sb.Append("<td>" + item.Cell + "</td>");
                sb.Append("<td>" + item.subCell + "</td>");
                sb.Append("<td>" + item.department + "</td>");
                sb.Append("<td>" + item.designation + "</td>");
                sb.Append("<td>" + item.shift + "</td>");
                sb.Append("<td>" + item.fromDate + "</td>");
                sb.Append("<td>" + item.toDate + "</td>");
                sb.Append("<td><ul>");
                foreach (var i in item.machinesList)
                {
                    sb.Append("<li>" + i.machineName + "</li>");
                }
                sb.Append("</ul></td></tr>");
            }

            sb.Append(@"
                        </table>
                        </body>
                        </html>");

            return(sb.ToString());
        }
Example #4
0
        /// <summary>
        /// Get Employee Details
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public List <OperatorDetailsShift> GetEmployeeDetails(DownloadPdf data)
        {
            DateTime FromDate = DateTime.Now;

            try
            {
                string[] dt     = data.fromDate.Split('/');
                string   frDate = dt[2] + '-' + dt[1] + '-' + dt[0];
                FromDate = Convert.ToDateTime(frDate);
            }
            catch
            {
                FromDate = Convert.ToDateTime(data.fromDate);
            }
            DateTime ToDate = DateTime.Now;

            try
            {
                string[] dt      = data.toDate.Split('/');
                string   torDate = dt[2] + '-' + dt[1] + '-' + dt[0];
                ToDate = Convert.ToDateTime(torDate);
            }
            catch
            {
                ToDate = Convert.ToDateTime(data.toDate);
            }

            List <OperatorDetailsShift> operatorDetailsShiftsList = new List <OperatorDetailsShift>();

            if (data.cellId != 0 && data.subCellId != 0 && data.departmentId != 0)
            {
                var dbChecks = db.UnitworkccsTbloperatordetails.Where(m => m.CellId == data.cellId && m.SubCellId == data.subCellId && m.DepartmentId == data.departmentId).Select(m => m.OpId).ToList();


                foreach (var i in dbChecks)
                {
                    var check = (from wf in db.UnitworkccsTblemployeeshiftdetails
                                 where wf.IsDeleted == 0 && wf.FromDate >= FromDate && wf.ToDate <= ToDate && wf.EmployeeId == i
                                 select new
                    {
                        employeeId = wf.EmployeeId,
                        fromDate = wf.FromDate,
                        toDate = wf.ToDate,
                        //shift = wf.Shift,
                        machineIds = wf.MachineIds,
                        employeeName = db.UnitworkccsTbloperatordetails.Where(m => m.OpId == wf.EmployeeId).Select(m => m.OperatorName).FirstOrDefault(),
                        cellName = db.UnitworkccsTblshop.Where(m => m.ShopId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.CellId).FirstOrDefault())).Select(m => m.ShopName).FirstOrDefault(),
                        subCellName = db.UnitworkccsTblcell.Where(m => m.CellId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.SubCellId).FirstOrDefault())).Select(m => m.CellName).FirstOrDefault(),
                        designation = db.UnitworkccsTblroles.Where(m => m.RoleId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.RoleId).FirstOrDefault())).Select(m => m.RoleName).FirstOrDefault(),
                        department = db.UnitworkccsTbldepartmentdetails.Where(m => m.DepartmentId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.DepartmentId).FirstOrDefault())).Select(m => m.DepartmentName).FirstOrDefault(),
                        employeeNo = db.UnitworkccsTbloperatordetails.Where(m => m.OpId == wf.EmployeeId).Select(m => m.OpNo).FirstOrDefault(),
                        shift = db.UnitworkccsTblshiftMstr.Where(m => m.ShiftId == Convert.ToInt32(wf.Shift)).Select(m => m.ShiftName).FirstOrDefault()
                    }).ToList();


                    foreach (var item in check)
                    {
                        OperatorDetailsShift operatorDetailsShift = new OperatorDetailsShift();
                        operatorDetailsShift.employeeName = item.employeeName;
                        DateTime fDate = Convert.ToDateTime(item.fromDate);
                        operatorDetailsShift.fromDate = fDate.ToString("yyyy-MM-dd");
                        DateTime tDate = Convert.ToDateTime(item.toDate);
                        operatorDetailsShift.toDate      = tDate.ToString("yyyy-MM-dd");
                        operatorDetailsShift.Cell        = item.cellName;
                        operatorDetailsShift.subCell     = item.subCellName;
                        operatorDetailsShift.department  = item.department;
                        operatorDetailsShift.designation = item.designation;
                        operatorDetailsShift.employeeNo  = item.employeeNo;
                        operatorDetailsShift.shift       = item.shift;
                        if (item.machineIds != null)
                        {
                            List <int> machineIds = new List <int>();
                            try
                            {
                                machineIds = item.machineIds.Split(',').Select(x => int.Parse(x.Trim())).ToList();
                            }
                            catch (Exception ex)
                            { }

                            List <MachineDetails1> machineDetailsList = new List <MachineDetails1>();
                            foreach (var ids in machineIds)
                            {
                                var dbCheck = db.UnitworkccsTblmachinedetails.Where(m => m.MachineId == ids).FirstOrDefault();
                                if (dbCheck != null)
                                {
                                    MachineDetails1 machineDetails = new MachineDetails1();
                                    machineDetails.machineId   = dbCheck.MachineId;
                                    machineDetails.machineName = dbCheck.MachineName;
                                    machineDetailsList.Add(machineDetails);
                                }
                            }
                            operatorDetailsShift.machinesList = machineDetailsList;
                        }
                        operatorDetailsShiftsList.Add(operatorDetailsShift);
                    }
                }
                //return operatorDetailsShiftsList;
            }
            else if (data.cellId != 0 && data.departmentId != 0)
            {
                var dbChecks = db.UnitworkccsTbloperatordetails.Where(m => m.CellId == data.cellId && m.DepartmentId == data.departmentId).Select(m => m.OpId).ToList();

                //List<OperatorDetailsShift> operatorDetailsShiftsList = new List<OperatorDetailsShift>();
                foreach (var i in dbChecks)
                {
                    var check = (from wf in db.UnitworkccsTblemployeeshiftdetails
                                 where wf.IsDeleted == 0 && wf.FromDate >= FromDate && wf.ToDate <= ToDate && wf.EmployeeId == i
                                 select new
                    {
                        employeeId = wf.EmployeeId,
                        fromDate = wf.FromDate,
                        toDate = wf.ToDate,
                        //shift = wf.Shift,
                        machineIds = wf.MachineIds,
                        employeeName = db.UnitworkccsTbloperatordetails.Where(m => m.OpId == wf.EmployeeId).Select(m => m.OperatorName).FirstOrDefault(),
                        cellName = db.UnitworkccsTblshop.Where(m => m.ShopId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.CellId).FirstOrDefault())).Select(m => m.ShopName).FirstOrDefault(),
                        subCellName = db.UnitworkccsTblcell.Where(m => m.CellId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.SubCellId).FirstOrDefault())).Select(m => m.CellName).FirstOrDefault(),
                        designation = db.UnitworkccsTblroles.Where(m => m.RoleId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.RoleId).FirstOrDefault())).Select(m => m.RoleName).FirstOrDefault(),
                        department = db.UnitworkccsTbldepartmentdetails.Where(m => m.DepartmentId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.DepartmentId).FirstOrDefault())).Select(m => m.DepartmentName).FirstOrDefault(),
                        employeeNo = db.UnitworkccsTbloperatordetails.Where(m => m.OpId == wf.EmployeeId).Select(m => m.OpNo).FirstOrDefault(),
                        shift = db.UnitworkccsTblshiftMstr.Where(m => m.ShiftId == Convert.ToInt32(wf.Shift)).Select(m => m.ShiftName).FirstOrDefault()
                    }).ToList();


                    foreach (var item in check)
                    {
                        OperatorDetailsShift operatorDetailsShift = new OperatorDetailsShift();
                        operatorDetailsShift.employeeName = item.employeeName;
                        DateTime fDate = Convert.ToDateTime(item.fromDate);
                        operatorDetailsShift.fromDate = fDate.ToString("yyyy-MM-dd");
                        DateTime tDate = Convert.ToDateTime(item.toDate);
                        operatorDetailsShift.toDate      = tDate.ToString("yyyy-MM-dd");
                        operatorDetailsShift.Cell        = item.cellName;
                        operatorDetailsShift.subCell     = item.subCellName;
                        operatorDetailsShift.department  = item.department;
                        operatorDetailsShift.designation = item.designation;
                        operatorDetailsShift.employeeNo  = item.employeeNo;
                        operatorDetailsShift.shift       = item.shift;
                        if (item.machineIds != null)
                        {
                            List <int> machineIds = new List <int>();
                            try
                            {
                                machineIds = item.machineIds.Split(',').Select(x => int.Parse(x.Trim())).ToList();
                            }
                            catch (Exception ex)
                            { }

                            List <MachineDetails1> machineDetailsList = new List <MachineDetails1>();
                            foreach (var ids in machineIds)
                            {
                                var dbCheck = db.UnitworkccsTblmachinedetails.Where(m => m.MachineId == ids).FirstOrDefault();
                                if (dbCheck != null)
                                {
                                    MachineDetails1 machineDetails = new MachineDetails1();
                                    machineDetails.machineId   = dbCheck.MachineId;
                                    machineDetails.machineName = dbCheck.MachineName;
                                    machineDetailsList.Add(machineDetails);
                                }
                            }
                            operatorDetailsShift.machinesList = machineDetailsList;
                        }
                        operatorDetailsShiftsList.Add(operatorDetailsShift);
                    }
                }
            }
            else if (data.departmentId != 0)
            {
                var dbChecks = db.UnitworkccsTbloperatordetails.Where(m => m.DepartmentId == data.departmentId).Select(m => m.OpId).ToList();

                //List<OperatorDetailsShift> operatorDetailsShiftsList = new List<OperatorDetailsShift>();
                foreach (var i in dbChecks)
                {
                    var check = (from wf in db.UnitworkccsTblemployeeshiftdetails
                                 where wf.IsDeleted == 0 && wf.FromDate >= FromDate && wf.ToDate <= ToDate && wf.EmployeeId == i
                                 select new
                    {
                        employeeId = wf.EmployeeId,
                        fromDate = wf.FromDate,
                        toDate = wf.ToDate,
                        //shift = wf.Shift,
                        machineIds = wf.MachineIds,
                        employeeName = db.UnitworkccsTbloperatordetails.Where(m => m.OpId == wf.EmployeeId).Select(m => m.OperatorName).FirstOrDefault(),
                        cellName = db.UnitworkccsTblshop.Where(m => m.ShopId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.CellId).FirstOrDefault())).Select(m => m.ShopName).FirstOrDefault(),
                        subCellName = db.UnitworkccsTblcell.Where(m => m.CellId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.SubCellId).FirstOrDefault())).Select(m => m.CellName).FirstOrDefault(),
                        designation = db.UnitworkccsTblroles.Where(m => m.RoleId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.RoleId).FirstOrDefault())).Select(m => m.RoleName).FirstOrDefault(),
                        department = db.UnitworkccsTbldepartmentdetails.Where(m => m.DepartmentId == (db.UnitworkccsTbloperatordetails.Where(n => n.OpId == wf.EmployeeId).Select(n => n.DepartmentId).FirstOrDefault())).Select(m => m.DepartmentName).FirstOrDefault(),
                        employeeNo = db.UnitworkccsTbloperatordetails.Where(m => m.OpId == wf.EmployeeId).Select(m => m.OpNo).FirstOrDefault(),
                        shift = db.UnitworkccsTblshiftMstr.Where(m => m.ShiftId == Convert.ToInt32(wf.Shift)).Select(m => m.ShiftName).FirstOrDefault()
                    }).ToList();


                    foreach (var item in check)
                    {
                        OperatorDetailsShift operatorDetailsShift = new OperatorDetailsShift();
                        operatorDetailsShift.employeeName = item.employeeName;
                        DateTime fDate = Convert.ToDateTime(item.fromDate);
                        operatorDetailsShift.fromDate = fDate.ToString("yyyy-MM-dd");
                        DateTime tDate = Convert.ToDateTime(item.toDate);
                        operatorDetailsShift.toDate      = tDate.ToString("yyyy-MM-dd");
                        operatorDetailsShift.Cell        = item.cellName;
                        operatorDetailsShift.subCell     = item.subCellName;
                        operatorDetailsShift.department  = item.department;
                        operatorDetailsShift.designation = item.designation;
                        operatorDetailsShift.employeeNo  = item.employeeNo;
                        operatorDetailsShift.shift       = item.shift;
                        if (item.machineIds != null)
                        {
                            List <int> machineIds = new List <int>();
                            try
                            {
                                machineIds = item.machineIds.Split(',').Select(x => int.Parse(x.Trim())).ToList();
                            }
                            catch (Exception ex)
                            { }

                            List <MachineDetails1> machineDetailsList = new List <MachineDetails1>();
                            foreach (var ids in machineIds)
                            {
                                var dbCheck = db.UnitworkccsTblmachinedetails.Where(m => m.MachineId == ids).FirstOrDefault();
                                if (dbCheck != null)
                                {
                                    MachineDetails1 machineDetails = new MachineDetails1();
                                    machineDetails.machineId   = dbCheck.MachineId;
                                    machineDetails.machineName = dbCheck.MachineName;
                                    machineDetailsList.Add(machineDetails);
                                }
                            }
                            operatorDetailsShift.machinesList = machineDetailsList;
                        }
                        operatorDetailsShiftsList.Add(operatorDetailsShift);
                    }
                }
            }
            return(operatorDetailsShiftsList);
        }