Files
2018-06-29 19:47:36 +00:00

1247 lines
28 KiB
C#

///////////////////////////////////////////////////////////
// Project.cs
// Implementation of Class Project
// CSLA type: Editable Root
// Created on: 07-Jun-2004 8:41:30 AM
// Object design: Joyce
// Coded: John 20-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>
/// Project object, used to group work orders for sorting, filtering and reporting purposes
/// </summary>
[Serializable]
public class Project : 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=null;
private SmartDate mDateStarted;
private SmartDate mDateCompleted;
private Guid mProjectOverseerID;
private string mAccountNumber="";
//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 Project()
{
//Set to read / write initially so that properties
//can be set
bReadOnly=false;
//New ID
mID = Guid.NewGuid();
Active=true;
//Set record history to defaults
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
mModified=new SmartDate();
mCreator=Guid.Empty;
mModifier=Guid.Empty;
mDocs=AssignedDocs.NewItems();
mDateStarted = new SmartDate(DBUtil.CurrentWorkingDateTime);
mDateCompleted=new SmartDate();
mProjectOverseerID=Guid.Empty;
//pre-break name rule
Name="";
//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 Project
/// If active = true then Project is selectable for workorders etc
/// If active = false then Project 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 Project
/// </summary>
public string Notes
{
get
{
return mNotes;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mNotes!=value)
{
mNotes = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Collection of <see cref="AssignedDoc"/> objects assigned to this Project
/// </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;
BrokenRules.Assert("NameRequired",
"Error.Object.RequiredFieldEmpty,Project.Label.Name",
"Name",value.Length==0);
BrokenRules.Assert("NameLength",
"Error.Object.FieldLengthExceeded255,Project.Label.Name",
"Name",value.Length>255);
MarkDirty();
}
}
}
}
/// <summary>
/// Date of project completion
/// </summary>
public object DateCompleted
{
get
{
return mDateCompleted.DBValue;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if (!AyaBizUtils.SmartDateEquals(mDateCompleted, value)) //Case 298
{
mDateCompleted.DBValue = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Optional account number for project
/// </summary>
public string AccountNumber
{
get
{
return mAccountNumber;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mAccountNumber!=value)
{
mAccountNumber = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Date of project start
/// </summary>
public object DateStarted
{
get
{
return mDateStarted.DBValue;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if (!AyaBizUtils.SmartDateEquals(mDateStarted, value)) //Case 298
{
mDateStarted.DBValue = value;
MarkDirty();
}
}
}
}
/// <summary>
/// AyaNova user (schedulable or non-scheduleable) selected to indicate who is
/// "overseeing" the project
/// </summary>
public Guid ProjectOverseerID
{
get
{
return mProjectOverseerID;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mProjectOverseerID!=value)
{
mProjectOverseerID = 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,Project.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,Project.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,Project.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,Project.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,Project.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,Project.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,Project.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,Project.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,Project.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,Project.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.Project, 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.Project")
)
);
}
#endregion
#region System.object overrides
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "Project" + mID.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(Object obj)
{
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
Project c=(Project)obj;
return mID==c.mID;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return ("Project"+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.Project")<(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, aName, " +
" aNotes, AACCOUNTNUMBER, aCustom1, aCustom2, aCustom3, " +
" aCustom4, aCustom5, aCustom6, aCustom7, aCustom8, aCustom9, " +
" aCustom0 FROM aProject WHERE (aID = @ID)"
,ID);
if(!dr.Read())
return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for ProjectID: " + 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("AACCOUNTNUMBER"));
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.Project;
return sr;
}
#endregion
#region Static methods
/// <summary>
/// returns new item with null serial number that is a duplicate of the ID called
/// originally
/// </summary>
/// <param name="ProjectID">Project ID that you want to make a duplicate copy of</param>
public static Project DuplicateItem(Guid ProjectID)
{
//TODO: code
return null;
}
/// <summary>
/// Create new Project
/// </summary>
/// <returns>Project</returns>
public static Project NewItem()
{
Project c;
if(AyaBizUtils.Right("Object.Project")>(int)SecurityLevelTypes.ReadOnly)
{
c = new Project();
return c;
}
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
LocalizedTextTable.GetLocalizedTextDirect("O.Project")));
}
/// <summary>
/// Fetch existing Project
/// </summary>
/// <returns>Project</returns>
/// <param name="_ID">Project Guid</param>
public static Project GetItem(Guid _ID)
{
if (_ID == AyaBizUtils.NewObjectGuid)
return NewItem();
if(AyaBizUtils.Right("Object.Project")>(int)SecurityLevelTypes.NoAccess)
return (Project)DataPortal.Fetch(new Criteria(_ID));
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
LocalizedTextTable.GetLocalizedTextDirect("O.Project")));
}
/// <summary>
/// Delete Project
/// </summary>
/// <param name="_ID">Project GUID</param>
public static void DeleteItem(Guid _ID)
{
if(AyaBizUtils.Right("Object.Project")>(int)SecurityLevelTypes.ReadWrite)
DataPortal.Delete(new Criteria(_ID));
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"),
LocalizedTextTable.GetLocalizedTextDirect("O.Project")));
}
/// <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("APROJECT", "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 aProject WHERE aID=@ID;",crit.ID);
if(!dr.Read())
DBUtil.ThrowFetchError("Project 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");
//Project fields
mActive=dr.GetBoolean("AACTIVE");
mNotes=dr.GetString("aNotes");
//Unbreak rule:
Name=dr.GetString("aName");
mAccountNumber=dr.GetString("AACCOUNTNUMBER");
mDateStarted=DBUtil.ToLocal(dr.GetSmartDate("aDateStarted"));
mDateCompleted=DBUtil.ToLocal(dr.GetSmartDate("aDateCompleted"));
mProjectOverseerID=dr.GetGuid("aProjectOverseerID");
//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=19);",crit.ID);
mDocs = AssignedDocs.GetItems(dr, RootObjectTypes.Project, RootObjectTypes.Project);
if(dr!=null) dr.Close();
}
finally
{
if(dr!=null) dr.Close();
}
MarkOld();
//Get access rights level
bReadOnly=AyaBizUtils.Right("Object.Project")<(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,"aProject");
#region Delete
if(IsDeleted)
{
if(!IsNew)
{
//Delete object and child objects
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aProject 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.Project,this.mID);
DBUtil.RemoveDocs(transaction,RootObjectTypes.Project,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 aProject (aID, aName, aDateCompleted, aNotes, aProjectOverseerID, AACCOUNTNUMBER, " +
"aDateStarted, AACTIVE, aCreated,aModified,aCreator,aModifier, aRegionID, " +
"aCustom1, aCustom2, aCustom3, aCustom4, aCustom5, aCustom6, aCustom7, aCustom8, aCustom9, aCustom0) " +
"VALUES (@ID,@Name,@DateCompleted,@Notes,@ProjectOverseerID,@AccountNumber, " +
"@DateStarted,@Active,@Created,@Modified,@CurrentUserID,@CurrentUserID, @RegionID, " +
"@Custom1,@Custom2,@Custom3,@Custom4,@Custom5,@Custom6,@Custom7,@Custom8,@Custom9,@Custom0)"
);
else
cm=DBUtil.GetCommandFromSQL(
"UPDATE aProject SET aID=@ID, aName=@Name, aDateCompleted=@DateCompleted, " +
"aNotes=@Notes, aProjectOverseerID=@ProjectOverseerID, " +
"AACCOUNTNUMBER=@AccountNumber, " +
"aDateStarted=@DateStarted, AACTIVE=@Active, " +
"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"
);
//Project fields
cm.AddInParameter("@ID",DbType.Guid,mID);
cm.AddInParameter("@Active",DbType.Boolean, mActive);
cm.AddLargeStringInParameter("@Notes", mNotes);
cm.AddInParameter("@Name",DbType.String, mName);
cm.AddInParameter("@AccountNumber",DbType.String, mAccountNumber);
cm.AddInParameter("@DateStarted",DbType.DateTime,DBUtil.ToUTC(mDateStarted).DBValue);
cm.AddInParameter("@DateCompleted",DbType.DateTime, DBUtil.ToUTC(mDateCompleted).DBValue);
cm.AddInParameter("@ProjectOverseerID",DbType.Guid, mProjectOverseerID);
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);
//Docs
mDocs.Update(transaction);
//Process keywords
DBUtil.ProcessKeywords(transaction,this.mID,RootObjectTypes.Project,IsNew,AyaBizUtils.Break(false,
mNotes,mName,mAccountNumber,
/*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 Project 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 aProject 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.Project,crit.ID);
DBUtil.RemoveDocs(transaction,RootObjectTypes.Project,crit.ID);
// Commit the transaction
transaction.Commit();
}
catch
{
// Rollback transaction
transaction.Rollback();
throw;
}
finally
{
connection.Close();
}
}
}
#endregion delete
#endregion
#region Override IsValid / IsDirty
/// <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
}//end Project
}//end namespace GZTW.AyaNova.BLL