Example #1
0
        public JSON GenerateFieldWorkAuthorizationMemo(FieldWorkAuthMemo Param)
        {
            JSON returnJSON = new JSON();

            Application app      = new Application();
            object      misValue = System.Reflection.Missing.Value;

            if (File.Exists(FormController.ServerPathTempForms() + Param.FileName + ".docx"))
            {
                File.Delete(FormController.ServerPathTempForms() + Param.FileName + ".docx");
            }

            try
            {
                File.Copy(FormController.ServerPathFormsTemplate() + "Field Work Authorization Memorandum.docx", FormController.ServerPathTempForms() + Param.FileName + ".docx");

                Document doc = app.Documents.Open(FormController.ServerPathTempForms() + Param.FileName + ".docx");

                Dictionary <string, string> bookmarks = new Dictionary <string, string> {
                    { "ToName", GenFunct.ToTitleCase($"{Param.Employee.EmployeeFirstName} {Param.Employee.EmployeeMiddleName}. {Param.Employee.EmployeeLastName} {Param.Employee.EmployeeSuffix}") },
                    { "ToPosition", Param.Position.PositionDescription },
                    { "Subject", Param.Subject },
                    { "Date", Param.Date },
                    { "DateOfFW", Param.DateOfFieldWork },
                    { "TimeOfFW", $"{DateTime.Parse(Param.FromTimeOfFiedWork).ToString(@"hh\:mm tt")} to {DateTime.Parse(Param.ToTimeOfFiedWork).ToString(@"hh\:mm tt")}" },
                    { "ProceedDirectlyFromResidence", Param.ProceedDirectlyFromResidence },
                    { "PersonToSee", GenFunct.ToTitleCase($"{Param.PersonToSee.FirstName} {Param.PersonToSee.MiddleName}. {Param.PersonToSee.LastName} {Param.PersonToSee.Suffix}") },
                    { "OfficeBusinessName", Param.OfficeBusinessName },
                    { "CompleteAddress", Param.CompleteAddress },
                    { "Purpose", Param.Purpose },
                    { "OtherInstruction", Param.OtherInstruction },
                };

                FormToWord.ApplyDataToBookmark(bookmarks, doc);

                doc.Save();
                doc.ExportAsFixedFormat(FormController.ServerPathTempForms() + Param.FileName + ".pdf", WdExportFormat.wdExportFormatPDF);
                doc.Close();

                app.Quit();

                LLFCForm LLFCFormObj = new LLFCForm();
                LLFCFormObj.FormDownloadFile = Param.FileName;

                returnJSON.FormData = LLFCFormObj;
            }
            catch (Exception ex)
            {
                app.Quit();
                returnJSON.Message = $"Error Occured: {ex.Message}";
            }

            return(returnJSON);
        }
        public IHttpActionResult GenerateFieldOfWorkAuthMemo(FieldWorkAuthMemo Param)
        {
            JSON returnJSON = new JSON();

            try
            {
                FieldWorkAuthMemoClass fieldWorkAuthMemoClass = new FieldWorkAuthMemoClass();

                returnJSON = fieldWorkAuthMemoClass.GenerateFieldWorkAuthorizationMemo(Param);

                var response = ResponseMessage(Response(returnJSON.FormData.FormDownloadFile));

                return(response);
            }
            catch (Exception ex)
            {
                returnJSON.Message = ex.Message;
                return(Json(returnJSON));
            }
        }