コード例 #1
0
        /// <summary>验证变量</summary>
        private XmlVariable ValidateVariable(XmlVariable oldVariable)
        {
            var newVariable = new XmlVariable();

            if (!this.Presenter.Validate(this.txtVariableName, ref newVariable.Name, "变量名称不允许为空!"))
            {
                return(null);
            }
            if (newVariable.Name.IndexOfAny(new char[] { '{', '}' }) >= 0)
            {
                this.Presenter.WorkItem.Alert("变量名称不允许包含字符'{'和'}'!");
                return(null);
            }
            if (oldVariable == null || !newVariable.Name.Equals(oldVariable.Name, StringComparison.OrdinalIgnoreCase))
            {
                if (this.Presenter.Config.Variables.Any(v => v.Name.Equals(newVariable.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    this.Presenter.WorkItem.Alert("变量名称已经存在!");
                    return(null);
                }
            }
            if (!this.Presenter.Validate(this.txtVariableTitle, ref newVariable.Title, "变量标题不允许为空!"))
            {
                return(null);
            }
            if (!this.Presenter.Validate(this.txtVariableValue, ref newVariable.Value, "变量值不允许为空!"))
            {
                return(null);
            }
            return(newVariable);
        }
コード例 #2
0
        /// <summary>加入一个变量</summary>
        private void AddVariable(XmlVariable variable)
        {
            var lvwItem = this.lvwExcelTemplateVariables.Items.Add(variable.Name, variable.Name, string.Empty);

            lvwItem.SubItems.Add(variable.Title);
            lvwItem.SubItems.Add(variable.BuildIn ? "是" : "否");
            lvwItem.SubItems.Add(variable.Value);
            lvwItem.Tag = variable;
        }
コード例 #3
0
        /// <summary>加入内置变量</summary>
        private void AddBuildInVariable(List <XmlVariable> variables, string name, string title, string value, IValueProvider provider = null)
        {
            var variable = variables.FirstOrDefault(e => e.Name == name);

            if (variable == null)
            {
                variable      = new XmlVariable();
                variable.Name = name;
                variables.Add(variable);
            }
            variable.Title = title;
            if (variable.Value.Length == 0)
            {
                variable.Value = value;
            }
            variable.BuildIn  = true;
            variable.Provider = provider;
        }