Exemplo n.º 1
0
        /// <summary>
        /// Delete the given MaterialParameter from the database
        /// </summary>
        public virtual void Delete(Model.MaterialParameter delMaterialParameter)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, delMaterialParameter);

                //Begin Checks
                if (!Exists(delMaterialParameter))
                {
                    throw new BusinessException(string.Format("There is no MaterialParameter with this id. ({0})", delMaterialParameter));
                }

                DataAccess.MaterialParameters materialParameters = new DataAccess.MaterialParameters();
                materialParameters.Delete(delMaterialParameter);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, delMaterialParameter);
                throw new BusinessException(string.Format("The MaterialParameter is still used by {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, delMaterialParameter);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new MaterialParameter to the database
        /// </summary>
        public virtual Int32 Add(Model.MaterialParameter newMaterialParameter)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, newMaterialParameter.ToString());
                var         helper  = Database.GetDbHelper();
                DbParameter IdParam = helper.CreateOutputParam("@Id", DbType.Int32);

                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add,
                                                               IdParam,
                                                               helper.CreateInputParam("@Code", newMaterialParameter.Code),
                                                               helper.CreateInputParam("@MaterialGroupId", newMaterialParameter.MaterialGroupId));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("Unable to add MaterialParameter with Id={0}", newMaterialParameter);
                }

                return((Int32)IdParam.Value);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newMaterialParameter.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get a MaterialParameter by id from the database
        /// </summary>
        public virtual Model.MaterialParameter GetById(Int32 id)
        {
            DbDataReader reader = null;

            try
            {
                var helper = Database.GetDbHelper();

                reader = helper.ExecuteSPReader(_storedProcedure_GetById,
                                                helper.CreateInputParam("@Id", id));

                Model.MaterialParameter result = null;

                if (reader.Read())
                {
                    result = CreateMaterialParameter(reader);
                }

                return(result);
            }
            catch (Exception ex)
            {
                Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id);
                throw DbHelper.TranslateException(ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Equals function to compare class
 /// </summary>
 public virtual bool Exists(Model.MaterialParameter materialParameter)
 {
     try
     {
         return(this.GetById(materialParameter.Id) != null);
     }
     catch (Exception ex)
     {
         Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, materialParameter);
         throw;
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Check Datafield constraints
        /// </summary>
        protected virtual void CheckConstraints(Model.MaterialParameter materialParameter)
        {
            //Range checks, etc checks go here
            if (materialParameter.Code == null)
            {
                throw new BusinessException(string.Format("Code may not be NULL. ({0})", materialParameter.Code));
            }

            if (materialParameter.Code.Length > 50)
            {
                throw new BusinessException(string.Format("Code may not be longer than 50 characters. ({0})", materialParameter.Code));
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Get a MaterialParameter by id from the database
 /// </summary>
 public virtual Model.MaterialParameter GetById(Int32 id)
 {
     try
     {
         DataAccess.MaterialParameters materialParameters = new DataAccess.MaterialParameters();
         Model.MaterialParameter       result             = materialParameters.GetById(id);
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id);
         throw;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Delete the given MaterialParameter from the database
        /// </summary>
        public virtual void Delete(Model.MaterialParameter materialParameter)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, materialParameter.ToString());

                var helper = Database.GetDbHelper();
                helper.ExecuteSPNonQuery(_storedProcedure_Delete,
                                         helper.CreateInputParam("@Id", materialParameter.Id));
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, materialParameter.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Create a Model.MaterialParameter
 /// </summary>
 protected virtual Model.MaterialParameter CreateMaterialParameter(DbDataReader reader)
 {
     try
     {
         Model.MaterialParameter result = new Model.MaterialParameter(
             (Int32)reader["Id"],
             (String)reader["Code"],
             (Int32)reader["MaterialGroupId"]
             );
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("", Trace.GetMethodName(), CLASSNAME, ex);
         throw DbHelper.TranslateException(ex);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Add a new MaterialParameter to the database
        /// </summary>
        public virtual Int32 Add(Model.MaterialParameter newMaterialParameter)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newMaterialParameter);

                CheckConstraints(newMaterialParameter);
                DataAccess.MaterialParameters materialParameters = new DataAccess.MaterialParameters();

                return(materialParameters.Add(newMaterialParameter));
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newMaterialParameter);
                throw new BusinessException(string.Format("No related object found in {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newMaterialParameter);
                throw;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Modify the given MaterialParameter in the database
        /// </summary>
        public virtual void Modify(Model.MaterialParameter modifiedMaterialParameter)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, modifiedMaterialParameter.ToString());

                var helper          = Database.GetDbHelper();
                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify,
                                                               helper.CreateInputParam("@Id", modifiedMaterialParameter.Id),
                                                               helper.CreateInputParam("@Code", modifiedMaterialParameter.Code),
                                                               helper.CreateInputParam("@MaterialGroupId", modifiedMaterialParameter.MaterialGroupId));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("No records were updated (Table: MaterialParameters). MaterialParameter=" + modifiedMaterialParameter.ToString());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedMaterialParameter.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Modify the given MaterialParameter in the database
        /// </summary>
        public virtual void Modify(Model.MaterialParameter modifiedMaterialParameter)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, modifiedMaterialParameter);

                //Begin Checks
                CheckConstraints(modifiedMaterialParameter);

                if (!Exists(modifiedMaterialParameter))
                {
                    throw new BusinessException(string.Format("There is no MaterialParameter with this id. ({0})", modifiedMaterialParameter));
                }

                DataAccess.MaterialParameters materialParameters = new DataAccess.MaterialParameters();
                materialParameters.Modify(modifiedMaterialParameter);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedMaterialParameter);
                throw;
            }
        }