public ActionResult JobForm(string id = "", string type = "")
        {
            Logger.Debug("Inside Job Controller- View Job");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    ViewBag.Type = type;
                    Job _job = new Job();
                    JobFormNew pJobFormView = new JobFormNew();
                    if (!string.IsNullOrEmpty(type) && type == "Visit")
                    {
                        _job = _IJobRepository.GetJobByID(new Guid(id));
                        //pJobFormView.JobGUID = id;
                        if (_job != null)
                        {
                            ViewBag.JobName = _job.JobName;
                        }
                    }
                    else
                    {
                        Market _market = _IMarketRepository.GetMarketByID(new Guid(id));
                        if (_market != null)
                        {
                            _job = _IJobRepository.GetJobByCustomerStopGUID(new Guid(id));
                            if (_job != null)
                            {
                                ViewBag.JobName = _job.JobName;
                            }
                        }
                    }

                    if (_job != null && !string.IsNullOrEmpty(_job.JobForm))
                    {
                        pJobFormView = JobFormJsonConvert(_job.JobForm, "ImageURL", _job.JobGUID.ToString());
                    }
                    if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                    {
                        JobFormHeading JobFormHeading = GetJobFormDetails(_job);
                        if (JobFormHeading != null)
                        {
                            pJobFormView.JobFormHeading = JobFormHeading;
                        }
                        else
                        {
                            JobFormHeading = null;
                        }
                        pJobFormView.JobFormHeading = JobFormHeading;
                        pJobFormView.FormValues.OrderBy(x => x.ControlID);
                    }

                    return View(pJobFormView);
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_A")
                    return RedirectToAction("../JobStatus/Index");
                else
                    return RedirectToAction("Index");
            }
        }
        private string GetJobFormHTMLForStoreNonVisit(JobFormNew JobFormNew)
        {
            try
            {
                List<string> parentIDList = new List<string>();
                List<string> controlIDList = new List<string>();
                int imagecount = 0;
                List<WorkersInMotion.Model.ViewModel.JobFormValueDetails> FormValues = new List<WorkersInMotion.Model.ViewModel.JobFormValueDetails>();
                StringBuilder sbJobForm = new StringBuilder();
                // sbJobForm.Append("<div style='page-break-before:always'>&nbsp;</div>");
                sbJobForm.Append("<html>");
                sbJobForm.Append("<head><script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false'></script></head>");
                sbJobForm.Append("<body>");
                #region Generate JobForm
                if (JobFormNew.JobFormHeading != null)
                {
                    sbJobForm.Append("<div id='" + JobFormNew.JobFormHeading.JobGUID + "' name='" + JobFormNew.JobFormHeading.JobGUID + "'>");
                    sbJobForm.Append("<div align='center'>");
                    sbJobForm.Append("<table style='width:100%' align='center' cellpadding='0'>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td colspan='2' style='font-size:18px;font-family:verdana;font-weight:bold;text-align:center;'>" + JobFormNew.JobFormHeading.JobName + "&nbsp;Report</td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td colspan='2' style='font-size:18px;font-family:verdana;font-weight:bold;text-align:center;'>&nbsp;</td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 65%;' align='left'>Client Name :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.PlaceName + "</span> </td>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 35%;' align='left'>Client ID :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.PlaceID + "</span> </td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 65%;' align='left'>Store ID :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.MarketID + "</span> </td>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 35%;' align='left'>Check-In :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.CheckInTime + "</span> </td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 65%;' align='left'>Store Name : <span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.MarketName + "</span></td>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 35%;' align='left'>Check-Out : <span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.CheckOutTime + "</span></td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;' align='left'>Address :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.MarketAddress + "</span> </td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("</table>");
                    sbJobForm.Append("</div>");
                    sbJobForm.Append("<a name='" + JobFormNew.JobFormHeading.JobGUID + "' style='text-decoration: none;'>&nbsp;</a>");
                    sbJobForm.Append("<hr style='boder:1px solid black;width:100%'/>");
                }
                else
                {
                    sbJobForm.Append("<div>");
                }

                if (JobFormNew != null && JobFormNew.FormValues != null)
                {
                    foreach (var item1 in JobFormNew.FormValues)
                    {
                        if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID == -100) || (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.controlParentLabel == "Email") || (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.controlParentLabel == "Phone"))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                //if (!parentIDList.Contains(item1.parentID.ToString()))
                                //{
                                //    parentIDList.Add(item1.parentID.ToString());
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<p style='color:black;font-weight:bold;font-size:12px;margin-left:1px;'>" + item1.controlParentLabel + "</p>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT) || ((one.ControlLabel == "Email" || one.ControlLabel == "Phone") && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                        // sbJobForm.Append("<p>&nbsp;</p>");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");

                            }
                        }
                        //}
                        //else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID == -101) || (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.controlParentLabel == "Date"))
                        //{
                        //    if (!parentIDList.Contains(item1.parentID.ToString()))
                        //    {
                        //        parentIDList.Add(item1.parentID.ToString());
                        //        sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                        //        sbJobForm.Append("<p style='color:black;font-weight:bold;font-size:12px;margin-left:1px;'>" + item1.controlParentLabel + "</p>");
                        //        sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                        //        sbJobForm.Append("<tr>");
                        //        sbJobForm.Append("<td align='left'>");
                        //        foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.parentID && ((one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID == -101) || (one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && one.ControlLabel == "Date")))))
                        //        {
                        //            if (!controlIDList.Contains(items.ControlID.ToString()))
                        //            {

                        //                controlIDList.Add(items.ControlID.ToString());
                        //                if (items.ControlLabel == "Year" || items.ControlLabel == "Day")
                        //                {
                        //                    sbJobForm.Append(" <span style='padding-left:0px;line-height:20px;font-size:10px;'>-" + items.Value + "</span>");
                        //                }
                        //                else
                        //                {
                        //                    sbJobForm.Append(" <span style='padding-left:10px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                        //                }


                        //            }
                        //        }
                        //        sbJobForm.Append("</td>");
                        //        sbJobForm.Append("</tr>");
                        //        sbJobForm.Append("</table>");
                        //        sbJobForm.Append("</div>");

                        //    }
                        //}

                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT) && (item1.ControlLabel == "Region"))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => ((one.ControlLabel == "Region" || one.ControlLabel == "Market") && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + items.ControlLabel + "</label><br></br>");
                                        sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                        // sbJobForm.Append("<p style='padding:0px 10px 0px 10px; border-bottom: 1px solid gray; border-left: 1px solid gray; border-right: 1px solid gray; line-height: 2px;'>&nbsp;</p>");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT) && (item1.ControlLabel == "Store Number # *" || item1.ControlLabel == "Store Address"))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => ((one.ControlLabel == "Store Number # *" || one.ControlLabel == "Store Address") && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + items.ControlLabel + "</label><br></br>");
                                        sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                        //sbJobForm.Append("<p>&nbsp;</p>");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID < 0))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<p style='color:black;font-weight:bold;font-size:12px;margin-left:1px;'>" + item1.controlParentLabel + "</p>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                //sbJobForm.Append("<td align='left'>");
                                //sbJobForm.Append("</td>");
                                foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        if (!controlIDList.Contains(items.ControlID.ToString()))
                                        {

                                            controlIDList.Add(items.ControlID.ToString());
                                            sbJobForm.Append("<td align='left' style='width:25%'>");
                                            sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                            sbJobForm.Append("</td>");

                                        }

                                    }
                                }

                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");

                            }
                        }
                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT || item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_DROP_DOWN) && item1.controlParentLabel != "Email" && item1.controlParentLabel != "Phone")
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                if (!string.IsNullOrEmpty(item1.ControlLabel) && !string.IsNullOrEmpty(item1.Value))
                                {
                                    sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                    sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>&nbsp;" + item1.ControlLabel + "</label>");
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    sbJobForm.Append("<tr>");
                                    sbJobForm.Append("<td align='left' style='width:40%'>");
                                    sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + item1.Value + "</span>");
                                    // sbJobForm.Append("<p style='padding:0px 10px 0px 10px; border-bottom: 1px solid gray; border-left: 1px solid gray; border-right: 1px solid gray; line-height: 2px;'>&nbsp;</p>");
                                    sbJobForm.Append("</td>");
                                    sbJobForm.Append("</tr>");
                                    sbJobForm.Append("</table>");
                                    sbJobForm.Append("</div>");
                                }
                            }
                        }

                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_CHECKBOX)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_CHECKBOX).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {

                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());


                                                sbJobForm.Append("<td align='left' style='width:25%'>");
                                                if (items.Value == "true")
                                                {

                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/checkbox_yes.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='checkbox' name='checked' id='mychk' value='on'/>");
                                                }
                                                else
                                                {
                                                    //sbJobForm.Append("<img src='http://localhost:4100/assets/img/1403875956_ui-check-box.png' alt='logo'  width='20px' height='20px' />");
                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/checkbox_no.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='checkbox' name='checked' id='mychk' value='on'/>");
                                                }
                                                sbJobForm.Append("<span style='color:black;font-size:10px;vertical-align:top'>" + items.ControlLabel + "</span>&nbsp;");
                                                sbJobForm.Append("</td>");

                                            }
                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_MULTITEXT)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left'>");
                                sbJobForm.Append("<tr>");
                                sbJobForm.Append("<td align='left'>");
                                sbJobForm.Append("<label style='font-size:12px;'>" + item1.ControlLabel + "</label>");

                                sbJobForm.Append("<label>:</label>");

                                sbJobForm.Append("<textarea cols='20' rows='2' style='background-color:#FFFFFD;font-size:10px;'>" + item1.Value + "</textarea>");
                                sbJobForm.Append("</td>");
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }
                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_LABEL)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left'>");
                                sbJobForm.Append("<tr>");
                                sbJobForm.Append("<td align='left'>");
                                sbJobForm.Append("<label style='font-size:12px;'>" + item1.ControlLabel + "</label>");

                                sbJobForm.Append("<label>:</label>");

                                sbJobForm.Append("<label style='font-size:10px;'>&nbsp;&nbsp;" + item1.Value + "</label>&nbsp;");
                                sbJobForm.Append("</td>");
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");


                                sbJobForm.Append("</div>");
                            }
                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_RADIO_GROUP)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                sbJobForm.Append("<div id='Div' class='leftbar-heading'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;border-bottom:10px;'>" + item1.ControlLabel + "</label>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='5'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_RADIO_BUTTON)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        if (items.Value == "true")
                                        {
                                            sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876293_radiobutton_yes.png") + "' alt='logo'  width='20px' height='20px' />");
                                            //sbJobForm.Append("<input type='radio' disabled='disabled' checked />");
                                        }
                                        else
                                        {
                                            // sbJobForm.Append("<input type='radio' disabled='disabled' />");
                                            sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876299_radiobutton_no.png") + "' alt='logo'  width='20px' height='20px' />");
                                        }
                                        sbJobForm.Append("<span style='color:black;border-bottom:10px;;font-size:10px;vertical-align:top;'>" + items.ControlLabel + "</span>&nbsp;");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }
                        }


                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_SWITCH)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.ControlLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_RADIO_BUTTON).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {

                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];

                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());

                                                sbJobForm.Append("<td align='left' style='width:25%'>");
                                                if (items.Value == "true")
                                                {
                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876293_radiobutton_yes.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<img src='http://localhost:4100/assets/img/1403876293_radiobutton_yes.png' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='radio' disabled='disabled' checked></input>");
                                                }
                                                else
                                                {
                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876299_radiobutton_no.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<img src='http://localhost:4100/assets/img/1403876299_radiobutton_no.png' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='radio' disabled='disabled'></input>");
                                                }
                                                sbJobForm.Append("<span style='color:black;font-size:10px;vertical-align:top;'>" + items.ControlLabel + "</span>&nbsp;");
                                                sbJobForm.Append("</td>");
                                            }

                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }

                                sbJobForm.Append("<div id='Div'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    if (!parentIDList.Contains(item1.ControlID.ToString()))
                                    {
                                        parentIDList.Add(item1.ControlID.ToString());
                                        sbJobForm.Append("<table style='width:100%' align='left'>");
                                        for (int i = 0; i < FormValues.Count; i = i + 3)
                                        {
                                            sbJobForm.Append("<tr>");
                                            for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                            {
                                                WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                                if (!controlIDList.Contains(items.ControlID.ToString()))
                                                {
                                                    controlIDList.Add(items.ControlID.ToString());


                                                    sbJobForm.Append("<td align='left'>");
                                                    if (!string.IsNullOrEmpty(items.ImagePath) && !string.IsNullOrEmpty(items.Value))
                                                    {
                                                        sbJobForm.Append("<div>");
                                                        sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' alt='logo'  width='120px' height='120px' />");
                                                        Logger.Debug(items.ImagePath + '/' + items.Value);
                                                        //sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' style='width:120px;height:120px;' />");
                                                        sbJobForm.Append("</div>");
                                                    }
                                                    sbJobForm.Append("<span style='color:black;font-size:10px;'>" + items.ControlLabel + "</span>&nbsp;");
                                                    sbJobForm.Append("</td>");

                                                }
                                            }
                                            sbJobForm.Append("</tr>");
                                        }
                                        sbJobForm.Append("</table>");
                                    }
                                }
                                sbJobForm.Append("</div>");

                                sbJobForm.Append("</div>");
                            }
                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {
                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());


                                                sbJobForm.Append("<td align='left'>");
                                                if (!string.IsNullOrEmpty(items.ImagePath) && !string.IsNullOrEmpty(items.Value))
                                                {
                                                    sbJobForm.Append("<div>");
                                                    sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' alt='logo'  width='120px' height='120px' />");
                                                    Logger.Debug(items.ImagePath + '/' + items.Value);
                                                    //sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + " style='width:120px;height:120px;'/>");
                                                    sbJobForm.Append("</div>");
                                                }
                                                sbJobForm.Append("<span style='color:black;font-size:10px;'>" + items.ControlLabel + "</span>&nbsp;");
                                                sbJobForm.Append("</td>");
                                            }
                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE_DESC)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE_DESC).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {
                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());


                                                sbJobForm.Append("<td align='left'>");
                                                if (!string.IsNullOrEmpty(items.ImagePath) && !string.IsNullOrEmpty(items.Value))
                                                {
                                                    sbJobForm.Append("<div>");

                                                    //string base64String = string.Empty;
                                                    //using (var webClient = new WebClient())
                                                    //{
                                                    //    byte[] imageAsByteArray = webClient.DownloadData(items.ImagePath + '/' + items.Value);
                                                    //    base64String = Convert.ToBase64String(imageAsByteArray, 0, imageAsByteArray.Length);
                                                    //}

                                                    //sbJobForm.Append("<img src='data:image/jpeg;base64," + base64String + "' alt='logo'  width='120' height='120' />");


                                                    sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' alt='logo'  width='120px' height='120px' />");
                                                    Logger.Debug(items.ImagePath + '/' + items.Value);
                                                    sbJobForm.Append("</div>");
                                                }
                                                foreach (var item in JobFormNew.FormValues.Where(one => one.parentID == items.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT))
                                                {
                                                    if (!controlIDList.Contains(item.ControlID.ToString()))
                                                    {

                                                        controlIDList.Add(item.ControlID.ToString());
                                                        sbJobForm.Append("<span style='color:black;font-size:10px;'>" + item.ControlLabel + "</span>");
                                                    }
                                                }
                                                sbJobForm.Append("&nbsp;");
                                                sbJobForm.Append("</td>");
                                            }
                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_ISSUES_TO_REPORT || item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_OPEN_CHARGEBACKS || item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_UNSOLD_QUOTES)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.ControlLabel + "</label>");


                                sbJobForm.Append("<div id='div_" + item1.ControlID + "'>");
                                if (JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID).ToList().Count > 0)
                                {
                                    foreach (var items in JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID))
                                    {
                                        if (!controlIDList.Contains(items.ControlID.ToString()))
                                        {
                                            controlIDList.Add(items.ControlID.ToString());
                                            sbJobForm.Append("<table style='width:100%' align='left'>");
                                            sbJobForm.Append("<tr>");
                                            sbJobForm.Append("<td align='left' style='width:100px'>");
                                            if (items.currentValueID > 0)
                                            {
                                                sbJobForm.Append("<span style='color:black;font-weight:bold;font-size:10px;'>" + items.Value + "</span>");
                                            }
                                            else
                                            {
                                                sbJobForm.Append("<span style='color:black;font-size:10px;'>" + items.Value + "</span>");
                                            }
                                            sbJobForm.Append("&nbsp;");
                                            sbJobForm.Append("</td>");
                                            sbJobForm.Append("</tr>");
                                            sbJobForm.Append("</table>");
                                        }
                                    }
                                }
                                else
                                {
                                    //sbJobForm.Append("<table style='width:100%' align='left'>");
                                    //sbJobForm.Append("<tr>");
                                    sbJobForm.Append("<div align='left' style='width:100px;font-size:10px;'>None</div>");
                                    //sbJobForm.Append("<tr>");
                                    //sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                                sbJobForm.Append("</div>");
                            }
                        }

                    }
                }
                sbJobForm.Append("</div>");

                #endregion
                string marker = string.Empty;
                if (JobFormNew != null && JobFormNew.CoordinateList != null && JobFormNew.CoordinateList.Count > 0)
                {

                    int i = 0;
                    string address = string.Empty;
                    foreach (CoOrdinates items in JobFormNew.CoordinateList)
                    {
                        i++;
                        if (i == JobFormNew.CoordinateList.Count)
                        {
                            if (!string.IsNullOrEmpty(items.EndTime))
                                marker = marker + "markers=size:small%7Ccolor:0xcc0000%7C" + items.Latitude + "," + items.Longitude;
                            else if (!string.IsNullOrEmpty(items.StartTime))
                                marker = marker + "markers=size:mid%7Ccolor:0x33d100%7C" + items.Latitude + "," + items.Longitude;
                            else if (!string.IsNullOrEmpty(items.StoreName))
                                marker = marker + "markers=color:0xff6600%7C" + items.Latitude + "," + items.Longitude;
                        }
                        else
                        {

                            if (!string.IsNullOrEmpty(items.EndTime))
                                marker = marker + "markers=size:small%7Ccolor:0xcc0000%7C" + items.Latitude + "," + items.Longitude + "&";
                            else if (!string.IsNullOrEmpty(items.StartTime))
                                marker = marker + "markers=size:mid%7Ccolor:0x33d100%7C" + items.Latitude + "," + items.Longitude + "&";
                            else if (!string.IsNullOrEmpty(items.StoreName))
                                marker = marker + "markers=color:0xff6600%7C" + items.Latitude + "," + items.Longitude + "&";


                        }
                        if (!string.IsNullOrEmpty(items.City))
                        {
                            address = address + "+" + items.City;
                        }
                        if (!string.IsNullOrEmpty(items.State))
                        {
                            address = address + "+" + items.State;
                        }
                        if (!string.IsNullOrEmpty(items.Country))
                        {
                            address = address + "+" + items.Country;
                        }
                        //markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284

                    }
                    sbJobForm.Append("<div style='page-break-before:always'>");
                    sbJobForm.Append("<img src='http://maps.googleapis.com/maps/api/staticmap?center=" + address + "&zoom=10&size=1000x1000&maptype=roadmap&" + marker + "'></img>");
                    sbJobForm.Append("</div>");
                }

                sbJobForm.Append("</body>");
                sbJobForm.Append("</html>");
                return sbJobForm.ToString();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return "";
            }
        }
        public ActionResult GeneratePDF(string pdfcontent)
        {
            Logger.Debug("Inside Store Visit Controller- GeneratePDF");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(pdfcontent.ToString()))
                    {
                        Response.ContentType = "application/pdf";

                        Response.Cache.SetCacheability(HttpCacheability.NoCache);

                        StringBuilder pVisit = new StringBuilder();
                        // pVisit.Append("<header>Prabhu</header>");
                        //pVisit.Append("<html>");
                        //pVisit.Append("<head>");
                        //pVisit.Append("<title></title>");
                        //pVisit.Append("</head>");
                        //pVisit.Append("<body>");
                        pVisit.Append("<div>");

                        pVisit.Append("<table style='clear:both;width:100%;border-spacing: 0px;border-color:black;color: black;border-collapse: collapse;font-family: verdana;font-size: 10px;border:1px solid black;' border='1' cellpadding='8'>");
                        pVisit.Append("<thead>");
                        if (pdfcontent == "StoreVisit" && Session["StoreVisit"] != null)
                        {
                            Session["VisitType"] = "Store Visit Report";
                            Response.AddHeader("content-disposition", "attachment;filename=Visits.pdf");
                            pVisit.Append("<tr>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Region</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store ID</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store Name</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Visit Date</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Status</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Field Manager</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Details</td>");
                            pVisit.Append("</tr>");
                            pVisit.Append("</thead>");
                            pVisit.Append("<tbody>");
                            List<StoreVisit> visit = new List<StoreVisit>();
                            visit = (List<StoreVisit>)Session["StoreVisit"];
                            if (visit.Count > 0)
                            {
                                foreach (StoreVisit item in visit)
                                {
                                    pVisit.Append("<tr>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.RegionName + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.MarketID + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.CustomerStopName + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.Date + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.Status + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.FMName + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'><a href='#" + item.JobGUID.ToString() + "'>Detail</a></td>");
                                    //pVisit.Append("<a href='#'>Detail</a>");
                                    pVisit.Append("</tr>");
                                }
                            }
                            else
                            {
                                TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                                return RedirectToAction("Index", "StoreVisit", new { id = "Visits" });
                            }
                        }
                        else if (pdfcontent == "StoreNonVisit" && Session["StoreNonVisit"] != null)
                        {
                            Session["VisitType"] = "Store Non-Visit Report";
                            Response.AddHeader("content-disposition", "attachment;filename=NonVisits.pdf");
                            pVisit.Append("<tr>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Region</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store ID</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store Name</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Last Visit Date</td>");
                            //pVisit.Append("<td style='font-weight:bold;font-size:10px;font-family:verdana'>Status</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Field Manager</td>");
                            pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Details</td>");
                            pVisit.Append("</tr>");
                            pVisit.Append("</thead>");
                            pVisit.Append("<tbody>");
                            List<MarketModel> nonvisit = new List<MarketModel>();
                            nonvisit = (List<MarketModel>)Session["StoreNonVisit"];
                            if (nonvisit.Count > 0)
                            {
                                foreach (MarketModel item in nonvisit)
                                {
                                    pVisit.Append("<tr>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.RegionName + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.MarketID + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.MarketName + "</td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.LastStoreVisitedDate + "</td>");
                                    //pVisit.Append("<td style='font-size:8px;font-family:verdana'></td>");
                                    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.FirstName + " " + item.LastName + "</td>");
                                    Job _jobnew = _IJobRepository.GetJobByCustomerStopGUID(new Guid(item.MarketGUID));
                                    if (_jobnew != null)
                                    {
                                        pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'><a href='#" + item.MarketGUID.ToString() + "'>Detail</a></td>");
                                    }
                                    else
                                    {
                                        pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'></td>");
                                    }
                                    pVisit.Append("</tr>");
                                }
                            }
                            else
                            {
                                TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                                return RedirectToAction("Index", "StoreVisit", new { id = "Non-Visits" });
                            }
                        }
                        else
                        {
                            pVisit.Append("<tr>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Region</td>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Store ID</td>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Store Name</td>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Visit Date</td>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Status</td>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Field Manager</td>");
                            pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Details</td>");
                            pVisit.Append("</tr>");
                            pVisit.Append("</thead>");
                            pVisit.Append("<tbody>");
                        }


                        pVisit.Append("</tbody>");
                        pVisit.Append("</table>");
                        pVisit.Append("</div>");
                        if (pdfcontent == "StoreVisit" && Session["StoreVisit"] != null)
                        {
                            List<StoreVisit> visit = new List<StoreVisit>();
                            visit = (List<StoreVisit>)Session["StoreVisit"];
                            if (visit.Count > 0)
                            {
                                List<string> jobNameList = new List<string>();
                                foreach (StoreVisit item in visit)
                                {
                                    JobFormNew pJobFormView = new JobFormNew();
                                    Job _job = new Job();
                                    _job = _IJobRepository.GetJobByID(item.JobGUID);
                                    if (_job != null)
                                    {
                                        ViewBag.JobName = _job.JobName;
                                        if (!jobNameList.Contains(_job.JobGUID.ToString()))
                                        {
                                            jobNameList.Add(_job.JobGUID.ToString());
                                            if (!string.IsNullOrEmpty(_job.JobForm))
                                            {
                                                pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString());
                                            }
                                            if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                                            {
                                                pJobFormView.FormValues.OrderBy(x => x.ControlID);
                                                //  pVisit.Append(GetJobFormHTMLForStoreVisit(pJobFormView, _job.JobName, _job.JobGUID.ToString(), _job.CustomerStopGUID.ToString(), _job.JobGUID.ToString(), _job.StatusCode != null ? Convert.ToInt32(_job.StatusCode) : 6));
                                            }
                                        }
                                    }

                                }
                            }
                        }
                        else if (pdfcontent == "StoreNonVisit" && Session["StoreNonVisit"] != null)
                        {
                            List<MarketModel> nonvisit = new List<MarketModel>();
                            nonvisit = (List<MarketModel>)Session["StoreNonVisit"];
                            if (nonvisit.Count > 0)
                            {
                                List<string> jobNameList = new List<string>();
                                foreach (MarketModel item in nonvisit)
                                {
                                    JobFormNew pJobFormView = new JobFormNew();
                                    Job _job = new Job();
                                    Market _market = _IMarketRepository.GetMarketByID(new Guid(item.MarketGUID));
                                    if (_market != null)
                                    {
                                        _job = _IJobRepository.GetJobByCustomerStopGUID(new Guid(item.MarketGUID));
                                        if (_job != null)
                                        {
                                            ViewBag.JobName = _job.JobName;
                                            if (!jobNameList.Contains(_job.CustomerStopGUID.ToString()))
                                            {
                                                jobNameList.Add(_job.CustomerStopGUID.ToString());
                                                if (!string.IsNullOrEmpty(_job.JobForm))
                                                {
                                                    pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString());
                                                }
                                                if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                                                {
                                                    pJobFormView.FormValues.OrderBy(x => x.ControlID);
                                                    // pVisit.Append(GetJobFormHTMLForStoreNonVisit(pJobFormView, _job.JobName, _job.CustomerStopGUID.ToString(), _job.CustomerGUID.ToString(), _job.StatusCode != null ? Convert.ToInt32(_job.StatusCode) : 6));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //pVisit.Append("</body>");
                        //pVisit.Append("</html>");



                        //byte[] byteArray = Encoding.UTF8.GetBytes(pVisit.ToString());
                        //MemoryStream ms = new MemoryStream(byteArray);

                        //Stream stream = ms;
                        //StreamReader sr = new StreamReader(stream);

                        ////Document document = new Document(new Rectangle(288f, 144f), 10f, 10f, 30f, 30f);
                        //Document document = new Document();

                        //FileStream fs = new FileStream(Request.PhysicalApplicationPath + "\\StoreVisit.pdf", FileMode.Create);
                        //PdfWriter writer = PdfWriter.GetInstance(document, fs);

                        Document document = new Document(PageSize.A4, 70, 55, 40, 25);
                        PdfWriter writer = PdfWriter.GetInstance(document, System.Web.HttpContext.Current.Response.OutputStream);

                        writer.PageEvent = new PDFFooter();
                        document.Open();

                        TextReader txtReader = new StringReader(pVisit.ToString());
                        var xmlWorkerHelper = XMLWorkerHelper.GetInstance();
                        xmlWorkerHelper.ParseXHtml(writer, document, txtReader);

                        //iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
                        //hw.Parse(sr);
                        document.Close();

                        //Response.ContentType = "application/pdf";

                        ////Set default file Name as current datetime
                        //Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMdd") + ".pdf");
                        System.Web.HttpContext.Current.Response.Write(document);

                        Response.Flush();
                        Response.End();
                        //WebClient client = new WebClient();
                        //Byte[] buffer = client.DownloadData(Request.PhysicalApplicationPath + "\\StoreVisit.pdf");
                        //return File(buffer, "application/pdf");
                    }
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
            return null;
        }
        public ActionResult GeneratePDFByID(string id = "", string type = "")
        {
            Logger.Debug("Inside Store Visit Controller- GeneratePDF");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    StringBuilder pVisit = new StringBuilder();
                    if (!string.IsNullOrEmpty(type) && type == "StoreVisit")
                    {
                        Job _job = _IJobRepository.GetJobByID(new Guid(id));
                        if (_job != null)
                        {
                            StoreVisit _storeVisit = ConvertToStoreVisit(_job);
                            if (_storeVisit != null)
                            {
                                Response.ContentType = "application/pdf";

                                Response.Cache.SetCacheability(HttpCacheability.NoCache);

                                //pVisit.Append("<div>");

                                //pVisit.Append("<table style='clear:both;width:100%;border-spacing: 0px;border-color:black;color: black;border-collapse: collapse;font-family: verdana;font-size: 10px;border:1px solid black;' border='1' cellpadding='8'>");
                                //pVisit.Append("<thead>");

                                Session["VisitType"] = "Store Visit Report";
                                string datevalue = Session["TimeZoneID"] != null ? _IUserRepository.GetLocalDateTime(DateTime.UtcNow, Session["TimeZoneID"].ToString()) : DateTime.UtcNow.ToString();
                                Response.AddHeader("content-disposition", "attachment;filename=" + Session["OrganizationName"].ToString() + "_StoreVisit_" + datevalue + ".pdf");
                                //Response.AddHeader("content-disposition", "attachment;filename=Visits.pdf");
                                //pVisit.Append("<tr>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Region</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store ID</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store Name</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Visit Date</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Status</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Field Manager</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Details</td>");
                                //pVisit.Append("</tr>");
                                //pVisit.Append("</thead>");

                                //pVisit.Append("<tbody>");
                                //pVisit.Append("<tr>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _storeVisit.RegionName + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _storeVisit.MarketID + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _storeVisit.CustomerStopName + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _storeVisit.Date + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _storeVisit.Status + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _storeVisit.FMName + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'><a href='#" + _storeVisit.JobGUID.ToString() + "'>Detail</a></td>");
                                ////pVisit.Append("<a href='#'>Detail</a>");
                                //pVisit.Append("</tr>");
                                //pVisit.Append("</tbody>");
                                //pVisit.Append("</table>");
                                //pVisit.Append("</div>");
                                if (_job != null)
                                {
                                    ViewBag.JobName = _job.JobName;
                                    JobFormNew pJobFormView = new JobFormNew();
                                    if (!string.IsNullOrEmpty(_job.JobForm))
                                    {
                                        pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString());
                                    }
                                    if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                                    {
                                        JobFormHeading JobFormHeading = GetJobFormDetails(_job);
                                        if (JobFormHeading != null)
                                        {
                                            pJobFormView.JobFormHeading = JobFormHeading;
                                        }
                                        else
                                        {
                                            pJobFormView.JobFormHeading = null;
                                        }

                                        pJobFormView.FormValues.OrderBy(x => x.ControlID);
                                        pVisit.Append(GetJobFormHTMLForStoreVisit(pJobFormView));
                                    }
                                    else
                                        pVisit.Append(GetJobFormHTMLForStoreVisit(pJobFormView));
                                }

                            }

                        }
                        else
                        {
                            TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                            return RedirectToAction("Index", "StoreVisit", new { id = "Visits" });
                        }
                    }
                    else if (!string.IsNullOrEmpty(type) && type == "StoreNonVisit")
                    {
                        Market pmarket = _IMarketRepository.GetMarketByID(new Guid(id));

                        if (pmarket != null)
                        {

                            MarketModel _marketModel = ConvertToStoreNonVisit(pmarket);
                            if (_marketModel != null)
                            {
                                //pVisit.Append("<div>");

                                //pVisit.Append("<table style='clear:both;width:100%;border-spacing: 0px;border-color:black;color: black;border-collapse: collapse;font-family: verdana;font-size: 10px;border:1px solid black;' border='1' cellpadding='8'>");
                                //pVisit.Append("<thead>");

                                Session["VisitType"] = "Store Non-Visit Report";
                                string datevalue = Session["TimeZoneID"] != null ? _IUserRepository.GetLocalDateTime(DateTime.UtcNow, Session["TimeZoneID"].ToString()) : DateTime.UtcNow.ToString();
                                Response.AddHeader("content-disposition", "attachment;filename=" + Session["OrganizationName"].ToString() + "_StoreNonVisit_" + datevalue + ".pdf");
                                //Response.AddHeader("content-disposition", "attachment;filename=NonVisits.pdf");
                                //pVisit.Append("<tr>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Region</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store ID</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store Name</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Last Visit Date</td>");
                                ////pVisit.Append("<td style='font-weight:bold;font-size:10px;font-family:verdana'>Status</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Field Manager</td>");
                                //pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Details</td>");
                                //pVisit.Append("</tr>");
                                //pVisit.Append("</thead>");

                                //pVisit.Append("<tbody>");
                                //pVisit.Append("<tr>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _marketModel.RegionName + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _marketModel.MarketID + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _marketModel.MarketName + "</td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _marketModel.LastStoreVisitedDate + "</td>");
                                ////pVisit.Append("<td style='font-size:8px;font-family:verdana'></td>");
                                //pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + _marketModel.FirstName + " " + _marketModel.LastName + "</td>");
                                //Job _jobnew = _IJobRepository.GetJobByCustomerStopGUID(new Guid(_marketModel.MarketGUID));
                                //if (_jobnew != null)
                                //{
                                //    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'><a href='#" + _marketModel.MarketGUID.ToString() + "'>Detail</a></td>");
                                //}
                                //else
                                //{
                                //    pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'></td>");
                                //}
                                //pVisit.Append("</tr>");
                                //pVisit.Append("</tbody>");
                                //pVisit.Append("</table>");
                                //pVisit.Append("</div>");

                                JobFormNew pJobFormView = new JobFormNew();

                                Job _job = _IJobRepository.GetJobByCustomerStopGUID(new Guid(_marketModel.MarketGUID));
                                if (_job != null)
                                {
                                    ViewBag.JobName = _job.JobName;

                                    if (!string.IsNullOrEmpty(_job.JobForm))
                                    {
                                        pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString());
                                    }
                                    if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                                    {
                                        JobFormHeading JobFormHeading = GetJobFormDetails(_job);
                                        if (JobFormHeading != null)
                                        {
                                            pJobFormView.JobFormHeading = JobFormHeading;
                                        }
                                        else
                                        {
                                            pJobFormView.JobFormHeading = null;
                                        }
                                        pJobFormView.FormValues.OrderBy(x => x.ControlID);
                                        pVisit.Append(GetJobFormHTMLForStoreNonVisit(pJobFormView));
                                    }

                                }
                            }
                        }
                        else
                        {
                            TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                            return RedirectToAction("Index", "StoreVisit", new { id = "Non-Visits" });
                        }
                    }

                    if (!string.IsNullOrEmpty(pVisit.ToString()))
                    {
                        Document document = new Document(PageSize.A4, 70, 55, 40, 25);
                        PdfWriter writer = PdfWriter.GetInstance(document, System.Web.HttpContext.Current.Response.OutputStream);
                        //writer.PageEvent = new PDFFooter();
                        document.Open();
                        TextReader txtReader = new StringReader(pVisit.ToString());
                        var xmlWorkerHelper = XMLWorkerHelper.GetInstance();
                        xmlWorkerHelper.ParseXHtml(writer, document, txtReader);
                        document.Close();
                        System.Web.HttpContext.Current.Response.Write(document);
                        Response.Flush();
                        Response.End();
                    }
                    else
                    {
                        TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                        return RedirectToAction("Index", "StoreVisit", new { id = "Non-Visits" });
                    }
                }

                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
            return null;
        }
        public ActionResult JobForm(string id = "")
        {
            Logger.Debug("Inside Job Controller- View Job");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    Job _job = new Job();
                    JobFormNew pJobFormView = new JobFormNew();
                    _job = _IJobRepository.GetJobByID(new Guid(id));

                    // pJobFormView.JobGUID = id;
                    if (_job != null)
                    {
                        ViewBag.JobName = _job.JobName;


                        //JobFormNew pJobFormView = (_job != null && !string.IsNullOrEmpty(_job.JobForm)) ? new JavaScriptSerializer().Deserialize<JobFormNew>(_job.JobForm) : null;


                        //if (pJobFormView != null)
                        //{
                        //    if (pJobFormView.Values != null)
                        //    {
                        //        pJobFormView.FormValues = new List<JobFormValueDetails>();
                        //        //for (int i = 0; i < pJobFormView.Values.Count; i++)
                        //        foreach (JobFormValues pFormValues in pJobFormView.Values)
                        //        {
                        //            //JobFormValues pFormValues = pJobFormView.Values[i];
                        //            JobFormValueDetails pFormDetails = new JobFormValueDetails();
                        //            string[] Controls = pFormValues.ControlID.Split('_');
                        //            if (Controls.Length > 2)
                        //            {
                        //                int controlid, controltype;
                        //                pFormDetails.FormID = Controls[0];
                        //                if (int.TryParse(Controls[1], out controlid))
                        //                {
                        //                    pFormDetails.ControlID = controlid;
                        //                }
                        //                else
                        //                {
                        //                    pFormDetails.ControlID = 0;
                        //                }
                        //                if (int.TryParse(Controls[2], out controltype))
                        //                {
                        //                    pFormDetails.ControlType = (ControlType)controltype;
                        //                }
                        //                else
                        //                {
                        //                    pFormDetails.ControlType = 0;
                        //                }

                        //            }
                        //            int parentid;
                        //            pFormDetails.Value = pFormValues.Value;
                        //            pFormDetails.ControlLabel = pFormValues.ControlLabel;
                        //            if (int.TryParse(pFormValues.parentID, out parentid))
                        //            {
                        //                pFormDetails.parentID = parentid;
                        //            }
                        //            else
                        //            {
                        //                pFormDetails.parentID = 0;
                        //            }
                        //            pFormDetails.controlParentLabel = pFormValues.controlParentLabel;
                        //            pFormDetails.ValueID = pFormValues.ValueID;
                        //            pFormDetails.currentValueID = pFormValues.currentValueID;

                        //            pFormDetails.ImagePath = System.Configuration.ConfigurationManager.AppSettings.Get("ImageURL").ToString() + Session["OrganizationGUID"].ToString() + "/Jobs/" + pJobFormView.JobGUID;

                        //            pJobFormView.FormValues.Add(pFormDetails);
                        //        }
                        //    }
                        //}


                        if (_job != null && !string.IsNullOrEmpty(_job.JobForm))
                        {
                            pJobFormView = JobFormJsonConvert(_job.JobForm, "ImageURL", _job.JobGUID.ToString());
                        }
                        if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                        {
                            JobFormHeading JobFormHeading = GetJobFormDetails(_job);
                            if (JobFormHeading != null)
                            {
                                pJobFormView.JobFormHeading = JobFormHeading;
                                ViewBag.StoreInformation = "Available";
                            }
                            else
                            {
                                ViewBag.StoreInformation = "None";
                                pJobFormView.JobFormHeading = null;
                            }
                            pJobFormView.FormValues.OrderBy(x => x.ControlID);
                        }

                        return View(pJobFormView);
                    }
                    else
                    {
                        pJobFormView = null;
                        return View(pJobFormView);
                    }
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }

            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_A")
                    return RedirectToAction("../JobStatus/Index");
                else
                    return RedirectToAction("Index");
            }
        }
        public ActionResult GeneratePDFByID(string id = "", string type = "")
        {
            Logger.Debug("Inside Site Visit Controller- GeneratePDF");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(id))
                    {
                        StringBuilder pVisit = new StringBuilder();
                        Job _job = _IJobRepository.GetJobByID(new Guid(id));
                        if (_job != null)
                        {
                            Response.ContentType = "application/pdf";

                            Response.Cache.SetCacheability(HttpCacheability.NoCache);
                            Session["VisitType"] = "Visit Report";
                            string datevalue = Session["TimeZoneID"] != null ? _IUserRepository.GetLocalDateTime(DateTime.UtcNow, Session["TimeZoneID"].ToString()) : DateTime.UtcNow.ToString();
                            Response.AddHeader("content-disposition", "attachment;filename=" + Session["OrganizationName"].ToString() + "_UserActivities_" + datevalue + ".pdf");
                            // Response.AddHeader("content-disposition", "attachment;filename=Visits.pdf");

                            JobFormNew pJobFormView = new JobFormNew();

                            if (_job != null)
                            {
                                ViewBag.JobName = _job.JobName;

                                if (!string.IsNullOrEmpty(_job.JobForm))
                                {
                                    pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString());
                                }
                                if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0)
                                {
                                    JobFormHeading JobFormHeading = GetJobFormDetails(_job);
                                    if (JobFormHeading != null)
                                    {
                                        pJobFormView.JobFormHeading = JobFormHeading;
                                    }
                                    else
                                    {
                                        pJobFormView.JobFormHeading = null;
                                    }
                                    pJobFormView.FormValues.OrderBy(x => x.ControlID);
                                    pVisit.Append(GetJobFormHTML(pJobFormView));
                                }

                            }
                        }
                        else
                        {
                            TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                            return RedirectToAction("Index", "UserActivities");
                        }

                        Document document = new Document(PageSize.A4, 70, 55, 40, 25);
                        PdfWriter writer = PdfWriter.GetInstance(document, System.Web.HttpContext.Current.Response.OutputStream);
                        //writer.PageEvent = new PDFFooter();
                        document.Open();
                        TextReader txtReader = new StringReader(pVisit.ToString());
                        var xmlWorkerHelper = XMLWorkerHelper.GetInstance();
                        xmlWorkerHelper.ParseXHtml(writer, document, txtReader);
                        document.Close();
                        System.Web.HttpContext.Current.Response.Write(document);
                        Response.Flush();
                        Response.End();
                    }
                    else
                    {
                        TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>";
                        return RedirectToAction("Index", "UserActivities");
                    }

                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
            return null;
        }