/// <summary> /// This function execute the code for word template fill-in. Call this after calling the Init() function /// </summary> public static void Run() { try { WordprocessingDocument document = WordprocessingDocument.Open(StaticValues.word_template_path, true); WordTemplateManager manager = new WordTemplateManager(document); manager.Process(); Helper_WordBase.PostProcessorFixLineBreaks(document); Helper_WordBase.DeleteAllSQLQueryInWord(document); document.Save(); document.Close(); } catch (Exception ex) { //StaticValues.logs += ex.Message + Environment.NewLine; StaticValues.logs += ex.ToString() + Environment.NewLine; StaticValues.is_success = false; // Write to debug screen on VS System.Diagnostics.Debug.WriteLine(StaticValues.logs); } }
/// <summary> /// Determine the type of content control and take neccessary actions /// </summary> /// <param name="content_control">A SdteElement instance represent a content control</param> /// <param name="condional">A DataRow instance contains required values for conditional (used in repeat content control)</param> protected void ProcessBasedOnContentControl(SdtElement content_control, DataRow conditional) { SdtAlias alias = content_control.Descendants <SdtAlias>().FirstOrDefault(); if (alias.Val.ToString().ToLower() == StaticValues.repeat_cc_name) { Helper_WordRepeat repeat_helper = new Helper_WordRepeat(content_control); repeat_helper.Execute(); } else if (alias.Val.ToString().ToLower() == StaticValues.columntable_cc_name) { Helper_WordTable_Columns table_helper = new Helper_WordTable_Columns(content_control); table_helper.AddConditionToSQLQuery(conditional); table_helper.AddDataToTable(); } else if (alias.Val.ToString().ToLower() == StaticValues.rowtable_cc_name) { Helper_WordTable_Rows table_helper = new Helper_WordTable_Rows(content_control); table_helper.AddConditionToSQLQuery(conditional); table_helper.AddDataToTable(); } else if (alias.Val.ToString().ToLower() == StaticValues.hybridtable_cc_name) { Helper_WordTable_Hybrid table_helper = new Helper_WordTable_Hybrid(content_control); table_helper.AddConditionToSQLQuery(conditional); table_helper.AddDataToTable(); } else if (alias.Val.ToString().ToLower() == StaticValues.barchart_cc_name) { Helper_WordBarChart chart_helper = new Helper_WordBarChart(content_control); chart_helper.AddConditionToSQLQuery(conditional); chart_helper.UpdateChartFromSQL(); } else if (alias.Val.ToString().ToLower() == StaticValues.piechart_cc_name) { Helper_WordPieChart chart_helper = new Helper_WordPieChart(content_control); chart_helper.AddConditionToSQLQuery(conditional); chart_helper.UpdateChartFromSQL(); } else if (alias.Val.ToString().ToLower() == StaticValues.linechart_cc_name) { Helper_WordLineChart chart_helper = new Helper_WordLineChart(content_control); chart_helper.AddConditionToSQLQuery(conditional); chart_helper.UpdateChartFromSQL(); } else if (alias.Val.ToString().ToLower() == StaticValues.val_cc_name) { Helper_WordBase helper = new Helper_WordBase(); helper.Init(content_control); helper.AddConditionToSQLQuery(conditional); string content = helper.GetDataFromDatabaseUsingSQL().Rows[0][0].ToString(); if (Helper_WordPicture.IsUrl(content) && Helper_WordPicture.IsImageUrl(content)) { // It is picture SdtElement image_cc = content_control.Descendants <SdtElement>().Where(s => s.Descendants <SdtAlias>().FirstOrDefault().Val.ToString().ToLower() == StaticValues.image_cc_name).FirstOrDefault(); Helper_WordPicture pic_helper = new Helper_WordPicture(image_cc, content); pic_helper.AddPictureFromUri(); } else // Just normal text { Helper_WordBase.ReplaceContentsInContentControl(content_control, content); } } }