2006-11-14 14:33:33 +00:00

497 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;
using System.Configuration;
using System.IO;
namespace Volian.CSLA.Library
{
/// <summary>
/// StructureTransition Generated by MyGeneration using the CSLA Object Mapping template
/// </summary>
[Serializable()]
public partial class StructureTransition : BusinessBase<StructureTransition>
{
#region Business Methods
private string _errorMessage = string.Empty;
public string ErrorMessage
{
get { return _errorMessage; }
}
private int _TransitionId;
[System.ComponentModel.DataObjectField(true, true)]
public int TransitionId
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _TransitionId;
}
}
private int _ToId;
/// <summary>
/// StructureID
/// </summary>
public int ToId
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _ToId;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (_ToId != value)
{
_ToId = value;
PropertyHasChanged();
}
}
}
private int _TranType;
public int TranType
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _TranType;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (_TranType != value)
{
_TranType = value;
PropertyHasChanged();
}
}
}
private int _SectID;
public int SectID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _SectID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (_SectID != value)
{
_SectID = value;
PropertyHasChanged();
}
}
}
private int _ProcID;
public int ProcID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _ProcID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (_ProcID != value)
{
_ProcID = value;
PropertyHasChanged();
}
}
}
private int _SetID;
public int SetID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _SetID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (_SetID != value)
{
_SetID = value;
PropertyHasChanged();
}
}
}
private int _PlantID;
public int PlantID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _PlantID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (_PlantID != value)
{
_PlantID = 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 _UserID = string.Empty;
public string UserID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty(true);
return _UserID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty(true);
if (value == null) value = string.Empty;
if (_UserID != value)
{
_UserID = value;
PropertyHasChanged();
}
}
}
private byte[] _LastChanged = new byte[8];//timestamp
// TODO: Check StructureTransition.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 StructureTransition</returns>
protected override object GetIdValue()
{
return _TransitionId;
}
// TODO: Replace base StructureTransition.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current StructureTransition</returns>
//public override string ToString()
//{
// return base.ToString();
//}
#endregion
#region ValidationRules
protected override void AddBusinessRules()
{
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringRequired, "UserID");
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 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(TransitionId, "<Role(s)>");
//AuthorizationRules.AllowRead(ToId, "<Role(s)>");
//AuthorizationRules.AllowWrite(ToId, "<Role(s)>");
//AuthorizationRules.AllowRead(TranType, "<Role(s)>");
//AuthorizationRules.AllowWrite(TranType, "<Role(s)>");
//AuthorizationRules.AllowRead(SectID, "<Role(s)>");
//AuthorizationRules.AllowWrite(SectID, "<Role(s)>");
//AuthorizationRules.AllowRead(ProcID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ProcID, "<Role(s)>");
//AuthorizationRules.AllowRead(SetID, "<Role(s)>");
//AuthorizationRules.AllowWrite(SetID, "<Role(s)>");
//AuthorizationRules.AllowRead(PlantID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PlantID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<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 StructureTransition New(int toId)
{
return new StructureTransition(toId);
}
internal static StructureTransition Get(SafeDataReader dr)
{
return new StructureTransition(dr);
}
public StructureTransition()
{
MarkAsChild();
_TransitionId = Transition.NextTransitionId;
_TranType = ext.DefaultTranType;
_SectID = ext.DefaultSectID;
_ProcID = ext.DefaultProcID;
_SetID = ext.DefaultSetID;
_PlantID = ext.DefaultPlantID;
_DTS = ext.DefaultDTS;
_UserID = ext.DefaultUserID;
}
private StructureTransition(int toId)
{
MarkAsChild();
// TODO: Add any initialization & defaults
_TranType = ext.DefaultTranType;
_SectID = ext.DefaultSectID;
_ProcID = ext.DefaultProcID;
_SetID = ext.DefaultSetID;
_PlantID = ext.DefaultPlantID;
_DTS = ext.DefaultDTS;
_UserID = ext.DefaultUserID;
_ToId = toId;
}
private StructureTransition(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
}
#endregion
#region Data Access Portal
private void Fetch(SafeDataReader dr)
{
try
{
_TransitionId = dr.GetInt32("TransitionId");
_ToId = dr.GetInt32("ToId");
_TranType = dr.GetInt32("TranType");
_SectID = dr.GetInt32("SectID");
_ProcID = dr.GetInt32("ProcID");
_SetID = dr.GetInt32("SetID");
_PlantID = dr.GetInt32("PlantID");
_DTS = dr.GetDateTime("DTS");
_UserID = dr.GetString("UserID");
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
}
catch (Exception ex) // FKItem Fetch
{
Database.LogException("StructureTransition.Fetch", ex);
throw new DbCslaException("StructureTransition.Fetch", ex);
}
MarkOld();
}
internal void Insert(Structure structure, SqlConnection cn)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
_LastChanged = Transition.Add(cn, ref _TransitionId, structure.StructureID, _ToId, _TranType, _SectID, _ProcID, _SetID, _PlantID, _DTS, _UserID);
MarkOld();
}
internal void Update(Structure structure, SqlConnection cn)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
_LastChanged = Transition.Update(cn, ref _TransitionId, structure.StructureID, _ToId, _TranType, _SectID, _ProcID, _SetID, _PlantID, _DTS, _UserID, ref _LastChanged);
MarkOld();
}
internal void DeleteSelf(Structure structure, 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;
Transition.Remove(cn, _TransitionId);
MarkNew();
}
#endregion
// Standard Default Code
#region extension
Extension ext = new Extension();
[Serializable()]
partial class Extension : extensionBase
{
}
[Serializable()]
class extensionBase
{
// Default Values
public virtual int DefaultTranType
{
get { return 0; }
}
public virtual int DefaultSectID
{
get { return 0; }
}
public virtual int DefaultProcID
{
get { return 0; }
}
public virtual int DefaultSetID
{
get { return 0; }
}
public virtual int DefaultPlantID
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
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 StructureTransitionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace Volian.CSLA.Library
//{
// public partial class StructureTransition
// {
// partial class Extension : extensionBase
// {
// // TODO: Override automatic defaults
// public virtual int DefaultTranType
// {
// get { return 0; }
// }
// public virtual int DefaultSectID
// {
// get { return 0; }
// }
// public virtual int DefaultProcID
// {
// get { return 0; }
// }
// public virtual int DefaultSetID
// {
// get { return 0; }
// }
// public virtual int DefaultPlantID
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// 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));
// }
// }
// }
//}