// // GET: /DocumentGeneration/ public PRCDocument InitialSetUpPRCDocument(PRCDocument.PRCDocumentType Type) { PRCDocument thePRCDocument = new PRCDocument(Type); thePRCDocument = AssignPRCDocumentTypeTemplateURLs(thePRCDocument); //need to test path exists - if not create new thePRCDocument.SavePath = Path.Combine(HttpRuntime.AppDomainAppPath, "GeneratedDocuments\\"); thePRCDocument.DateCreated = DateTime.Now; thePRCDocument.Sent = false; string bookingOrBookingExtraSelectionID = ""; bookingOrBookingExtraSelectionID = (thePRCDocument.BookingID != null) ? thePRCDocument.BookingID.ToString() : thePRCDocument.BookingExtraSelectionID.ToString(); string bookingOrBookingExtraLetterPrefix = (thePRCDocument.BookingID != null) ? "B" : "BES"; //c142_LateBookingVoucher_01/01/2014_BE123 string fileNamePrefix = "c" + thePRCDocument.CustomerID.ToString() + "_" + DateTime.Now.ToString("dd_MM_yyyy") + "_" + bookingOrBookingExtraLetterPrefix + bookingOrBookingExtraSelectionID; thePRCDocument.FileName = fileNamePrefix; return(thePRCDocument); }
public EventCommandCreateDocument(Event anEvent, Customer customer, PRCDocument.PRCDocumentType documentType, Booking booking = null, BookingExtraSelection bes = null) { //inject properties this.Event = anEvent; this.customer = customer; this.documentType = documentType; this.booking = booking; this.bes = bes; }
//Returns local filepath and file name of the document public string CreateDocumentToFileSystem(Customer customer, PRCDocument.PRCDocumentType type, Booking booking = null, BookingExtraSelection bes = null) { try { PRCDocument aDocument = new PRCDocument(customer, type, booking, bes); var filepathAndName = MergeDocumentWithDatabaseAndReturnFilePath(customer, type, booking, bes); return(filepathAndName); } catch (Exception ex) { throw ex; } }
public byte[] CreateDocument(Customer customer, PRCDocument.PRCDocumentType type, Booking booking = null, BookingExtraSelection bes = null) { try { PRCDocument aDocument = new PRCDocument(customer, type, booking, bes); var filepathAndName = MergeDocumentWithDatabaseAndReturnFilePath(customer, type, booking, bes); var documentBytes = System.IO.File.ReadAllBytes(filepathAndName); return(documentBytes); } catch (Exception ex) { throw; } }
public EventCommandDocumentOutDirectoryBundleAndEmail(string docsPath, Event anEvent, Customer customer, PRCDocument.PRCDocumentType documentType, Booking booking = null, BookingExtraSelection bes = null) { this.Event = anEvent; this.customer = customer; this.documentType = documentType; this.booking = booking; this.bes = bes; this.BundleDir = docsPath; }
private string MergeDocumentWithDatabaseAndReturnFilePath(Customer customer, PRCDocument.PRCDocumentType type, Booking booking = null, BookingExtraSelection bes = null) { //BOOKING needs to have a propertyID, BES needs to have the ExtraID!!!! var db = new PortugalVillasContext(); var bookPartTable = new DataTable(); var besPartTable = new DataTable(); var extraAttributes = new DataTable(); PRCDocument aDocument = new PRCDocument(type); aDocument = InitialSetUpPRCDocument(type); //tables for merge List <DataTable> tablesForMerge_PreMerge = new List <DataTable>(); PRCDocumentData theDocumentDataInstance = new PRCDocumentData(); //PRC tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.StandardPRCInformation, 1)); //CUSTOMERS tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData(PRCDocumentData.PRCReturnDataTableWrapperTypes.CustomerByCustomerID, customer.CustomerID)); //works*/ //CUSTOMER BANK DETAILS if (booking != null) { tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.CustomerBankDetailByCustomerID, customer.CustomerID)); //COMMISSION FOR YEAR var TotalCommisssion = new DataTable(); TotalCommisssion.Columns.Add("TotalCommissionThisYear"); TotalCommisssion.Columns.Add("CommissionDateTime"); DataRow _row = TotalCommisssion.NewRow(); _row["TotalCommissionThisYear"] = db.Bookings.Where(x => x.PropertyID == booking.PropertyID).Sum(x => x.CommissionAmount); _row["CommissionDateTime"] = DateTime.Now.ToShortDateString(); TotalCommisssion.Rows.Add(_row); tablesForMerge_PreMerge.Add(TotalCommisssion); //BOOKING tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData(PRCDocumentData.PRCReturnDataTableWrapperTypes.BookingByBookingID, booking.BookingID)); //PROPERTY tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData(PRCDocumentData.PRCReturnDataTableWrapperTypes.PropertyByPropertyID, (long)booking.PropertyID)); //TOWN tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.PropertyTownByPropertyTownID, Convert.ToInt64(db.Properties.Where(x => x.PropertyID == booking.PropertyID).FirstOrDefault().PropertyTownID))); //REGION tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.PropertyRegionByPropertyRegionID, db.Properties.Where(x => x.PropertyID == booking.PropertyID).FirstOrDefault().PropertyTown.PropertyRegionID)); //BOOKINGPART bookPartTable = theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.BookingParticipantByBookingID, booking.BookingID); bookPartTable.TableName = "BOOKINGPARTTABLE"; tablesForMerge_PreMerge.Add(bookPartTable); if (booking.BookingParentContainerID != null) { //PARENT tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.StandardBookingParentContainer, (long)booking.BookingParentContainerID)); } BookingParentContainer bookingParentContainer; //PROPERTY OWNER tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.StandardPropertyOwner, (long)booking.PropertyID)); } if (bes != null) { //get top level item for same sub type to pull out attributes: long?extraIDforAtts = null; try { extraIDforAtts = db.BookingExtras.Where(x => x.TopLevelItem == true) .Where(y => y.BookingExtraSubTypeID == bes.BookingExtra.BookingExtraSubTypeID) .FirstOrDefault().BookingExtraID; } catch (Exception) { extraIDforAtts = db.BookingExtras.Where(x => x.MaxPersons > 10) .Where(y => y.BookingExtraSubTypeID == bes.BookingExtra.BookingExtraSubTypeID) .FirstOrDefault().BookingExtraID; } //BES tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.BookingExtraSelectionByBookingExtraSelectionID, bes.BookingExtraSelectionID)); //BEST PART (name etc) besPartTable = theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.BookingExtraParticipantByBookingExtraSelectionID, bes.BookingExtraSelectionID); besPartTable.TableName = "BESPARTTABLE"; tablesForMerge_PreMerge.Add(besPartTable); //EXTRA tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.BookingExtraByBookingExtraID, bes.BookingExtraID)); //PARENT if (bes.BookingParentContainerID != null) { tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.StandardBookingParentContainer, (long)bes.BookingParentContainerID)); } //ATTRIBUTES if (extraIDforAtts != null) { extraAttributes = theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.BookingExtraAttributesByBookingExtraID, (long)extraIDforAtts); extraAttributes.TableName = "ATTRIBUTETABLE"; } //test if there is a related booking / property IF it's a solo BES event if (booking != null) { if (bes.BookingParentContainerID != 0) { booking = db.Bookings.Where(x => x.BookingParentContainerID == bes.BookingParentContainerID).FirstOrDefault(); //PROPERTY tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData(PRCDocumentData.PRCReturnDataTableWrapperTypes.PropertyByPropertyID, (long)booking.PropertyID)); //TOWN tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.PropertyTownByPropertyTownID, Convert.ToInt64(db.Properties.Where(x => x.PropertyID == booking.PropertyID).FirstOrDefault().PropertyTownID))); //REGION tablesForMerge_PreMerge.Add( theDocumentDataInstance.GetPRCDocumentData( PRCDocumentData.PRCReturnDataTableWrapperTypes.PropertyRegionByPropertyRegionID, db.Properties.Where(x => x.PropertyID == booking.PropertyID).FirstOrDefault().PropertyTown.PropertyRegionID)); } } } List <DataTable> tablesForMerge = new List <DataTable>(); foreach (var dataTable in tablesForMerge_PreMerge) { if (dataTable.Rows.Count > 0) { DataTable tableToModAndReturn = dataTable.Copy(); //clone every table DataTable dtCloned = dataTable.Copy(); //change every datetime column to a string //for every dateTime colum, load into new table foreach (DataColumn col in dtCloned.Columns) { var theType = dtCloned.Columns[col.ColumnName].DataType.ToString(); if (dtCloned.Columns[col.ColumnName].DataType.ToString() == "DateTime") { //change the type var name = col.ColumnName; var value = ""; if (dtCloned.Rows[0][col].ToString().Count() >= 10) { value = /*DateTime.Parse(*/ Convert.ToDateTime(dtCloned.Rows[0][col].ToString()).ToString("dd/MM/yyyy"); //).ToString("dd/MM/yyyy"); } tableToModAndReturn.Columns.Remove(name); tableToModAndReturn.Columns.Add(new DataColumn { ColumnName = name, DefaultValue = value }); } } tablesForMerge.Add(tableToModAndReturn); } } Aspose.Words.Document theDoc = new Aspose.Words.Document(HttpRuntime.AppDomainAppPath + aDocument.ServerDocumentURL); //execute the merges foreach (var dataTable in tablesForMerge) { for (int i = 0; i < dataTable.Rows.Count; i++) { theDoc.MailMerge.Execute(dataTable.Rows[i]); } } //N.B The regions in the document need to correspond to the table name for the below merge to work theDoc.MailMerge.ExecuteWithRegions(bookPartTable); theDoc.MailMerge.ExecuteWithRegions(besPartTable); theDoc.MailMerge.ExecuteWithRegions(extraAttributes); string filepathAndName = aDocument.SavePath + aDocument.FileName + ".pdf"; theDoc.Save(aDocument.SavePath + aDocument.FileName + ".pdf"); db.Dispose(); return(filepathAndName); }
public ActionResult AddBookingEvent(FormCollection eventAndBooking) { try { var bookingId = Convert.ToInt32(eventAndBooking["BookingID"]); var eventTypeId = Convert.ToInt32(eventAndBooking["EventTypeID"]); //get the booking var booking = db.Bookings.Where(x => x.BookingID.Equals(bookingId)).FirstOrDefault(); var property = booking.Property; //get the customer var customer = db.Customers.FirstOrDefault(x => x.CustomerID.Equals(booking.CustomerID)); var documentType = new PRCDocument.PRCDocumentType(); //create new event and assign the correct typeID HERE, then can make event creation generic var eventToAdd = CreateBookingEventViaFactory(eventTypeId, booking); /*var whatAmIReturning = FullyInstantiateAndRunEvent(customer, booking);*/ //////////GET TYPE OF DOCUMENT////// //STORE IN EVENT - DocumentEnum and Email Enum if (eventToAdd.EventType.DocumentEnumID != null) { documentType = (PRCDocument.PRCDocumentType)eventToAdd.EventType.DocumentEnumID; } ////BEGIN GENERIC CODE ///////////////////////////////////////// ////////CREATE EVENT DEPENDING ON SUB TYPE EventCommandCreateDocument createDocCommand; EventCommandSendEmail sendEmail; EventCommandDocumentOutDirectoryBundleAndEmail docBundle; switch (eventToAdd.EventType.EventSubTypeID) { case 1: //does nothing, just add event case 2: //email out sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 3: createDocCommand = new EventCommandCreateDocument(eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(createDocCommand); eventToAdd.EventCommands.Add(sendEmail); //document out + email that document break; case 4: //email reminder sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 5: //create only sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 6: //composite bundle and email //get directory for docs var bundleDir = HttpRuntime.AppDomainAppPath + "FinalBookingDocuments\\" + property.LegacyReference.ToLower() + "\\"; docBundle = new EventCommandDocumentOutDirectoryBundleAndEmail(bundleDir, eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailEnumID, customer, booking); eventToAdd.EventCommands.Add(docBundle); eventToAdd.EventCommands.Add(sendEmail); break; } var commandsAndResultsToLog = new List<EventCommand>(); //execute the commands //create document using executes //create emails and bodies //do all sending var result = new EventCommandResult(); foreach (var command in eventToAdd.EventCommands) { command.EventCommandResults.Add(command.ExecuteCommand()); commandsAndResultsToLog.Add(command); } /////END CREATE EVENT //////////////////////////// //DO LOGGING //if successful log the event and the commands that ran //save event EventLogger log = new EventLogger(db); //strip out event wiring before loggin eventToAdd.EventCommands = null; var doLogging = log.LogEvent(eventToAdd); var EventCommandLogger = new CommandLogger(db); var eventLogger = new EventLogger(db, EventCommandLogger); //save eventcoomand and result foreach (var commandAndResult in commandsAndResultsToLog) { EventCommandLogger.Log(eventToAdd.EventID, commandAndResult); } //save document generated //if there's any docs, write them to the DB foreach (var doc in eventToAdd.Documents) { doc.EventID = eventToAdd.EventID; doc.DocumentDescription = documentType.ToString(); doc.EmailTo = customer.EmailAddress; doc.CustomerID = customer.CustomerID; db.Documents.Add(doc); db.SaveChanges(); } //for view ViewBag.Bookingid = bookingId; var eventsForDDL = db.EventTypes.Where(x => x.EventSchemeTypeID == 1 || x.EventSchemeTypeID == 2).ToList(); ViewBag.EventTypeDDL = eventsForDDL; } catch (Exception ex) { MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "Adding Booking Event Failed"; mail.theAsposeMessage.Body = ex.Message.ToString(); mail.theAsposeMessage.Body += "----------------------------------"; mail.theAsposeMessage.Body += ex.InnerException.ToStringDescriptive(); throw ex; } return View(); }
public ActionResult AddBookingEvent(FormCollection eventAndBooking) { try { var bookingId = Convert.ToInt32(eventAndBooking["BookingID"]); var eventTypeId = Convert.ToInt32(eventAndBooking["EventTypeID"]); //get the booking var booking = db.Bookings.Where(x => x.BookingID.Equals(bookingId)).FirstOrDefault(); var property = booking.Property; //get the customer var customer = db.Customers.FirstOrDefault(x => x.CustomerID.Equals(booking.CustomerID)); var documentType = new PRCDocument.PRCDocumentType(); //create new event and assign the correct typeID HERE, then can make event creation generic var eventToAdd = CreateBookingEventViaFactory(eventTypeId, booking); /*var whatAmIReturning = FullyInstantiateAndRunEvent(customer, booking);*/ //////////GET TYPE OF DOCUMENT////// //STORE IN EVENT - DocumentEnum and Email Enum if (eventToAdd.EventType.DocumentEnumID != null) { documentType = (PRCDocument.PRCDocumentType)eventToAdd.EventType.DocumentEnumID; } ////BEGIN GENERIC CODE ///////////////////////////////////////// ////////CREATE EVENT DEPENDING ON SUB TYPE EventCommandCreateDocument createDocCommand; EventCommandSendEmail sendEmail; EventCommandDocumentOutDirectoryBundleAndEmail docBundle; switch (eventToAdd.EventType.EventSubTypeID) { case 1: //does nothing, just add event case 2: //email out sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 3: createDocCommand = new EventCommandCreateDocument(eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(createDocCommand); eventToAdd.EventCommands.Add(sendEmail); //document out + email that document break; case 4: //email reminder sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 5: //create only sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 6: //composite bundle and email //get directory for docs var bundleDir = HttpRuntime.AppDomainAppPath + "FinalBookingDocuments\\" + property.LegacyReference.ToLower() + "\\"; docBundle = new EventCommandDocumentOutDirectoryBundleAndEmail(bundleDir, eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailEnumID, customer, booking); eventToAdd.EventCommands.Add(docBundle); eventToAdd.EventCommands.Add(sendEmail); break; } var commandsAndResultsToLog = new List <EventCommand>(); //execute the commands //create document using executes //create emails and bodies //do all sending var result = new EventCommandResult(); foreach (var command in eventToAdd.EventCommands) { command.EventCommandResults.Add(command.ExecuteCommand()); commandsAndResultsToLog.Add(command); } /////END CREATE EVENT //////////////////////////// //DO LOGGING //if successful log the event and the commands that ran //save event EventLogger log = new EventLogger(db); //strip out event wiring before loggin eventToAdd.EventCommands = null; var doLogging = log.LogEvent(eventToAdd); var EventCommandLogger = new CommandLogger(db); var eventLogger = new EventLogger(db, EventCommandLogger); //save eventcoomand and result foreach (var commandAndResult in commandsAndResultsToLog) { EventCommandLogger.Log(eventToAdd.EventID, commandAndResult); } //save document generated //if there's any docs, write them to the DB foreach (var doc in eventToAdd.Documents) { doc.EventID = eventToAdd.EventID; doc.DocumentDescription = documentType.ToString(); doc.EmailTo = customer.EmailAddress; doc.CustomerID = customer.CustomerID; db.Documents.Add(doc); db.SaveChanges(); } //for view ViewBag.Bookingid = bookingId; var eventsForDDL = db.EventTypes.Where(x => x.EventSchemeTypeID == 1 || x.EventSchemeTypeID == 2).ToList(); ViewBag.EventTypeDDL = eventsForDDL; } catch (Exception ex) { MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "Adding Booking Event Failed"; mail.theAsposeMessage.Body = ex.Message.ToString(); mail.theAsposeMessage.Body += "----------------------------------"; mail.theAsposeMessage.Body += ex.InnerException.ToStringDescriptive(); throw ex; } return(View()); }