// Copyright (c) 2015-2017 schick Informatik // Description: Klasse kapselt eine vom ENI-2 verwendete Validierungsregel using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; namespace bsmd.database { public class ValidationRule : DatabaseEntity { public ValidationRule() { this.tablename = "[dbo].[ValidationRule]"; } #region Properties public string Name { get; set; } public string Context { get; set; } public string Rule { get; set; } public DateTime Created { get; set; } public string CreatedBy { get; set; } public DateTime? Changed { get; set; } public string ChangedBy { get; set; } public bool? IsActive { get; set; } #endregion #region overrides public override string ToString() { return this.Name; } #endregion #region DatabaseEntity implementation public override List LoadList(IDataReader reader) { List result = new List(); while (reader.Read()) { ValidationRule vr = new ValidationRule(); vr.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) vr.Name = reader.GetString(1); if (!reader.IsDBNull(2)) vr.Context = reader.GetString(2); if (!reader.IsDBNull(3)) vr.Rule = reader.GetString(3); if (!reader.IsDBNull(4)) vr.Changed = reader.GetDateTime(4); if (!reader.IsDBNull(5)) vr.ChangedBy = reader.GetString(5); if (!reader.IsDBNull(6)) vr.Created = reader.GetDateTime(6); if (!reader.IsDBNull(7)) vr.CreatedBy = reader.GetString(7); if (!reader.IsDBNull(8)) vr.IsActive = reader.GetBoolean(8); result.Add(vr); } reader.Close(); return result; } public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) { string query = string.Format("SELECT Id, Name, Context, [Rule], Changed, ChangedBy, Created, CreatedBy, IsActive FROM {0} ORDER BY Name", this.Tablename); switch (filter) { case Message.LoadFilter.ALL: default: break; } cmd.CommandText = query; } public override void PrepareSave(IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; scmd.Parameters.AddWithNullableValue("@P1", this.Name); scmd.Parameters.AddWithNullableValue("@P2", this.Context); scmd.Parameters.AddWithNullableValue("@P3", this.Rule); scmd.Parameters.AddWithNullableValue("@P4", this.Changed); scmd.Parameters.AddWithNullableValue("@P5", this.ChangedBy); scmd.Parameters.AddWithNullableValue("@P6", this.Created); scmd.Parameters.AddWithNullableValue("@P7", this.CreatedBy); scmd.Parameters.AddWithNullableValue("@P8", this.IsActive); if (this.IsNew) { this.CreateId(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, Name, Context, [Rule], Changed, ChangedBy, Created, CreatedBy, IsActive) " + "VALUES ( @ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8 )", this.Tablename); } else { scmd.Parameters.AddWithValue(@"ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET Name = @P1, Context = @P2, [Rule] = @P3, Changed = @P4, ChangedBy = @P5, " + "Created = @P6, CreatedBy = @P7, IsActive = @P8 WHERE Id = @ID", this.Tablename); } } #endregion } }