public void Maketemplate(string outPath) { DbWorker dbWorker = new DbWorker(); string appPath = Directory.GetCurrentDirectory(); if (File.Exists(appPath + outPath)) { File.Delete(Path.GetFullPath(appPath + outPath)); } File.Copy(Path.GetFullPath(appPath + "\\Template\\шаблон.docx"), appPath + outPath); Dictionary <string, string> req = dbWorker.GetSertificateData(); if (req != null) { var valuesToFill = new Content( new FieldContent("CoursTipe", req["CoursType"]), new FieldContent("LastName", req["LastName"]), new FieldContent("FirstName", req["FirstName"]), new FieldContent("MiddleName", req["MiddleName"]), new FieldContent("DateFrom", req["StartDate"]), new FieldContent("DateEnd", req["EndDate"]), new FieldContent("EducationType", req["CoursType"]), new FieldContent("CoursName", req["CoursName"]), new FieldContent("Volume", req["Volume"]), new FieldContent("DateNow", DateTime.Now.ToString()), new FieldContent("RegisterNumber", req["RegisterNumber"]) ); using (var outputDocument = new TemplateProcessor(appPath + outPath) .SetRemoveContentControls(true)) { outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); } } else { MessageBox.Show("Данных по обучающимся не найдено!"); } }
/// <summary> /// Направление на прохождение курсов /// </summary> /// <param name="outPath"></param> /// <param name="id"></param> /// <param name="educationId"></param> /// <param name="templateName"></param> public void CourseReferral(string outPath, string educationId, string templateName) { DbWorker dbWorker = new DbWorker(); string appPath = Directory.GetCurrentDirectory(); File.Copy(Path.GetFullPath(appPath + "\\Template\\" + templateName), outPath); Dictionary <string, object> req = dbWorker.GetSertificateData(educationId); if (req != null) { Content valuesToFill = new Content( new FieldContent("CoursTipe", req["CoursType"].ToString()), new FieldContent("LastName", req["LastName"].ToString()), new FieldContent("FirstName", req["FirstName"].ToString()), new FieldContent("MiddleName", req["MiddleName"].ToString()), new FieldContent("DateOfBirth", ((DateTime)req["DateOfBirth"]).ToString("dd.MM.yyyy")), new FieldContent("DateFrom", req["StartDate"].ToString()), new FieldContent("DateEnd", req["EndDate"].ToString()), new FieldContent("EducationType", req["CoursType"].ToString()), new FieldContent("CoursName", req["CoursName"].ToString()), new FieldContent("Volume", req["Volume"].ToString()), new FieldContent("DateNow", DateTime.Now.ToString("dd.MM.yyyy")) //,new FieldContent("RegisterNumber", req["RegisterNumber"].ToString()) ); using (TemplateProcessor outputDocument = new TemplateProcessor(outPath) .SetRemoveContentControls(true)) { outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); } } else { MessageBox.Show("Данных по обучающимся не найдено!"); } }