void setContext(ITypeDescriptorContext context) { _metaConnection = context.Instance as MetaConnection; _metaEnum = context.Instance as MetaEnum; _metaTable = context.Instance as MetaTable; _metaColumn = context.Instance as MetaColumn; _metaJoin = context.Instance as MetaJoin; _reportView = context.Instance as ReportView; _reportOutput = context.Instance as ReportOutput; _reportSchedule = context.Instance as ReportSchedule; _parameter = context.Instance as Parameter; _security = context.Instance as SealSecurity; _emailDevice = context.Instance as OutputEmailDevice; }
public void AddRestriction(MetaColumn column, bool forPrompt) { if (column != null) { //Add restriction to current place ReportRestriction restriction = ReportRestriction.CreateReportRestriction(); restriction.Source = ModelPanel.Model.Source; restriction.Model = ModelPanel.Model; restriction.MetaColumnGUID = column.GUID; restriction.Name = column.Name; //Set PivotPos for aggregate restrictions restriction.PivotPosition = IsAggregate ? PivotPosition.Data : PivotPosition.Row; restriction.SetDefaults(); if (restriction.IsText && !restriction.IsEnum) restriction.Operator = Operator.Contains; ModelPanel.MainForm.IsModified = true; //Check for duplicate int index = 1; string initialName = restriction.DisplayNameEl; while (Restrictions.FirstOrDefault(i => i.DisplayRestriction == restriction.DisplayRestriction) != null) { index++; restriction.DisplayName = initialName + " " + index.ToString(); } Restrictions.Add(restriction); if (forPrompt) { restriction.Prompt = PromptType.Prompt; restrictionsTextBox.Selection.Length = 0; if (restrictionsTextBox.TextLength > 0) restrictionsTextBox.Selection.Start = restrictionsTextBox.TextLength; } string insertedText = ""; if (restrictionsTextBox.TextLength > 0 && restrictionsTextBox.Caret.Position >= restrictionsTextBox.TextLength) { if (restrictionsTextBox.Text.Last() != '\n') insertedText = "\r\n"; insertedText += "AND "; } insertedText += kStartRestrictionChar + restriction.DisplayRestriction + kStopRestrictionChar; restrictionsTextBox.Selection.Text = insertedText; restrictionsTextBox.Caret.Position -= 1; highlightRestriction(false); } Commit(); }
/// <summary> /// Add a MetaColumn in a MetaTable /// </summary> public MetaColumn AddColumn(MetaTable table) { MetaColumn result = MetaColumn.Create("ColumnName"); result.Source = this; MetaColumn col = table.Columns.FirstOrDefault(); if (col != null) { result.Category = col.Category; } else { result.Category = !string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(table.Name.Trim()); } result.DisplayOrder = table.GetLastDisplayOrder(); table.Columns.Add(result); return(result); }
/// <summary> /// Helper to create a MetaEnum for a given MetaColumn /// </summary> public MetaEnum CreateEnumFromColumn(MetaColumn column) { MetaEnum result = AddEnum(); result.IsEditable = true; result.Name = column.DisplayName; result.IsDynamic = true; if (!IsNoSQL) { result.Sql = string.Format("SELECT DISTINCT \r\n{0} \r\nFROM {1} \r\nORDER BY 1", column.Name, column.MetaTable.FullSQLName); } else { result.Script = @"@using System.Data @{ MetaEnum enumList = Model; MetaSource source = enumList.Source; MetaTable table = source.MetaData.Tables.FirstOrDefault(i => i.Name == TableName); if (table != null) { DataTable dataTable = table.BuildNoSQLTable(true); enumList.Values.Clear(); foreach (DataRow val in dataTable.Rows) { if (!enumList.Values.Exists(i => i.Id == val[ColumnName].ToString())) { enumList.Values.Add(new MetaEV() { Id = val[ColumnName].ToString() }); } } } } "; result.Script = result.Script.Replace("TableName", Helper.QuoteDouble(column.MetaTable.Name)); result.Script = result.Script.Replace("ColumnName", Helper.QuoteDouble(column.Name)); } result.RefreshEnum(); return(result); }
public void CheckTable(MetaColumn column) { if (_source == null) { return; } _information = ""; _error = ""; if (IsMasterTable && IsSQL && string.IsNullOrEmpty(Sql)) { _information = Helper.FormatMessage("No Select SQL Statement defined for the Master table..."); return; } if (IsMasterTable && !IsSQL && string.IsNullOrEmpty(DefinitionScript)) { _information = Helper.FormatMessage("No Script defined for the Master table..."); return; } try { if (IsSQL) { string colNames = "", groupByNames = ""; foreach (var col in Columns) { if (column != null && col != column) { continue; } Helper.AddValue(ref colNames, ",", col.Name); if (!col.IsAggregate) { Helper.AddValue(ref groupByNames, ",", col.Name); } } if (string.IsNullOrEmpty(colNames)) { colNames = "1"; } string sql = string.Format("SELECT {0} FROM {1} WHERE 1=0", colNames, FullSQLName); if (!string.IsNullOrEmpty(WhereSQL)) { sql += string.Format("\r\nAND ({0})", Helper.ParseRazor(WhereSQL, this)); } if (Columns.Exists(i => i.IsAggregate) && !string.IsNullOrEmpty(groupByNames)) { sql += string.Format("\r\nGROUP BY {0}", groupByNames); } _error = _source.CheckSQL(sql, new List <MetaTable>() { this }, null, false); } else { BuildNoSQLTable(true); } if (string.IsNullOrEmpty(_error)) { _information = "Table checked successfully"; } else { _information = "Error got when checking table."; } if (column != null) { column.Error = _error; if (string.IsNullOrEmpty(column.Error)) { column.Information = "Column checked successfully"; } else { column.Information = "Error got when checking column."; } column.Information = Helper.FormatMessage(column.Information); } } catch (TemplateCompilationException ex) { _error = Helper.GetExceptionMessage(ex); } catch (Exception ex) { _error = ex.Message; _information = "Error got when checking the table."; } _information = Helper.FormatMessage(_information); UpdateEditorAttributes(); }
/// <summary> /// Check the table. If a MetaColumn is specified, only the column is checked. /// </summary> public void CheckTable(MetaColumn column) { if (_source == null) { return; } Information = ""; Error = ""; if (IsMasterTable && IsSQL && string.IsNullOrEmpty(Sql)) { Information = Helper.FormatMessage("No SQL Select Statement defined for the Master table..."); return; } if (IsMasterTable && !IsSQL && string.IsNullOrEmpty(DefinitionScript)) { Information = Helper.FormatMessage("No Script defined for the Master table..."); return; } try { if (IsSQL) { string colNames = "", groupByNames = ""; foreach (var col in Columns) { if (column != null && col != column) { continue; } Helper.AddValue(ref colNames, ",", col.Name); if (!col.IsAggregate) { Helper.AddValue(ref groupByNames, ",", col.Name); } } if (string.IsNullOrEmpty(colNames)) { colNames = "1"; } string CTE = "", name = ""; GetExecSQLName(ref CTE, ref name); string sql = string.Format("{0}SELECT {1} FROM {2} WHERE 1=0", CTE, colNames, name); if (!string.IsNullOrWhiteSpace(WhereSQL)) { var where = RazorHelper.CompileExecute(WhereSQL, this); if (!string.IsNullOrWhiteSpace(where)) { sql += string.Format("\r\nAND ({0})", RazorHelper.CompileExecute(where, this)); } } if (Columns.Exists(i => i.IsAggregate) && !string.IsNullOrEmpty(groupByNames)) { sql += string.Format("\r\nGROUP BY {0}", groupByNames); } Error = _source.CheckSQL(sql, new List <MetaTable>() { this }, null, false); } else { BuildNoSQLTable(true); } if (string.IsNullOrEmpty(Error)) { Information = "Table checked successfully"; } else { Information = "Error got when checking table."; } if (column != null) { column.Error = Error; if (string.IsNullOrEmpty(column.Error)) { column.Information = "Column checked successfully"; } else { column.Information = "Error got when checking column."; } column.Information = Helper.FormatMessage(column.Information); } } catch (TemplateCompilationException ex) { Error = Helper.GetExceptionMessage(ex); } catch (Exception ex) { Error = ex.Message; Information = "Error got when checking the table."; } Information = Helper.FormatMessage(Information); }
public static MetaColumn Create(string name) { MetaColumn result = new MetaColumn() { Name = name, DisplayName = name, Type = ColumnType.Text, Category = "Default" }; result.GUID = Guid.NewGuid().ToString(); return result; }
public string TranslateColumn(MetaColumn col) { return(RepositoryTranslate(CultureInfo.TwoLetterISOLanguageName, "Element", col.Category + '.' + col.DisplayName, col.DisplayName)); }
/// <summary> /// Refresh the dynamic columns /// </summary> public void Refresh() { if (_source == null || !DynamicColumns) { return; } try { Information = ""; Error = ""; MustRefresh = true; //Build table def from SQL or table name var sql = ""; if (IsForSQLModel) { if (Model.UseRawSQL) { sql = Sql; } else { sql = string.Format("SELECT * FROM ({0}) a WHERE 1=0", Sql); } } else { string CTE = "", name = ""; GetExecSQLName(ref CTE, ref name); sql = string.Format("{0}SELECT * FROM {1} WHERE 1=0", CTE, name); } DataTable defTable = GetDefinitionTable(sql); int position = 1; foreach (DataColumn column in defTable.Columns) { string fullColumnName = (IsSQL && !IsForSQLModel ? Source.GetTableName(AliasName) + "." : "") + Source.GetColumnName(column.ColumnName); MetaColumn newColumn = Columns.FirstOrDefault(i => i.Name.ToLower() == fullColumnName.ToLower()); column.ColumnName = fullColumnName; //Set it here to clear the columns later ColumnType type = Helper.NetTypeConverter(column.DataType); if (newColumn == null) { newColumn = MetaColumn.Create(fullColumnName); newColumn.Source = _source; newColumn.DisplayName = (KeepColumnNames ? column.ColumnName.Trim() : Helper.DBNameToDisplayName(column.ColumnName.Trim())); newColumn.Category = (Alias == MetaData.MasterTableName ? "Master" : AliasName); newColumn.DisplayOrder = GetLastDisplayOrder(); Columns.Add(newColumn); newColumn.Type = type; newColumn.SetStandardFormat(); } newColumn.Source = _source; if (type != newColumn.Type) { newColumn.Type = type; newColumn.SetStandardFormat(); } newColumn.DisplayOrder = position++; } //Clear columns for No SQL or SQL Model if (!IsSQL || IsForSQLModel) { Columns.RemoveAll(i => !defTable.Columns.Contains(i.Name)); } MustRefresh = false; Information = "Dynamic columns have been refreshed successfully"; } catch (Exception ex) { Error = ex.Message; Information = "Error got when refreshing dynamic columns."; } Information = Helper.FormatMessage(Information); }
public void ChangeColumnGUID(string guid) { _metaColumn = null; _metaColumnGUID = guid; }
/// <summary> /// Fill a list of columns from a table catalog /// </summary> public void AddColumnsFromCatalog(List <MetaColumn> columns, DbConnection connection, MetaTable table) { if (table.Name == null) { throw new Exception("No table name has been defined..."); } //handle if table name = dbname.owner.tablename string name = table.Name.Replace("[", "").Replace("]", ""); string[] names = name.Split('.'); DataTable schemaColumns = null; Helper.ExecutePrePostSQL(connection, ReportModel.ClearCommonRestrictions(table.PreSQL), table, table.IgnorePrePostError); if (names.Length == 3) { schemaColumns = connection.GetSchema("Columns", names); } else if (names.Length == 2) { schemaColumns = connection.GetSchema("Columns", new string[] { null, names[0], names[1] }); } else { schemaColumns = connection.GetSchema("Columns", new string[] { null, null, name }); } Helper.ExecutePrePostSQL(connection, ReportModel.ClearCommonRestrictions(table.PostSQL), table, table.IgnorePrePostError); foreach (DataRow row in schemaColumns.Rows) { try { string tableName = (!string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(row["TABLE_NAME"].ToString().Trim())); MetaColumn column = MetaColumn.Create(tableName + "." + GetColumnName(row["COLUMN_NAME"].ToString())); column.DisplayName = table.KeepColumnNames ? row["COLUMN_NAME"].ToString().Trim() : Helper.DBNameToDisplayName(row["COLUMN_NAME"].ToString().Trim()); column.DisplayOrder = table.GetLastDisplayOrder(); MetaColumn col = table.Columns.FirstOrDefault(); if (col != null) { column.Category = col.Category; } else { column.Category = !string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(table.Name.Trim()); } column.Source = this; string odbcType = ""; if (row.Table.Columns.Contains("TYPE_NAME")) { odbcType = row["TYPE_NAME"].ToString(); } column.Type = connection is OdbcConnection?Helper.ODBCToNetTypeConverter(odbcType) : Helper.DatabaseToNetTypeConverter(row["DATA_TYPE"]); column.SetStandardFormat(); if (!columns.Exists(i => i.Name == column.Name)) { columns.Add(column); } } catch { } } }
public string TranslateColumn(MetaColumn col) { return RepositoryTranslate(CultureInfo.TwoLetterISOLanguageName, "Element", col.Category + '.' + col.DisplayName, col.DisplayName); }
public Button AddElement(ElementPanel panel, MetaColumn column, bool selectButton) { ReportElement element = ReportElement.Create(); element.Source = Model.Source; element.Format = ""; element.Model = Model; element.MetaColumnGUID = column.GUID; element.Name = column.Name; element.PivotPosition = panel.Position; element.SetDefaults(); Model.Elements.Add(element); return AddElement(panel, element, selectButton); }
public void SetSourceReference(MetaSource source) { _metaColumn = null; _source = source; }
public bool CanEditColumn(MetaColumn column) { return (!NoEditionCategories.Contains(column.Category) && !NoEditionTags.Contains(column.Tag)); }
public void ChangeColumnGUID(string guid) { _metaColumn = null; _metaColumnGUID = guid; _type = ColumnType.Default; _numericStandardFormat = NumericStandardFormat.Default; _datetimeStandardFormat = DateTimeStandardFormat.Default; _displayName = ""; }
public string ShowValues(MetaColumn column) { string result = ""; try { if (IsSQL) { string sql = string.Format("SELECT {0} FROM {1}", column.Name, FullSQLName); result = string.Format("{0}\r\n\r\n{1}:\r\n", sql, column.DisplayName); DbConnection connection = _source.GetOpenConnection(); DbCommand command = connection.CreateCommand(); command.CommandText = sql; var reader = command.ExecuteReader(); int cnt = 1000; while (reader.Read() && --cnt >= 0) { string valueStr = ""; if (!reader.IsDBNull(0)) { object value = reader[0]; CultureInfo culture = (_source.Report != null ? _source.Report.ExecutionView.CultureInfo : _source.Repository.CultureInfo); if (value is IFormattable) valueStr = ((IFormattable)value).ToString(column.Format, culture); else valueStr = value.ToString(); } result += string.Format("{0}\r\n", valueStr); } reader.Close(); command.Connection.Close(); } else { result = string.Format("{0}:\r\n", column.DisplayName); DataTable table = BuildNoSQLTable(true); foreach (DataRow row in table.Rows) { result += string.Format("{0}\r\n", row[column.Name]); } } } catch (Exception ex) { result = ex.Message; } return result; }
public void CheckTable(MetaColumn column) { if (_source == null) return; _information = ""; _error = ""; if (IsMasterTable && IsSQL && string.IsNullOrEmpty(Sql)) { _information = Helper.FormatMessage("No Select SQL Statement defined for the Master table..."); return; } if (IsMasterTable && !IsSQL && string.IsNullOrEmpty(DefinitionScript)) { _information = Helper.FormatMessage("No Script defined for the Master table..."); return; } try { if (IsSQL) { string colNames = "", groupByNames = ""; foreach (var col in Columns) { if (column != null && col != column) continue; Helper.AddValue(ref colNames, ",", col.Name); if (!col.IsAggregate) Helper.AddValue(ref groupByNames, ",", col.Name); } if (string.IsNullOrEmpty(colNames)) colNames = "1"; string sql = string.Format("SELECT {0} FROM {1} WHERE 1=0", colNames, FullSQLName); if (!string.IsNullOrEmpty(WhereSQL)) { sql += string.Format("\r\nAND ({0})", Helper.ParseRazor(WhereSQL, this)); } if (Columns.Exists(i => i.IsAggregate) && !string.IsNullOrEmpty(groupByNames)) { sql += string.Format("\r\nGROUP BY {0}", groupByNames); } _error = _source.CheckSQL(sql, new List<MetaTable>() { this }, null, false); } else { BuildNoSQLTable(true); } if (string.IsNullOrEmpty(_error)) _information = "Table checked successfully"; else _information = "Error got when checking table."; if (column != null) { column.Error = _error; if (string.IsNullOrEmpty(column.Error)) column.Information = "Column checked successfully"; else column.Information = "Error got when checking column."; column.Information = Helper.FormatMessage(column.Information); } } catch (TemplateCompilationException ex) { _error = Helper.GetExceptionMessage(ex); } catch (Exception ex) { _error = ex.Message; _information = "Error got when checking the table."; } _information = Helper.FormatMessage(_information); UpdateEditorAttributes(); }
/// <summary> /// Translate an Element /// </summary> public string TranslateColumn(MetaColumn col) { return(RepositoryTranslate("Element", col.Category + '.' + col.DisplayName, col.DisplayName)); }
public bool CanEditColumn(MetaColumn column) { return(!NoEditionCategories.Contains(column.Category) && !NoEditionTags.Contains(column.Tag)); }
public MetaEnum CreateEnumFromColumn(MetaColumn column) { MetaEnum result = AddEnum(); result.IsEditable = true; result.Name = column.DisplayName; if (!IsNoSQL) { result.IsDynamic = true; result.Sql = string.Format("SELECT DISTINCT \r\n{0} \r\nFROM {1} \r\nORDER BY 1", column.Name, column.MetaTable.FullSQLName); result.RefreshEnum(); } else { result.IsDynamic = false; column.MetaTable.BuildNoSQLTable(true); foreach (DataRow row in column.MetaTable.NoSQLTable.Rows) { result.Values.Add(new MetaEV() { Id = row[column.Name].ToString(), Val = row[column.Name].ToString() }); } } return result; }