/////////////////////////////////////////////////////////// // UnitModel.cs // Implementation of Class UnitModel // CSLA type: Editable Root // Created on: 07-Jun-2004 8:41:39 AM // Object design: Joyce // Coded: John 30-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 { /// /// Represents a Model of a object. Used for categorization, filtering and sorting in grids, reporting and warranty tracking. /// [Serializable] public class UnitModel : 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 string mModelNumber=""; private Guid mVendorID; private string mUPC=""; private Guid mUnitModelCategoryID; private SmartDate mIntroducedDate; private bool mLifeTimeWarranty; private bool mDiscontinued; private SmartDate mDiscontinuedDate; private int mWarrantyLength; private string mWarrantyTerms=""; //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=""; #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private UnitModel() { //Set to read / write initially so that properties //can be set bReadOnly=false; //New ID mID = Guid.NewGuid(); Active=true; mIntroducedDate=new SmartDate(); mDiscontinuedDate=new SmartDate(); //Set record history to defaults mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime); mModified=new SmartDate(); mCreator=Guid.Empty; mModifier=Guid.Empty; mDocs=AssignedDocs.NewItems(); mLifeTimeWarranty=false; } #endregion #region Business properties /// /// Get internal id number Read only property because it's set internally, not /// externally /// public Guid ID { get { return mID; } } /// /// Get created date /// /// /// public string Created { get { return mCreated.ToString(); } } /// /// Get modified date /// /// /// public string Modified { get { return mModified.ToString(); } } /// /// Get user record ID of person who created this record /// /// /// public Guid Creator { get { return mCreator; } } /// /// Get user ID of person who modified this record /// /// /// public Guid Modifier { get { return mModifier; } } /// /// Get /set active status of UnitModel /// If active = true then UnitModel is selectable for workorders etc /// If active = false then UnitModel in not selectable, but history can be viewed /// public bool Active { get { return mActive; } set { if(bReadOnly) ThrowSetError(); else { if(mActive!=value) { mActive = value; MarkDirty(); } } } } /// /// Notes about UnitModel /// public string Notes { get { return mNotes; } set { if(bReadOnly) ThrowSetError(); else { if(mNotes!=value) { mNotes = value; MarkDirty(); } } } } /// /// Collection of objects tied to this unit model /// public AssignedDocs Docs { get { return mDocs; } } /// /// Name /// public string Name { get { return mName; } set { if(bReadOnly) ThrowSetError(); else { if(mName!=value) { mName = value; MarkDirty(); } } } } /// /// For reporting and grouping purposes. For example, washing maching and dryer /// would be in category "Appliances" whereas a printer or scanner would be in /// "Computer Equipment" /// public Guid UnitModelCategoryID { get { return mUnitModelCategoryID; } set { if(bReadOnly) ThrowSetError(); else { if(mUnitModelCategoryID!=value) { mUnitModelCategoryID = value; MarkDirty(); } } } } /// /// who manufactures this model of /// public Guid VendorID { get { return mVendorID; } set { if(bReadOnly) ThrowSetError(); else { if(mVendorID!=value) { mVendorID = value; MarkDirty(); } } } } /// /// Default is false /// If true, can not have LifeTimeWarranty /// Notifies user of this and DiscontinuedDate when unit with this unitmodel is /// selected in a workorder /// public bool Discontinued { get { return mDiscontinued; } set { if(bReadOnly) ThrowSetError(); else { if(mDiscontinued!=value) { mDiscontinued = value; MarkDirty(); } } } } /// /// If Discontinued selected, able to enter in discontinued date /// public object DiscontinuedDate { get { return mDiscontinuedDate.DBValue; } set { if(bReadOnly) ThrowSetError(); else { if (!AyaBizUtils.SmartDateEquals(mDiscontinuedDate, value)) //Case 298 { mDiscontinuedDate.DBValue = value; MarkDirty(); } } } } /// /// Default is false /// If true, DiscontinuedWarranty not applicable /// public bool LifeTimeWarranty { get { return mLifeTimeWarranty; } set { if(bReadOnly) ThrowSetError(); else { if(mLifeTimeWarranty!=value) { mLifeTimeWarranty = value; MarkDirty(); } } } } /// /// Warranty length in months /// Ignored if LifeTimeWarranty selected /// public int WarrantyLength { get { return mWarrantyLength; } set { if(bReadOnly) ThrowSetError(); else { if(mWarrantyLength!=value) { mWarrantyLength = value; MarkDirty(); } } } } /// /// Information on warranty terms /// Displays in workorder when unit with this unitmodel selected /// public string WarrantyTerms { get { return mWarrantyTerms; } set { if(bReadOnly) ThrowSetError(); else { if(mWarrantyTerms!=value) { mWarrantyTerms = value; MarkDirty(); } } } } /// /// String as mixed numbers and letters /// public string ModelNumber { get { return mModelNumber; } set { if(bReadOnly) ThrowSetError(); else { if(mModelNumber!=value) { mModelNumber = value; BrokenRules.Assert("ModelNumberRequired", "Error.Object.RequiredFieldEmpty,UnitModel.Label.ModelNumber", "ModelNumber",value.Length==0); BrokenRules.Assert("ModelNumberLength", "Error.Object.FieldLengthExceeded255,UnitModel.Label.ModelNumber", "ModelNumber",value.Length>255); MarkDirty(); } } } } /// /// Universal Product Code for this model type /// public string UPC { get { return mUPC; } set { if(bReadOnly) ThrowSetError(); else { if(mUPC!=value) { mUPC = value; MarkDirty(); } } } } /// /// Date unitmodel introduced/released /// public object IntroducedDate { get { return mIntroducedDate.DBValue; } set { if(bReadOnly) ThrowSetError(); else { if (!AyaBizUtils.SmartDateEquals(mIntroducedDate, value)) //Case 298 { mIntroducedDate.DBValue = value; MarkDirty(); } } } } //CUSTOM FIELDS /// /// Custom1 /// public string Custom1 { get { return mCustom1; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom1!=value) { mCustom1 = value; BrokenRules.Assert("Custom1Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom1","Custom1",value.Length>500); MarkDirty(); } } } } /// /// Custom2 /// public string Custom2 { get { return mCustom2; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom2!=value) { mCustom2 = value; BrokenRules.Assert("Custom2Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom2","Custom2",value.Length>500); MarkDirty(); } } } } /// /// Custom3 /// public string Custom3 { get { return mCustom3; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom3!=value) { mCustom3 = value; BrokenRules.Assert("Custom3Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom3","Custom3",value.Length>500); MarkDirty(); } } } } /// /// Custom4 /// public string Custom4 { get { return mCustom4; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom4!=value) { mCustom4 = value; BrokenRules.Assert("Custom4Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom4","Custom4",value.Length>500); MarkDirty(); } } } } /// /// Custom5 /// public string Custom5 { get { return mCustom5; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom5!=value) { mCustom5 = value; BrokenRules.Assert("Custom5Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom5","Custom5",value.Length>500); MarkDirty(); } } } } /// /// Custom6 /// public string Custom6 { get { return mCustom6; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom6!=value) { mCustom6 = value; BrokenRules.Assert("Custom6Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom6","Custom6",value.Length>500); MarkDirty(); } } } } /// /// Custom7 /// public string Custom7 { get { return mCustom7; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom7!=value) { mCustom7 = value; BrokenRules.Assert("Custom7Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom7","Custom7",value.Length>500); MarkDirty(); } } } } /// /// Custom8 /// public string Custom8 { get { return mCustom8; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom8!=value) { mCustom8 = value; BrokenRules.Assert("Custom8Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom8","Custom8",value.Length>500); MarkDirty(); } } } } /// /// Custom9 /// public string Custom9 { get { return mCustom9; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom9!=value) { mCustom9 = value; BrokenRules.Assert("Custom9Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom9","Custom9",value.Length>500); MarkDirty(); } } } } /// /// Custom0 /// public string Custom0 { get { return mCustom0; } set { if(bReadOnly) ThrowSetError(); else { if(mCustom0!=value) { mCustom0 = value; BrokenRules.Assert("Custom0Length", "Error.Object.FieldLengthExceeded500,UnitModel.Label.Custom0","Custom0",value.Length>500); MarkDirty(); } } } } /// /// Flag - indicates if current user can open the wiki page for this object /// See method for details /// /// This is cached for the lifetime of this object /// public bool CanWiki//case 73 { get { if (!bCanWiki.HasValue) bCanWiki = WikiPage.ShowWikiLink(RootObjectTypes.UnitModel, mID); return bCanWiki.Value; } } //cache the result in case the UI calls this repeatedly private bool? bCanWiki = null; /// /// 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) /// private void ThrowSetError() { throw new System.Security.SecurityException ( string.Format ( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"), LocalizedTextTable.GetLocalizedTextDirect("O.UnitModel") ) ); } #endregion #region System.object overrides /// /// /// /// public override string ToString() { return "UnitModel" + mID.ToString(); } /// /// /// /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; UnitModel c=(UnitModel)obj; return mID==c.mID; } /// /// /// /// public override int GetHashCode() { return ("UnitModel"+mID).GetHashCode(); } #endregion #region Searching /// /// Returns a search result object based on search terms /// for the ID specified /// /// /// /// public static SearchResult GetSearchResult(Guid ID, string[]searchTerms) { if(AyaBizUtils.Right("Object.UnitModel")<(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 aCreated, aModified, aCreator, aModifier, aName, " + "aNotes, aModelNumber, aUPC, aWarrantyTerms, aCustom1, aCustom2, " + " aCustom3, aCustom4, aCustom5, aCustom6, aCustom7, " + " aCustom8, aCustom9, aCustom0 FROM aUnitModel WHERE " + "(aID = @ID)" ,ID); if(!dr.Read()) return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for UnitModelID: " + ID.ToString()); sr.Description=dr.GetString("aName"); sb.Append(sr.Description); sb.Append(" "); sb.Append(dr.GetString("aModelNumber")); sb.Append(" "); sb.Append(dr.GetString("aNotes")); sb.Append(" "); sb.Append(dr.GetString("aUPC")); sb.Append(" "); sb.Append(dr.GetString("aWarrantyTerms")); 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.UnitModel; return sr; } #endregion #region Static methods /// /// Create new UnitModel /// /// UnitModel public static UnitModel NewItem() { UnitModel c; if(AyaBizUtils.Right("Object.UnitModel")>(int)SecurityLevelTypes.ReadOnly) { c = new UnitModel(); return c; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"), LocalizedTextTable.GetLocalizedTextDirect("O.UnitModel"))); } /// /// Fetch existing UnitModel /// /// UnitModel /// UnitModel Guid public static UnitModel GetItem(Guid _ID) { if (_ID == AyaBizUtils.NewObjectGuid) return NewItem(); if(AyaBizUtils.Right("Object.UnitModel")>(int)SecurityLevelTypes.NoAccess) return (UnitModel)DataPortal.Fetch(new Criteria(_ID)); else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), LocalizedTextTable.GetLocalizedTextDirect("O.UnitModel"))); } /// /// Delete UnitModel /// /// UnitModel GUID public static void DeleteItem(Guid _ID) { if(AyaBizUtils.Right("Object.UnitModel")>(int)SecurityLevelTypes.ReadWrite) DataPortal.Delete(new Criteria(_ID)); else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"), LocalizedTextTable.GetLocalizedTextDirect("O.UnitModel"))); } /// /// Retrieve internal ID from name. /// /// /// Text value /// Guid ID value or Guid.Empty if no match public static Guid GetIDFromName(string Name) { return GuidFetcher.GetItem("AUNITMODEL", "ANAME", Name); } #endregion #region DAL DATA ACCESS #region Fetch /// /// 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 aUnitModel WHERE aID=@ID;",crit.ID); if(!dr.Read()) DBUtil.ThrowFetchError("UnitModel 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"); //UnitModel fields mActive=dr.GetBoolean("AACTIVE"); mNotes=dr.GetString("aNotes"); mName=dr.GetString("aName"); mModelNumber=dr.GetString("aModelNumber"); mVendorID=dr.GetGuid("aVendorID"); mUPC=dr.GetString("aUPC"); mUnitModelCategoryID=dr.GetGuid("aUnitModelCategoryID"); mIntroducedDate=DBUtil.ToLocal(dr.GetSmartDate("aIntroducedDate")); mLifeTimeWarranty=dr.GetBoolean("aLifeTimeWarranty"); mDiscontinued=dr.GetBoolean("aDiscontinued"); mDiscontinuedDate=DBUtil.ToLocal(dr.GetSmartDate("aDiscontinuedDate")); mWarrantyTerms=dr.GetString("aWarrantyTerms"); mWarrantyLength=dr.GetInt32("aWarrantyLength"); if(dr!=null) dr.Close(); /* * Load child collection objects */ //Docs dr=DBUtil.GetReaderFromSQLString("SELECT * FROM AASSIGNEDDOC WHERE (aRootObjectID=@ID and aRootObjectType=8);",crit.ID); mDocs = AssignedDocs.GetItems(dr, RootObjectTypes.UnitModel, RootObjectTypes.UnitModel); if(dr!=null) dr.Close(); } finally { if(dr!=null) dr.Close(); } MarkOld(); //Get access rights level bReadOnly=AyaBizUtils.Right("Object.UnitModel")<(int)SecurityLevelTypes.ReadWrite; } #endregion fetch #region Update /// /// Called by DataPortal to delete/add/update data into the database /// 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,"aUnitModel"); #region Delete if(IsDeleted) { if(!IsNew) { //Delete object and child objects DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aUnitModel 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.UnitModel,this.mID); DBUtil.RemoveDocs(transaction,RootObjectTypes.UnitModel,this.mID); // Commit the transaction transaction.Commit(); } catch { // Rollback transaction transaction.Rollback(); throw; } finally { connection.Close(); } } //----------------------------- } MarkNew(); return; } #endregion #region Add / Update if(mLifeTimeWarranty==true) this.mWarrantyLength=0; if(mDiscontinued==false) this.mDiscontinuedDate.DBValue=System.DBNull.Value; //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 aUnitModel (aNotes, aID, AACTIVE, aName, " + "aModelNumber, aVendorID, aUPC, aUnitModelCategoryID, " + "aLifeTimeWarranty, aIntroducedDate, aDiscontinued, " + "aDiscontinuedDate, aWarrantyLength, aWarrantyTerms, " + "aCreated,aModified, aCreator,aModifier, aCustom1, aCustom2, " + "aCustom3, aCustom4, aCustom5, aCustom6, aCustom7, " + "aCustom8, aCustom9, aCustom0) VALUES (@Notes,@ID, " + "@Active,@Name,@ModelNumber,@VendorID,@UPC, @UnitModelCategoryID, " + "@LifeTimeWarranty,@IntroducedDate, " + "@Discontinued,@DiscontinuedDate,@WarrantyLength,@WarrantyTerms, " + "@Created,@Modified, @CurrentUserID,@CurrentUserID, @Custom1, " + "@Custom2,@Custom3,@Custom4,@Custom5,@Custom6, " + "@Custom7,@Custom8,@Custom9,@Custom0)" ); else cm=DBUtil.GetCommandFromSQL( "UPDATE aUnitModel SET aNotes=@Notes, aID=@ID, AACTIVE=@Active, " + "aName=@Name, aModelNumber=@ModelNumber, " + "aVendorID=@VendorID, aUPC=@UPC, aUnitModelCategoryID=@UnitModelCategoryID, " + "aLifeTimeWarranty=@LifeTimeWarranty, " + "aIntroducedDate=@IntroducedDate, " + "aDiscontinued=@Discontinued, aDiscontinuedDate=@DiscontinuedDate, " + "aWarrantyLength=@WarrantyLength, " + "aWarrantyTerms=@WarrantyTerms, aModifier=@CurrentUserID, " + "aModified=@Modified, aCustom1=@Custom1, " + "aCustom2=@Custom2, aCustom3=@Custom3, aCustom4=@Custom4, " + "aCustom5=@Custom5, aCustom6=@Custom6, " + "aCustom7=@Custom7, aCustom8=@Custom8, aCustom9=@Custom9, " + "aCustom0=@Custom0 WHERE aID=@ID" ); //UnitModel specific 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("@ModelNumber",DbType.String,mModelNumber); cm.AddInParameter("@VendorID",DbType.Guid,mVendorID); cm.AddInParameter("@UPC",DbType.String,mUPC); cm.AddInParameter("@UnitModelCategoryID",DbType.Guid,mUnitModelCategoryID); cm.AddInParameter("@IntroducedDate",DbType.DateTime,DBUtil.ToUTC(mIntroducedDate).DBValue); cm.AddInParameter("@LifeTimeWarranty",DbType.Boolean,mLifeTimeWarranty); cm.AddInParameter("@Discontinued",DbType.Boolean,mDiscontinued); cm.AddInParameter("@DiscontinuedDate",DbType.DateTime,DBUtil.ToUTC(mDiscontinuedDate).DBValue); cm.AddInParameter("@WarrantyTerms",DbType.String,mWarrantyTerms); cm.AddInParameter("@WarrantyLength",DbType.Int32,mWarrantyLength); //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.UnitModel,IsNew,AyaBizUtils.Break(false, mNotes,mName,mModelNumber,mUPC,mWarrantyTerms, /*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 /// /// Remove a UnitModel record . /// /// protected override void DataPortal_Delete(object Criteria) { Criteria crit = (Criteria)Criteria; //Delete object and child objects DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aUnitModel 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.UnitModel,crit.ID); DBUtil.RemoveDocs(transaction,RootObjectTypes.UnitModel,crit.ID); // Commit the transaction transaction.Commit(); } catch { // Rollback transaction transaction.Rollback(); throw; } finally { connection.Close(); } } } #endregion #endregion #region Override IsValid / IsDirty /// /// /// public override bool IsValid { get { return base.IsValid && mDocs.IsValid; } } /// /// /// public override bool IsDirty { get { return base.IsDirty || mDocs.IsDirty; } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid ID; public Criteria(Guid _ID) { ID=_ID; } } #endregion }//end UnitModel }//end namespace GZTW.AyaNova.BLL