public partial class TaskTable : DatabaseTable<Task>
{
protected internal ProjectManagerDataset _dataset;
public TaskTable(ProjectManagerDataset dataset)
{
_dataset = dataset;
}
public override void Destroy()
{
string sql = "IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Tasks') DROP TABLE Tasks";
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
command.ExecuteNonQuery();
}
public override void Create()
{
Destroy();
string sql = "CREATE TABLE Tasks([TaskId] int IDENTITY(1,1) PRIMARY KEY, [Name] varchar(64), [State] int, [StartDate] datetime, [InsertDate] datetime, [EndDate] datetime, [ExpiryDate] datetime, [Priority] tinyint, [Percentage] tinyint, [ExpectedWork] int, [EffectiveWork] int, [AlertTime] int)";
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
command.ExecuteNonQuery();
}
public override Task Add(Task value)
{
string sql = String.Format("INSERT INTO Tasks([Name], [State], [StartDate], [InsertDate], [EndDate], [ExpiryDate], [Priority], [Percentage], [ExpectedWork], [EffectiveWork], [AlertTime]) VALUES ({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11})", "", value._name == null ? "null" : FormatValue(value._name), value._state == null ? "null" : ((int)value._state).ToString(), value._startDate == null ? "null" : FormatValue(value._startDate), value._insertDate == null ? "null" : FormatValue(value._insertDate), value._endDate == null ? "null" : FormatValue(value._endDate), value._expiryDate == null ? "null" : FormatValue(value._expiryDate), value._priority == null ? "null" : value._priority.ToString(), value._percentage == null ? "null" : value._percentage.ToString(), value._expectedWork == null ? "null" : value._expectedWork.ToString(), value._effectiveWork == null ? "null" : value._effectiveWork.ToString(), value._alertTime == null ? "null" : value._alertTime.ToString());
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
command.ExecuteNonQuery();
command.CommandText = "SELECT IDENT_CURRENT('Tasks')";
value._taskId = (int)(decimal)command.ExecuteScalar();
value._table = this;
return value;
}
public override void Delete(int taskId)
{
string sql = String.Format("DELETE FROM Tasks WHERE TaskId = " + taskId);
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
command.ExecuteNonQuery();
}
public override void Delete(Task value)
{
Delete((int)value.TaskId);
}
public override void Update(Task value)
{
string sql = String.Format("UPDATE Tasks SET [Name] = {1}, [State] = {2}, [StartDate] = {3}, [InsertDate] = {4}, [EndDate] = {5}, [ExpiryDate] = {6}, [Priority] = {7}, [Percentage] = {8}, [ExpectedWork] = {9}, [EffectiveWork] = {10}, [AlertTime] = {11} WHERE TaskId = {0}", value._taskId == null ? "null" : value._taskId.ToString(), value._name == null ? "null" : FormatValue(value._name), value._state == null ? "null" : ((int)value._state).ToString(), value._startDate == null ? "null" : FormatValue(value._startDate), value._insertDate == null ? "null" : FormatValue(value._insertDate), value._endDate == null ? "null" : FormatValue(value._endDate), value._expiryDate == null ? "null" : FormatValue(value._expiryDate), value._priority == null ? "null" : value._priority.ToString(), value._percentage == null ? "null" : value._percentage.ToString(), value._expectedWork == null ? "null" : value._expectedWork.ToString(), value._effectiveWork == null ? "null" : value._effectiveWork.ToString(), value._alertTime == null ? "null" : value._alertTime.ToString());
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
command.ExecuteNonQuery();
value._table = this;
}
public override Task GetById(Int32 id)
{
return GetList("TaskId = " + id)[0];
}
public void Execute(string sql)
{
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
command.ExecuteNonQuery();
}
public override Task[] GetList(string filter)
{
string where = "";
string sql = "SELECT [TaskId], [Name], [State], [StartDate], [InsertDate], [EndDate], [ExpiryDate], [Priority], [Percentage], [ExpectedWork], [EffectiveWork], [AlertTime] FROM Tasks";
if (!string.IsNullOrEmpty(filter))
{
if (where.Length > 0)
where += " AND ";
where += filter;
}
if (where != "") sql += " WHERE " + where;
return FillData(sql);
}
public override Task[] FillData(string sql)
{
List<Task> list = new List<Task>();
DbCommand command = _dataset._maindb.CreateCommand();
command.CommandText = sql;
lock (_dataset._maindb)
{
DbDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
Task value = new Task();
value._taskId = reader.IsDBNull(0) ? null : (int?)reader.GetValue(0);
value._name = reader.IsDBNull(1) ? null : (string)reader.GetValue(1);
value._state = reader.IsDBNull(2) ? null : (TaskState?)(int)reader.GetValue(2);
value._startDate = reader.IsDBNull(3) ? null : (DateTime?)reader.GetValue(3);
value._insertDate = reader.IsDBNull(4) ? null : (DateTime?)reader.GetValue(4);
value._endDate = reader.IsDBNull(5) ? null : (DateTime?)reader.GetValue(5);
value._expiryDate = reader.IsDBNull(6) ? null : (DateTime?)reader.GetValue(6);
value._priority = reader.IsDBNull(7) ? null : (byte?)reader.GetValue(7);
value._percentage = reader.IsDBNull(8) ? null : (byte?)reader.GetValue(8);
value._expectedWork = reader.IsDBNull(9) ? null : (int?)reader.GetValue(9);
value._effectiveWork = reader.IsDBNull(10) ? null : (int?)reader.GetValue(10);
value._alertTime = reader.IsDBNull(11) ? null : (int?)reader.GetValue(11);
value._partial = false;
value._table = this;
list.Add(value);
}
}
finally
{
reader.Close();
}
}
return list.ToArray();
}
}
public partial class Task : DataEntity
{
protected internal int? _taskId;
protected internal string _name;
protected internal TaskState? _state;
protected internal DateTime? _startDate;
protected internal DateTime? _insertDate;
protected internal DateTime? _endDate;
protected internal DateTime? _expiryDate;
protected internal byte? _priority;
protected internal byte? _percentage;
protected internal int? _expectedWork;
protected internal int? _effectiveWork;
protected internal int? _alertTime;
protected internal TaskDependentTaskTable _dependentTask;
protected internal MessageTable _tickets;
protected internal TaskTable _table;
public Task(int? taskId)
{
_taskId = taskId;
_partial = true;
}
public void Update()
{
_table.Update(this);
}
public void Delete()
{
_table.Delete(this);
}
public Task()
{
}
public Task(string name, TaskState? state, DateTime? startDate, DateTime? insertDate, DateTime? endDate, DateTime? expiryDate, byte? priority, byte? percentage, int? expectedWork, int? effectiveWork, int? alertTime)
{
_name = name;
_state = state;
_startDate = startDate;
_insertDate = insertDate;
_endDate = endDate;
_expiryDate = expiryDate;
_priority = priority;
_percentage = percentage;
_expectedWork = expectedWork;
_effectiveWork = effectiveWork;
_alertTime = alertTime;
_partial = false;
}
public int? TaskId
{
get
{
return _taskId;
}
set
{
_taskId = value;
}
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public TaskState? State
{
get
{
return _state;
}
set
{
_state = value;
}
}
public DateTime? StartDate
{
get
{
return _startDate;
}
set
{
_startDate = value;
}
}
public DateTime? InsertDate
{
get
{
return _insertDate;
}
set
{
_insertDate = value;
}
}
public DateTime? EndDate
{
get
{
return _endDate;
}
set
{
_endDate = value;
}
}
public DateTime? ExpiryDate
{
get
{
return _expiryDate;
}
set
{
_expiryDate = value;
}
}
public byte? Priority
{
get
{
return _priority;
}
set
{
_priority = value;
}
}
public byte? Percentage
{
get
{
return _percentage;
}
set
{
_percentage = value;
}
}
public int? ExpectedWork
{
get
{
return _expectedWork;
}
set
{
_expectedWork = value;
}
}
public int? EffectiveWork
{
get
{
return _effectiveWork;
}
set
{
_effectiveWork = value;
}
}
public int? AlertTime
{
get
{
return _alertTime;
}
set
{
_alertTime = value;
}
}
public TaskDependentTaskTable DependentTask
{
get
{
if (_dependentTask == null)
{
_dependentTask = new TaskDependentTaskTable(_table._dataset);
_dependentTask.SetTask(this);
}
return _dependentTask;
}
}
public MessageTable Tickets
{
get
{
if (_tickets == null)
{
_tickets = new MessageTable(_table._dataset);
_tickets.SetTask(this);
}
return _tickets;
}
}
public override void ToXml(XmlWriter writer, bool deep)
{
writer.WriteStartElement("Task");
writer.WriteAttributeString("id", _taskId.ToString());
writer.WriteElementString("Name", Name == null ? "" : Name.ToString());
writer.WriteElementString("State", State == null ? "" : State.ToString());
writer.WriteElementString("StartDate", StartDate == null ? "" : StartDate.ToString());
writer.WriteElementString("InsertDate", InsertDate == null ? "" : InsertDate.ToString());
writer.WriteElementString("EndDate", EndDate == null ? "" : EndDate.ToString());
writer.WriteElementString("ExpiryDate", ExpiryDate == null ? "" : ExpiryDate.ToString());
writer.WriteElementString("Priority", Priority == null ? "" : Priority.ToString());
writer.WriteElementString("Percentage", Percentage == null ? "" : Percentage.ToString());
writer.WriteElementString("ExpectedWork", ExpectedWork == null ? "" : ExpectedWork.ToString());
writer.WriteElementString("EffectiveWork", EffectiveWork == null ? "" : EffectiveWork.ToString());
writer.WriteElementString("AlertTime", AlertTime == null ? "" : AlertTime.ToString());
if (deep)
DependentTask.ToXml(writer, false);
if (deep)
Tickets.ToXml(writer, false);
writer.WriteEndElement();
}
}