Beispiel #1
0
 public ProductView(AccessToken accToken, Product ProductInfo)
 {
     InitializeComponent();
     _myAccessToken = accToken;
     _productManager = new ProductManager();
     _vendorManager = new VendorManager();
     _vendorSourceManager = new VendorSourceItemManager();
     _currentProduct = ProductInfo;
     //Assigning the current product values to the appropriate controls.
     this.Text = "Update Product";
     btMorph.Text = "Update Product";
     tbProductID.Text = ProductInfo.Id.ToString();
     tbDescription.Text = ProductInfo.description;
     tbItemName.Text = ProductInfo.Name;
     nudUnitPrice.Value = ProductInfo.unitPrice;
     nudAvailableQty.Value = ProductInfo.available;
     nudOnHandQty.Value = ProductInfo.reserved;
     nudReorderThreshold.Value = (decimal)ProductInfo._reorderThreshold;
     nudReorderAmount.Value = (decimal)ProductInfo._reorderAmount;
     nudOnOrderAmount.Value = ProductInfo._onOrder;
     txtDimensions.Text = ProductInfo._shippingDemensions;
     nudWeight.Value = (decimal)ProductInfo._shippingWeight;
     PopulateActiveCombo();
     PopulateLocationCombo();
     PopulateListView(lvVendors, ProductInfo.Id);
     this.btnClear.Enabled = false;
     lblPriceDisplay.Text = String.Format("{0:C}", ProductInfo.unitPrice);
     tbItemName.Focus();
     Instance = this;
 }
 public FrmAttachVendorSource(Product product, AccessToken _myAccessToken)
 {
     InitializeComponent();
     _currentProduct = product;
     _vendorSource = new VendorSourceItemManager();
     _vendorManager = new VendorManager();
     _vendors = _vendorManager.GetVendors();
     var RoleAccess = new RoleAccess(_myAccessToken, this);
 }
        public static VendorOrderLineItem Get(VendorOrder vendorOrder, Product product, SqlConnection myConnection)
        {
            VendorOrderLineItem vendorOrderLineItem = null;
            myConnection = myConnection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_GetVendorOrderLineItem", myConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                mySqlCommand.Parameters.AddWithValue("@VendorOrderID", vendorOrder.Id);
                mySqlCommand.Parameters.AddWithValue("@ProductID", product.Id);

                myConnection.Open();

                var mySqlReader = mySqlCommand.ExecuteReader();
                if (mySqlReader.HasRows)
                {
                    while (mySqlReader.Read())
                    {
                        vendorOrderLineItem = new VendorOrderLineItem(mySqlReader.GetInt32(0), mySqlReader.GetInt32(1))
                        {
                            QtyOrdered = mySqlReader.GetInt32(2),
                            QtyReceived = mySqlReader.GetInt32(3),
                            QtyDamaged = mySqlReader.GetInt32(4)
                        };
                    }

                }

                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 vendorOrderLineItem;
        }
