Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/LoanItem.cs
2018-06-29 19:47:36 +00:00

1439 lines
34 KiB
C#

///////////////////////////////////////////////////////////
// LoanItem.cs
// Implementation of Class LoanItem
// CSLA type: Editable Root
// Created on: 12-Nov-2005
// Object design: Joyce/John
// Coded: John 12-Nov-2005
///////////////////////////////////////////////////////////
using System;
using System.Data;
using CSLA.Data;
using GZTW.Data;
using CSLA;
using System.Threading;
using CSLA.Security;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// LoanItem representing an item that will be loaned or rented to a client and tracked in the <see cref="WorkorderItemLoan"/> object
/// </summary>
[Serializable]
public class LoanItem : 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 mSerial="";
private string mName=null;
private Guid mCurrentWorkorderItemLoan;
//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 420
private decimal mRateHour = 0m;
private decimal mRateHalfDay = 0m;
private decimal mRateDay = 0m;
private decimal mRateWeek = 0m;
private decimal mRateMonth = 0m;
private decimal mRateYear = 0m;
//case 58
private Guid mRegionID;
#endregion
#region Constructor
/// <summary>
/// Private constructor to prevent direct instantiation
/// </summary>
private LoanItem()
{
//Set to read / write initially so that properties
//can be set
bReadOnly=false;
//New ID
mID = Guid.NewGuid();
Active=true;
mCurrentWorkorderItemLoan=Guid.Empty;
Name="";
//Set record history to defaults
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
mModified=new SmartDate();
mCreator=Guid.Empty;
mModifier=Guid.Empty;
mDocs=AssignedDocs.NewItems();
//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 LoanItem
/// If active = true then LoanItem is selectable for workorders etc
/// If active = false then LoanItem 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 unit
/// </summary>
public string Notes
{
get
{
return mNotes;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mNotes!=value)
{
mNotes = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get Loan item name
/// </summary>
public string Name
{
get
{
return mName;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mName!=value)
{
mName = value;
BrokenRules.Assert("NameRequired",
"Error.Object.RequiredFieldEmpty,LoanItem.Label.Name",
"Name",value.Length==0);
BrokenRules.Assert("NameLength",
"Error.Object.FieldLengthExceeded255,LoanItem.Label.Name",
"Name",value.Length>255);
MarkDirty();
}
}
}
}
/// <summary>
/// Collection of <see cref="AssignedDoc"/> objects assigned to this loan item
/// </summary>
public AssignedDocs Docs
{
get
{
return mDocs;
}
}
/// <summary>
/// Unique identification number of loan item
/// </summary>
public string Serial
{
get
{
return mSerial;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mSerial!=value)
{
mSerial = 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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.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,LoanItem.Label.Custom0","Custom0",value.Length>500);
MarkDirty();
}
}
}
}
//Case 420 next 6 properties
/// <summary>
/// Hourly charge rate
/// </summary>
public decimal RateHour
{
get
{
return mRateHour;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mRateHour != value)
{
mRateHour = value;
MarkDirty();
}
}
}
}
/// <summary>
/// HalfDayly charge rate
/// </summary>
public decimal RateHalfDay
{
get
{
return mRateHalfDay;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mRateHalfDay != value)
{
mRateHalfDay = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Dayly charge rate
/// </summary>
public decimal RateDay
{
get
{
return mRateDay;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mRateDay != value)
{
mRateDay = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Weekly charge rate
/// </summary>
public decimal RateWeek
{
get
{
return mRateWeek;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mRateWeek != value)
{
mRateWeek = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Monthly charge rate
/// </summary>
public decimal RateMonth
{
get
{
return mRateMonth;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mRateMonth != value)
{
mRateMonth = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Yearly charge rate
/// </summary>
public decimal RateYear
{
get
{
return mRateYear;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mRateYear != value)
{
mRateYear = value;
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.LoanItem, 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.LoanItem")
)
);
}
#endregion
#region System.object overrides
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "LoanItem" + mID.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(Object obj)
{
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
LoanItem c=(LoanItem)obj;
return mID==c.mID;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return ("LoanItem"+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.LoanItem")<(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, aCreated, aModified, aCreator, aModifier, aSerial, " +
" aNotes, aName, aCustom2, " +
" aCustom3, aCustom4, aCustom5, aCustom6, aCustom7, " +
"aCustom8, aCustom9, aCustom0, aCustom1 FROM aLoanItem WHERE " +
"(aID = @ID)"
,ID);
if(!dr.Read())
return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for LoanItemID: " + ID.ToString());
if (!AyaBizUtils.InYourRegion(dr.GetGuid("aRegionID"))) return new SearchResult();//case 58
sr.Description=dr.GetString("aSerial");
sb.Append(sr.Description);
sb.Append(" ");
sb.Append(dr.GetString("aName"));
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.LoanItem;
return sr;
}
#endregion
#region Static methods
/// <summary>
/// Create new LoanItem
/// </summary>
/// <returns>LoanItem</returns>
public static LoanItem NewItem()
{
LoanItem c;
if(AyaBizUtils.Right("Object.LoanItem")>(int)SecurityLevelTypes.ReadOnly)
{
c = new LoanItem();
// c.mGoToAddress=Address.NewItem();
// c.mGoToAddress.AddressType=AddressTypes.Physical;
return c;
}
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
LocalizedTextTable.GetLocalizedTextDirect("O.LoanItem")));
}
/// <summary>
/// Fetch existing LoanItem
/// </summary>
/// <returns>LoanItem</returns>
/// <param name="_ID">LoanItem Guid</param>
public static LoanItem GetItem(Guid _ID)
{
if (_ID == AyaBizUtils.NewObjectGuid)
return NewItem();
if(AyaBizUtils.Right("Object.LoanItem")>(int)SecurityLevelTypes.NoAccess)
return (LoanItem)DataPortal.Fetch(new Criteria(_ID));
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
LocalizedTextTable.GetLocalizedTextDirect("O.LoanItem")));
}
/// <summary>
/// Delete LoanItem
/// </summary>
/// <param name="_ID">LoanItem GUID</param>
public static void DeleteItem(Guid _ID)
{
if(AyaBizUtils.Right("Object.LoanItem")>(int)SecurityLevelTypes.ReadWrite)
DataPortal.Delete(new Criteria(_ID));
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"),
LocalizedTextTable.GetLocalizedTextDirect("O.LoanItem")));
}
//Case 421:
/// <summary>
/// Check for the existance of a loanitem
/// in the database by ID OR by serialnumber
/// </summary>
/// <param name="ID">Guid of item</param>
/// <param name="SerialNumber">Serial number of item</param>
/// <returns></returns>
public static bool Exists(Guid ID, string SerialNumber)
{
//case 497 new class
return LoanItemExistanceChecker.LoanItemExists(ID, SerialNumber);
}
/// <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("ALOANITEM", "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 aLoanItem WHERE aID=@ID;",crit.ID);
if(!dr.Read())
DBUtil.ThrowFetchError("LoanItem 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");
//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");
//Case 420
mRateHour = dr.GetDecimal("aRateHour");
mRateHalfDay = dr.GetDecimal("aRateHalfDay");
mRateDay = dr.GetDecimal("aRateDay");
mRateWeek = dr.GetDecimal("aRateWeek");
mRateMonth = dr.GetDecimal("aRateMonth");
mRateYear = dr.GetDecimal("aRateYear");
//LoanItem fields
Active=dr.GetBoolean("AACTIVE");
Name=dr.GetString("aName");
mNotes=dr.GetString("aNotes");
mSerial=dr.GetString("aSerial");
this.mCurrentWorkorderItemLoan=dr.GetGuid("aCurrentWorkorderItemLoan");
//case 58
mRegionID = dr.GetGuid("aRegionID");
if(dr!=null) dr.Close();
/*
* Load child collection objects
*/
;
//Docs
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM AASSIGNEDDOC WHERE (aRootObjectID=@ID and aRootObjectType=15);",crit.ID);
mDocs = AssignedDocs.GetItems(dr, RootObjectTypes.LoanItem, RootObjectTypes.LoanItem);
if(dr!=null) dr.Close();
}
finally
{
if(dr!=null) dr.Close();
}
MarkOld();
//Get access rights level
bReadOnly=AyaBizUtils.Right("Object.LoanItem")<(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,"aLoanItem");
#region Delete
if(IsDeleted)
{
if(!IsNew)
{
//Delete object and child objects
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aLoanItem WHERE aID = @ID;");
cmDelete.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.RemoveKeywords(transaction,RootObjectTypes.LoanItem,this.mID);
DBUtil.RemoveDocs(transaction,RootObjectTypes.LoanItem,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 aLoanItem (aID, AACTIVE, aSerial, aNotes, aName,aCurrentWorkorderItemLoan, " +
"aCreated,aModified,aCreator,aModifier, aRegionID, " +
"aCustom1, aCustom2, aCustom3, aCustom4, aCustom5, " +
"aCustom6, aCustom7, aCustom8, aCustom9, aCustom0, " +
//Case 420 added rates to existing query
"aRateHour,aRateHalfDay,aRateDay,aRateWeek,aRateMonth,aRateYear " +
") " +
"VALUES (@ID,@Active,@Serial,@Notes, @Name,@CurrentWorkorderItemLoan, " +
"@Created,@Modified,@CurrentUserID,@CurrentUserID, @RegionID, " +
"@Custom1,@Custom2,@Custom3,@Custom4,@Custom5,@Custom6, " +
"@Custom7,@Custom8,@Custom9,@Custom0, " +
//Case 420
"@RateHour,@RateHalfDay,@RateDay,@RateWeek,@RateMonth,@RateYear " +
")"
);
else
cm=DBUtil.GetCommandFromSQL(
"UPDATE aLoanItem SET aID=@ID, AACTIVE=@Active, aSerial=@Serial, " +
"aNotes=@Notes, aName=@Name, aCurrentWorkorderItemLoan=@CurrentWorkorderItemLoan, " +
"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, " +
//Case 420
"aRateHour=@RateHour,aRateHalfDay=@RateHalfDay, aRateDay=@RateDay, " +
"aRateWeek=@RateWeek, aRateMonth=@RateMonth, aRateYear=@RateYear " +
"WHERE aID=@ID"
);
//LoanItem specific fields
cm.AddInParameter("@ID",DbType.Guid,mID);
cm.AddInParameter("@Active",DbType.Boolean, mActive);
cm.AddLargeStringInParameter("@Notes", mNotes);
cm.AddInParameter("@Serial",DbType.String, mSerial);
cm.AddInParameter("@CurrentWorkorderItemLoan",DbType.Guid, mCurrentWorkorderItemLoan);
cm.AddInParameter("@Name",DbType.String,mName);
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);
//Case 420 rates
cm.AddInParameter("@RateHour", DbType.Decimal, mRateHour);
cm.AddInParameter("@RateHalfDay", DbType.Decimal, mRateHalfDay);
cm.AddInParameter("@RateDay", DbType.Decimal, mRateDay);
cm.AddInParameter("@RateWeek", DbType.Decimal, mRateWeek);
cm.AddInParameter("@RateMonth", DbType.Decimal, mRateMonth);
cm.AddInParameter("@RateYear", DbType.Decimal, mRateYear);
using (IDbConnection connection = DBUtil.DB.GetConnection())
{
connection.Open();
IDbTransaction transaction = connection.BeginTransaction();
try
{
DBUtil.DB.ExecuteNonQuery(cm, transaction);
//Update child objects
//Docs
mDocs.Update(transaction);
//Process keywords
DBUtil.ProcessKeywords(transaction,this.mID,RootObjectTypes.LoanItem,IsNew,AyaBizUtils.Break(false,
mName,mNotes,mSerial,
/*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;
}
#endregion
}
#endregion update
#region Delete
/// <summary>
/// Remove a LoanItem 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 aLoanItem WHERE aID = @ID;");
cmDelete.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.RemoveKeywords(transaction,RootObjectTypes.LoanItem,crit.ID);
DBUtil.RemoveDocs(transaction,RootObjectTypes.LoanItem,crit.ID);
// Commit the transaction
transaction.Commit();
}
catch
{
// Rollback transaction
transaction.Rollback();
throw;
}
finally
{
connection.Close();
}
}
}
#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 && mDocs.IsValid ;
}
}
/// <summary>
///
/// </summary>
public override bool IsDirty
{
get
{
return base.IsDirty || mDocs.IsDirty ;
}
}
#endregion
#region criteria
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
public Guid ID;
public Criteria(Guid _ID)
{
ID=_ID;
}
}
#endregion
#region Exists Case 421
//case 497 see above
//[Serializable(), System.ComponentModel.Browsable(false)]
//public class ExistsHelper
//{
// public bool _Exists = false;
// public Guid _ID;
// public string _SerialNumber;
// public ExistsHelper(Guid ID, string SerialNumber)
// {
// _ID = ID;
// _SerialNumber = SerialNumber;
// }
// public static bool GetExists(Guid ID, string SerialNumber)
// {
// ExistsHelper e = new ExistsHelper(ID, SerialNumber);
// DataPortal.Update(e);
// return e._Exists;
// }
// public void DataPortal_Update()
// {
// if (!string.IsNullOrEmpty(_SerialNumber))
// {
// DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
// "SELECT aID FROM aLoanItem WHERE " +
// "(aSerial = @SERIAL)"
// );
// dbCommandWrapper.AddInParameter("@SERIAL", DbType.String, _SerialNumber);
// if (DBUtil.ToGuid(DBUtil.DB.ExecuteScalar(dbCommandWrapper)) == Guid.Empty)
// this._Exists = false;
// else
// this._Exists = true;
// }
// else
// {
// if (DBUtil.ToGuid(DBUtil.GetScalarFromSQLString(
// "SELECT aID FROM aLoanItem WHERE " +
// "(aID = @ID)", _ID
// )) == Guid.Empty)
// this._Exists = false;
// else
// this._Exists = true;
// }
// }
//}
#endregion
}//end LoanItem
}//end namespace GZTW.AyaNova.BLL