private void btnAdd_Click(object sender, EventArgs e)
 {
     if(btnAdd.Text.Equals("Add Vendor"))
     {
         VendorSourceItem vendorSource = new VendorSourceItem()
         {
             ProductID = _currentProduct.Id,
             VendorID = ((KeyValuePair<int,string>)comboVendors.SelectedItem).Key,
             UnitCost = nudUnitPrice.Value,
             ItemsPerCase = (int)nudCase.Value,
             MinQtyToOrder = (int)nudMinnimum.Value,
             Active = true,
         };
         try
         {
             if (_vendorSource.AddVendorSourceItem(vendorSource))
             {
                 this.DialogResult = DialogResult.OK;
                 MessageBox.Show("The vendor details were added to this product.");
             }
             else
             {
                 MessageBox.Show("The vendor was not attached to the product.\nThat Product/Vendor combination may already exist.");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else if(btnAdd.Text.Equals("Update Vendor"))
     {
         VendorSourceItem vendorSource = new VendorSourceItem()
         {
             ProductID = _currentProduct.Id,
             VendorID = ((KeyValuePair<int, string>)comboVendors.SelectedItem).Key,
             UnitCost = nudUnitPrice.Value,
             ItemsPerCase = (int)nudCase.Value,
             MinQtyToOrder = (int)nudMinnimum.Value,
             Active = true,
         };
         try
         {
             if (_vendorSource.UpdateVendorSourceItem(vendorSource, _currentVendorSourceItem))
             {
                 this.DialogResult = DialogResult.OK;
                 MessageBox.Show("The vendor details for this product were updated.");
             }
             else
             {
                 MessageBox.Show("The vendor details were not updated. This information may have already been updated by another employee. Please try again.");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error has Occured. Error Message: " + ex.Message);
         }
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     var vsiManager = new VendorSourceItemManager();
     var vsrcItem = new VendorSourceItem
     {
         ProductID = (int) productCb.SelectedValue,
         VendorID = (int) vendorCb.SelectedValue,
         MinQtyToOrder = (int) minQty.Value,
         UnitCost = Convert.ToDecimal(unitCost.Text),
         Active = true
     };
     vsiManager.AddVendorSourceItem(vsrcItem);
 }
 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 FrmAttachVendorSource(Product product, VendorSourceItem currentVendorSourceItem)
 {
     InitializeComponent();
     _vendorSource = new VendorSourceItemManager();
     _vendorManager = new VendorManager();
     _currentVendorSourceItem = currentVendorSourceItem;
     _vendors = _vendorManager.GetVendors();
     _currentProduct = product;
     nudCase.Value = _currentVendorSourceItem.ItemsPerCase;
     nudMinnimum.Value = _currentVendorSourceItem.MinQtyToOrder;
     nudUnitPrice.Value = _currentVendorSourceItem.UnitCost;
     btnAdd.Text = "Update Vendor";
     comboVendors.Enabled = false;
 }
 public static bool AddVendorSourceItem(VendorSourceItem vendorSrcItem, SqlConnection myConnection)
 {
     //Questional usage of ?? its incase myConnection comes in null it will grab a new connection.
     //Thoughts?
     myConnection = myConnection ?? GetInventoryDbConnection();
     try
     {
         var mySqlCommand = new SqlCommand("proc_InsertIntoVendorSourceItems", myConnection)
         {
             CommandType = CommandType.StoredProcedure
         };
         mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID);
         mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID);
         mySqlCommand.Parameters.AddWithValue("@unitCost", vendorSrcItem.UnitCost);
         mySqlCommand.Parameters.AddWithValue("@minQtyToOrder", vendorSrcItem.MinQtyToOrder);
         mySqlCommand.Parameters.AddWithValue("@itemsPerCase", vendorSrcItem.ItemsPerCase);
         mySqlCommand.Parameters.AddWithValue("@active", vendorSrcItem.Active ? 1 : 0); //Change to bit, Ternary Operator
         myConnection.Open();
         if (mySqlCommand.ExecuteNonQuery() == 1)
         {
             return true;
         }
     }
     catch (DataException ex)
     {
         Console.WriteLine(ex.Message);
         throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex);
     }
     catch (SqlException ex)
     {
         if (ex.Number == 2627)
         {
             throw new ApplicationException("This vendor is already attached to this product therefore it could not be added.");
         }
         else
         {
             throw new ApplicationException(Messeges.GetMessage("SqlException"), ex);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw new ApplicationException(Messeges.GetMessage("Exception"), ex);
     }
     finally
     {
         myConnection.Close();
     }
     return false;
 }
        public static bool DeactivateVendorSourceItem(VendorSourceItem vendorSrcItem, SqlConnection myConnection)
        {
            myConnection = myConnection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_DeactivateVendorSourceItem", myConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID);
                mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID);
                myConnection.Open();
                if (mySqlCommand.ExecuteNonQuery() == 1)
                {
                    return true;
                }

            }
            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
            {
                myConnection.Close();
            }
            return false;
        }
Beispiel #7
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;
        }
 public Boolean UpdateVendorSourceItem(VendorSourceItem vendorSrcItem, VendorSourceItem origVendorSrcItem)
 {
     return VendorSourceItemDAL.UpdateVendorSourceItem(vendorSrcItem, origVendorSrcItem, _connection);
 }
 public Boolean ReactivateVendorSourceItem(VendorSourceItem vendorSrcItem)
 {
     return VendorSourceItemDAL.ReactivateVendorSourceItem(vendorSrcItem, _connection);
 }
 public Boolean DeleteVendorSourceItem(VendorSourceItem vendorSrcItem)
 {
     return VendorSourceItemDAL.DeleteVendorSourceItem(vendorSrcItem, _connection);
 }
 public Boolean AddVendorSourceItem(VendorSourceItem vendorSrcItem)
 {
     //Do error checking here
     return VendorSourceItemDAL.AddVendorSourceItem(vendorSrcItem, _connection);
 }
 public static bool UpdateVendorSourceItem(VendorSourceItem vendorSrcItem, VendorSourceItem origVendorSrcItem, SqlConnection myConnection)
 {
     myConnection = myConnection ?? GetInventoryDbConnection();
     try
     {
         //Talk about checking data first in sql, Passing the old data and verifiy its still the same.
         var mySqlCommand = new SqlCommand("proc_UpdateVendorSourceItem", myConnection)
         {
             CommandType = CommandType.StoredProcedure
         };
         mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID);
         mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID);
         mySqlCommand.Parameters.AddWithValue("@unitCost", vendorSrcItem.UnitCost);
         mySqlCommand.Parameters.AddWithValue("@minQtyToOrder", vendorSrcItem.MinQtyToOrder);
         mySqlCommand.Parameters.AddWithValue("@itemsPerCase", vendorSrcItem.ItemsPerCase);
         mySqlCommand.Parameters.AddWithValue("@orig_productID", origVendorSrcItem.ProductID);
         mySqlCommand.Parameters.AddWithValue("@orig_vendorID", origVendorSrcItem.VendorID);
         mySqlCommand.Parameters.AddWithValue("@orig_unitCost", origVendorSrcItem.UnitCost);
         mySqlCommand.Parameters.AddWithValue("@orig_minQtyToOrder", origVendorSrcItem.MinQtyToOrder);
         mySqlCommand.Parameters.AddWithValue("@orig_itemsPerCase", origVendorSrcItem.ItemsPerCase);
         myConnection.Open();
         if (mySqlCommand.ExecuteNonQuery() == 1)
         {
             return true;
         }
     }
     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
     {
         myConnection.Close();
     }
     return false;
 }
        public static List<VendorSourceItem> GetVendorSourceItemsByVendor(int vendorId, SqlConnection myConnection)
        {
            var vendorSourceItemList = new List<VendorSourceItem>();

            myConnection = myConnection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_GetVendorSourceItemsByVendor", myConnection);
                mySqlCommand.Parameters.AddWithValue("@vendorID", vendorId);
                mySqlCommand.CommandType = CommandType.StoredProcedure;

                myConnection.Open();

                var mySqlReader = mySqlCommand.ExecuteReader();
                if (mySqlReader.HasRows)
                {
                    while (mySqlReader.Read())
                    {
                        var vendorSrcItem = new VendorSourceItem(mySqlReader.GetInt32(0), mySqlReader.GetInt32(1))
                        {
                            UnitCost = (Decimal) mySqlReader.GetSqlMoney(2),
                            MinQtyToOrder = mySqlReader.GetInt32(3),
                            ItemsPerCase = mySqlReader.GetInt32(4),
                            Active = true
                        };

                        //Add item to list
                        vendorSourceItemList.Add(vendorSrcItem);
                    }

                }

                mySqlReader.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
            {
                myConnection.Close();
            }

            return vendorSourceItemList;
        }