#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.DataImporter.DbExplorer.Interfaces {
[StorableClass]
public class DbTable {
private DbTable()
: base() {
this.columns = new List();
this.informationLoaded = new DateTime(1990, 1, 1);
}
public DbTable(string ownerName, string tableName)
: this() {
this.ownerName = ownerName;
this.tableName = tableName;
}
[Storable]
private string ownerName;
public string OwnerName {
get { return this.ownerName; }
set { this.ownerName = value; }
}
[Storable]
private string tableName;
public string TableName {
get { return this.tableName; }
set { this.tableName = value; }
}
[Storable]
private List columns;
public IEnumerable Columns {
get { return this.columns; }
}
public bool IsSelected {
get { return columns.Any(col => col.Selected); }
}
private int affectedRows;
public int AffectedRows {
get { return this.affectedRows; }
set { this.affectedRows = value; }
}
private int totalRows;
public int TotalRows {
get { return this.totalRows; }
set { this.totalRows = value; }
}
private DateTime informationLoaded;
public DateTime InformationLoaded {
get { return this.informationLoaded; }
}
public void AddColumn(DbColumn column) {
this.columns.Add(column);
}
public void ClearSelection() {
foreach (DbColumn col in columns) {
col.Selected = false;
col.FilterColumn = false;
col.LikeValue = "";
}
}
public void SelectAllColumns() {
foreach (DbColumn col in this.columns)
col.Selected = true;
}
public int SelectedColumnsCount {
get { return this.columns.Count(col => col.Selected); }
}
public IEnumerable SelectedColumns {
get { return this.columns.Where(col => col.Selected); }
}
public IEnumerable FilterColumns {
get { return this.columns.Where(col => col.FilterColumn); }
}
public void UpdateInformationLoaded() {
this.informationLoaded = DateTime.Now;
}
public bool ReloadOfInformationNeeded {
get { return DateTime.Now.Subtract(this.InformationLoaded).Minutes > 5; }
}
public override string ToString() {
string s = this.tableName + " " + SelectedColumnsCount + "/" + this.columns.Count;
return s;
}
}
}