/// <summary> /// 匹配Excel模版 /// </summary> /// <param name="matchErrorList"></param> /// <param name="aTemplateRule"></param> private bool MatchTemplate(TemplateRule aTemplateRule) { if (aTemplateRule.SheetNum == _excelStructure.SheetNum) { foreach (var aSheet in _excelStructure.Sheets) { if (aTemplateRule.SheetRules.Any(s => s.SheetName == aSheet.SheetName)) { var unMatchColumns = aTemplateRule[aSheet.SheetName].ColumnRules .Where(c => !aSheet.Columns.Any(a => a.ColumnName == c.ColumnName)) .Select(c => c.ColumnName) .ToList(); if (!unMatchColumns.Any()) continue; var message = $"----工作表[{aSheet.SheetName}]不包含列:[{ConvertListToString(unMatchColumns, "]、[")}]与模板《{aTemplateRule.TemplateName}》.[{aSheet.SheetName}],不匹配!"; _checkReport.TemplateMatchError("匹配列失败", message); return false; } else //2.1.2 模版不包含Excel中的某一个Sheet页,或者Sheet页中列数不一致 { var message = $"----模板《{aTemplateRule.TemplateName}》中没有找到与[{aSheet.SheetName}](共{aSheet.ColumnNum}列)匹配的工作表,不匹配!"; _checkReport.TemplateMatchError("匹配工作表失败", message); return false; } } } else { var message = $"----模版<<{aTemplateRule.TemplateName}>>有{aTemplateRule.SheetNum}个工作表;而Excel中有{_excelStructure.SheetNum}个工作表,不匹配!"; _checkReport.TemplateMatchError("匹配工作表页数失败", message); return false; } return true; }
private void lbRules_SelectedValueChanged(object sender, EventArgs e) { try { string ruleName = lbRules?.SelectedItem?.ToString() ?? string.Empty; if (!string.IsNullOrEmpty(ruleName)) { Template template = templateCore.GetTemplate(txtName.Text); TemplateRule rule = template.TemplateRules.FirstOrDefault(tr => tr.Name.Equals(ruleName)); txtRuleFile.Text = rule.File; txtRuleTargeProjectNamespace.Text = rule.TargeNamespace; txtRuleName.Text = rule.Target; txtRuleNamespace.Text = rule.DestinationPath; chkRuleKeep.Checked = !rule.Overide; SetRichTextBox(templateCore.GetEditFile(rule)); ScrenRuleControl(EnScrenRuleControl.Rule); WriteStatus($"View details of the '{template.Name}' rule of the '{rule.Name}' template"); } } catch { WriteStatus($"An error occurred while select one rule of the template '{txtName.Text}'"); } }
internal void DeleteRule(string templateName, string ruleName) { Template template = GetTemplate(templateName); TemplateRule templateRule = template.TemplateRules.First(tr => tr.File.Equals(ruleName)); fileCore.DeleteRule(templateRule); template.TemplateRules.Remove(templateRule); }
internal void EditRule(TemplateRule templateRule, string contentFile) { string fullName = GetFullNameFileRule(templateRule); using (StreamWriter writer = GetWriter(fullName)) { writer.Write(contentFile); } }
internal void CreateRule(string templateName, TemplateRule templateRule, string contentFile) { fileCore.CreteRule(templateRule, contentFile); Template template = GetTemplate(templateName); template.TemplateRules.Add(templateRule); SaveTemplates(); }
internal void EditRule(string templateName, TemplateRule templateRule, string contentFile) { fileCore.EditRule(templateRule, contentFile); Template template = GetTemplate(templateName); TemplateRule templateRuleOld = template.TemplateRules.First(tr => tr.Name.Equals(templateRule.Name)); template.TemplateRules.Remove(templateRuleOld); template.TemplateRules.Add(templateRule); SaveTemplates(); }
private void tsbRuleSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtRuleFile.Text)) { WriteStatus("Input 'File Template' cannot be empty."); return; } if (string.IsNullOrEmpty(txtRuleTargeProjectNamespace.Text)) { WriteStatus("Input 'Target Project Namespace' cannot be empty."); return; } if (string.IsNullOrEmpty(txtRuleName.Text)) { WriteStatus("Input 'Target File Rule' cannot be empty."); return; } string templateName = txtName.Text; TemplateRule templateRule = new TemplateRule { File = templateCore.CreateFileRulePath(templateName, txtRuleFile.Text), TargeNamespace = txtRuleTargeProjectNamespace.Text, Target = txtRuleName.Text, DestinationPath = txtRuleNamespace.Text, Overide = !chkRuleKeep.Checked }; string contentFile = rtbRuleEditFile.Text; if (isEditRule) { templateCore.EditRule(templateName, templateRule, contentFile); } else { templateCore.CreateRule(templateName, templateRule, contentFile); } AddRuleInListBox(templateName); WriteStatus($"Save the '{txtName.Text}' rule from the '{txtRuleName.Text}' template"); ScrenRuleControl(EnScrenRuleControl.Default); ClearScrenRule(); } catch (Exception ex) { WriteStatus($"Error trying to delete rule: {ex.Message}"); } }
internal void CreteRule(TemplateRule templateRule, string contentFile) { string fullName = GetFullNameFileRule(templateRule); if (!Directory.Exists(Path.GetDirectoryName(fullName))) { Directory.CreateDirectory(Path.GetDirectoryName(fullName)); } using (StreamWriter writer = GetWriter(fullName)) { writer.Write(contentFile); } }
private TemplateBuilder CreateTemplateBuider(string nameNewFile, string solutionPath, TemplateRule rule) { return(new TemplateBuilder { NameDefault = nameNewFile, PathNamespace = rule.TargeNamespace,//Path.GetFileName(solutionPath), FileName = rule.Target, SolutionPath = solutionPath, DestinationPath = rule.DestinationPath, FileContent = fileCore.ReadTemplateFile(Path.Combine(Configuration.PhysicalPathTemplate, rule.File)), Overide = rule.Overide }); }
internal string GetEditFile(TemplateRule templateRule) { return(fileCore.ReadEditFile(templateRule)); }
public void SetTemplateRule(TemplateRule templateRule) { _templateRule = templateRule; }
public void AddTemplateRule(TemplateRule templateRule) { if (_templateRules == null) _templateRule = new TemplateRule(); _templateRules.Add(templateRule); }
internal string ReadEditFile(TemplateRule templateRule) { string fullName = GetFullNameFileRule(templateRule); return(ReadTemplateFile(fullName)); }
private string GetFullNameFileRule(TemplateRule templateRule) { return(Path.Combine(configuration.PhysicalPathTemplate, templateRule.File)); }
internal void DeleteRule(TemplateRule templateRule) { string fullName = GetFullNameFileRule(templateRule); File.Delete(fullName); }