protected override ProductRule CreateEntity()
        {
            //属性
            _entity = new ProductRule()
            {
                Name        = _data.GetAttribute("name"),
                Description = _data.GetAttribute("description"),
                Template    = _data.GetAttribute("template"),
                Export      = _data.GetAttribute("export")
            };
            _entity.ShrinkSheet = ParseUtil.ParseBoolean(_data.GetAttribute("shrinkSheet"), false);
            string tmpStr = _data.GetAttribute("shrinkExSheets");

            _entity.ShrinkExSheets = string.IsNullOrEmpty(tmpStr) ? new string[0] : tmpStr.Split(',');

            //子结点:DataList
            //_entity.AddSources(parseDataList(_validator.QuerySubNodes("DataSource/DataList", _data)));
            //子结点:DataTable
            //_entity.AddSources(parseSource(_validator.QuerySubNodes("DataSource/TableSource", _data)));
            //子结点:Sheet
            //_entity.AddSheets(parseSheet(_validator.QuerySubNodes("Sheets/*", _data)));
            _entity.AddSources(parseSubElement <DataListElement, ListSource>(_validator.QuerySubNodes("DataSource/DataList", _data)));
            _entity.AddSources(parseSubElement <SourceElement, Source>(_validator.QuerySubNodes("DataSource/TableSource", _data)));
            _entity.AddSheets(parseSubElement <SheetElement, Sheet>(_validator.QuerySubNodes("Sheets/*", _data)));
            return(_entity);
        }
        protected override Cell CreateEntity()
        {
            BaseEntity  container = _upperElement.CurrentEntity;
            ProductRule prodRule  = container.ProductRule;

            _entity = new Cell(prodRule, container, new Location(_data.GetAttribute("location")));
            parseSource(_data.GetAttribute("source"));
            _entity.DataIndex   = ParseUtil.ParseInt(_data.GetAttribute("index"), 0);
            _entity.ValueAppend = ParseUtil.ParseBoolean(_data.GetAttribute("valueAppend"), false);
            _entity.Value       = ParseUtil.IfNullOrEmpty(_data.GetAttribute("value"));
            _entity.FillType    = ParseUtil.ParseEnum <FillType>(_data.GetAttribute("fill"), FillType.Origin);
            return(_entity);
        }
Beispiel #3
0
        protected override Field CreateEntity()
        {
            Table       table = _tableElement.Entity;
            ProductRule prod  = table.ProductRule;

            _entity               = new Field(table, _data.GetAttribute("name"));
            _entity.ColIndex      = ParseUtil.ParseColumnIndex(_data.GetAttribute("colIndex"), -1);
            _entity.Type          = ParseUtil.ParseEnum <FieldType>(_data.GetAttribute("type"), FieldType.Unknown);
            _entity.Format        = _data.GetAttribute("format");
            _entity.CommentColumn = _data.GetAttribute("annnotationField");
            _entity.RefColumn     = _data.GetAttribute("refField");
            _entity.LinkType      = _data.GetAttribute("linkType");
            string tmpStr = _data.GetAttribute("dropDownListSource");

            if (!string.IsNullOrEmpty(tmpStr))
            {
                Source tmpSource = prod.GetSource(tmpStr);

                /**
                 * dropDownListSource数据源要么引用预定义的DataList,要么指定了DataTable.Field;否则将被忽略
                 */
                if (tmpSource != null && tmpSource is ListSource)
                {
                    _entity.DropDownListSource = tmpSource as ListSource;
                }
                else if (tmpSource == null && tmpStr.Contains('.'))
                {
                    tmpSource = new ListSource(tmpStr.Split('.')[0], tmpStr.Split('.')[1]);
                    _entity.DropDownListSource = tmpSource as ListSource;
                    prod.RegistSource(tmpSource);
                }
            }
            _entity.Spannable = ParseUtil.ParseBoolean(_data.GetAttribute("spannable"), false);
            _entity.ColSpan   = ParseUtil.ParseInt(_data.GetAttribute("colspan"), 1);
            _entity.SumField  = ParseUtil.ParseBoolean(_data.GetAttribute("sumfield"), false);
            _entity.EmptyFill = _data.GetAttribute("emptyFill");
            return(_entity);
        }
        protected override RegionTable CreateEntity()
        {
            Sheet       sheet    = _sheetElement.Entity;
            ProductRule prodRule = sheet.ProductRule;

            Location tmpLocation = new Location(_data.GetAttribute("location"));

            _entity        = new RegionTable(prodRule, sheet, tmpLocation);
            _entity.Freeze = ParseUtil.ParseBoolean(_data.GetAttribute("freeze"), false);

            XmlNodeList regionNodes = _sheetElement.ProductRuleElement.QuerySubNodes("Region", _data);

            foreach (XmlElement regionNode in regionNodes)
            {
                Region region = new RegionElement(regionNode, this).Entity;
                if (region != null)
                {
                    _entity.AddRegion(region);
                }
            }
            _entity.LinkRegionSource();
            return(_entity);
        }
