private FastReport.Report CreateReport() { var report = new Report(); if (!_reportItemM.IsNew) { report.LoadFromString(_reportItemM.Body); } var postgresConn = FindConnection(report, "Current data") as PostgresDataConnection; if (postgresConn == null) { postgresConn = new PostgresDataConnection() { Name = "Current data", Enabled = true }; report.Dictionary.Connections.Add(postgresConn); } postgresConn.ConnectionString = Program.connString.ToString(); Interfaces.tablesInfo tableInfo = null; if (_reportItemM.Type == enTypeReport.Table || _reportItemM.Type == enTypeReport.Object) { tableInfo = Program.app.getTableInfo(_filter.IdTable); } if (_isDesign) { cti.ThreadProgress.ShowWait("CreateReport"); foreach (var item in _reports) { try { var table = FindTableDataSource(postgresConn, item); if (table == null) { table = CreateTableDataSource(item); table.Enabled = (_reportItemM.Type == enTypeReport.Object || _reportItemM.Type == enTypeReport.Table); postgresConn.Tables.Add(table); } if (item.Table.photo) { var tmPhoto = new TableModel_M(item.Table, item.Type, true); var tablePhoto = FindTablePhotoDataSource(postgresConn, tmPhoto); if (tablePhoto == null) { tablePhoto = CreateTablePhotoDataSource(tmPhoto); tablePhoto.Enabled = false; postgresConn.Tables.Add(tablePhoto); } //var pkColumn = table.Columns.FindByName(item.Table.pkField); //var pkColumnPhoto = tablePhoto.Columns.FindByName("id_obj"); //var relName = table.TableName + "_" + item.Table.nameMap + "_photo"; //RelationCollection //var ds = new DataSet(); //ds.Tables.Add(table); //ds.Tables.Add(tablePhoto); //var d = new DataRelation(relName, pkColumn, pkColumnPhoto); //report.RegisterData(d, relName); // Declare all the tables that will have relations var nameRelation = table.TableName + "_" + item.Table.nameMap + "_photo"; Relation rel = report.Dictionary.Relations.FindByName(nameRelation); if (rel == null) { var ParentTable = postgresConn.FindObject(item.Table.nameDB) as TableDataSource; var PhotoTable = postgresConn.FindObject(item.Table.nameDB + "_photo") as TableDataSource; // Declare the relations rel = new Relation(); rel.Enabled = false; rel.Name = nameRelation; rel.ParentDataSource = ParentTable; rel.ChildDataSource = PhotoTable; rel.ParentColumns = new string[] { item.Table.pkField }; rel.ChildColumns = new string[] { Resources.Report_VM_photoIdObj }; report.Dictionary.Relations.Add(rel); } } } catch (Exception ex) { Debug.WriteLine(ex.Message, "NpgsqlException"); continue; } } cti.ThreadProgress.Close("CreateReport"); } //if (tableInfo != null) //report.SetParameterValue("idCurrentObject", "\"" + tableInfo.pkField + "\" = " + _filter.IdObj); return(report); }
public TableModel_M(Interfaces.tablesInfo table, enTypeReport type, bool isFileTable = false) { _table = table; _type = type; _isFileTable = isFileTable; }