Esempio n. 1
0
        /// <summary>
        /// Modify the given BomItem in the database
        /// </summary>
        public virtual void Modify(Model.BomItem modifiedBomItem)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, modifiedBomItem.ToString());

                var helper          = Database.GetDbHelper();
                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Modify,
                                                               helper.CreateInputParam("@Id", modifiedBomItem.Id),
                                                               helper.CreateInputParam("@OrderId", modifiedBomItem.OrderId),
                                                               helper.CreateInputParam("@MaterialId", modifiedBomItem.MaterialId),
                                                               helper.CreateInputParam("@Quantity", modifiedBomItem.Quantity),
                                                               helper.CreateInputParam("@UOM", modifiedBomItem.UOM));

                if (recordsAffected == 0)
                {
                    throw new DalNothingUpdatedException("No records were updated (Table: BomItems). BomItem=" + modifiedBomItem.ToString());
                }
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedBomItem.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
        /// <summary>
        /// Delete the given BomItem from the database
        /// </summary>
        public virtual void Delete(Model.BomItem delBomItem)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, delBomItem);

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

                DataAccess.BomItems bomItems = new DataAccess.BomItems();
                bomItems.Delete(delBomItem);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, delBomItem);
                throw new BusinessException(string.Format("The BomItem is still used by {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, delBomItem);
                throw;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Add a new BomItem to the database
        /// </summary>
        public virtual Int32 Add(Model.BomItem newBomItem)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, newBomItem.ToString());
                var         helper  = Database.GetDbHelper();
                DbParameter IdParam = helper.CreateOutputParam("@Id", DbType.Int32);

                int recordsAffected = helper.ExecuteSPNonQuery(_storedProcedure_Add,
                                                               IdParam,
                                                               helper.CreateInputParam("@OrderId", newBomItem.OrderId),
                                                               helper.CreateInputParam("@MaterialId", newBomItem.MaterialId),
                                                               helper.CreateInputParam("@Quantity", newBomItem.Quantity),
                                                               helper.CreateInputParam("@UOM", newBomItem.UOM));

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

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

            try
            {
                var helper = Database.GetDbHelper();

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

                Model.BomItem result = null;

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

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

            if (bomItem.UOM.Length > 10)
            {
                throw new BusinessException(string.Format("UOM may not be longer than 10 characters. ({0})", bomItem.UOM));
            }
        }
 /// <summary>
 /// Get a BomItem by id from the database
 /// </summary>
 public virtual Model.BomItem GetById(Int32 id)
 {
     try
     {
         DataAccess.BomItems bomItems = new DataAccess.BomItems();
         Model.BomItem       result   = bomItems.GetById(id);
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id);
         throw;
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Delete the given BomItem from the database
        /// </summary>
        public virtual void Delete(Model.BomItem bomItem)
        {
            try
            {
                Trace.WriteVerbose("({0})", Trace.GetMethodName(), CLASSNAME, bomItem.ToString());

                var helper = Database.GetDbHelper();
                helper.ExecuteSPNonQuery(_storedProcedure_Delete,
                                         helper.CreateInputParam("@Id", bomItem.Id));
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, bomItem.ToString());
                throw DbHelper.TranslateException(ex);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Create a Model.BomItem
 /// </summary>
 protected virtual Model.BomItem CreateBomItem(DbDataReader reader)
 {
     try
     {
         Model.BomItem result = new Model.BomItem(
             (Int32)reader["Id"],
             (Int32)reader["OrderId"],
             (Int32)reader["MaterialId"],
             (Decimal)reader["Quantity"],
             (String)reader["UOM"]
             );
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("", Trace.GetMethodName(), CLASSNAME, ex);
         throw DbHelper.TranslateException(ex);
     }
 }
        /// <summary>
        /// Add a new BomItem to the database
        /// </summary>
        public virtual Int32 Add(Model.BomItem newBomItem)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newBomItem);

                CheckConstraints(newBomItem);
                DataAccess.BomItems bomItems = new DataAccess.BomItems();

                return(bomItems.Add(newBomItem));
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newBomItem);
                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, newBomItem);
                throw;
            }
        }
        /// <summary>
        /// Modify the given BomItem in the database
        /// </summary>
        public virtual void Modify(Model.BomItem modifiedBomItem)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, modifiedBomItem);

                //Begin Checks
                CheckConstraints(modifiedBomItem);

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

                DataAccess.BomItems bomItems = new DataAccess.BomItems();
                bomItems.Modify(modifiedBomItem);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedBomItem);
                throw;
            }
        }