Beispiel #4
0
        public static Boolean DeleteProduct(Product product, SqlConnection connection)
        {
            //?? Null-coalescing operator.
            //If the connection is null a new connection will be returned.
            SqlConnection conn = connection ?? GetInventoryDbConnection();
            try
            {
                //Establishes the connection.
                conn.Open();
                //Creates the command object, passing the SP and connection object.
                SqlCommand sqlCmd = new SqlCommand("proc_DeleteProduct", conn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@ProductID", product.Id);
                sqlCmd.Parameters.AddWithValue("@OnHand", product.reserved);
                sqlCmd.Parameters.AddWithValue("@Available", product.available);
                sqlCmd.Parameters.AddWithValue("@Description", product.description);
                sqlCmd.Parameters.AddWithValue("@Location", product.location);
                sqlCmd.Parameters.AddWithValue("@UnitPrice", product.unitPrice);
                sqlCmd.Parameters.AddWithValue("@ShortDesc", product.Name);
                sqlCmd.Parameters.AddWithValue("@ReorderThreshold", product._reorderThreshold);
                sqlCmd.Parameters.AddWithValue("@ReorderAmount", product._reorderAmount);
                sqlCmd.Parameters.AddWithValue("@OnOrder", product._onOrder);
                sqlCmd.Parameters.AddWithValue("@ShippingDimensions", product._shippingDemensions);
                sqlCmd.Parameters.AddWithValue("@ShippingWeight", product._shippingWeight);
                sqlCmd.Parameters.AddWithValue("@Active", product.Active);

                //If the procedure returns 1 set to true, if 0 remain false.
                if (sqlCmd.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
            {
                conn.Close();
            }
            return false;
        }
 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 bool AddLineItem(VendorOrder order, Product product, int qty)
 {
     if (order == null) throw new ApplicationException("Vendor Order is null");
     if (product == null) throw new ApplicationException("Product cannot be null");
     if (qty == null) qty = 0;
     VendorOrderLineItem lineItem = new VendorOrderLineItem(order.Id, product.Id);
     lineItem.QtyOrdered = qty;
     var result = VendorOrderLineItemDAL.Add(lineItem, _connection);
     if (result)
     {
         order.AddLineItem(lineItem);
     }
     return result;
 }
 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 bool AddNewLineItemToVendorOrder(VendorOrder vendorOrder,Product productToAdd, int qtyReceived, string note, int qtyDamaged)
 {
     if (productToAdd == null) throw new ApplicationException("Product can't be null");
     if (vendorOrder == null) throw new ApplicationException("VendorOrder can't be null");
     if (qtyReceived <= 0) throw new ApplicationException("Quantity recieved has to be greater than 0");
     var newVendorOrderLineItem = new VendorOrderLineItem(vendorOrder.Id, productToAdd.Id)
     {
         QtyOrdered = 0,
         QtyReceived = qtyReceived,
         QtyDamaged = qtyDamaged,
         Note = note
     };
     return VendorOrderLineItemDAL.Add(newVendorOrderLineItem, _connection);
 }
Beispiel #9
0
        public static Boolean DeactivateProduct(Product product, SqlConnection connection)
        {
            //?? Null-coalescing operator.
            //If the connection is null a new connection will be returned.
            SqlConnection conn = connection ?? GetInventoryDbConnection();
            try
            {
                //Establishes the connection.
                conn.Open();
                //Creates the command object, passing the SP and connection object.
                SqlCommand sqlCmd = new SqlCommand("proc_DeactivateProduct", conn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@ProductID", product.Id);

                //If the procedure returns 1 set to true, if 0 remain false.
                if (sqlCmd.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
            {
                conn.Close();
            }
            return false;
        }
        private void btnAddLineItem_Click(object sender, EventArgs e)
        {
            ReceivingManager _receivingManager = new ReceivingManager();
            VendorOrderManager _vendorOrderManager = new VendorOrderManager();
            VendorOrder vendorOrder;
            Product product;
            Int32 qtyReceived;
            Int32 qtyDamaged;

            Int32 vendorID = Int32.Parse(txtVendorID.Text);
            vendorOrder = new VendorOrder(Int32.Parse(txtVendorOrderID.Text), vendorID);
            int index = cbProductName.SelectedItem.ToString().IndexOf(" ");
            var productID = Int32.Parse(cbProductName.SelectedItem.ToString().Substring(0, index));
            product = new Product(productID);
            qtyReceived = Int32.Parse(upQuantityReceived.Value.ToString());
            qtyDamaged = Int32.Parse(upQtyDamaged.Value.ToString());
            string note = txtNotes.Text;
            _receivingManager.AddNewLineItemToVendorOrder(vendorOrder, product, qtyReceived, note, qtyDamaged);
            MessageBox.Show("Line Item Added");

            this.Close();
        }
        private void btRemove_Click(object sender, EventArgs e)
        {
            int index = this.lvOrderItems.SelectedIndices[0];
            String productID = this.lvOrderItems.Items[0].SubItems[0].ToString();
            productID = productID.Replace("ListViewSubItem: {","");
            productID = productID.Replace("}","");
            int prodId = Int32.Parse(productID);
            Product product = new Product();

            try
            {
                lvOrderItems.Items.RemoveAt(index);
            }
            catch (Exception ex)
            {

                MessageBox.Show("No item selected from List View.");
                if (_myAccessToken.Role.Id == 1400)
                {
                    MessageBox.Show(ex.ToString());
                }
                if(lvOrderItems.Items.Count <= 0)
                {
                    comboVendor.Enabled = true;
                }

            }

            try
            {
                product = _myProductManager.GetProduct(prodId);
                comboProduct.Items.Add(product.Id + " " + product.Name);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to add remove product into Product Drop down");
            }
            calculateTotal();

            btRemove.Enabled = false;
        }
Beispiel #12
0
        private void btMorph_Click(object sender, EventArgs e)
        {
            bool validProduct = true;
            string errorMessage = "Please correct the following errors:\n";

            if (btMorph.Text == "Add Product")
            {
                if (Validation.IsBlank(tbItemName.Text) || Validation.IsNullOrEmpty(tbItemName.Text))
                {
                    validProduct = false;
                    errorMessage += "\nEnter a short description.";
                }
                if (tbItemName.Text.Length > 50)
                {
                    validProduct = false;
                    errorMessage += "\nThe name must be 50 characters or less.";
                }
                if (Validation.IsBlank(tbDescription.Text) || Validation.IsNullOrEmpty(tbDescription.Text))
                {
                    validProduct = false;
                    errorMessage += "\nEnter a description.";
                }
                if(tbDescription.Text.Length > 250)
                {
                    validProduct = false;
                    errorMessage += "\nThe description must be 250 characters or less.";
                }
                if(txtDimensions.Text.Length > 50)
                {
                    validProduct = false;
                    errorMessage += "\nThe shipping dimensions must be 50 characters or less.";
                }
                if (validProduct)
                {
                    Product newProduct = new Product()
                    {
                        description = tbDescription.Text,
                        Name = tbItemName.Text,
                        unitPrice = nudUnitPrice.Value,
                        available = (int)nudAvailableQty.Value,
                        reserved = (int)nudOnHandQty.Value,
                        _reorderThreshold = (int?)nudReorderThreshold.Value,
                        _reorderAmount = (int?)nudReorderAmount.Value,
                        _onOrder = (int)nudOnOrderAmount.Value,
                        location = comboWHSL.SelectedIndex == 0 ? null : comboWHSL.SelectedItem.ToString(),
                        _shippingWeight = (double)nudWeight.Value,
                        _shippingDemensions = txtDimensions.Text == null || txtDimensions.Text == "" ? null : txtDimensions.Text,
                        Active = Convert.ToBoolean(cbActive.SelectedItem)
                    };
                    try
                    {
                        if (_productManager.AddProduct(newProduct))
                        {
                            this.DialogResult = DialogResult.OK;
                            MessageBox.Show("The product was added to inventory.");
                        }
                        else
                        {
                            MessageBox.Show("The product was not added to inventory.\nPlease try again.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error has Occured. Error Message: " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show(errorMessage);
                }
            }
            else if (btMorph.Text == "Update Product")
            {
                if (Validation.IsBlank(tbItemName.Text) || Validation.IsNullOrEmpty(tbItemName.Text))
                {
                    validProduct = false;
                    errorMessage += "\nEnter a short description.";
                }
                if (tbItemName.Text.Length > 50)
                {
                    validProduct = false;
                    errorMessage += "\nThe name must be 50 characters or less.";
                }
                if (Validation.IsBlank(tbDescription.Text) || Validation.IsNullOrEmpty(tbDescription.Text))
                {
                    validProduct = false;
                    errorMessage += "\nEnter a description.";
                }
                if (tbDescription.Text.Length > 250)
                {
                    validProduct = false;
                    errorMessage += "\nThe description must be 250 characters or less.";
                }
                if (txtDimensions.Text.Length > 50)
                {
                    validProduct = false;
                    errorMessage += "\nThe shipping dimensions must be 50 characters or less.";
                }
                if (validProduct)
                {
                    Product newProduct = new Product()
                    {
                        description = tbDescription.Text,
                        Name = tbItemName.Text,
                        unitPrice = nudUnitPrice.Value,
                        available = (int)nudAvailableQty.Value,
                        reserved = (int)nudOnHandQty.Value,
                        _reorderThreshold = (int?)nudReorderThreshold.Value,
                        _reorderAmount = (int?)nudReorderAmount.Value,
                        _onOrder = (int)nudOnOrderAmount.Value,
                        location = comboWHSL.SelectedIndex == 0 ? null : comboWHSL.SelectedItem.ToString(),
                        _shippingWeight = (double)nudWeight.Value,
                        _shippingDemensions = txtDimensions.Text == null || txtDimensions.Text == "" ? null : txtDimensions.Text,
                        Active = Convert.ToBoolean(cbActive.SelectedItem)
                    };
                    try
                    {
                        if (_productManager.UpdateProduct(newProduct, _currentProduct))
                        {
                            this.DialogResult = DialogResult.OK;
                            MessageBox.Show("The product was updated.");
                        }
                        else
                        {
                            MessageBox.Show("The product was not updated.\nAnother user may have already updated this product.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error has Occured. Error Message: " + ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show(errorMessage);
                }
            }
        }
 public Boolean AddProduct(Product product)
 {
     if (product == null) throw new ArgumentException("The product was null, therefore it cannot be added.");
     //Returns true or false depending on if the record was inserted.
     return ProductDAL.InsertProduct(product, _connection);
 }
 public Boolean DeleteProduct(Product product)
 {
     if (product == null) throw new ArgumentException("The product was null, therefore it cannot be deleted.");
     return ProductDAL.DeleteProduct(product, _connection);
 }
 public Boolean ReactivateProduct(Product product)
 {
     if (product == null) throw new ArgumentException("The product was null, therefore it cannot be set as active.");
     return ProductDAL.ReactivateProduct(product, _connection);
 }
 public Boolean UpdateProduct(Product product, Product originalProduct)
 {
     if (product == null || originalProduct == null) throw new ArgumentException("The product was null, therefore it cannot be updated.");
     return ProductDAL.UpdateProduct(product, originalProduct, _connection);
 }
        private void populateProduct(int vendorId)
        {
            List<VendorSourceItem> vendorProducts = new List<VendorSourceItem>();
            vendorProducts = _myVendorItem.GetVendorSourceItemsByVendor(vendorId);

            comboProduct.Items.Clear();

            foreach (VendorSourceItem item in vendorProducts)
            {
                Product product = new Product();
                product = _myProductManager.GetProduct(item.ProductID);

                comboProduct.Items.Add(product.Id + " " + product.Name);
            }
        }
        private void btAddLineItem_Click(object sender, EventArgs e)
        {
            try
            {
                Product product = new Product();
                int index = comboProduct.SelectedItem.ToString().IndexOf(" ");
                string id = comboProduct.SelectedItem.ToString().Substring(0, index);

                product = _myProductManager.GetProduct(int.Parse(id));

                int qty = int.Parse(comboQuanity.SelectedItem.ToString());
                decimal totalAmount = Math.Round(qty * product.unitPrice,2);

                ListViewItem lineItem = new ListViewItem();

                lineItem.Text = product.Id.ToString();
                lineItem.SubItems.Add(product.Name);
                lineItem.SubItems.Add(Math.Round(product.unitPrice,2).ToString());
                lineItem.SubItems.Add(qty.ToString());
                lineItem.SubItems.Add(totalAmount.ToString());

                lvOrderItems.Items.Add(lineItem);

                lvOrderItems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

                comboProduct.Items.RemoveAt(comboProduct.SelectedIndex);

                comboVendor.Enabled = false;

                calculateTotal();
            }
            catch (Exception ex)
            {
                MessageBox.Show("A Generic error as occured. You should fix this message " + ex.ToString());
            }
        }
Beispiel #19
0
        public static List<Product> FetchProductsByActive(Boolean activeState, SqlConnection connection)
        {
            List<Product> products = new List<Product>();
            //?? Null-coalescing operator.
            //If the connection is null a new connection will be returned.
            SqlConnection conn = connection ?? GetInventoryDbConnection();
            try
            {
                //Establishes the connection.
                conn.Open();
                //Creates the command object, passing the SP and connection object.
                SqlCommand sqlCmd = new SqlCommand("proc_GetProductsByActive", conn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@Active", activeState ? 1 : 0);

                //Creates the reader object by ExecutingReader on the cmd object.
                SqlDataReader reader = sqlCmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var product = new Product(reader.GetInt32(0))
                        {
                            available = reader.GetInt32(1),
                            reserved = reader.GetInt32(2),
                            description = reader.GetString(3),
                            location = reader[4] as string,
                            unitPrice = (Decimal)reader.GetSqlMoney(5),
                            Name = reader.GetString(6),
                            _reorderThreshold = reader[7] as int?,
                            _reorderAmount = reader[8] as int?,
                            _onOrder = reader.GetInt32(9),
                            _shippingDemensions = reader[10] as string,
                            _shippingWeight = reader[11] as double?,
                            Active = reader.GetBoolean(12)
                        };
                        //Add the current product to the list.
                        products.Add(product);
                        //Null the product reference.
                    }
                }
                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 products;
        }
Beispiel #20
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;
        }
 private void fillProductDropDown(ComboBox cb, List<Product> listOfProducts)
 {
     var p = new Product(0) {Name = ""};
     cb.DataSource = listOfProducts;
     cb.DisplayMember = "Name";
     cb.ValueMember = "ID";
 }