Beispiel #5
0
        protected override Sheet CreateEntity()
        {
            _entity           = new Sheet(_productRuleElement.Entity);
            _entity.Name      = _data.GetAttribute("name");
            _entity.IsDynamic = ParseUtil.ParseBoolean(_data.GetAttribute("dynamic"), false);
            _entity.NameRule  = _data.GetAttribute("nameRule");
            string sourceName = _data.GetAttribute("source");

            if (!string.IsNullOrEmpty(sourceName))
            {
                //_entity.SetDynamicSource(_entity.ProductRule.RegistSource(source));
                _entity.ProductRule.RegistSource(sourceName);
                _entity.SourceName = sourceName;
            }
            //_entity.AddCells(parseCell(_productRuleElement.QuerySubNodes("Cells/Cell", _data)));
            //_entity.AddTables(parseTable(_productRuleElement.QuerySubNodes("Tables/Table", _data)));
            //_entity.AddTables(parseHeaderTable(_productRuleElement.QuerySubNodes("Tables/HeaderTable", _data)));
            //_entity.AddTables(parseDynamicArea(_productRuleElement.QuerySubNodes("DynamicAreas/DynamicArea", _data)));
            _entity.AddCells(parseSubElement <CellElement, Cell>(_productRuleElement.QuerySubNodes("Cells/Cell", _data)));
            _entity.AddTables(parseSubElement <TableElement, Table>(_productRuleElement.QuerySubNodes("Tables/Table", _data)));
            _entity.AddTables(parseSubElement <RegionTableElement, RegionTable>(_productRuleElement.QuerySubNodes("Tables/HeaderTable", _data)));
            _entity.AddTables(parseSubElement <DynamicAreaElement, DynamicArea>(_productRuleElement.QuerySubNodes("DynamicAreas/DynamicArea", _data)));
            return(_entity);
        }
        protected override Region CreateEntity()
        {
            RegionTable table    = _regionTableElement.Entity;
            ProductRule prodRule = table.ProductRule;

            string tmpStr = _data.GetAttribute("type");

            if (string.IsNullOrEmpty(tmpStr))
            {
                return(null);
            }
            _entity = "corner".Equals(tmpStr.ToLower()) ? (Region) new CornerRegion(table) :
                      "rowheader".Equals(tmpStr.ToLower()) ? new RowHeaderRegion(table) :
                      "columnheader".Equals(tmpStr.ToLower()) ? (Region) new ColumnHeaderRegion(table) :
                      new BodyRegion(table);
            tmpStr = _data.GetAttribute("source");
            if (!string.IsNullOrEmpty(tmpStr))
            {
                string[] values = tmpStr.Split('.');
                if (values.Length > 1)
                {
                    _entity.Field = values[1];
                }
                _entity.Source = prodRule.RegistSource(values[0]);
            }
            _entity.EmptyFill = _data.GetAttribute("emptyFill");

            if (_entity is BodyRegion)
            {
                //暂无逻辑
            }
            else if (_entity is HeaderRegion)
            {
                HeaderRegion header = _entity as HeaderRegion;
                header.Source = parseTreeSource(tmpStr, _data.GetAttribute("innerMapping"), prodRule) ?? header.Source;

                tmpStr = _data.GetAttribute("headerBodyMapping");
                header.HeaderBodyRelation = parseRelation(header.Source, tmpStr, prodRule);
                //tmpStr = _data.GetAttribute("treeSource");
                //header.TreeSource = parseTreeSource(tmpStr, _data.GetAttribute("treeInnerMapping"), prodRule);
                ////header.IdField = element.GetAttribute("IdField");
                ////header.ParentField = element.GetAttribute("parentField");
                //tmpStr = _data.GetAttribute("headerTreeMapping");
                //header.HeaderTreeRelation = parseRelation(header.Source, tmpStr, prodRule);
                //if (header.HeaderTreeRelation != null)
                //{
                //    header.HeaderTreeRelation.ReferecedSource = header.TreeSource;
                header.MaxLevel     = ParseUtil.ParseInt(_data.GetAttribute("maxLevel"), -1);
                header.ColSpannable = ParseUtil.ParseBoolean(_data.GetAttribute("colSpannable"));
                header.RowSpannable = ParseUtil.ParseBoolean(_data.GetAttribute("rowSpannable"));
                header.IsBasedOn    = ParseUtil.ParseBoolean(_data.GetAttribute("basedSource"));
                //}
            }
            else if (_entity is CornerRegion)
            {
                tmpStr = _data.GetAttribute("spanRule");
                if (!string.IsNullOrEmpty(tmpStr))
                {
                    CornerSpanRule spanRule = CornerSpanRule.None;
                    if (!Enum.TryParse(tmpStr, true, out spanRule))
                    {
                        spanRule = "row".Equals(tmpStr.ToLower()) ? CornerSpanRule.BaseOnRowHeader :
                                   "column".Equals(tmpStr.ToLower()) ? CornerSpanRule.BaseOnColumnHeader :
                                   "one".Equals(tmpStr.ToLower()) ? CornerSpanRule.AllInOne : CornerSpanRule.None;
                    }
                    (_entity as CornerRegion).SpanRule = spanRule;
                }
            }
            return(_entity);
        }
        protected override Table CreateEntity()
        {
            BaseEntity  container = _upperElement.CurrentEntity;
            ProductRule prodRule  = container.ProductRule;

            Location tmpLocation = new Location(_data.GetAttribute("location"));

            _entity = new Table(prodRule, container, tmpLocation);
            string tmpStr = _data.GetAttribute("source");

            if (!string.IsNullOrEmpty(tmpStr))
            {
                _entity.SourceName = tmpStr;
                //只要不是动态解析的数据源,Source不能为空
                if ((container is Sheet && !(container as Sheet).IsDynamic) || !DynamicSource.NeedDynamicParse(tmpStr))
                {
                    //_entity.Source = prodRule.RegistSource(tmpStr);
                    prodRule.RegistSource(tmpStr);
                }
            }
            _entity.RowNumIndex   = ParseUtil.ParseColumnIndex(_data.GetAttribute("rowNumIndex"), -1);
            _entity.CopyFill      = ParseUtil.ParseBoolean(_data.GetAttribute("copyFill"), true);
            _entity.SumLocation   = ParseUtil.ParseEnum <LocationPolicy>(_data.GetAttribute("sumLocation"), LocationPolicy.Undefined);
            _entity.SumOffset     = ParseUtil.ParseInt(_data.GetAttribute("sumOffset"), _entity.SumLocation == LocationPolicy.Undefined || _entity.SumLocation == LocationPolicy.Absolute ? -1 : 0);
            _entity.AutoFitHeight = ParseUtil.ParseBoolean(_data.GetAttribute("autoFitHeight"), false);
            int groupLevel = ParseUtil.ParseInt(_data.GetAttribute("groupLevel"), 0);

            if (groupLevel > 0)
            {
                tmpStr = _data.GetAttribute("groupNumShow");
                if (!string.IsNullOrEmpty(tmpStr))
                {
                    bool[]   shows = new bool[groupLevel];
                    string[] bools = tmpStr.Split(',');

                    for (int i = 0; i < bools.Length && i < shows.Length; i++)
                    {
                        if (bool.Parse(bools[i]))
                        {
                            shows[i] = true;
                        }
                    }
                    _entity.SetGroup(shows);
                }
            }

            _entity.AdjustSumOffset();

            #region Field重复出现的处理
            List <Field> fieldlist = new List <Field>();
            tmpStr = _data.GetAttribute("fields");
            if (!string.IsNullOrEmpty(tmpStr))
            {
                string[] fieldArray = tmpStr.Split(',');
                foreach (var fieldname in fieldArray)
                {
                    fieldlist.Add(new Field(_entity, fieldname));
                }
            }
            _entity.AddFields(fieldlist);

            //子结点
            parseField(_upperElement.ProductRuleElement.QuerySubNodes("Field", _data));

            #endregion Field重复出现的处理

            // 行号处理
            parseRowNum(_upperElement.ProductRuleElement.QuerySubNodes("RowNum", _data));

            //区域计算:计算行号、字段的列位置,以及Table填充列范围
            _entity.CalculateArea();

            //汇总列:在确定字段位置之后处理
            tmpStr = _data.GetAttribute("sumColumns");
            if (!string.IsNullOrEmpty(tmpStr))
            {
                string[] columns = tmpStr.Split(',');
                _entity.AddSumColumns(columns);
            }
            return(_entity);
        }