public bool AddVendorOrder(VendorOrder order)
        {
            if (order == null) throw new ApplicationException("Order cannot be null");
            if (order.DateOrdered == null) order.DateOrdered = DateTime.Now;
            var result = VendorOrderDAL.Add(order, _connection);
            if (result)
            {
                var newVendorOrder = VendorOrderDAL.GetVendorOrderByVendorAndDate(order.VendorID,_connection);
                if (order.LineItems != null)
                {
                    foreach (var item in order.LineItems)
                    {
                        item.VendorOrderId = newVendorOrder.Id;
                        if (item.Note == null || item.Note == "")
                        {
                            item.Note = "no note";
                        }
                        if (VendorOrderLineItemDAL.Add(item, _connection)) {
                            prodMan.AddToOnOrder(item.QtyOrdered, item.ProductID);
                        }

                    }
                }
            }
            return result;
        }
        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;
        }
Example #3
0
        public static List<VendorOrder> GetAll(SqlConnection connection)
        {
            List<VendorOrder> allOrders = new List<VendorOrder>();
            connection = connection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_GetAllVendorOrders", connection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                connection.Open();
                var myReader = mySqlCommand.ExecuteReader();
                if (myReader.HasRows)
                {
                    while (myReader.Read())
                    {
                        var newVendorOrder = new VendorOrder(myReader.GetInt32(0), myReader.GetInt32(1))
                         {
                             DateOrdered = (DateTime)myReader.GetSqlDateTime(2),
                             NumberOfShipments = myReader.GetInt32(3),
                             Finalized = myReader.GetBoolean(4),
                             Active = myReader.GetBoolean(5)
                         };
                        allOrders.Add(newVendorOrder);
                    };
                }
                myReader.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
            {

                connection.Close();
            }
            return allOrders;
        }
 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 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);
 }
        public FrmAddLineItemToVendorOrder(VendorOrder vendorOrder, AccessToken acctkn)
        {
            InitializeComponent();
            _myAccessToken = acctkn;
            var RoleAccess = new RoleAccess(acctkn, this);
            this.vendorOrder = vendorOrder;
            txtVendorOrderID.Text = vendorOrder.Id.ToString();
            VendorManager _vendorManager = new VendorManager();

            var vendor = vendorOrder.VendorID;
            txtVendorName.Text = _vendorManager.GetVendor(vendorOrder.VendorID).Name;
            txtVendorID.Text = vendorOrder.VendorID.ToString();
            txtVendorName.ReadOnly = true;
            txtVendorID.ReadOnly = true;
            fillProductDropDown(vendorOrder.VendorID);
        }
        private void btnUpdatedNote_Click(object sender, EventArgs e)
        {
            var note = txtNotes.Text;

            _receivingManager = new ReceivingManager();
            VendorOrderManager _vendorOrderManager = new VendorOrderManager();

            vendorOrder = new VendorOrder(Int32.Parse(txtVendorOrderID.Text.ToString()),Int32.Parse(txtVendorID.Text.ToString()));

            VendorOrderLineItem vendorOrderLineItem = new VendorOrderLineItem(Int32.Parse(txtVendorOrderID.Text), Int32.Parse(txtProductID.Text));

            vendorOrderLineItem.Note = note;
            _receivingManager.UpdateLineItemNote(vendorOrderLineItem, note);
            MessageBox.Show("Note added to Order");

            this.Close();
        }
Example #8
0
        public frmReceiving(VendorOrder vendorOrder, AccessToken acctkn)
        {
            InitializeComponent();
            _myAccessToken = acctkn;

             VendorManager _vendorManager = new VendorManager();
             this.vendorOrder = vendorOrder;

            txtVendorOrderID.Text = vendorOrder.Id.ToString();
            txtVendorName.Text = _vendorManager.GetVendor(vendorOrder.VendorID).Name.ToString();
            txtVendorID.Text = _vendorManager.GetVendor(vendorOrder.VendorID).Id.ToString();
            txtNumberofShipments.Text = _vendorOrderManager.getVendorOrder(vendorOrder.Id).NumberOfShipments.ToString();
            txtDateOrdered.Text = _vendorOrderManager.getVendorOrder(vendorOrder.Id).DateOrdered.ToString();
            vendorOrder = new VendorOrder(Int32.Parse(txtVendorOrderID.Text.ToString()), Int32.Parse(txtVendorID.Text.ToString()));
            populateListView();
            //try
            //{
            //    lvReceiving.Clear();
            //    vendorOrderLineItemList = _receivingManager.GetAllLineItemsByVendorOrder(vendorOrder);
            //    foreach (var vendorOrderLineItem in vendorOrderLineItemList)
            //    {
            //        var item = new ListViewItem();
            //        item.Text = vendorOrderLineItem.ProductID.ToString();
            //        item.SubItems.Add(_productManager.GetProduct(vendorOrderLineItem.ProductID).Name.ToString());
            //        item.SubItems.Add(vendorOrderLineItem.QtyOrdered.ToString());
            //        item.SubItems.Add(vendorOrderLineItem.QtyReceived.ToString());
            //        item.SubItems.Add(vendorOrderLineItem.QtyDamaged.ToString());
            //        item.SubItems.Add(vendorOrderLineItem.Note);
            //        lvReceiving.Items.Add(item);
            //    }
            //    lvReceiving.Columns.Add("ProductID");
            //    lvReceiving.Columns.Add("Product Name");
            //    lvReceiving.Columns.Add("Quantity Ordered");
            //    lvReceiving.Columns.Add("Quantity Received");
            //    lvReceiving.Columns.Add("Quantity Damaged");
            //    lvReceiving.Columns.Add("Note");

            //    lvReceiving.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("An error occured while loading the vendor listView. " + ex.ToString());
            //}
        }
