/// -------------------------------------------------------------------------------- /// <summary> /// Provides a means by which to ensure all locks have been removed for this user /// in situations where an unexpected exception occurs and/or the user logs out of /// system. /// </summary> /// -------------------------------------------------------------------------------- public void UnlockAll() { SQL.SQLDelete objDelete = new SQL.SQLDelete(); objDelete.TableName = pstrLockTableName; objDelete.Where.Add("UserID", SQL.ComparisonOperator.EqualTo, pstrCurrentUserID); using (ConnectionScope connection = new ConnectionScope(pobjDatabase)) connection.ExecuteNonQuery(objDelete); }
/// -------------------------------------------------------------------------------- /// <summary> /// Deletes an object's database record. If the collection's IDatabaseObjects.Subset /// has been implemented then the object must exist within the subset, otherwise the /// object will not be deleted. If the object has not been saved to the database the /// function will exit without executing an SQL DELETE command. After deleting the /// database record the object is set to Nothing. The calling function should receive /// the object ByRef for this to have any affect. Setting the object to Nothing /// minimises the possibility of the deleted object being used in code after /// ObjectDelete has been called. /// </summary> /// /// <param name="objCollection"> /// The collection that contains the object to delete. If the item does not exist /// within the collection then the object will not be deleted. /// </param> /// /// <param name="objItem"> /// The object to delete. The calling function should receive this object ByRef /// as the object is set to Nothing after deletion. /// Reference Type: <see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject) /// </param> /// /// <example> /// <code> /// Public Sub Delete(ByRef objProduct As Product) /// /// objDatabase.ObjectDelete(Me, objProduct) /// 'objProduct will now be Nothing /// /// End Sub /// </code> /// </example> /// -------------------------------------------------------------------------------- /// public void ObjectDelete(IDatabaseObjects objCollection, ref IDatabaseObject objItem) { if (objItem.IsSaved) { SQL.SQLDelete objDelete = new SQL.SQLDelete(); SQL.SQLConditions objSubset; objDelete.TableName = objCollection.TableName(); objDelete.Where.Add(objCollection.DistinctFieldName(), SQL.ComparisonOperator.EqualTo, objItem.DistinctValue); objSubset = objCollection.Subset(); if (objSubset != null && !objSubset.IsEmpty) objDelete.Where.Add(objSubset); using (ConnectionScope objConnection = new ConnectionScope(this)) objConnection.ExecuteNonQuery(objDelete); objItem.IsSaved = false; if (Transaction.Current != null) { IDatabaseObject objItemCopy = objItem; Transaction.Current.EnlistVolatile(new TransactionExecuteActionOnRollback(() => objItemCopy.IsSaved = true), EnlistmentOptions.None); } } //The function that calls ObjectDelete objItem MUST be ByRef for this to have any effect objItem = null; }
/// -------------------------------------------------------------------------------- /// <summary> /// UnLocks this object. Throws an exception if the object is not locked by the current /// user or the object has not been saved. /// </summary> /// -------------------------------------------------------------------------------- public void UnLock(IDatabaseObjects objCollection, IDatabaseObject objObject) { //If the table is locked by someone else if (!this.IsLockedByCurrentUser(objCollection, objObject)) throw new MethodAccessException("Object already locked"); else if (!objObject.IsSaved) throw new MethodAccessException("Object is not saved and cannot be unlocked"); SQL.SQLDelete objDelete = new SQL.SQLDelete(); objDelete.TableName = pstrLockTableName; objDelete.Where.Add("TableName", SQL.ComparisonOperator.EqualTo, objCollection.TableName()); objDelete.Where.Add("RecordID", SQL.ComparisonOperator.EqualTo, objObject.DistinctValue.ToString()); objDelete.Where.Add("UserID", SQL.ComparisonOperator.EqualTo, pstrCurrentUserID); using (ConnectionScope connection = new ConnectionScope(pobjDatabase)) connection.ExecuteNonQuery(objDelete); }
/// -------------------------------------------------------------------------------- /// <summary> /// Deletes all of the objects in the collection. If IDatabaseObjects.Subset /// has been implemented then only the objects within the subset are deleted, not /// the table's entire contents. /// </summary> /// /// <param name="objCollection"> /// The collection from which all objects are to be deleted. /// </param> /// -------------------------------------------------------------------------------- /// public void ObjectsDeleteAll(IDatabaseObjects objCollection) { SQL.SQLDelete objDelete = new SQL.SQLDelete(); objDelete.TableName = objCollection.TableName(); objDelete.Where = objCollection.Subset(); using (ConnectionScope objConnection = new ConnectionScope(this)) objConnection.ExecuteNonQuery(objDelete); }