433 lines
12 KiB
C#
433 lines
12 KiB
C#
// ========================================================================
|
|
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using Csla;
|
|
using Csla.Data;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
|
|
namespace Volian.CSLA.Library
|
|
{
|
|
/// <summary>
|
|
/// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
public partial class ConnectionFolder : BusinessBase<ConnectionFolder>
|
|
{
|
|
#region Business Methods
|
|
private string _errorMessage = string.Empty;
|
|
public string ErrorMessage
|
|
{
|
|
get { return _errorMessage; }
|
|
}
|
|
private int _FolderID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int FolderID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _FolderID;
|
|
}
|
|
}
|
|
private int _ParentID;
|
|
/// <summary>
|
|
/// {child Folders.FolderID}
|
|
/// </summary>
|
|
public int ParentID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _ParentID;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_ParentID != value)
|
|
{
|
|
_ParentID = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _Name = string.Empty;
|
|
public string Name
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _Name;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
if (_Name != value)
|
|
{
|
|
_Name = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _Title = string.Empty;
|
|
public string Title
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _Title;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
if (_Title != value)
|
|
{
|
|
_Title = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _Config = string.Empty;
|
|
public string Config
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _Config;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
if (_Config != value)
|
|
{
|
|
_Config = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private DateTime _DTS = new DateTime();
|
|
public DateTime DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _DTS;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_DTS != value)
|
|
{
|
|
_DTS = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _UsrID = string.Empty;
|
|
public string UsrID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _UsrID;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
if (_UsrID != value)
|
|
{
|
|
_UsrID = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _LastChanged = new byte[8];//timestamp
|
|
// TODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique
|
|
/// <summary>
|
|
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
|
|
/// </summary>
|
|
/// <returns>A Unique ID for the current ConnectionFolder</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _FolderID;
|
|
}
|
|
// TODO: Replace base ConnectionFolder.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current ConnectionFolder</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
#endregion
|
|
#region ValidationRules
|
|
protected override void AddBusinessRules()
|
|
{
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "Name");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "UsrID");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100));
|
|
// TODO: Add other validation rules
|
|
}
|
|
// Sample data comparison validation rule
|
|
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
|
|
//{
|
|
// if (_started > _ended)
|
|
// {
|
|
// e.Description = "Start date can't be after end date";
|
|
// return false;
|
|
// }
|
|
// else
|
|
// return true;
|
|
//}
|
|
#endregion
|
|
#region Authorization Rules
|
|
protected override void AddAuthorizationRules()
|
|
{
|
|
//TODO: Who can read/write which fields
|
|
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
|
|
}
|
|
public static bool CanAddObject()
|
|
{
|
|
// TODO: Can Add Authorization
|
|
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
|
return true;
|
|
}
|
|
public static bool CanGetObject()
|
|
{
|
|
// TODO: CanGet Authorization
|
|
return true;
|
|
}
|
|
public static bool CanDeleteObject()
|
|
{
|
|
// TODO: CanDelete Authorization
|
|
//bool result = false;
|
|
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
|
|
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
|
|
//return result;
|
|
return true;
|
|
}
|
|
public static bool CanEditObject()
|
|
{
|
|
// TODO: CanEdit Authorization
|
|
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
|
return true;
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
public int CurrentEditLevel
|
|
{ get { return EditLevel; } }
|
|
internal static ConnectionFolder New(string name)
|
|
{
|
|
return new ConnectionFolder(name);
|
|
}
|
|
internal static ConnectionFolder Get(SafeDataReader dr)
|
|
{
|
|
return new ConnectionFolder(dr);
|
|
}
|
|
public ConnectionFolder()
|
|
{
|
|
MarkAsChild();
|
|
_FolderID = Folder.NextFolderID;
|
|
_ParentID = ext.DefaultParentID;
|
|
_DTS = ext.DefaultDTS;
|
|
_UsrID = ext.DefaultUsrID;
|
|
}
|
|
private ConnectionFolder(string name)
|
|
{
|
|
MarkAsChild();
|
|
// TODO: Add any initialization & defaults
|
|
_ParentID = ext.DefaultParentID;
|
|
_DTS = ext.DefaultDTS;
|
|
_UsrID = ext.DefaultUsrID;
|
|
_Name = name;
|
|
}
|
|
private ConnectionFolder(SafeDataReader dr)
|
|
{
|
|
MarkAsChild();
|
|
Fetch(dr);
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
try
|
|
{
|
|
_FolderID = dr.GetInt32("FolderID");
|
|
_ParentID = dr.GetInt32("ParentID");
|
|
_Name = dr.GetString("Name");
|
|
_Title = dr.GetString("Title");
|
|
_Config = dr.GetString("Config");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UsrID = dr.GetString("UsrID");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
}
|
|
catch (Exception ex) // FKItem Fetch
|
|
{
|
|
Database.LogException("ConnectionFolder.Fetch", ex);
|
|
throw new DbCslaException("ConnectionFolder.Fetch", ex);
|
|
}
|
|
MarkOld();
|
|
}
|
|
internal void Insert(Connection connection, SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
_LastChanged = Folder.Add(cn, ref _FolderID, _ParentID, connection.DBID, _Name, _Title, _Config, _DTS, _UsrID);
|
|
MarkOld();
|
|
}
|
|
internal void Update(Connection connection, SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, connection.DBID, _Name, _Title, _Config, _DTS, _UsrID, ref _LastChanged);
|
|
MarkOld();
|
|
}
|
|
internal void DeleteSelf(Connection connection, SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
// if we're new then don't update the database
|
|
if (this.IsNew) return;
|
|
Folder.Remove(cn, _FolderID);
|
|
MarkNew();
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
Extension ext = new Extension();
|
|
[Serializable()]
|
|
partial class Extension : extensionBase
|
|
{
|
|
}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Values
|
|
public virtual int DefaultParentID
|
|
{
|
|
get { return 0; }
|
|
}
|
|
public virtual int DefaultDBID
|
|
{
|
|
get { return 0; }
|
|
}
|
|
public virtual DateTime DefaultDTS
|
|
{
|
|
get { return DateTime.Now; }
|
|
}
|
|
public virtual string DefaultUsrID
|
|
{
|
|
get { return Environment.UserName.ToUpper(); }
|
|
}
|
|
// Authorization Rules
|
|
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
{
|
|
// Needs to be overriden to add new authorization rules
|
|
}
|
|
// Validation Rules
|
|
public virtual void AddValidationRules(Csla.Validation.ValidationRules rules)
|
|
{
|
|
// Needs to be overriden to add new validation rules
|
|
}
|
|
}
|
|
#endregion
|
|
} // Class
|
|
} // Namespace
|
|
|
|
|
|
//// The following is a sample Extension File. You can use it to create ConnectionFolderExt.cs
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Text;
|
|
//using Csla;
|
|
|
|
//namespace Volian.CSLA.Library
|
|
//{
|
|
// public partial class ConnectionFolder
|
|
// {
|
|
// partial class Extension : extensionBase
|
|
// {
|
|
// // TODO: Override automatic defaults
|
|
// public virtual int DefaultParentID
|
|
// {
|
|
// get { return 0; }
|
|
// }
|
|
// public virtual int DefaultDBID
|
|
// {
|
|
// get { return 0; }
|
|
// }
|
|
// public virtual DateTime DefaultDTS
|
|
// {
|
|
// get { return DateTime.Now; }
|
|
// }
|
|
// public virtual string DefaultUsrID
|
|
// {
|
|
// get { return Environment.UserName.ToUpper(); }
|
|
// }
|
|
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
// {
|
|
// //rules.AllowRead(Dbid, "<Role(s)>");
|
|
// }
|
|
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
|
|
// {
|
|
// rules.AddRule(
|
|
// Csla.Validation.CommonRules.StringMaxLength,
|
|
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|