532 lines
16 KiB
C#
532 lines
16 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>
|
|
/// ZStep Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
public partial class ZStep : BusinessBase<ZStep>
|
|
{
|
|
#region Business Methods
|
|
private string _errorMessage = string.Empty;
|
|
public string ErrorMessage
|
|
{
|
|
get { return _errorMessage; }
|
|
}
|
|
private int _StepID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int StepID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _StepID;
|
|
}
|
|
}
|
|
private string _OldStepSequence = string.Empty;
|
|
public string OldStepSequence
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _OldStepSequence;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
if (_OldStepSequence != value)
|
|
{
|
|
_OldStepSequence = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _LastChanged = new byte[8];//timestamp
|
|
// TODO: Replace base ZStep.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current ZStep</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
// TODO: Check ZStep.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 ZStep</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _StepID;
|
|
}
|
|
#endregion
|
|
#region ValidationRules
|
|
protected override void AddBusinessRules()
|
|
{
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "OldStepSequence");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("OldStepSequence", 12));
|
|
ext.AddValidationRules(ValidationRules);
|
|
// TODO: Add other validation rules
|
|
// ValidationRules.AddRule(StartDateGTEndDate, "Started");
|
|
}
|
|
// 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(StepID, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(OldStepSequence, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(OldStepSequence, "<Role(s)>");
|
|
ext.AddAuthorizationRules(AuthorizationRules);
|
|
}
|
|
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; } }
|
|
private ZStep()
|
|
{/* require use of factory methods */}
|
|
public static ZStep New()
|
|
{
|
|
if (!CanAddObject())
|
|
throw new System.Security.SecurityException("User not authorized to add a ZStep");
|
|
return DataPortal.Create<ZStep>();
|
|
}
|
|
public static ZStep New(int stepID, string oldStepSequence)
|
|
{
|
|
ZStep tmp = ZStep.New();
|
|
tmp._StepID = stepID;
|
|
tmp.OldStepSequence = oldStepSequence;
|
|
return tmp;
|
|
}
|
|
public static ZStep MakeZStep(int stepID, string oldStepSequence)
|
|
{
|
|
ZStep tmp = ZStep.New(stepID, oldStepSequence);
|
|
tmp.Save();
|
|
return tmp;
|
|
}
|
|
public static ZStep Get(int stepID)
|
|
{
|
|
if (!CanGetObject())
|
|
throw new System.Security.SecurityException("User not authorized to view a ZStep");
|
|
return DataPortal.Fetch<ZStep>(new PKCriteria(stepID));
|
|
}
|
|
public static ZStep Get(SafeDataReader dr)
|
|
{
|
|
if (dr.Read()) return new ZStep(dr);
|
|
return null;
|
|
}
|
|
private ZStep(SafeDataReader dr)
|
|
{
|
|
_StepID = dr.GetInt32("StepID");
|
|
_OldStepSequence = dr.GetString("OldStepSequence");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
}
|
|
public static void Delete(int stepID)
|
|
{
|
|
if (!CanDeleteObject())
|
|
throw new System.Security.SecurityException("User not authorized to remove a ZStep");
|
|
DataPortal.Delete(new PKCriteria(stepID));
|
|
}
|
|
public override ZStep Save()
|
|
{
|
|
if (IsDeleted && !CanDeleteObject())
|
|
throw new System.Security.SecurityException("User not authorized to remove a ZStep");
|
|
else if (IsNew && !CanAddObject())
|
|
throw new System.Security.SecurityException("User not authorized to add a ZStep");
|
|
else if (!CanEditObject())
|
|
throw new System.Security.SecurityException("User not authorized to update a ZStep");
|
|
return base.Save();
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
[Serializable()]
|
|
private class PKCriteria
|
|
{
|
|
private int _StepID;
|
|
public int StepID
|
|
{ get { return _StepID; } }
|
|
public PKCriteria(int stepID)
|
|
{
|
|
_StepID = stepID;
|
|
}
|
|
}
|
|
// TODO: If Create needs to access DB - It should not be marked RunLocal
|
|
[RunLocal()]
|
|
private new void DataPortal_Create(object criteria)
|
|
{
|
|
|
|
// Database Defaults
|
|
|
|
// TODO: Add any defaults that are necessary
|
|
ValidationRules.CheckRules();
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getZStep";
|
|
cm.Parameters.AddWithValue("@StepID", criteria.StepID);
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
dr.Read();
|
|
_StepID = dr.GetInt32("StepID");
|
|
_OldStepSequence = dr.GetString("OldStepSequence");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.DataPortal_Fetch", ex);
|
|
_errorMessage = ex.Message;
|
|
throw new DbCslaException("ZStep.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_Insert()
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "addZStep";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@StepID", _StepID);
|
|
cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence);
|
|
// Output Calculated Columns
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
|
param_LastChanged.Direction = ParameterDirection.Output;
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// TODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
// update child objects
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.DataPortal_Insert", ex);
|
|
_errorMessage = ex.Message;
|
|
throw new DbCslaException("ZStep.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static byte[] Add(SqlConnection cn, int stepID, string oldStepSequence)
|
|
{
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "addZStep";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@StepID", stepID);
|
|
cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence);
|
|
// Output Calculated Columns
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
|
param_LastChanged.Direction = ParameterDirection.Output;
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// TODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.Add", ex);
|
|
throw new DbCslaException("ZStep.Add", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_Update()
|
|
{
|
|
if (IsDirty)// If this is dirty - open the connection
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
if (base.IsDirty)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "updateZStep";
|
|
// All Fields including Calculated Fields
|
|
cm.Parameters.AddWithValue("@StepID", _StepID);
|
|
cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence);
|
|
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
|
|
// Output Calculated Columns
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
|
param_LastChanged.Direction = ParameterDirection.Output;
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// TODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
// use the open connection to update child objects
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.DataPortal_Update", ex);
|
|
_errorMessage = ex.Message;
|
|
if (!ex.Message.EndsWith("has been edited by another user."))throw ex;
|
|
}
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static byte[] Update(SqlConnection cn, int stepID, string oldStepSequence, ref byte[] lastChanged)
|
|
{
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "updateZStep";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@StepID", stepID);
|
|
cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence);
|
|
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
|
|
// Output Calculated Columns
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
|
param_LastChanged.Direction = ParameterDirection.Output;
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// TODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.Update", ex);
|
|
throw new DbCslaException("ZStep.Update", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_DeleteSelf()
|
|
{
|
|
DataPortal_Delete(new PKCriteria(_StepID));
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
private void DataPortal_Delete(PKCriteria criteria)
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "deleteZStep";
|
|
cm.Parameters.AddWithValue("@StepID", criteria.StepID);
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.DataPortal_Delete", ex);
|
|
_errorMessage = ex.Message;
|
|
throw new DbCslaException("ZStep.DataPortal_Delete", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static void Remove(SqlConnection cn, int stepID)
|
|
{
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "deleteZStep";
|
|
// Input PK Fields
|
|
cm.Parameters.AddWithValue("@StepID", stepID);
|
|
// TODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.Remove", ex);
|
|
throw new DbCslaException("ZStep.Remove", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Exists
|
|
public static bool Exists(int stepID)
|
|
{
|
|
ExistsCommand result;
|
|
result = DataPortal.Execute<ExistsCommand>
|
|
(new ExistsCommand(stepID));
|
|
return result.Exists;
|
|
}
|
|
[Serializable()]
|
|
private class ExistsCommand : CommandBase
|
|
{
|
|
private int _StepID;
|
|
private bool _exists;
|
|
public bool Exists
|
|
{
|
|
get { return _exists; }
|
|
}
|
|
public ExistsCommand(int stepID)
|
|
{
|
|
_StepID = stepID;
|
|
}
|
|
protected override void DataPortal_Execute()
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
cn.Open();
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "existsZStep";
|
|
cm.Parameters.AddWithValue("@StepID", _StepID);
|
|
int count = (int)cm.ExecuteScalar();
|
|
_exists = (count > 0);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Database.LogException("ZStep.DataPortal_Execute", ex);
|
|
throw new DbCslaException("ZStep.DataPortal_Execute", ex);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
Extension ext = new Extension();
|
|
[Serializable()]
|
|
partial class Extension : extensionBase
|
|
{
|
|
}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Values
|
|
// 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 ZStepExt.cs
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Text;
|
|
//using Csla;
|
|
|
|
//namespace Volian.CSLA.Library
|
|
//{
|
|
// public partial class ZStep
|
|
// {
|
|
// partial class Extension : extensionBase
|
|
// {
|
|
// // TODO: Override automatic defaults
|
|
// 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));
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|