The purpose of this upgrade is to improve the user experience when using the Admin tool to Update ROs. Currently for larger RO dbs (like Barakah) we can run up against memory constraints that do not allow all the ROs to be updated at one time. This is based upon some initial resource where some places were identified where we could improve memory usage. Some of these should benefit PROMS as a whole while others will be specific to the RO Update option in Admin Tools.
1334 lines
56 KiB
C#
1334 lines
56 KiB
C#
// ========================================================================
|
|
// Copyright 2007 - 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;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
using Csla.Validation;
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
/// <summary>
|
|
/// User Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(UserConverter))]
|
|
public partial class User : BusinessBase<User>, IDisposable, IVEHasBrokenRules
|
|
{
|
|
#region Log4Net
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
#region Refresh
|
|
private List<User> _RefreshUsers = new List<User>();
|
|
private List<UserMembership> _RefreshUserMemberships = new List<UserMembership>();
|
|
private void AddToRefreshList(List<User> refreshUsers, List<UserMembership> refreshUserMemberships)
|
|
{
|
|
if (IsDirty)
|
|
refreshUsers.Add(this);
|
|
if (_UserMemberships != null && _UserMemberships.IsDirty)
|
|
{
|
|
foreach (UserMembership tmp in _UserMemberships)
|
|
{
|
|
if (tmp.IsDirty) refreshUserMemberships.Add(tmp);
|
|
}
|
|
}
|
|
}
|
|
private void BuildRefreshList()
|
|
{
|
|
_RefreshUsers = new List<User>();
|
|
_RefreshUserMemberships = new List<UserMembership>();
|
|
AddToRefreshList(_RefreshUsers, _RefreshUserMemberships);
|
|
}
|
|
private void ProcessRefreshList()
|
|
{
|
|
foreach (User tmp in _RefreshUsers)
|
|
{
|
|
UserInfo.Refresh(tmp);
|
|
}
|
|
foreach (UserMembership tmp in _RefreshUserMemberships)
|
|
{
|
|
MembershipInfo.Refresh(tmp);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Collection
|
|
private static List<User> _CacheList = new List<User>();
|
|
protected static void AddToCache(User user)
|
|
{
|
|
if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache
|
|
}
|
|
protected static void RemoveFromCache(User user)
|
|
{
|
|
while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache
|
|
}
|
|
private static Dictionary<string, List<User>> _CacheByPrimaryKey = new Dictionary<string, List<User>>();
|
|
private static void ConvertListToDictionary()
|
|
{
|
|
List<User> remove = new List<User>();
|
|
foreach (User tmp in _CacheList)
|
|
{
|
|
if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString()))
|
|
{
|
|
_CacheByPrimaryKey[tmp.UID.ToString()] = new List<User>(); // Add new list for PrimaryKey
|
|
}
|
|
_CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list
|
|
remove.Add(tmp);
|
|
}
|
|
foreach (User tmp in remove)
|
|
RemoveFromCache(tmp);
|
|
}
|
|
protected static User GetCachedByPrimaryKey(int uid)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = uid.ToString();
|
|
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
|
return null;
|
|
}
|
|
#endregion
|
|
#region Business Methods
|
|
private string _ErrorMessage = string.Empty;
|
|
public string ErrorMessage
|
|
{
|
|
get { return _ErrorMessage; }
|
|
}
|
|
private static int _nextUID = -1;
|
|
public static int NextUID
|
|
{
|
|
get { return _nextUID--; }
|
|
}
|
|
private int _UID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int UID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UID;
|
|
}
|
|
}
|
|
private string _UserID = string.Empty;
|
|
public string UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UserID;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_UserID != value)
|
|
{
|
|
_UserID = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _FirstName = string.Empty;
|
|
public string FirstName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _FirstName;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_FirstName != value)
|
|
{
|
|
_FirstName = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _MiddleName = string.Empty;
|
|
public string MiddleName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _MiddleName;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_MiddleName != value)
|
|
{
|
|
_MiddleName = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _LastName = string.Empty;
|
|
public string LastName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _LastName;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_LastName != value)
|
|
{
|
|
_LastName = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _Suffix = string.Empty;
|
|
public string Suffix
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Suffix;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_Suffix != value)
|
|
{
|
|
_Suffix = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _CourtesyTitle = string.Empty;
|
|
public string CourtesyTitle
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _CourtesyTitle;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_CourtesyTitle != value)
|
|
{
|
|
_CourtesyTitle = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _PhoneNumber = string.Empty;
|
|
public string PhoneNumber
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _PhoneNumber;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_PhoneNumber != value)
|
|
{
|
|
_PhoneNumber = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _CFGName = string.Empty;
|
|
public string CFGName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _CFGName;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_CFGName != value)
|
|
{
|
|
_CFGName = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _UserLogin = string.Empty;
|
|
public string UserLogin
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UserLogin;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_UserLogin != value)
|
|
{
|
|
_UserLogin = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _UserName = string.Empty;
|
|
public string UserName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UserName;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_UserName != value)
|
|
{
|
|
_UserName = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _Config = string.Empty;
|
|
public string Config
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Config;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
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
|
|
{
|
|
return _DTS;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_DTS != value)
|
|
{
|
|
_DTS = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _UsrID = string.Empty;
|
|
public string UsrID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UsrID;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_UsrID != value)
|
|
{
|
|
_UsrID = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _LastChanged = new byte[8];//timestamp
|
|
private int _UserMembershipCount = 0;
|
|
/// <summary>
|
|
/// Count of UserMemberships for this User
|
|
/// </summary>
|
|
public int UserMembershipCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UserMembershipCount;
|
|
}
|
|
}
|
|
private UserMemberships _UserMemberships = null;
|
|
/// <summary>
|
|
/// Related Field
|
|
/// </summary>
|
|
[TypeConverter(typeof(UserMembershipsConverter))]
|
|
public UserMemberships UserMemberships
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_UserMembershipCount > 0 && _UserMemberships == null)
|
|
_UserMemberships = UserMemberships.GetByUID(UID);
|
|
else if (_UserMemberships == null)
|
|
_UserMemberships = UserMemberships.New();
|
|
return _UserMemberships;
|
|
}
|
|
}
|
|
public override bool IsDirty
|
|
{
|
|
get { return base.IsDirty || (_UserMemberships == null ? false : _UserMemberships.IsDirty); }
|
|
}
|
|
public override bool IsValid
|
|
{
|
|
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_UserMemberships == null ? true : _UserMemberships.IsValid); }
|
|
}
|
|
// TODO: Replace base User.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current User</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
// TODO: Check User.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 User</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _UID;
|
|
}
|
|
#endregion
|
|
#region ValidationRules
|
|
[NonSerialized]
|
|
private bool _CheckingBrokenRules = false;
|
|
public IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
if (_CheckingBrokenRules) return null;
|
|
if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
|
|
try
|
|
{
|
|
_CheckingBrokenRules = true;
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_UserMemberships != null && (hasBrokenRules = _UserMemberships.HasBrokenRules) != null) return hasBrokenRules;
|
|
return hasBrokenRules;
|
|
}
|
|
finally
|
|
{
|
|
_CheckingBrokenRules = false;
|
|
}
|
|
}
|
|
}
|
|
public BrokenRulesCollection BrokenRules
|
|
{
|
|
get
|
|
{
|
|
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
|
|
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
|
|
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
|
|
}
|
|
}
|
|
protected override void AddBusinessRules()
|
|
{
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "UserID");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("CFGName", 8));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32));
|
|
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));
|
|
//ValidationRules.AddDependantProperty("x", "y");
|
|
_UserExtension.AddValidationRules(ValidationRules);
|
|
// TODO: Add other validation rules
|
|
}
|
|
protected override void AddInstanceBusinessRules()
|
|
{
|
|
_UserExtension.AddInstanceValidationRules(ValidationRules);
|
|
// 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(UID, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(FirstName, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(MiddleName, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(LastName, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Suffix, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(CourtesyTitle, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(PhoneNumber, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(CFGName, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(UserLogin, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(UserName, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(FirstName, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(MiddleName, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(LastName, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Suffix, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(CourtesyTitle, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(PhoneNumber, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(CFGName, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(UserLogin, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(UserName, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
|
|
_UserExtension.AddAuthorizationRules(AuthorizationRules);
|
|
}
|
|
protected override void AddInstanceAuthorizationRules()
|
|
{
|
|
//TODO: Who can read/write which fields
|
|
_UserExtension.AddInstanceAuthorizationRules(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;
|
|
}
|
|
/// <summary>
|
|
/// determines if related records (Foreign Keys) will keep this Item from being deleted
|
|
/// </summary>
|
|
public bool CanDelete
|
|
{
|
|
get
|
|
{
|
|
// Check to make sure that there are not any related records
|
|
int usedByCount = 0;
|
|
usedByCount += _UserMembershipCount;
|
|
return (usedByCount == 0);
|
|
}
|
|
}
|
|
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 static int _UserUnique = 0;
|
|
protected static int UserUnique
|
|
{ get { return ++_UserUnique; } }
|
|
private int _MyUserUnique = UserUnique;
|
|
public int MyUserUnique
|
|
{ get { return _MyUserUnique; } }
|
|
protected User()
|
|
{/* require use of factory methods */
|
|
AddToCache(this);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
RemoveFromDictionaries();
|
|
}
|
|
private void RemoveFromDictionaries()
|
|
{
|
|
RemoveFromCache(this);
|
|
if (_CacheByPrimaryKey.ContainsKey(UID.ToString()))
|
|
{
|
|
List<User> listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items
|
|
while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list
|
|
if (listUser.Count == 0) //If there are no items left in the list
|
|
_CacheByPrimaryKey.Remove(UID.ToString()); // remove the list
|
|
}
|
|
}
|
|
public static User New()
|
|
{
|
|
if (!CanAddObject())
|
|
throw new System.Security.SecurityException("User not authorized to add a User");
|
|
try
|
|
{
|
|
return DataPortal.Create<User>();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on User.New", ex);
|
|
}
|
|
}
|
|
public static User New(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID)
|
|
{
|
|
User tmp = User.New();
|
|
tmp.UserID = userID;
|
|
tmp.FirstName = firstName;
|
|
tmp.MiddleName = middleName;
|
|
tmp.LastName = lastName;
|
|
tmp.Suffix = suffix;
|
|
tmp.CourtesyTitle = courtesyTitle;
|
|
tmp.PhoneNumber = phoneNumber;
|
|
tmp.CFGName = cFGName;
|
|
tmp.UserLogin = userLogin;
|
|
tmp.UserName = userName;
|
|
tmp.Config = config;
|
|
tmp.DTS = dts;
|
|
tmp.UsrID = usrID;
|
|
return tmp;
|
|
}
|
|
public static User MakeUser(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID)
|
|
{
|
|
User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID);
|
|
if (tmp.IsSavable)
|
|
{
|
|
User tmp2 = tmp;
|
|
tmp = tmp2.Save();
|
|
tmp2.Dispose();
|
|
}
|
|
else
|
|
{
|
|
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
|
tmp._ErrorMessage = "Failed Validation:";
|
|
foreach (Csla.Validation.BrokenRule br in brc)
|
|
{
|
|
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
|
}
|
|
}
|
|
return tmp;
|
|
}
|
|
public static User New(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config)
|
|
{
|
|
User tmp = User.New();
|
|
tmp.FirstName = firstName;
|
|
tmp.MiddleName = middleName;
|
|
tmp.LastName = lastName;
|
|
tmp.Suffix = suffix;
|
|
tmp.CourtesyTitle = courtesyTitle;
|
|
tmp.PhoneNumber = phoneNumber;
|
|
tmp.CFGName = cFGName;
|
|
tmp.UserLogin = userLogin;
|
|
tmp.UserName = userName;
|
|
tmp.Config = config;
|
|
return tmp;
|
|
}
|
|
public static User MakeUser(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config)
|
|
{
|
|
User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config);
|
|
if (tmp.IsSavable)
|
|
{
|
|
User tmp2 = tmp;
|
|
tmp = tmp2.Save();
|
|
tmp2.Dispose();
|
|
}
|
|
else
|
|
{
|
|
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
|
tmp._ErrorMessage = "Failed Validation:";
|
|
foreach (Csla.Validation.BrokenRule br in brc)
|
|
{
|
|
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
|
}
|
|
}
|
|
return tmp;
|
|
}
|
|
public static User Get(int uid)
|
|
{
|
|
if (!CanGetObject())
|
|
throw new System.Security.SecurityException("User not authorized to view a User");
|
|
try
|
|
{
|
|
User tmp = GetCachedByPrimaryKey(uid);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<User>(new PKCriteria(uid));
|
|
AddToCache(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp.Dispose(); // Clean-up User
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on User.Get", ex);
|
|
}
|
|
}
|
|
public static User Get(SafeDataReader dr)
|
|
{
|
|
if (dr.Read()) return new User(dr);
|
|
return null;
|
|
}
|
|
internal User(SafeDataReader dr)
|
|
{
|
|
ReadData(dr);
|
|
}
|
|
public static void Delete(int uid)
|
|
{
|
|
if (!CanDeleteObject())
|
|
throw new System.Security.SecurityException("User not authorized to remove a User");
|
|
try
|
|
{
|
|
DataPortal.Delete(new PKCriteria(uid));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on User.Delete", ex);
|
|
}
|
|
}
|
|
public override User Save()
|
|
{
|
|
if (IsDeleted && !CanDeleteObject())
|
|
throw new System.Security.SecurityException("User not authorized to remove a User");
|
|
else if (IsNew && !CanAddObject())
|
|
throw new System.Security.SecurityException("User not authorized to add a User");
|
|
else if (!CanEditObject())
|
|
throw new System.Security.SecurityException("User not authorized to update a User");
|
|
try
|
|
{
|
|
BuildRefreshList();
|
|
User user = base.Save();
|
|
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
|
AddToCache(user);//Refresh the item in AllList
|
|
ProcessRefreshList();
|
|
return user;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on CSLA Save", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
[Serializable()]
|
|
protected class PKCriteria
|
|
{
|
|
private int _UID;
|
|
public int UID
|
|
{ get { return _UID; } }
|
|
public PKCriteria(int uid)
|
|
{
|
|
_UID = uid;
|
|
}
|
|
}
|
|
// TODO: If Create needs to access DB - It should not be marked RunLocal
|
|
[RunLocal()]
|
|
private new void DataPortal_Create()
|
|
{
|
|
_UID = NextUID;
|
|
// Database Defaults
|
|
_UserID = _UserExtension.DefaultUserID;
|
|
_DTS = _UserExtension.DefaultDTS;
|
|
_UsrID = _UserExtension.DefaultUsrID;
|
|
// TODO: Add any defaults that are necessary
|
|
ValidationRules.CheckRules();
|
|
}
|
|
private void ReadData(SafeDataReader dr)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.ReadData", GetHashCode());
|
|
try
|
|
{
|
|
_UID = dr.GetInt32("UID");
|
|
_UserID = dr.GetString("UserID");
|
|
_FirstName = dr.GetString("FirstName");
|
|
_MiddleName = dr.GetString("MiddleName");
|
|
_LastName = dr.GetString("LastName");
|
|
_Suffix = dr.GetString("Suffix");
|
|
_CourtesyTitle = dr.GetString("CourtesyTitle");
|
|
_PhoneNumber = dr.GetString("PhoneNumber");
|
|
_CFGName = dr.GetString("CFGName");
|
|
_UserLogin = dr.GetString("UserLogin");
|
|
_UserName = dr.GetString("UserName");
|
|
_Config = dr.GetString("Config");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UsrID = dr.GetString("UsrID");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
_UserMembershipCount = dr.GetInt32("MembershipCount");
|
|
MarkOld();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.ReadData", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("User.ReadData", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Fetch", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getUser";
|
|
cm.Parameters.AddWithValue("@UID", criteria.UID);
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
if (!dr.Read())
|
|
{
|
|
_ErrorMessage = "No Record Found";
|
|
return;
|
|
}
|
|
ReadData(dr);
|
|
// load child objects
|
|
dr.NextResult();
|
|
_UserMemberships = UserMemberships.Get(dr);
|
|
}
|
|
}
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("User.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_Insert()
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
SQLInsert();
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Insert", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("User.DataPortal_Insert", ex);
|
|
}
|
|
finally
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Insert", GetHashCode());
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
internal void SQLInsert()
|
|
{
|
|
if (!this.IsDirty) return;
|
|
try
|
|
{
|
|
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "addUser";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@UserID", _UserID);
|
|
cm.Parameters.AddWithValue("@FirstName", _FirstName);
|
|
cm.Parameters.AddWithValue("@MiddleName", _MiddleName);
|
|
cm.Parameters.AddWithValue("@LastName", _LastName);
|
|
cm.Parameters.AddWithValue("@Suffix", _Suffix);
|
|
cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle);
|
|
cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber);
|
|
cm.Parameters.AddWithValue("@CFGName", _CFGName);
|
|
cm.Parameters.AddWithValue("@UserLogin", _UserLogin);
|
|
cm.Parameters.AddWithValue("@UserName", _UserName);
|
|
cm.Parameters.AddWithValue("@Config", _Config);
|
|
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
|
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
|
// Output Calculated Columns
|
|
SqlParameter param_UID = new SqlParameter("@newUID", SqlDbType.Int);
|
|
param_UID.Direction = ParameterDirection.Output;
|
|
cm.Parameters.Add(param_UID);
|
|
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
|
|
_UID = (int)cm.Parameters["@newUID"].Value;
|
|
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
MarkOld();
|
|
// update child objects
|
|
if (_UserMemberships != null) _UserMemberships.Update(this);
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLInsert", GetHashCode());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLInsert", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("User.SQLInsert", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static byte[] Add(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Add", 0);
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "addUser";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@UserID", userID);
|
|
cm.Parameters.AddWithValue("@FirstName", firstName);
|
|
cm.Parameters.AddWithValue("@MiddleName", middleName);
|
|
cm.Parameters.AddWithValue("@LastName", lastName);
|
|
cm.Parameters.AddWithValue("@Suffix", suffix);
|
|
cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle);
|
|
cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
|
|
cm.Parameters.AddWithValue("@CFGName", cFGName);
|
|
cm.Parameters.AddWithValue("@UserLogin", userLogin);
|
|
cm.Parameters.AddWithValue("@UserName", userName);
|
|
cm.Parameters.AddWithValue("@Config", config);
|
|
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
|
cm.Parameters.AddWithValue("@UsrID", usrID);
|
|
// Output Calculated Columns
|
|
SqlParameter param_UID = new SqlParameter("@newUID", SqlDbType.Int);
|
|
param_UID.Direction = ParameterDirection.Output;
|
|
cm.Parameters.Add(param_UID);
|
|
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
|
|
uid = (int)cm.Parameters["@newUID"].Value;
|
|
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Add", ex);
|
|
throw new DbCslaException("User.Add", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_Update()
|
|
{
|
|
if (!IsDirty) return; // If not dirty - nothing to do
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Update", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
SQLUpdate();
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Update", ex);
|
|
_ErrorMessage = ex.Message;
|
|
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
internal void SQLUpdate()
|
|
{
|
|
if (!IsDirty) return; // If not dirty - nothing to do
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLUpdate", GetHashCode());
|
|
try
|
|
{
|
|
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
|
if (base.IsDirty)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "updateUser";
|
|
// All Fields including Calculated Fields
|
|
cm.Parameters.AddWithValue("@UID", _UID);
|
|
cm.Parameters.AddWithValue("@UserID", _UserID);
|
|
cm.Parameters.AddWithValue("@FirstName", _FirstName);
|
|
cm.Parameters.AddWithValue("@MiddleName", _MiddleName);
|
|
cm.Parameters.AddWithValue("@LastName", _LastName);
|
|
cm.Parameters.AddWithValue("@Suffix", _Suffix);
|
|
cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle);
|
|
cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber);
|
|
cm.Parameters.AddWithValue("@CFGName", _CFGName);
|
|
cm.Parameters.AddWithValue("@UserLogin", _UserLogin);
|
|
cm.Parameters.AddWithValue("@UserName", _UserName);
|
|
cm.Parameters.AddWithValue("@Config", _Config);
|
|
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
|
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
|
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;
|
|
}
|
|
}
|
|
MarkOld();
|
|
// use the open connection to update child objects
|
|
if (_UserMemberships != null) _UserMemberships.Update(this);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLUpdate", ex);
|
|
_ErrorMessage = ex.Message;
|
|
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
|
|
}
|
|
}
|
|
internal void Update()
|
|
{
|
|
if (!this.IsDirty) return;
|
|
if (base.IsDirty)
|
|
{
|
|
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
|
if (IsNew)
|
|
_LastChanged = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID);
|
|
else
|
|
_LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged);
|
|
MarkOld();
|
|
}
|
|
if (_UserMemberships != null) _UserMemberships.Update(this);
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static byte[] Update(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID, ref byte[] lastChanged)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Update", 0);
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "updateUser";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@UID", uid);
|
|
cm.Parameters.AddWithValue("@UserID", userID);
|
|
cm.Parameters.AddWithValue("@FirstName", firstName);
|
|
cm.Parameters.AddWithValue("@MiddleName", middleName);
|
|
cm.Parameters.AddWithValue("@LastName", lastName);
|
|
cm.Parameters.AddWithValue("@Suffix", suffix);
|
|
cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle);
|
|
cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
|
|
cm.Parameters.AddWithValue("@CFGName", cFGName);
|
|
cm.Parameters.AddWithValue("@UserLogin", userLogin);
|
|
cm.Parameters.AddWithValue("@UserName", userName);
|
|
cm.Parameters.AddWithValue("@Config", config);
|
|
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
|
cm.Parameters.AddWithValue("@UsrID", usrID);
|
|
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)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Update", ex);
|
|
throw new DbCslaException("User.Update", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_DeleteSelf()
|
|
{
|
|
DataPortal_Delete(new PKCriteria(_UID));
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
private void DataPortal_Delete(PKCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Delete", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "deleteUser";
|
|
cm.Parameters.AddWithValue("@UID", criteria.UID);
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Delete", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("User.DataPortal_Delete", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static void Remove(SqlConnection cn, int uid)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Remove", 0);
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "deleteUser";
|
|
// Input PK Fields
|
|
cm.Parameters.AddWithValue("@UID", uid);
|
|
// TODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Remove", ex);
|
|
throw new DbCslaException("User.Remove", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Exists
|
|
public static bool Exists(int uid)
|
|
{
|
|
ExistsCommand result;
|
|
try
|
|
{
|
|
result = DataPortal.Execute<ExistsCommand>(new ExistsCommand(uid));
|
|
return result.Exists;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on User.Exists", ex);
|
|
}
|
|
}
|
|
[Serializable()]
|
|
private class ExistsCommand : CommandBase
|
|
{
|
|
private int _UID;
|
|
private bool _exists;
|
|
public bool Exists
|
|
{
|
|
get { return _exists; }
|
|
}
|
|
public ExistsCommand(int uid)
|
|
{
|
|
_UID = uid;
|
|
}
|
|
protected override void DataPortal_Execute()
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Execute", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
cn.Open();
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "existsUser";
|
|
cm.Parameters.AddWithValue("@UID", _UID);
|
|
int count = (int)cm.ExecuteScalar();
|
|
_exists = (count > 0);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Execute", ex);
|
|
throw new DbCslaException("User.DataPortal_Execute", ex);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
UserExtension _UserExtension = new UserExtension();
|
|
[Serializable()]
|
|
partial class UserExtension : extensionBase
|
|
{
|
|
}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Values
|
|
public virtual string DefaultUserID
|
|
{
|
|
get { return Environment.UserName.ToUpper(); }
|
|
}
|
|
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
|
|
}
|
|
// Instance Authorization Rules
|
|
public virtual void AddInstanceAuthorizationRules(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
|
|
}
|
|
// InstanceValidation Rules
|
|
public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
|
|
{
|
|
// Needs to be overriden to add new validation rules
|
|
}
|
|
}
|
|
#endregion
|
|
} // Class
|
|
#region Converter
|
|
internal class UserConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is User)
|
|
{
|
|
// Return the ToString value
|
|
return ((User)value).ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|
|
|
|
|
|
//// The following is a sample Extension File. You can use it to create UserExt.cs
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Text;
|
|
//using Csla;
|
|
|
|
//namespace VEPROMS.CSLA.Library
|
|
//{
|
|
// public partial class User
|
|
// {
|
|
// partial class UserExtension : extensionBase
|
|
// {
|
|
// // TODO: Override automatic defaults
|
|
// public virtual string DefaultUserID
|
|
// {
|
|
// get { return Environment.UserName.ToUpper(); }
|
|
// }
|
|
// 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 AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
// {
|
|
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
|
|
// }
|
|
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
|
|
// {
|
|
// rules.AddRule(
|
|
// Csla.Validation.CommonRules.StringMaxLength,
|
|
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
|
|
// }
|
|
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
|
|
// {
|
|
// rules.AddInstanceRule(/* Instance Validation Rule */);
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|