Example #1
0
 public Boolean AddNewLineItem(Product product, VendorSourceItem vendorSrcItem, int caseAmt)
 {
     if (product == null) throw new ArgumentNullException("Product is null");
     if (vendorSrcItem == null) throw new ArgumentNullException("VendorSourceItem is null");
     Reorder addOrder = new Reorder();
     addOrder.Product = product;
     addOrder.VendorSourceItem = vendorSrcItem;
     addOrder.ShouldReorder = true;
     addOrder.CasesToOrder = caseAmt;
     addOrder.ReorderTotal = GetReorderRowTotal(addOrder);
     return true;
     //throw new NotImplementedException();
 }
 public frmReorderChangeLevels(Reorder _product, AccessToken _myAccessToken)
 {
     InitializeComponent();
     _curProduct = _product;
     var RoleAccess = new RoleAccess(_myAccessToken, this);
 }
Example #3
0
        public static List<Reorder> GetReorderReportData(int vendorId, int reorderActive)
        {
            List<Reorder> reorders = new List<Reorder>();
            SqlConnection conn = GetInventoryDbConnection();
            try
            {
                conn.Open();
                SqlCommand sqlCmd = new SqlCommand("proc_GenerateReorderReports", conn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@VendorID", vendorId);
                sqlCmd.Parameters.AddWithValue("@ReorderActive", reorderActive);
                SqlDataReader reader = sqlCmd.ExecuteReader();

                if (reader.HasRows)
                {

                    while (reader.Read())
                    {
                        Reorder order = new Reorder();
                        var product = new Product(reader.GetInt32(0))
                        {
                            Name = reader.GetString(reader.GetOrdinal("ShortDesc")),
                            _reorderThreshold = reader.GetInt32(reader.GetOrdinal("ReorderThreshold")),
                            _reorderAmount = reader.GetInt32(reader.GetOrdinal("ReorderAmount")),
                            Active = true
                        };
                        order.Product = product;
                        var vendorSrcItem = new VendorSourceItem(reader.GetInt32(reader.GetOrdinal("ProductID")), reader.GetInt32(reader.GetOrdinal("VendorID")))
                        {
                            UnitCost = (Decimal)reader.GetSqlMoney(reader.GetOrdinal("UnitCost")),
                            MinQtyToOrder = reader.GetInt32(reader.GetOrdinal("MinQtyToOrder")),
                            ItemsPerCase = reader.GetInt32(reader.GetOrdinal("ItemsPerCase")),
                            Active = true
                        };
                        order.CasesToOrder = (int)product._reorderAmount / vendorSrcItem.ItemsPerCase + (product._reorderAmount % vendorSrcItem.ItemsPerCase == 0 ? 0 : 1);
                        order.ReorderTotal = (double)order.CasesToOrder * (double)vendorSrcItem.ItemsPerCase * (double)vendorSrcItem.UnitCost;
                        order.ShouldReorder = true;
                        order.VendorSourceItem = vendorSrcItem;
                        reorders.Add(order);
                    }
                }
                reader.Close();
            }
            catch (DataException ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("SqlException"), ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("Exception"), ex);
            }
            finally
            {
                conn.Close();
            }
            return reorders;
        }
Example #4
0
 public Boolean AddToOrder(Reorder reorder)
 {
     _reorders.Add(reorder);
     return UpdateOrderList(reorder, false);
 }
Example #5
0
 private Boolean UpdateOrderList(Reorder reorder, Boolean remove)
 {
     reorder.ShouldReorder = !remove;
     return UpdateOrderInCollection(reorder);
 }
Example #6
0
        private Boolean UpdateOrderInCollection(Reorder reorder)
        {
            if (reorder == null)
            {
                throw new ArgumentNullException("Reorder item cannot be null");
            }
            if (_reorders.Count == 0)
            {
                throw new ApplicationException("There are no reorder objects in the collection");
            }
            //if (!_reorders.Contains(reorder))
            //{
            //    throw new ApplicationException("No reorder found in reorders collection");
            //}
            foreach (var reorderI in _reorders)
                {
                    if (reorderI == reorder)
                    {
                        reorderI.CasesToOrder = reorder.CasesToOrder;
                        reorderI.ShouldReorder = reorder.ShouldReorder;
                        //reorderI.Product = reorder.Product;
                        reorderI.VendorSourceItem = reorder.VendorSourceItem;

                        return true;
                    }
                }
            return false;
        }
Example #7
0
 private Double GetReorderRowTotal(Reorder reorder)
 {
     try
     {
         return (Double)(reorder.CasesToOrder * reorder.VendorSourceItem.UnitCost * reorder.VendorSourceItem.ItemsPerCase);
     }
     catch(Exception ex)
     {
         throw new ArithmeticException("Calculating row total threw an exception." + ex.Message);
     }
 }
Example #8
0
 public Double UpdateReorderAmount(Reorder reorder, int amt)
 {
     reorder.CasesToOrder = amt;
     if (UpdateOrderInCollection(reorder))
     {
         return GetReorderRowTotal(reorder);
     }
     else
     {
         throw new ApplicationException("Never should happen, Houston We Have A Problem");
     }
 }
Example #9
0
 public Boolean RemoveFromOrder(Reorder reorder)
 {
     return UpdateOrderList(reorder, true);
 }