public RequestResponse DeleteSingleService(int id) { RequestResponse RequestResponse = new RequestResponse(); try { //First check if its used in project already bool ifExist = new ServiceCRUD().CheckIfServiceAsocWithProject(id); if (ifExist == true) { RequestResponse.Message = "Not deleted, Record is used in Project."; RequestResponse.Success = false; return(RequestResponse); } new ServiceCRUD().DeleteSingle(id); RequestResponse.Message = "Record deleted"; RequestResponse.Success = true; } catch (Exception ex) { RequestResponse.Message = ex.Message; RequestResponse.Success = false; } return(RequestResponse); }
public void HTMLToPdf(string FilePath, string newpath, ProjectENT model, CompanyProfileENT setings, string contentRootPath, ProjectWorkflowENT Param) { PostCodeENT PostNumbData = new MiscellaneousCRUD().GetSinglePostCodeByPostNumber(Convert.ToString(setings.postCode)); List <ProjectService> ListProjectServices = new ProjectCRUD().ListOfProjectServicesByWorkflowID(Param.WorkflowId, Param.ProjectId); List <int?> ServiceIDs = ListProjectServices.Select(x => x.ServiceId).ToList(); List <ServiceENT> ServiceMultiData = new ServiceCRUD().GetMultipleServiceByMultiServiceIDs(ServiceIDs); string pdfPath = newpath; // The file location of the new PDF file PdfReader reader = new PdfReader(FilePath); // filename is the path to the PDF template file. FileStream output = new FileStream(pdfPath, FileMode.OpenOrCreate); // you can also use a Memory Stream. PdfStamper stamper = new PdfStamper(reader, output); // the stamper is required for updating fields. AcroFields af = reader.AcroFields; stamper.AcroFields.GenerateAppearances = false; ////Table one //stamper.AcroFields.SetField("Tekst498", "uzb"); //stamper.AcroFields.SetField("Tekst257", "uzb1"); //stamper.AcroFields.SetField("Tekst261", "uzb2"); //stamper.AcroFields.SetField("Tekst266", "uzb3"); stamper.AcroFields.SetField("Tekst264", "uzb3"); stamper.AcroFields.SetField("Tekst257", model.GardsNo); stamper.AcroFields.SetField("Tekst261", model.Bruksnmmer); stamper.AcroFields.SetField("Tekst264", model.Kommune); stamper.AcroFields.SetField("Tekst254", model.Address); stamper.AcroFields.SetField("Tekst255", model.PostNo); stamper.AcroFields.SetField("Tekst256", model.Poststed); ////Table two stamper.AcroFields.SetField("Foretak_2", setings.companyName); stamper.AcroFields.SetField("Organisasjonsnr", setings.organizationalNumber); stamper.AcroFields.SetField("Adresse_2", setings.address); stamper.AcroFields.SetField("Tekst4", Convert.ToString(setings.postCode)); //stamper.AcroFields.SetField("Tekst5", setings.City.Name); stamper.AcroFields.SetField("Tekst5", PostNumbData.Poststed); stamper.AcroFields.SetField("Tekst105", setings.ownerName); stamper.AcroFields.SetField("Telefon", setings.telephone); stamper.AcroFields.SetField("Mobiltelefon", setings.mobile); //stamper.AcroFields.SetField("Tekst106", setings.EmailAddress); ////Services Table int a = 1; //Empty 1st two rows of grid stamper.AcroFields.SetField("NedtrekkslisteRow1", "-"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow1", ""); stamper.AcroFields.SetField("Nedtrekksliste23", "-"); stamper.AcroFields.SetField("Avmerkingsboks10#1", "Off"); stamper.AcroFields.SetField("Avmerkingsboks810", "Off"); stamper.AcroFields.SetField("Nedtrekk121", "-"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow2", ""); stamper.AcroFields.SetField("Nedtrekksliste24", "-"); stamper.AcroFields.SetField("Avmerkingsboks1101", "Off"); stamper.AcroFields.SetField("Avmerkingsboks110#10", "Off"); //Empty Ends foreach (var item in ListProjectServices) { ServiceENT DataSingleService = ServiceMultiData.Where(x => x.Id == (Convert.ToInt32(item.ServiceId))).FirstOrDefault(); if (DataSingleService.ServiceTypeId != 3) { if (a == 1) { //string valuename = GetCheckBoxExportValue(af, "Avmerkingsboks10#1"); stamper.AcroFields.SetField("NedtrekkslisteRow1", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow1", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste23", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks10#1", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks810", "Ja"); } else if (a == 2) { //string valuename = GetCheckBoxExportValue(af, "Avmerkingsboks1102"); stamper.AcroFields.SetField("Nedtrekk121", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow2", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste24", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1101", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks110#10", "Ja"); } else if (a == 3) { stamper.AcroFields.SetField("NedtrekkslisteRow21", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow3", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste25", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1102", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks1102#10", "Ja"); } else if (a == 4) { //stamper.AcroFields.SetField("NedtrekkslisteRow4", "kontroll"); stamper.AcroFields.SetField("NedtrekkslisteRow3", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow4", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste26", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1103", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8103", "Ja"); } else if (a == 5) { stamper.AcroFields.SetField("NedtrekkslisteRow5", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow5", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste27", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1104", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8104", "Ja"); } else if (a == 6) { stamper.AcroFields.SetField("NedtrekkslisteRow6", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow6", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste28", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1105", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8105", "Ja"); } else if (a == 7) { stamper.AcroFields.SetField("NedtrekkslisteRow7", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow7", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste29", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1106", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8106", "Ja"); } else if (a == 8) { stamper.AcroFields.SetField("NedtrekkslisteRow8", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow8", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste30", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1107", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8107", "Ja"); } else if (a == 9) { stamper.AcroFields.SetField("NedtrekkslisteRow9", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow9", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste31", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1108", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8108", "Ja"); } else if (a == 10) { stamper.AcroFields.SetField("NedtrekkslisteRow10", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow10", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste32", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks1109", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks8109", "Ja"); } else if (a == 11) { stamper.AcroFields.SetField("NedtrekkslisteRow109", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow109", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste3131", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks11080", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks81081", "Ja"); } else if (a == 12) { stamper.AcroFields.SetField("NedtrekkslisteRow1110", "kontroll"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow1010", item.Service.Name); stamper.AcroFields.SetField("Nedtrekksliste3232", DataSingleService.ServiceTypeId.ToString()); stamper.AcroFields.SetField("Avmerkingsboks11092", "Ja"); stamper.AcroFields.SetField("Avmerkingsboks81092", "Ja"); } #region commented //stamper.AcroFields.SetField("NedtrekkslisteRow1", "kontroll"); //stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow1", item.Service.Name); ////stamper.AcroFields.SetField("Responsible_ActionClass_" + a, item.Quantity.ToString()); //stamper.AcroFields.SetField("Nedtrekksliste23", item.Service.ServiceTypeID.ToString()); ////stamper.AcroFields.SetField("Responsible_FramePermit_" + a, "X"); ////stamper.AcroFields.SetField("Responsible_BuildingPermit_" + a, "X"); //stamper.AcroFields.SetField("Avmerkingsboks10#1", "47"); //stamper.AcroFields.SetField("Avmerkingsboks810", "78"); ////var aaa = stamper.AcroFields.Fields["Avmerkingsboks10#1"]; //stamper.AcroFields.SetField("Responsible_Function_" + a, "kontroll"); //stamper.AcroFields.SetField("Responsible_Description_" + a, item.Service.Name); ////stamper.AcroFields.SetField("Responsible_ActionClass_" + a, item.Quantity.ToString()); //stamper.AcroFields.SetField("Responsible_ActionClass_" + a, item.Service.ServiceTypeID.ToString()); //stamper.AcroFields.SetField("Responsible_FramePermit_" + a, "X"); //stamper.AcroFields.SetField("Responsible_BuildingPermit_" + a, "X"); //stamper.AcroFields.SetField("Responsible_TempUsePermit_" + a, "X"); //stamper.AcroFields.SetField("Responsible_Complete_" + a, "X"); #endregion a++; } } if (a == 1 && ListProjectServices.Count == 0) { stamper.AcroFields.SetField("NedtrekkslisteRow1", "-"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow1", ""); stamper.AcroFields.SetField("Nedtrekksliste23", "-"); stamper.AcroFields.SetField("Avmerkingsboks10#1", "Off"); stamper.AcroFields.SetField("Avmerkingsboks810", "Off"); a++; } if (a == 2 && ListProjectServices.Count == 1) { stamper.AcroFields.SetField("Nedtrekk121", "-"); stamper.AcroFields.SetField("Beskrivelse av ansvarsområdetRow2", ""); stamper.AcroFields.SetField("Nedtrekksliste24", "-"); stamper.AcroFields.SetField("Avmerkingsboks1101", "Off"); stamper.AcroFields.SetField("Avmerkingsboks110#10", "Off"); } ////Last Table //Changings done after clients feedback///////////////////////////////////////////////////////// //stamper.AcroFields.SetField("ResponsibleApp_Company", model.Contact.Name); //stamper.AcroFields.SetField("Date", DateTime.Now.ToString("dd.MM.yy")); //stamper.AcroFields.SetField("ResponsibleApp_Person_Cap", model.Customer.Name); //stamper.AcroFields.SetField("ResponsibleApp_Company", ""); stamper.AcroFields.SetField("Tekst98", DateTime.Now.ToString("dd.MM.yy")); stamper.AcroFields.SetField("Gjentas med blokkbokstaver", setings.ownerName); var pdfContentByte = stamper.GetOverContent(1); //var url = @"http://nbk.d.com.pk/Resources/global/images/RuneSignature.jpg"; var url = contentRootPath + "/Images/RuneSignature.jpg"; //var uri = new Uri(url); //var path = Path.GetFileName(uri.AbsolutePath); //HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(url); // below lines will be commented for azure //WebResponse imageResponse = imageRequest.GetResponse(); //Stream inputImageStream = imageResponse.GetResponseStream(); //////Stream inputImageStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); //iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream); //image.SetAbsolutePosition(150, 60); //image.ScalePercent(40f); //pdfContentByte.AddImage(image); #region commented ////Add signature image code STARTS //AcroFields.FieldPosition fieldPosition = stamper.AcroFields.GetFieldPositions("Gjentas med blokkbokstaver")[0]; //PushbuttonField imageField = new PushbuttonField(stamper.Writer, fieldPosition.position, "Gjentas med blokkbokstaver"); //imageField.Layout = PushbuttonField.LAYOUT_ICON_ONLY; //string imageFile = "http://nbk.d.com.pk/Resources/global/images/RuneSignature.jpg"; //imageField.Image = iTextSharp.text.Image.GetInstance(imageFile); //imageField.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS; //imageField.ProportionalIcon = false; //imageField.Options = BaseField.READ_ONLY; //stamper.AcroFields.RemoveField("Gjentas med blokkbokstaver"); //stamper.AddAnnotation(imageField.Field, fieldPosition.page); ////Add signature image code ENDS ////stamper.AcroFields.ReplacePushbuttonField("Gjentas med blokkbokstaver", imageField.Field); #endregion stamper.Close(); reader.Close(); }