542 lines
14 KiB
C#
542 lines
14 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;
|
|
|
|
namespace Volian.Object.Library
|
|
{
|
|
/// <summary>
|
|
/// RolePermission Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
public partial class RolePermission : BusinessBase<RolePermission>
|
|
{
|
|
#region Business Methods
|
|
|
|
|
|
private int _pid;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Pid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _pid;
|
|
}
|
|
}
|
|
private int _permlevel;
|
|
/// <summary>
|
|
/// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments
|
|
/// </summary>
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int PermLevel
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _permlevel;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_permlevel != value)
|
|
{
|
|
_permlevel = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private int _versiontype;
|
|
/// <summary>
|
|
/// 0 - Working Draft, 1 - Temporary Change, 2 Approved
|
|
/// </summary>
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int VersionType
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _versiontype;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_versiontype != value)
|
|
{
|
|
_versiontype = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private int _permvalue;
|
|
/// <summary>
|
|
/// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All)
|
|
/// </summary>
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int PermValue
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _permvalue;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_permvalue != value)
|
|
{
|
|
_permvalue = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private int _permad;
|
|
/// <summary>
|
|
/// 0 - Allow, 1 - Deny
|
|
/// </summary>
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Permad
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _permad;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_permad != value)
|
|
{
|
|
_permad = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _startdate=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string StartDate
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _startdate;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
_startdate = value;
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(value);
|
|
if (_startdate != tmp.ToShortDateString())
|
|
{
|
|
_startdate = tmp.ToShortDateString();
|
|
// TODO: Any Cross Property Validation
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
private string _enddate=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string EndDate
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _enddate;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
_enddate = value;
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(value);
|
|
if (_enddate != tmp.ToShortDateString())
|
|
{
|
|
_enddate = tmp.ToShortDateString();
|
|
// TODO: Any Cross Property Validation
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
private DateTime _dts=new DateTime();
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
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;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
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 RolePermission.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 RolePermission</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _pid;
|
|
}
|
|
// TODO: Replace base RolePermission.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current RolePermission</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
|
|
#endregion
|
|
#region ValidationRules
|
|
|
|
protected override void AddBusinessRules()
|
|
{
|
|
ValidationRules.AddRule(StartDateValid, "StartDate");
|
|
ValidationRules.AddRule(EndDateValid, "EndDate");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100));
|
|
// TODO: Add other validation rules
|
|
}
|
|
private bool StartDateValid(object target, Csla.Validation.RuleArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(_startdate);
|
|
}
|
|
catch
|
|
{
|
|
e.Description="Invalid Date";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
private bool EndDateValid(object target, Csla.Validation.RuleArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(_enddate);
|
|
}
|
|
catch
|
|
{
|
|
e.Description="Invalid Date";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
// 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(Pid, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(PermLevel, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(PermLevel, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(PermValue, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(PermValue, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Permad, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Permad, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(EndDate, "<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
|
|
|
|
internal static RolePermission New(int permlevel, int versiontype, int permvalue)
|
|
{
|
|
return new RolePermission(permlevel, versiontype, permvalue);
|
|
}
|
|
|
|
internal static RolePermission Get(SafeDataReader dr)
|
|
{
|
|
return new RolePermission(dr);
|
|
}
|
|
|
|
private RolePermission()
|
|
{
|
|
MarkAsChild();
|
|
_permad = ext.DefaultPermad;
|
|
_startdate = ext.DefaultStartDate;
|
|
_dts = ext.DefaultDts;
|
|
_usrid = ext.DefaultUsrid;
|
|
}
|
|
|
|
private RolePermission(int permlevel, int versiontype, int permvalue)
|
|
{
|
|
MarkAsChild();
|
|
// TODO: Add any initialization & defaults
|
|
_permad = ext.DefaultPermad;
|
|
_startdate = ext.DefaultStartDate;
|
|
_dts = ext.DefaultDts;
|
|
_usrid = ext.DefaultUsrid;
|
|
_permlevel = permlevel;
|
|
_versiontype = versiontype;
|
|
_permvalue = permvalue;
|
|
}
|
|
|
|
private RolePermission(SafeDataReader dr)
|
|
{
|
|
MarkAsChild();
|
|
Fetch(dr);
|
|
}
|
|
|
|
|
|
#endregion
|
|
#region Data Access Portal
|
|
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
try{
|
|
_pid = dr.GetInt32("PID");
|
|
_permlevel = dr.GetInt32("PermLevel");
|
|
_versiontype = dr.GetInt32("VersionType");
|
|
_permvalue = dr.GetInt32("PermValue");
|
|
_permad = dr.GetInt32("PermAD");
|
|
_startdate = dr.GetSmartDate("StartDate").Text;
|
|
_enddate = dr.GetSmartDate("EndDate").Text;
|
|
_dts = dr.GetDateTime("DTS");
|
|
_usrid = dr.GetString("UsrID");
|
|
dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Database.LogException("RolePermission",ex);
|
|
}
|
|
MarkOld();
|
|
}
|
|
|
|
internal void Insert(Role role,SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
_lastchanged=Permission.Add(cn, ref _pid, role.Rid, _permlevel, _versiontype, _permvalue, _permad, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid);
|
|
MarkOld();
|
|
}
|
|
|
|
internal void Update(Role role,SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
_lastchanged=Permission.Update(cn, ref _pid, role.Rid, _permlevel, _versiontype, _permvalue, _permad, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged);
|
|
}
|
|
|
|
internal void DeleteSelf(Role role,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;
|
|
Permission.Remove(cn,_pid);
|
|
MarkNew();
|
|
}
|
|
|
|
#endregion
|
|
// Standard Default Code
|
|
// #region extension
|
|
Extension ext = new Extension();
|
|
[Serializable()]
|
|
partial class Extension : extensionBase
|
|
{
|
|
}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Values
|
|
public virtual int DefaultPermad
|
|
{
|
|
get { return 0; }
|
|
}
|
|
public virtual string DefaultStartDate
|
|
{
|
|
get { return DateTime.Now.ToShortDateString(); }
|
|
}
|
|
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
|
|
|
|
// The follwing is a sample Extension File. You can use it to create RolePermissionExt.cs
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Text;
|
|
//using Csla;
|
|
|
|
//namespace PatrialClass
|
|
//{
|
|
// public partial class RolePermission
|
|
// {
|
|
// partial class Extension : extensionBase
|
|
// {
|
|
// TODO: Override automatic defaults
|
|
// public virtual int DefaultPermad
|
|
// {
|
|
// get { return 0; }
|
|
// }
|
|
// public virtual SmartDate DefaultStartDate
|
|
// {
|
|
// get { return DateTime.Now.ToShortDateString(); }
|
|
// }
|
|
// 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));
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
} // Class
|
|
} // Namespace
|