示例#1
0
		/// <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;
		}
示例#2
0
        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}'");
            }
        }
示例#3
0
        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);
        }
示例#4
0
        internal void EditRule(TemplateRule templateRule, string contentFile)
        {
            string fullName = GetFullNameFileRule(templateRule);

            using (StreamWriter writer = GetWriter(fullName))
            {
                writer.Write(contentFile);
            }
        }
示例#5
0
        internal void CreateRule(string templateName, TemplateRule templateRule, string contentFile)
        {
            fileCore.CreteRule(templateRule, contentFile);

            Template template = GetTemplate(templateName);

            template.TemplateRules.Add(templateRule);

            SaveTemplates();
        }
示例#6
0
        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();
        }
示例#7
0
        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}");
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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
            });
        }
示例#10
0
 internal string GetEditFile(TemplateRule templateRule)
 {
     return(fileCore.ReadEditFile(templateRule));
 }
示例#11
0
		public void SetTemplateRule(TemplateRule templateRule)
		{
			_templateRule = templateRule;
		}
示例#12
0
		public void AddTemplateRule(TemplateRule templateRule)
		{
			if (_templateRules == null)
				_templateRule = new TemplateRule();
			_templateRules.Add(templateRule);
		}
示例#13
0
        internal string ReadEditFile(TemplateRule templateRule)
        {
            string fullName = GetFullNameFileRule(templateRule);

            return(ReadTemplateFile(fullName));
        }
示例#14
0
 private string GetFullNameFileRule(TemplateRule templateRule)
 {
     return(Path.Combine(configuration.PhysicalPathTemplate, templateRule.File));
 }
示例#15
0
        internal void DeleteRule(TemplateRule templateRule)
        {
            string fullName = GetFullNameFileRule(templateRule);

            File.Delete(fullName);
        }