1261 lines
29 KiB
C#
1261 lines
29 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Contract.cs
|
|
// Implementation of Class Contract
|
|
// CSLA type: Editable Root
|
|
// Created on: 07-Jun-2004 8:41:19 AM
|
|
// Object design: Joyce
|
|
// Coded: John 29-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Contract
|
|
/// </summary>
|
|
[Serializable]
|
|
public class Contract : BusinessBase {
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private bool mActive;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private AssignedDocs mDocs;
|
|
private string mNotes="";
|
|
private string mName="";
|
|
|
|
|
|
private decimal mDiscountParts;
|
|
private bool mContractRatesOnly;
|
|
|
|
//Child collections
|
|
|
|
private ContractRates mContractRates;
|
|
|
|
|
|
//Custom fields
|
|
private string mCustom1="";
|
|
private string mCustom2="";
|
|
private string mCustom3="";
|
|
private string mCustom4="";
|
|
private string mCustom5="";
|
|
private string mCustom6="";
|
|
private string mCustom7="";
|
|
private string mCustom8="";
|
|
private string mCustom9="";
|
|
private string mCustom0="";
|
|
|
|
//case 58
|
|
private Guid mRegionID;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private Contract()
|
|
{
|
|
|
|
|
|
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
Active=true;
|
|
|
|
mContractRates=ContractRates.NewItems();
|
|
|
|
mDocs=AssignedDocs.NewItems();
|
|
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
|
|
//Built-in "Default" region
|
|
mRegionID = Region.DefaultRegionID;//case 58
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
/// <summary>
|
|
/// Get internal id number Read only property because it's set internally, not
|
|
/// externally
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get modified date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user record ID of person who created this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user ID of person who modified this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get /set active status of Contract
|
|
/// If active = true then Contract is selectable for workorders etc
|
|
/// If active = false then Contract in not selectable, but history can be viewed
|
|
/// </summary>
|
|
public bool Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mActive!=value)
|
|
{
|
|
mActive = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Notes about Contract
|
|
/// </summary>
|
|
public string Notes
|
|
{
|
|
get
|
|
{
|
|
return mNotes;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mNotes!=value)
|
|
{
|
|
mNotes = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <see cref="AssignedDocs"/> attributed to this Contract
|
|
/// </summary>
|
|
public AssignedDocs Docs
|
|
{
|
|
get
|
|
{
|
|
return mDocs;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Original sales Name number
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mName!=value)
|
|
{
|
|
mName = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Most businesses will enter in a discount that a unit receives that is applied
|
|
/// to parts to cut down on the entry involved with this, as then you could enter
|
|
/// in the discount % once, but it would get applied to any part selected for this
|
|
/// unit without having to enter in the actual price for every single part. (note
|
|
/// if client has a discount, and unit has a discount - the discount on the unit
|
|
/// overrides if the unit is selected in the workorder)
|
|
/// </summary>
|
|
public decimal DiscountParts
|
|
{
|
|
get
|
|
{
|
|
return mDiscountParts;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mDiscountParts!=value)
|
|
{
|
|
mDiscountParts = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Collection of rates that are accessible for this contract
|
|
/// </summary>
|
|
public ContractRates Rates
|
|
{
|
|
get
|
|
{
|
|
return mContractRates;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default = false
|
|
/// If true user can select rate from general rateslist rather than the ones
|
|
/// specifically set for this contract
|
|
/// </summary>
|
|
public bool ContractRatesOnly
|
|
{
|
|
get
|
|
{
|
|
return mContractRatesOnly;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mContractRatesOnly!=value)
|
|
{
|
|
mContractRatesOnly = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Limit to specific region or available to all regions using Region.DefaultRegionID
|
|
/// </summary>
|
|
public Guid RegionID
|
|
{
|
|
get
|
|
{
|
|
return mRegionID;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mRegionID != value)
|
|
{
|
|
mRegionID = value;
|
|
BrokenRules.Assert("RegionIDRequired",
|
|
"Error.Object.RequiredFieldEmpty,O.Region",
|
|
"RegionID", value == Guid.Empty);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//CUSTOM FIELDS
|
|
|
|
/// <summary>
|
|
/// Custom1
|
|
/// </summary>
|
|
public string Custom1
|
|
{
|
|
get
|
|
{
|
|
return mCustom1;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom1!=value)
|
|
{
|
|
mCustom1 = value;
|
|
BrokenRules.Assert("Custom1Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom1","Custom1",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom2
|
|
/// </summary>
|
|
public string Custom2
|
|
{
|
|
get
|
|
{
|
|
return mCustom2;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom2!=value)
|
|
{
|
|
mCustom2 = value;
|
|
BrokenRules.Assert("Custom2Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom2","Custom2",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom3
|
|
/// </summary>
|
|
public string Custom3
|
|
{
|
|
get
|
|
{
|
|
return mCustom3;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom3!=value)
|
|
{
|
|
mCustom3 = value;
|
|
BrokenRules.Assert("Custom3Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom3","Custom3",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom4
|
|
/// </summary>
|
|
public string Custom4
|
|
{
|
|
get
|
|
{
|
|
return mCustom4;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom4!=value)
|
|
{
|
|
mCustom4 = value;
|
|
BrokenRules.Assert("Custom4Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom4","Custom4",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom5
|
|
/// </summary>
|
|
public string Custom5
|
|
{
|
|
get
|
|
{
|
|
return mCustom5;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom5!=value)
|
|
{
|
|
mCustom5 = value;
|
|
BrokenRules.Assert("Custom5Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom5","Custom5",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom6
|
|
/// </summary>
|
|
public string Custom6
|
|
{
|
|
get
|
|
{
|
|
return mCustom6;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom6!=value)
|
|
{
|
|
mCustom6 = value;
|
|
BrokenRules.Assert("Custom6Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom6","Custom6",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom7
|
|
/// </summary>
|
|
public string Custom7
|
|
{
|
|
get
|
|
{
|
|
return mCustom7;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom7!=value)
|
|
{
|
|
mCustom7 = value;
|
|
BrokenRules.Assert("Custom7Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom7","Custom7",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom8
|
|
/// </summary>
|
|
public string Custom8
|
|
{
|
|
get
|
|
{
|
|
return mCustom8;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom8!=value)
|
|
{
|
|
mCustom8 = value;
|
|
BrokenRules.Assert("Custom8Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom8","Custom8",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom9
|
|
/// </summary>
|
|
public string Custom9
|
|
{
|
|
get
|
|
{
|
|
return mCustom9;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom9!=value)
|
|
{
|
|
mCustom9 = value;
|
|
BrokenRules.Assert("Custom9Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom9","Custom9",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom0
|
|
/// </summary>
|
|
public string Custom0
|
|
{
|
|
get
|
|
{
|
|
return mCustom0;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom0!=value)
|
|
{
|
|
mCustom0 = value;
|
|
BrokenRules.Assert("Custom0Length",
|
|
"Error.Object.FieldLengthExceeded500,Contract.Label.Custom0","Custom0",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flag - indicates if current user can open the wiki page for this object
|
|
/// See <see cref="WikiPage.ShowWikiLink(RootObjectTypes, Guid)"/> method for details
|
|
///
|
|
/// This is cached for the lifetime of this object
|
|
/// </summary>
|
|
|
|
public bool CanWiki//case 73
|
|
{
|
|
get
|
|
{
|
|
if (!bCanWiki.HasValue)
|
|
bCanWiki = WikiPage.ShowWikiLink(RootObjectTypes.Contract, mID);
|
|
return bCanWiki.Value;
|
|
}
|
|
|
|
}
|
|
//cache the result in case the UI calls this repeatedly
|
|
private bool? bCanWiki = null;
|
|
|
|
/// <summary>
|
|
/// Throw an error when a read only user
|
|
/// tries to set a property
|
|
/// (this should normally never be called unless someone is using the developer api since the UI
|
|
/// should prevent it from happening initially)
|
|
/// </summary>
|
|
private void ThrowSetError()
|
|
{
|
|
throw new System.Security.SecurityException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Contract")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "Contract" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
Contract c=(Contract)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("Contract"+mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Searching
|
|
|
|
/// <summary>
|
|
/// Returns a search result object based on search terms
|
|
/// for the ID specified
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
/// <param name="searchTerms"></param>
|
|
/// <returns></returns>
|
|
public static SearchResult GetSearchResult(Guid ID, string[]searchTerms)
|
|
{
|
|
|
|
|
|
|
|
if(AyaBizUtils.Right("Object.Contract")<(int)SecurityLevelTypes.ReadOnly)
|
|
return new SearchResult();
|
|
|
|
|
|
SearchResult sr=new SearchResult();
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
|
|
"SELECT aRegionID, aCreator, aModifier, aCreated, aModified, aName, " +
|
|
" aNotes, aCustom1, aCustom2, aCustom3, aCustom4, aCustom5, " +
|
|
" aCustom6, aCustom7, aCustom8, aCustom9, aCustom0 FROM " +
|
|
"aContract WHERE (aID = @ID)"
|
|
|
|
,ID);
|
|
|
|
if(!dr.Read())
|
|
return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for ContractID: " + ID.ToString());
|
|
|
|
if (!AyaBizUtils.InYourRegion(dr.GetGuid("aRegionID"))) return new SearchResult();//case 58
|
|
|
|
sr.Description=dr.GetString("aName");
|
|
sb.Append(sr.Description);
|
|
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aNotes"));
|
|
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom0"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom1"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom2"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom3"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom4"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom5"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom6"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom7"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom8"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom9"));
|
|
|
|
sr.Created=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
sr.Modified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
sr.Creator=dr.GetGuid("aCreator");
|
|
sr.Modifier=dr.GetGuid("aModifier");
|
|
|
|
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
|
|
|
|
//Formulate results
|
|
ExtractAndRank er = new ExtractAndRank();
|
|
er.Process(sb.ToString().Trim(),searchTerms);
|
|
sr.Extract=er.Extract;
|
|
sr.Rank=er.Ranking;
|
|
sr.AncestorRootObjectID=ID;
|
|
sr.AncestorRootObjectType=RootObjectTypes.Contract;
|
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// Create new Contract
|
|
/// </summary>
|
|
/// <returns>Contract</returns>
|
|
public static Contract NewItem()
|
|
{
|
|
Contract c;
|
|
|
|
if(AyaBizUtils.Right("Object.Contract")>(int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
c = new Contract();
|
|
|
|
return c;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Contract")));
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetch existing Contract
|
|
/// MRU tracked
|
|
/// </summary>
|
|
/// <returns>Contract</returns>
|
|
/// <param name="_ID">Contract Guid</param>
|
|
public static Contract GetItem(Guid _ID)
|
|
{
|
|
return GetItemMRU(_ID, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetch existing Contract
|
|
/// don't track MRU
|
|
/// </summary>
|
|
/// <returns>Contract</returns>
|
|
/// <param name="_ID">Contract Guid</param>
|
|
public static Contract GetItemNoMRU(Guid _ID)
|
|
{
|
|
return GetItemMRU(_ID, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get item, optional MRU
|
|
/// See <see cref="UserMRU"/>
|
|
/// </summary>
|
|
/// <param name="_ID"></param>
|
|
/// <param name="TrackMRU"></param>
|
|
/// <returns></returns>
|
|
public static Contract GetItemMRU(Guid _ID, bool TrackMRU)
|
|
{
|
|
if (_ID == AyaBizUtils.NewObjectGuid)
|
|
return NewItem();
|
|
|
|
if (AyaBizUtils.Right("Object.Contract") > (int)SecurityLevelTypes.NoAccess)
|
|
return (Contract)DataPortal.Fetch(new Criteria(_ID,TrackMRU));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Contract")));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Delete Contract
|
|
/// </summary>
|
|
/// <param name="_ID">Contract GUID</param>
|
|
public static void DeleteItem(Guid _ID)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.Contract")>(int)SecurityLevelTypes.ReadWrite)
|
|
DataPortal.Delete(new Criteria(_ID, true));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Contract")));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve internal ID from name.
|
|
///
|
|
/// </summary>
|
|
/// <param name="Name">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromName(string Name)
|
|
{
|
|
return GuidFetcher.GetItem("ACONTRACT", "ANAME", Name);
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
//set to false to load items initially
|
|
bReadOnly=false;
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aContract WHERE aID=@ID;",crit.ID);
|
|
if(!dr.Read())
|
|
DBUtil.ThrowFetchError("Contract ID: " + crit.ID.ToString());
|
|
|
|
//Standard fields
|
|
mID=dr.GetGuid("aID");
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
|
|
//case 58
|
|
mRegionID = dr.GetGuid("aRegionID");
|
|
|
|
//Custom fields
|
|
mCustom1=dr.GetString("aCustom1");
|
|
mCustom2=dr.GetString("aCustom2");
|
|
mCustom3=dr.GetString("aCustom3");
|
|
mCustom4=dr.GetString("aCustom4");
|
|
mCustom5=dr.GetString("aCustom5");
|
|
mCustom6=dr.GetString("aCustom6");
|
|
mCustom7=dr.GetString("aCustom7");
|
|
mCustom8=dr.GetString("aCustom8");
|
|
mCustom9=dr.GetString("aCustom9");
|
|
mCustom0=dr.GetString("aCustom0");
|
|
|
|
//Contract fields
|
|
mActive=dr.GetBoolean("AACTIVE");
|
|
mNotes=dr.GetString("aNotes");
|
|
mName=dr.GetString("aName");
|
|
mDiscountParts=dr.GetDecimal("aDiscountParts");
|
|
mContractRatesOnly=dr.GetBoolean("aContractRatesOnly");
|
|
|
|
|
|
if(dr!=null) dr.Close();
|
|
|
|
//Load child collection objects
|
|
|
|
//Rates
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
"SELECT * " +
|
|
"FROM aContractRate WHERE aContractRate.aContractID=@ID;"
|
|
,crit.ID);
|
|
mContractRates = ContractRates.GetItems(dr);
|
|
if(dr!=null) dr.Close();
|
|
|
|
//Docs
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM AASSIGNEDDOC WHERE (aRootObjectID=@ID and aRootObjectType=18);",crit.ID);
|
|
mDocs = AssignedDocs.GetItems(dr, RootObjectTypes.Contract, RootObjectTypes.Contract);
|
|
if(dr!=null) dr.Close();
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
MarkOld();
|
|
|
|
if(crit.TrackMRU)
|
|
if(AyaBizUtils.AllowAutomaticMRUOnUpdate) AyaBizUtils.MRU.Add(RootObjectTypes.Contract, mID);
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.Contract")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
}
|
|
|
|
|
|
#endregion fetch
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Called by DataPortal to delete/add/update data into the database
|
|
/// </summary>
|
|
protected override void DataPortal_Update()
|
|
{
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
DBUtil.CheckSafeToUpdate(this.mModified.Date,this.mID,"aContract");
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aContract WHERE aID = @ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
|
|
DBCommandWrapper cmDeleteContractRates = DBUtil.GetCommandFromSQL("DELETE FROM aContractRate WHERE aContractID = @ID;");
|
|
cmDeleteContractRates.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
DBUtil.DB.ExecuteNonQuery(cmDeleteContractRates, transaction);
|
|
DBUtil.RemoveKeywords(transaction,RootObjectTypes.Contract,this.mID);
|
|
DBUtil.RemoveDocs(transaction,RootObjectTypes.Contract,this.mID);
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Add / Update
|
|
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
DBCommandWrapper cm = null;
|
|
if(IsNew)//Add or update?
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aContract (aID, aDiscountParts, aName, AACTIVE, aNotes, aContractRatesOnly, aCreated,aModified,aCreator,aModifier, aRegionID, " +
|
|
"aCustom1, aCustom2, aCustom3, aCustom4, aCustom5, aCustom6, aCustom7, aCustom8, aCustom9, aCustom0) " +
|
|
"VALUES (@ID,@DiscountParts, @Name,@Active,@Notes,@ContractRatesOnly,@Created,@Modified,@CurrentUserID,@CurrentUserID, @RegionID, " +
|
|
"@Custom1,@Custom2,@Custom3,@Custom4,@Custom5,@Custom6,@Custom7,@Custom8,@Custom9,@Custom0)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aContract SET aID=@ID, aDiscountParts=@DiscountParts, " +
|
|
"aName=@Name, AACTIVE=@Active, aNotes=@Notes, " +
|
|
"aContractRatesOnly=@ContractRatesOnly, aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified,aRegionID=@RegionID, aCustom1=@Custom1, " +
|
|
"aCustom2=@Custom2, aCustom3=@Custom3, " +
|
|
"aCustom4=@Custom4, aCustom5=@Custom5, aCustom6=@Custom6, " +
|
|
"aCustom7=@Custom7, aCustom8=@Custom8, " +
|
|
"aCustom9=@Custom9, aCustom0=@Custom0 WHERE " +
|
|
"aID=@ID"
|
|
);
|
|
|
|
|
|
cm.AddInParameter("@ID",DbType.Guid,mID);
|
|
cm.AddInParameter("@Active",DbType.Boolean, mActive);
|
|
cm.AddLargeStringInParameter("@Notes", mNotes);
|
|
cm.AddInParameter("@Name",DbType.String, mName);
|
|
cm.AddInParameter("@DiscountParts",DbType.Decimal, mDiscountParts);
|
|
cm.AddInParameter("@ContractRatesOnly",DbType.Boolean, mContractRatesOnly);
|
|
|
|
cm.AddInParameter("@RegionID", DbType.Guid, mRegionID);//case 58
|
|
|
|
|
|
//Standard fields
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
|
|
//Custom fields
|
|
cm.AddLargeStringInParameter("@Custom1", mCustom1);
|
|
cm.AddLargeStringInParameter("@Custom2", mCustom2);
|
|
cm.AddLargeStringInParameter("@Custom3", mCustom3);
|
|
cm.AddLargeStringInParameter("@Custom4", mCustom4);
|
|
cm.AddLargeStringInParameter("@Custom5", mCustom5);
|
|
cm.AddLargeStringInParameter("@Custom6", mCustom6);
|
|
cm.AddLargeStringInParameter("@Custom7", mCustom7);
|
|
cm.AddLargeStringInParameter("@Custom8", mCustom8);
|
|
cm.AddLargeStringInParameter("@Custom9", mCustom9);
|
|
cm.AddLargeStringInParameter("@Custom0", mCustom0);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, transaction);
|
|
|
|
//Update child objects
|
|
mContractRates.Update(this,transaction);
|
|
|
|
//Docs
|
|
mDocs.Update(transaction);
|
|
|
|
//Process keywords
|
|
DBUtil.ProcessKeywords(transaction,this.mID,RootObjectTypes.Contract,IsNew,AyaBizUtils.Break(false,
|
|
mNotes,mName,
|
|
/*Custom fields*/
|
|
mCustom1,mCustom2,mCustom3,mCustom4,mCustom5,mCustom6,mCustom7,mCustom8,mCustom9,mCustom0));
|
|
|
|
MarkOld();//db is now synched with object
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
if(AyaBizUtils.AllowAutomaticMRUOnUpdate) AyaBizUtils.MRU.Add(RootObjectTypes.Contract, mID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
#endregion update
|
|
|
|
#region Delete
|
|
|
|
/// <summary>
|
|
/// Remove a Contract record .
|
|
/// </summary>
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Delete(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aContract WHERE aID = @ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,crit.ID);
|
|
|
|
DBCommandWrapper cmDeleteContractRates = DBUtil.GetCommandFromSQL("DELETE FROM aContractRate WHERE aContractID = @ID;");
|
|
cmDeleteContractRates.AddInParameter("@ID",DbType.Guid,crit.ID);
|
|
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
DBUtil.DB.ExecuteNonQuery(cmDeleteContractRates, transaction);
|
|
|
|
DBUtil.RemoveKeywords(transaction,RootObjectTypes.Contract,crit.ID);
|
|
DBUtil.RemoveDocs(transaction,RootObjectTypes.Contract,crit.ID);
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
AyaBizUtils.MRU.Remove(RootObjectTypes.Contract, crit.ID);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion delete
|
|
|
|
#endregion
|
|
|
|
#region Override IsValid / IsDirty
|
|
//Override base class version if there are child objects
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override bool IsValid
|
|
{
|
|
get
|
|
{
|
|
return base.IsValid && mContractRates.IsValid && mDocs.IsValid;
|
|
}
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
return base.IsDirty || mContractRates.IsDirty || mDocs.IsDirty;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Guid ID;
|
|
public bool TrackMRU;
|
|
public Criteria(Guid _ID, bool _TrackMRU)
|
|
{
|
|
ID=_ID;
|
|
TrackMRU = _TrackMRU;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Contract
|
|
|
|
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |