public static void Process(WordprocessingDocument docx, DataColumnInfo dcInfo, ReportDetailTemplate detail, SimpleField field) { var p = GetFirstParent <Paragraph>(field); var drawing = p?.Descendants <Drawing>().FirstOrDefault(); var chartRef = drawing?.Descendants <ChartReference>().FirstOrDefault(); if (chartRef == null) { return; } var firstOrDefault = docx.MainDocumentPart .Parts .FirstOrDefault(c => c.RelationshipId == chartRef.Id); if (firstOrDefault == null) { return; } var chartPart = (ChartPart)firstOrDefault .OpenXmlPart; var data = GetChartData(detail); ChartUpdater.UpdateChart(chartPart, data); }
public static DataSetData FromDataSet(DataSet ds) { DataSetData dsd = new DataSetData(); dsd.Tables = new ObservableCollection <DataTableInfo>(); foreach (DataTable t in ds.Tables) { DataTableInfo tableInfo = new DataTableInfo { TableName = t.TableName }; dsd.Tables.Add(tableInfo); tableInfo.Columns = new ObservableCollection <DataColumnInfo>(); foreach (DataColumn c in t.Columns) { DataColumnInfo col = new DataColumnInfo { ColumnName = c.ColumnName, ColumnTitle = c.ColumnName, DataTypeName = c.DataType.FullName, MaxLength = c.MaxLength, IsKey = c.Unique, IsReadOnly = (c.Unique || c.ReadOnly), IsRequired = !c.AllowDBNull }; if (c.DataType == typeof(System.Guid)) { col.IsReadOnly = true; col.DisplayIndex = -1; } tableInfo.Columns.Add(col); } } dsd.DataXML = ds.GetXml(); return(dsd); }
public static void Process(WordprocessingDocument docx, DataColumnInfo dcInfo, ReportDetailTemplate detail, string contentControlTag) { var data = GetChartData(detail); ChartUpdater.UpdateChart(docx, contentControlTag, data); }
protected virtual FilterControlColumn CreateFilterControlColumn(DataColumnInfo columnInfo, CriteriaEditorHelper editorHelper, List <ITestable> testableControls) { FilterControlColumn column = null; ITypeInfo info2; IMemberInfo memberInfo = editorHelper.FilteredTypeInfo.FindMember(columnInfo.Name); if ((memberInfo == null) || !memberInfo.IsVisible) { return(null); } IModelMemberViewItem modelDetailViewItem = this.CreatePropertyEditorModel(memberInfo, out info2); ASPxPropertyEditor testable = this.CreatePropertyEditor(false, modelDetailViewItem, info2, editorHelper.Application, editorHelper.ObjectSpace); if (testable != null) { testable.ViewEditMode = ViewEditMode.Edit; testable.CreateControl(); if (((testable.TestControl != null) && !(testable is ASPxLookupPropertyEditor)) && !SimpleTypes.IsClass(columnInfo.Type)) { testableControls.Add(new TestableUnknownClientIdWrapper(testable)); } } if (testable is ICustomValueParser) { this.valueParsers.Add((ICustomValueParser)testable); } if (testable != null) { this.disposablePropertyEditors.Add(testable); if ((testable is ASPxLookupPropertyEditor) || SimpleTypes.IsClass(columnInfo.Type)) { FilterControlLookupEditColumn column2 = new FilterControlLookupEditColumn { PropertiesLookupEdit = { ObjectSpace = editorHelper.ObjectSpace, ObjectTypeInfo = editorHelper.FilteredTypeInfo, MemberInfo = memberInfo, Model = modelDetailViewItem } }; column2.PropertiesLookupEdit.Model.LookupEditorMode = LookupEditorMode.AllItems; column2.TestCaption = testable.TestCaption; testableControls.Add(new TestableUnknownClientIdWrapper(column2)); column = column2; } else { column = new FilterControlPropertyEditorColumn(memberInfo.MemberType) { PropertiesASPxPropertyEditor = { ASPxPropertyEditor = testable } }; } } if (column == null) { column = this.CreateFilterControlColumnByType(columnInfo.Type); } column.PropertyName = columnInfo.Name.Replace("!", ""); column.DisplayName = CaptionHelper.GetMemberCaption(editorHelper.FilteredTypeInfo, column.PropertyName); return(column); }
static void SetListSourceRowValue(GridControl gridControl, int listSourceRowIndex, string columnName, object value) { DataColumnInfo column = gridControl.DataController.Columns[columnName]; if (column == null || listSourceRowIndex < 0) { return; } gridControl.DataController.Helper.SetRowValue(listSourceRowIndex, column.Index, value); }
private static bool GetTableName(ReportTemplate template, DataColumnInfo dcInfo) { var name = dcInfo.TableName.ToUpper(); dcInfo.TableNameInDb = string.Empty; foreach (DataTable t in template.DataSet.Tables) { if (t.TableName.ToUpper() != name) { continue; } dcInfo.TableNameInDb = t.TableName; dcInfo.HasRows = t.Rows.Count > 0; return(dcInfo.HasRows); } return(false); }
/// <summary> /// Calculates a list of <see cref="SelectableRange"/> objects that represent /// the range of the expression. /// </summary> /// <param name="context"></param> /// <param name="field"></param> /// <param name="range"></param> /// <param name="exp"></param> private static void CalcRange(IQueryContext context, DataColumnInfo field, SelectableRangeSet range, Expression exp) { var binary = (BinaryExpression)exp; Operator op = binary.Operator; if (op.IsLogical()) { if (op == Operator.And) { IList <Expression> andList = CreateAndList(new List <Expression>(), exp); foreach (Expression expr in andList) { UpdateRange(context, range, field, expr); } } else if (op == Operator.Or) { // Split left and right of logical operator. Expression[] exps = { binary.Left, binary.Right }; // Calculate the range of the left and right SelectableRangeSet left = new SelectableRangeSet(); CalcRange(context, field, left, exps[0]); SelectableRangeSet right = new SelectableRangeSet(); CalcRange(context, field, right, exps[1]); // Union the left and right range with the current range range.Union(left); range.Union(right); } else { throw new ApplicationException("Unrecognised logical operator."); } } else { // Not an operator so this is the value. UpdateRange(context, range, field, exp); } }
public override ITable Evaluate(IQueryContext context) { ITable t = Child.Evaluate(context); Expression exp = expression; // Assert that all variables in the expression are identical. IEnumerable <ObjectName> allVars = exp.AllVariables(); ObjectName v = null; foreach (ObjectName cv in allVars) { if (v != null && !cv.Equals(v)) { throw new ApplicationException("Assertion failed: Range plan does not contain common variable."); } v = cv; } // Find the variable field in the table. int col = ((Table)t).FindFieldName(v); if (col == -1) { throw new ApplicationException("Couldn't find column reference in table: " + v); } DataColumnInfo field = t.TableInfo[col]; // Calculate the range SelectableRangeSet range = new SelectableRangeSet(); CalcRange(context, field, range, exp); // Select the range from the table SelectableRange[] ranges = range.ToArray(); return(t.RangeSelect(v, ranges)); }
public static DataSetData FromDataSet(DataSet ds) { DataSetData dsd = new DataSetData(); dsd.Tables = new ObservableCollection<DataTableInfo>(); foreach (DataTable t in ds.Tables) { DataTableInfo tableInfo = new DataTableInfo {TableName = t.TableName}; dsd.Tables.Add(tableInfo); tableInfo.Columns = new ObservableCollection<DataColumnInfo>(); foreach (DataColumn c in t.Columns) { DataColumnInfo col = new DataColumnInfo { ColumnName = c.ColumnName, ColumnTitle = c.ColumnName, DataTypeName = c.DataType.FullName, MaxLength=c.MaxLength, IsKey=c.Unique, IsReadOnly=(c.Unique || c.ReadOnly), IsRequired = !c.AllowDBNull}; if (c.DataType == typeof(System.Guid)) { col.IsReadOnly = true; col.DisplayIndex = -1; } tableInfo.Columns.Add(col); } } dsd.DataXML = ds.GetXml(); return dsd; }
internal static DataColumnInfo GetColumnInfo(string fieldName) { if (fieldName == null) { throw new ArgumentException("Error: table-MERGEFIELD should be formatted as follows: XYZ_TableName_ColumnName."); } var sep = new[] { '_' }; var splits = fieldName.Split(sep, StringSplitOptions.RemoveEmptyEntries); var cInfo = new DataColumnInfo { TableName = splits[1] }; if (splits.Length == 3) { cInfo.FieldName = splits[2]; } if (splits[0].ToUpper().Equals("TBL")) { cInfo.FieldType = FieldType.Table; } else if (splits[0].ToUpper().Equals("CRT")) { cInfo.FieldType = FieldType.Chart; } else if (splits[0].ToUpper().Equals("IMG")) { cInfo.FieldType = FieldType.Image; } else { cInfo.FieldType = FieldType.Invalid; } return(cInfo); }
public void RestoreGridViewLayout(ASPxGridView grid) { foreach (ColumnInfoBase column in Columns) { DataColumnInfo dataColumnInfo = column as DataColumnInfo; if (dataColumnInfo != null) { column.RestoreGridViewColumn(grid.Columns[dataColumnInfo.FieldName]); continue; } if (column is CommandColumnInfo) { column.RestoreGridViewColumn(GetSpecificColumn <GridViewCommandColumn>(grid)); continue; } if (column is BandColumnInfo) { column.RestoreGridViewColumn(GetSpecificColumn <GridViewBandColumn>(grid)); continue; } } grid.FilterExpression = FilterExpression; grid.PageIndex = PageIndex; }
public static void Process(WordprocessingDocument docx, DataColumnInfo dcInfo, DataTable dataTable, SimpleField field, string fieldName) { string[] switches; if (string.IsNullOrEmpty(fieldName) || dcInfo.FieldType != FieldType.Table) { return; } var wordRow = GetFirstParent <TableRow>(field); if (wordRow == null) { return; } var wordTable = GetFirstParent <Table>(wordRow); if (!dcInfo.HasRows || wordTable == null) { return; } var props = new List <TableCellProperties>(); var cellcolumnnames = new List <string>(); var paragraphInfo = new List <string>(); var cellfields = new List <SimpleField>(); foreach (var cell in wordRow.Descendants <TableCell>()) { props.Add(cell.GetFirstChild <TableCellProperties>()); Paragraph p = cell.GetFirstChild <Paragraph>(); if (p != null) { var pp = p.GetFirstChild <ParagraphProperties>(); paragraphInfo.Add(pp?.OuterXml); } else { paragraphInfo.Add(null); } var colname = string.Empty; SimpleField colfield = null; foreach (var cellfield in cell.Descendants <SimpleField>()) { colfield = cellfield; colname = GetColumnInfo(GetFieldName(cellfield, out switches)).FieldName; break; } cellcolumnnames.Add(colname); cellfields.Add(colfield); } // keep reference to row properties var rprops = wordRow.GetFirstChild <TableRowProperties>(); foreach (DataRow row in dataTable.Rows) { TableRow nrow = new TableRow(); if (rprops != null) { nrow.Append(new TableRowProperties(rprops.OuterXml)); } for (var i = 0; i < props.Count; i++) { TableCellProperties cellproperties = new TableCellProperties(props[i].OuterXml); TableCell cell = new TableCell(); cell.Append(cellproperties); Paragraph p = new Paragraph(new ParagraphProperties(paragraphInfo[i])); cell.Append(p); // cell must contain at minimum a paragraph ! if (!string.IsNullOrEmpty(cellcolumnnames[i])) { if (!dataTable.Columns.Contains(cellcolumnnames[i])) { throw new Exception(string.Format("Unable to complete template: column name '{0}' is unknown in parameter tables !", cellcolumnnames[i])); } if (!row.IsNull(cellcolumnnames[i])) { string val = row[cellcolumnnames[i]].ToString(); p.Append(GetRunElementForText(val, cellfields[i])); } } nrow.Append(cell); } wordTable.Append(nrow); } }
/// <summary> /// Updates a range with the given expression. /// </summary> /// <param name="context"></param> /// <param name="range"></param> /// <param name="field"></param> /// <param name="e"></param> private static void UpdateRange(IQueryContext context, SelectableRangeSet range, DataColumnInfo field, Expression e) { var binary = (BinaryExpression)e; Operator op = binary.Operator; Expression[] exps = { binary.Left, binary.Right }; // Evaluate to an object DataObject cell = exps[1].Evaluate(context); // If the evaluated object is not of a comparable type, then it becomes // null. DataType fieldType = field.DataType; if (!cell.DataType.IsComparable(fieldType)) { cell = new DataObject(fieldType, null); } // Intersect this in the range set range.Intersect(op, cell); }
/// <summary> /// Moves some columns of this collection to another collection- /// </summary> /// <param name="destination">The destination collection where the columns are moved to.</param> /// <param name="destindex">The index in the destination collection where the columns are moved to.</param> /// <param name="selectedColumns">The indices of the column of the source collection that are moved.</param> public void MoveColumnsTo(DataColumnCollection destination, int destindex, IAscendingIntegerCollection selectedColumns) { int nOriginalColumnCount = ColumnCount; int numberMoved = selectedColumns.Count; DataColumn[] tmpColumn = new DataColumn[numberMoved]; DataColumnInfo[] tmpInfo = new DataColumnInfo[numberMoved]; object[] tmpScript = new object[numberMoved]; for(int i=0;i<numberMoved;i++) { tmpColumn[i] = this[selectedColumns[i]]; tmpInfo[i] = (DataColumnInfo)this.m_ColumnInfo[m_ColumnsByNumber[i]]; tmpScript[i] = this.m_ColumnScripts[tmpColumn[i]]; } this.RemoveColumns(selectedColumns,false); destination.Insert(tmpColumn,tmpInfo,0,true); // Move the column scripts also for(int i=0; i<numberMoved; i++) { if(tmpScript[i]!=null) destination.m_ColumnScripts.Add(tmpColumn[i],tmpScript[i]); } }
/// <summary> /// Copy constructor. /// </summary> /// <param name="from">Another object to copy from.</param> public DataColumnInfo(DataColumnInfo from) { this.Name = from.Name; this.Number = from.Number; this.Group = from.Group; this.Kind = from.Kind; }
/// <summary> /// 转换实体 /// </summary> /// <param name="row">数据行</param> /// <returns></returns> public DataColumnInfo DataRowToModel(DataRow row) { var model = new DataColumnInfo(); if (row != null) { if (!row["Id"].IsNullOrEmpty()) { model.Id = row["Id"].ToInt32(); } if (!row["Name"].IsNullOrEmpty()) { model.Name = row["Name"].ToStringValue(); } if (!row["IsIdentity"].IsNullOrEmpty()) { model.IsIdentity = row["IsIdentity"].ToInt32(); model.IsIdentityDesc = EnumOperate.GetEnumDesc((IsIdentity)model.IsIdentity); } if (!row["IdentSeed"].IsNullOrEmpty()) { model.IdentSeed = row["IdentSeed"].ToInt32(); } if (!row["IdentIncr"].IsNullOrEmpty()) { model.IdentIncr = row["IdentIncr"].ToInt32(); } if (!row["IsKey"].IsNullOrEmpty()) { model.IsKey = row["IsKey"].ToInt32(); model.IsKeyDesc = EnumOperate.GetEnumDesc((IsKey)model.IsKey); } if (!row["Type"].IsNullOrEmpty()) { model.Type = row["Type"].ToStringValue(); } if (!row["Bytes"].IsNullOrEmpty()) { model.Bytes = row["Bytes"].ToInt32(); } if (!row["Length"].IsNullOrEmpty()) { model.Length = row["Length"].ToInt32(); } if (!row["Scale"].IsNullOrEmpty()) { model.Scale = row["Scale"].ToInt32(); } if (!row["IsNullable"].IsNullOrEmpty()) { model.IsNullable = row["IsNullable"].ToInt32(); model.IsNullableDesc = EnumOperate.GetEnumDesc((IsNullable)model.IsNullable); } if (!row["DefaultValue"].IsNullOrEmpty()) { model.DefaultValue = row["DefaultValue"].ToStringValue(); } if (!row["Description"].IsNullOrEmpty()) { model.Description = row["Description"].ToStringValue(); } } return(model); }
/// <summary> /// Inserts multiple DataColumns into the collection at index <c>nDestinationIndex</c>. The caller must garantuee, that the names are not already be present, /// or the argument <c>renameColumnsIfNecessary</c> must be set to true! /// </summary> /// <param name="columns">The array of data columns to insert.</param> /// <param name="info">The corresponding column information for the columns to insert.</param> /// <param name="nDestinationIndex">The index into the collection where the columns are inserted.</param> /// <param name="renameColumnsIfNecessary">If set to true, the columns to insert are automatically renamed if already be present in the destination collection. If false, /// an exception is thrown if a column with the same name is already be present in the destination table.</param> protected void Insert(DataColumn[] columns, DataColumnInfo[] info, int nDestinationIndex, bool renameColumnsIfNecessary) { this.Suspend(); int indexOfAddedColumns = this.ColumnCount; int numberToAdd = columns.Length; // first add the columns to the collection for(int i=0;i<numberToAdd;i++) { if(renameColumnsIfNecessary && this.ContainsColumn(info[i].Name)) info[i].Name = this.FindUniqueColumnNameWithBase(info[i].Name); this.Add(columns[i],info[i]); } // then move the columns to the desired position this.ChangeColumnPosition(new Altaxo.Collections.IntegerRangeAsCollection(indexOfAddedColumns,numberToAdd),nDestinationIndex); this.Resume(); }
/// <summary> /// Inserts multiple DataColumns into the collection at index <c>nDestinationIndex</c>. The caller must garantuee, that the names are not already be present! /// </summary> /// <param name="columns">The array of data columns to insert.</param> /// <param name="info">The corresponding column information for the columns to insert.</param> /// <param name="nDestinationIndex">The index into the collection where the columns are inserted.</param> protected void Insert(DataColumn[] columns, DataColumnInfo[] info, int nDestinationIndex) { Insert(columns,info,nDestinationIndex,false); }
/// <summary> /// Add a column using a DataColumnInfo object. The provided info must not be used elsewhere, since it is used directly. /// </summary> /// <param name="datac">The column to add.</param> /// <param name="info">The DataColumnInfo object for the column to add.</param> private void Add(Altaxo.Data.DataColumn datac, DataColumnInfo info) { System.Diagnostics.Debug.Assert(this.ContainsColumn(datac)==false); System.Diagnostics.Debug.Assert(datac.ParentObject==null,"This private function should be only called with fresh DataColumns, if not, alter the behaviour of the calling function"); System.Diagnostics.Debug.Assert(false==this.m_ColumnsByName.ContainsKey(info.Name),"Trying to add a column with a name that is already present (this error must be fixed in the calling function)"); info.Number = this.m_ColumnsByNumber.Count; this.m_ColumnsByNumber.Add(datac); this.m_ColumnsByName[info.Name]=datac; this.m_ColumnInfo[datac] = info; datac.ParentObject = this; if(info.IsIndependentVariable) this.EnsureUniqueColumnKindsForIndependentVariables(info.Group,datac); this.EhChildChanged(null,ChangeEventArgs.CreateColumnAddArgs(info.Number,datac.Count)); }