Beispiel #1
0
        /// <summary>Inserts a SectorTarget record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="modelId">The value for the ModelId column.</param>
        /// <param name="sectorId">The value for the SectorId column.</param>
        /// <param name="percent">The value for the Percent column.</param>
        public static void Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int modelId, int sectorId, decimal percent)
        {
            // Accessor for the SectorTarget Table.
            ServerDataModel.SectorTargetDataTable sectorTargetTable = ServerDataModel.SectorTarget;
            // Apply Defaults
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerDataModel.SectorTargetRow sectorTargetRow = sectorTargetTable.NewSectorTargetRow();
            sectorTargetRow[sectorTargetTable.RowVersionColumn] = rowVersion;
            sectorTargetRow[sectorTargetTable.ModelIdColumn]    = modelId;
            sectorTargetRow[sectorTargetTable.SectorIdColumn]   = sectorId;
            sectorTargetRow[sectorTargetTable.PercentColumn]    = percent;
            sectorTargetTable.AddSectorTargetRow(sectorTargetRow);
            adoTransaction.DataRows.Add(sectorTargetRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"SectorTarget\" (\"rowVersion\",\"ModelId\",\"SectorId\",\"Percent\") values (@rowV" +
                                                   "ersion,@modelId,@sectorId,@percent)");

            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("@modelId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelId));
            sqlCommand.Parameters.Add(new SqlParameter("@sectorId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sectorId));
            sqlCommand.Parameters.Add(new SqlParameter("@percent", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, percent));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #2
0
        /// <summary>Archives a SectorTarget 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="modelId">The value for the ModelId column.</param>
        /// <param name="sectorId">The value for the SectorId 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 modelId, int sectorId)
        {
            // Accessor for the SectorTarget Table.
            ServerDataModel.SectorTargetDataTable sectorTargetTable = ServerDataModel.SectorTarget;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.SectorTargetRow sectorTargetRow = sectorTargetTable.FindByModelIdSectorId(modelId, sectorId);
            if ((sectorTargetRow == null))
            {
                throw new Exception(string.Format("The SectorTarget table does not have an element identified by {0}{0}", modelId, sectorId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((sectorTargetRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            sectorTargetRow[sectorTargetTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(sectorTargetRow);
            sectorTargetRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"SectorTarget\" set \"IsArchived\" = 1 where \"ModelId\"=@modelId and \"SectorId" +
                                                   "\"=@sectorId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@modelId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelId));
            sqlCommand.Parameters.Add(new SqlParameter("@sectorId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sectorId));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #3
0
 /// <summary>Loads a SectorTarget record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Load(ParameterList parameters)
 {
     // Accessor for the SectorTarget Table.
     ServerDataModel.SectorTargetDataTable sectorTargetTable = ServerDataModel.SectorTarget;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalModelId = parameters["modelId"];
     string externalSectorId = parameters["sectorId"];
     decimal percent = parameters["percent"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int modelId = Model.FindRequiredKey(configurationId, "modelId", externalModelId);
     int sectorId = Sector.FindRequiredKey(configurationId, "sectorId", externalSectorId);
     // Find the record using the unique identifier.  If it doesn't exist, it will be inserted, if it does exist,
     // it will be updated.
     ServerDataModel.SectorTargetRow sectorTargetRow = sectorTargetTable.FindByModelIdSectorId(modelId, sectorId);
     if ((sectorTargetRow == null))
     {
         // Call the internal 'Insert' method to complete the operation.
         MarkThree.Quasar.Core.SectorTarget.Insert(adoTransaction, sqlTransaction, ref rowVersion, modelId, sectorId, percent);
     }
     else
     {
         // This will bypass the optimistic concurrency checking required by the internal method.
         rowVersion = ((long)(sectorTargetRow[sectorTargetTable.RowVersionColumn]));
         // Call the internal 'Update' method to complete the operation.
         MarkThree.Quasar.Core.SectorTarget.Update(adoTransaction, sqlTransaction, ref rowVersion, modelId, sectorId, percent);
     }
     // Return values
     parameters["rowVersion"] = rowVersion;
 }
Beispiel #4
0
 /// <summary>Updates a SectorTarget record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Update(ParameterList parameters)
 {
     // Accessor for the SectorTarget Table.
     ServerDataModel.SectorTargetDataTable sectorTargetTable = ServerDataModel.SectorTarget;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalModelId = parameters["modelId"];
     string externalSectorId = parameters["sectorId"];
     object percent = parameters["percent"].Value;
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int modelId = Model.FindRequiredKey(configurationId, "modelId", externalModelId);
     int sectorId = Sector.FindRequiredKey(configurationId, "sectorId", externalSectorId);
     // This will bypass the internal optimistic concurrency checking by providing the current rowVersion to the 
     // internal method.
     ServerDataModel.SectorTargetRow sectorTargetRow = sectorTargetTable.FindByModelIdSectorId(modelId, sectorId);
     rowVersion = ((long)(sectorTargetRow[sectorTargetTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.SectorTarget.Update(adoTransaction, sqlTransaction, ref rowVersion, modelId, sectorId, percent);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Beispiel #5
0
 /// <summary>Archives a SectorTarget record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Archive(ParameterList parameters)
 {
     // Accessor for the SectorTarget Table.
     ServerDataModel.SectorTargetDataTable sectorTargetTable = ServerDataModel.SectorTarget;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalModelId = parameters["modelId"];
     string externalSectorId = parameters["sectorId"];
     // Resolve External Identifiers
     int modelId = Model.FindRequiredKey(configurationId, "modelId", externalModelId);
     int sectorId = Sector.FindRequiredKey(configurationId, "sectorId", externalSectorId);
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerDataModel.SectorTargetRow sectorTargetRow = sectorTargetTable.FindByModelIdSectorId(modelId, sectorId);
     rowVersion = ((long)(sectorTargetRow[sectorTargetTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.SectorTarget.Archive(adoTransaction, sqlTransaction, rowVersion, modelId, sectorId);
 }