Example #9
0
 public static bool Add(VendorOrder order, SqlConnection connection)
 {
     connection = connection ?? GetInventoryDbConnection();
     try
     {
         var mySqlCommand = new SqlCommand("proc_InsertVendorOrder", connection)
         {
             CommandType = CommandType.StoredProcedure
         };
         mySqlCommand.Parameters.AddWithValue("@VendorID", order.VendorID);
         //mySqlCommand.Parameters.AddWithValue("@DateOrdered", order.DateOrdered.ToString("yyyy-MM-dd HH:mm:ss"));
         mySqlCommand.Parameters.AddWithValue("@NumberOfShipments", order.NumberOfShipments);
         connection.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
     {
         connection.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();
        }
Example #11
0
 private void button1_Click(object sender, EventArgs e)
 {
     VendorOrder thisOrder = new VendorOrder(vendorOrder.Id);
     thisOrder.LineItems = vendorOrderLineItemList;
     _vendorOrderManager.FinalizeVendorOrder(vendorOrder);
 }
Example #12
0
 public static bool Update(VendorOrder oldVendorOrder, VendorOrder newVendorOrder, SqlConnection connection)
 {
     connection = connection ?? GetInventoryDbConnection();
     try
     {
         var mySqlCommand = new SqlCommand("proc_UpdateVendorOrder", connection)
         {
             CommandType = CommandType.StoredProcedure
         };
         mySqlCommand.Parameters.AddWithValue("@VendorOrderID", newVendorOrder.Id);
         mySqlCommand.Parameters.AddWithValue("@VendorID", newVendorOrder.VendorID);
         mySqlCommand.Parameters.AddWithValue("@AmountOfShipments", newVendorOrder.NumberOfShipments);
         mySqlCommand.Parameters.AddWithValue("@Finalized", newVendorOrder.Finalized);
         mySqlCommand.Parameters.AddWithValue("@orig_AmountOfShipments", oldVendorOrder.NumberOfShipments);
         mySqlCommand.Parameters.AddWithValue("@orig_Finalized", oldVendorOrder.Finalized);
         connection.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
     {
         connection.Close();
     }
     return false;
 }
Example #13
0
        public static VendorOrder GetVendorOrderByVendorAndDate(int vendorId, SqlConnection connection)
        {
            VendorOrder newVendorOrder;
            connection = connection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_GetVendorOrderByVendorAndDate", connection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                mySqlCommand.Parameters.AddWithValue("@VendorId", vendorId);
                connection.Open();
                var myReader = mySqlCommand.ExecuteReader();
                if (myReader.HasRows)
                {
                    while (myReader.Read())
                    {
                        newVendorOrder = new VendorOrder(myReader.GetInt32(0), myReader.GetInt32(1))
                        {
                            DateOrdered = (DateTime)myReader.GetSqlDateTime(2),
                            NumberOfShipments = myReader.GetInt32(3),
                            Finalized = myReader.GetBoolean(4),
                            Active = myReader.GetBoolean(5)
                        };
                        return newVendorOrder;
                    };
                }
                myReader.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
            {
                connection.Close();
            }

            throw new ApplicationException("Vendor Order from vendor: "
                    + vendorId + "not found");
        }
 public Boolean FinalizeVendorOrder(VendorOrder order)
 {
     if (order == null) throw new ApplicationException("VendorOrder cannot be null");
     if (order.LineItems == null) throw new ApplicationException("VendorOrder cannot have zero line items");
     var oldOrder = new VendorOrder(order.Id, order.VendorID);
     oldOrder.Finalized = order.Finalized;
     oldOrder.NumberOfShipments = order.NumberOfShipments;
     order.Finalized = true;
     foreach (VendorOrderLineItem item in order.LineItems)
     {
         prodMan.AddToAvailable(item.QtyReceived, item.ProductID);
         prodMan.AddToOnHand(item.QtyDamaged + item.QtyReceived, item.ProductID);
         prodMan.RemoveFromOnOrder(item.QtyReceived + item.QtyDamaged, item.ProductID);
     }
     var result = VendorOrderDAL.Update(oldOrder, order, _connection);
     return result;
 }
        public static List<VendorOrderLineItem> GetExceptionItems(VendorOrder vendorOrder, SqlConnection myConnection)
        {
            var exceptionItemsList = new List<VendorOrderLineItem>();

            myConnection = myConnection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_GetExceptionItems", myConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                myConnection.Open();

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

                }

                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 exceptionItemsList;
        }
Example #16
0
 public static bool Add(VendorOrder order)
 {
     return true;
 }
        private void btSaveOrder_Click(object sender, EventArgs e)
        {
            try
            {
                List<VendorOrderLineItem> lineItemList = new List<VendorOrderLineItem>();
                int index = comboVendor.SelectedItem.ToString().IndexOf(" ");
                int id = Convert.ToInt32(comboVendor.SelectedItem.ToString().Substring(0, index));
                _myVendorManager = new VendorManager();

                var vendorName = _myVendorManager.GetVendor(id).Name;

                //VendorOrder myVendorOrder = new VendorOrder(int.Parse(id));
                VendorOrder myVendorOrder = new VendorOrder(id);
                myVendorOrder.NumberOfShipments = Convert.ToInt32(comboShipments.SelectedItem.ToString());
                myVendorOrder.DateOrdered = Convert.ToDateTime(tbOrderDate.Text);
                myVendorOrder.Name = vendorName;

                for (int i = 0; i < lvOrderItems.Items.Count;i++)
                {

                    Int32 productId = Int32.Parse(lvOrderItems.Items[i].SubItems[0].Text);
                    VendorOrderLineItem item = new VendorOrderLineItem(id, productId);
                    item.Name = lvOrderItems.Items[i].SubItems[1].Text;
                    item.QtyOrdered = Int32.Parse(lvOrderItems.Items[i].SubItems[3].Text);
                    lineItemList.Add(item);

                }
                myVendorOrder.LineItems = lineItemList;

                Boolean success = _myVendorOrderManager.AddVendorOrder(myVendorOrder);
                if (success == true)
                {
                    MessageBox.Show("Order Added.");
                    populateListView();
                    comboProduct.Items.Clear();
                }
                else
                {
                    MessageBox.Show("A field is not filled in. Please verify all fields are correct.");
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show("A Generic error as occured. You should fix this message " + ex.ToString());
            }
        }
 public bool UpdateShipmentsReceived(VendorOrder order, int qtyReceived)
 {
     if(order == null) throw new ApplicationException("VendorOrder cannot be null");
     if(qtyReceived + order.NumberOfShipments < 0) throw new ApplicationException("Total quantity of shipments received cannot be negative");
     var oldOrder = order;
     order.NumberOfShipments += qtyReceived;
     var result = VendorOrderDAL.Update(oldOrder, order, _connection);
     return result;
 }
Example #19
0
 public static bool Update(VendorOrder oldVendorOrder, VendorOrder newVendorOrder, SqlConnection connection)
 {
     return true;
 }
Example #20
0
 public Boolean OrderReorders()
 {
     VendorOrder order = new VendorOrder(_reorders[0].VendorSourceItem.VendorID);
     foreach (var reorder in _reorders)
     {
         if (reorder.ShouldReorder == true && reorder.CasesToOrder > 0)
         {
             order.AddLineItem(new VendorOrderLineItem(reorder.Product.Id, (reorder.CasesToOrder * reorder.VendorSourceItem.ItemsPerCase), 0, 0));
         }
     }
     return _voMangaer.AddVendorOrder(order);
 }
 public List<VendorOrderLineItem> GetExceptionItemsByVendorOrder(VendorOrder vendorOrder)
 {
     if (vendorOrder == null) throw new ApplicationException("No such VendorOrder");
     var exceptionLineItems = VendorOrderLineItemDAL.GetExceptionItemsByVendorOrder(vendorOrder, _connection);
     return exceptionLineItems ?? new List<VendorOrderLineItem>();
 }
Example #22
0
        private void btnAddLineItemtoCurrentListView_Click(object sender, EventArgs e)
        {
            vendorOrder = new VendorOrder(Int32.Parse(txtVendorOrderID.Text), Int32.Parse(txtVendorID.Text));

            FrmAddLineItemToVendorOrder _FrmAddLineItemToVendorOrder = new FrmAddLineItemToVendorOrder(vendorOrder, _myAccessToken);
            _FrmAddLineItemToVendorOrder.ShowDialog();
            populateListView();
        }