Пример #1
0
        /// <summary>Archives a Restriction record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="restrictionId">The value for the RestrictionId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int restrictionId)
        {
            // Accessor for the Restriction Table.
            ServerDataModel.RestrictionDataTable restrictionTable = ServerDataModel.Restriction;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.RestrictionRow restrictionRow = restrictionTable.FindByRestrictionId(restrictionId);
            if ((restrictionRow == null))
            {
                throw new Exception(string.Format("The Restriction table does not have an element identified by {0}", restrictionId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((restrictionRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < restrictionRow.GetViolationRows().Length); index = (index + 1))
            {
                ServerDataModel.ViolationRow childViolationRow = restrictionRow.GetViolationRows()[index];
                Violation.Archive(adoTransaction, sqlTransaction, childViolationRow.RowVersion, childViolationRow.ViolationId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            restrictionRow[restrictionTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(restrictionRow);
            restrictionRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Restriction\" set \"IsArchived\" = 1 where \"RestrictionId\"=@restrictionId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #2
0
        /// <summary>Inserts a Restriction record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="severity">The value for the Severity column.</param>
        /// <param name="approval">The value for the Approval column.</param>
        /// <param name="description">The value for the Description column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="externalId1">The value for the ExternalId1 column.</param>
        public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int severity, int approval, string description, object externalId0, object externalId1)
        {
            // Accessor for the Restriction Table.
            ServerDataModel.RestrictionDataTable restrictionTable = ServerDataModel.Restriction;
            // Apply Defaults
            if ((externalId0 == null))
            {
                externalId0 = System.DBNull.Value;
            }
            if ((externalId1 == null))
            {
                externalId1 = System.DBNull.Value;
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerDataModel.RestrictionRow restrictionRow = restrictionTable.NewRestrictionRow();
            restrictionRow[restrictionTable.RowVersionColumn]  = rowVersion;
            restrictionRow[restrictionTable.SeverityColumn]    = severity;
            restrictionRow[restrictionTable.ApprovalColumn]    = approval;
            restrictionRow[restrictionTable.DescriptionColumn] = description;
            restrictionRow[restrictionTable.ExternalId0Column] = externalId0;
            restrictionRow[restrictionTable.ExternalId1Column] = externalId1;
            restrictionTable.AddRestrictionRow(restrictionRow);
            adoTransaction.DataRows.Add(restrictionRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"Restriction\" (\"rowVersion\",\"RestrictionId\",\"Severity\",\"Approval\",\"Descrip" +
                                                   "tion\",\"ExternalId0\",\"ExternalId1\") values (@rowVersion,@restrictionId,@severity," +
                                                   "@approval,@description,@externalId0,@externalId1)");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionRow[restrictionTable.RestrictionIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@severity", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, severity));
            sqlCommand.Parameters.Add(new SqlParameter("@approval", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, approval));
            sqlCommand.Parameters.Add(new SqlParameter("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId1", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId1));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(restrictionRow.RestrictionId);
        }
Пример #3
0
        /// <summary>Updates a Restriction record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">The version number of the row</param>
        /// <param name="restrictionId">The value for the RestrictionId column.</param>
        /// <param name="severity">The value for the Severity column.</param>
        /// <param name="approval">The value for the Approval column.</param>
        /// <param name="description">The value for the Description column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="externalId1">The value for the ExternalId1 column.</param>
        public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int restrictionId, object severity, object approval, object description, object externalId0, object externalId1)
        {
            // Accessor for the Restriction Table.
            ServerDataModel.RestrictionDataTable restrictionTable = ServerDataModel.Restriction;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.RestrictionRow restrictionRow = restrictionTable.FindByRestrictionId(restrictionId);
            if ((restrictionRow == null))
            {
                throw new Exception(string.Format("The Restriction table does not have an element identified by {0}", restrictionId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((restrictionRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((severity == null))
            {
                severity = restrictionRow[restrictionTable.SeverityColumn];
            }
            if ((approval == null))
            {
                approval = restrictionRow[restrictionTable.ApprovalColumn];
            }
            if ((description == null))
            {
                description = restrictionRow[restrictionTable.DescriptionColumn];
            }
            if ((externalId0 == null))
            {
                externalId0 = restrictionRow[restrictionTable.ExternalId0Column];
            }
            if ((externalId1 == null))
            {
                externalId1 = restrictionRow[restrictionTable.ExternalId1Column];
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Update the record in the ADO database.
            restrictionRow[restrictionTable.RowVersionColumn]  = rowVersion;
            restrictionRow[restrictionTable.SeverityColumn]    = severity;
            restrictionRow[restrictionTable.ApprovalColumn]    = approval;
            restrictionRow[restrictionTable.DescriptionColumn] = description;
            restrictionRow[restrictionTable.ExternalId0Column] = externalId0;
            restrictionRow[restrictionTable.ExternalId1Column] = externalId1;
            adoTransaction.DataRows.Add(restrictionRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Restriction\" set \"RowVersion\"=@rowVersion,\"Severity\"=@severity,\"Approval\"" +
                                                   "=@approval,\"Description\"=@description,\"ExternalId0\"=@externalId0,\"ExternalId1\"=@" +
                                                   "externalId1 where \"RestrictionId\"=@restrictionId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@restrictionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, restrictionId));
            sqlCommand.Parameters.Add(new SqlParameter("@severity", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, severity));
            sqlCommand.Parameters.Add(new SqlParameter("@approval", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, approval));
            sqlCommand.Parameters.Add(new SqlParameter("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId1", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId1));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }