private void btnUpdateLineItem_Click(object sender, EventArgs e)
        {
            ReceivingManager _receivingManger = new ReceivingManager();
            int productId = Int32.Parse(txtLineItemProductID.Text);
            int vendorOrderId = Int32.Parse(txtLineItemVendorOrderID.Text);

            //int quantityDamaged =

            VendorOrderLineItem oldLineItem = new VendorOrderLineItem(vendorOrderId, productId);
            oldLineItem.QtyReceived = item.QtyReceived;
            oldLineItem.QtyOrdered = item.QtyOrdered;
            oldLineItem.QtyDamaged = item.QtyDamaged;
            updateItem = new VendorOrderLineItem(vendorOrderId, productId);
            updateItem.Name = txtLineItemProductName.Text;
            updateItem.QtyDamaged = Int32.Parse(upDownQuantityDamaged.Value.ToString());
            updateItem.QtyOrdered = Int32.Parse(txtLineItemQuantityOrdered.Text);
            updateItem.QtyReceived = Int32.Parse(upDownQuantityReceived.Value.ToString());

            _receivingManager = new ReceivingManager();
            //_receivingManager.UpdateQtyDamaged(oldLineItem, updateItem);
            _receivingManager.UpdateQtyReceived(updateItem, oldLineItem);
            //_receivingManager.UpdateQtyDamaged(updateItem, oldLineItem);

            MessageBox.Show("Quantity Fields Updated");

            this.Close();
        }
 public bool UpdateLineItemNote(VendorOrderLineItem currentLineItem, String note)
 {
     if (currentLineItem == null) throw new ApplicationException("VendorOrderLineItem is null");
     if (note == null) note = "";
     if (note.Length > 250) throw new ApplicationException("Note can only be 250 characters long.");
     var oldLineItem = currentLineItem;
     currentLineItem.Note = note;
     var result = VendorOrderLineItemDAL.UpdateNote(currentLineItem, _connection);
     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;
        }
Beispiel #4
0
 public void RemoveLineItem(VendorOrderLineItem lineItem)
 {
     if (_lineItems.Contains(lineItem))
     {
         _lineItems.Remove(lineItem);
     }
     else
     {
         //not sure if we need to throw this.
         throw new ApplicationException("line item doesn't exsist");
     }
 }
 public bool UpdateQtyDamaged(VendorOrderLineItem currentLineItem, VendorOrderLineItem oldLineItem)
 {
     if (currentLineItem == null) throw new ApplicationException("VendorOrderLineItem is null");
     if (currentLineItem.QtyDamaged < 0)
     {
         Console.Write("Qty Damaged can't be negative");
         throw new ApplicationException("Quantity damaged cannot be negative.");
     }
     currentLineItem.QtyReceived = oldLineItem.QtyReceived;
     currentLineItem.QtyDamaged = oldLineItem.QtyDamaged + currentLineItem.QtyDamaged;
     var result = VendorOrderLineItemDAL.Update(oldLineItem, currentLineItem, _connection);
     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 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;
 }
        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();
        }
        public static bool Add(VendorOrderLineItem vendorOrderLineItem, SqlConnection myConnection)
        {
            myConnection = myConnection ?? GetInventoryDbConnection();
            try
            {
                var mySqlCommand = new SqlCommand("proc_InsertIntoVendorOrderLineItems", myConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                mySqlCommand.Parameters.AddWithValue("@ProductID", vendorOrderLineItem.ProductID);
                mySqlCommand.Parameters.AddWithValue("@VendorOrderID", vendorOrderLineItem.VendorOrderId);
                mySqlCommand.Parameters.AddWithValue("@QtyOrdered", vendorOrderLineItem.QtyOrdered);
                mySqlCommand.Parameters.AddWithValue("@QtyReceived", vendorOrderLineItem.QtyReceived);
                mySqlCommand.Parameters.AddWithValue("@QtyDamaged", vendorOrderLineItem.QtyDamaged);
                mySqlCommand.Parameters.AddWithValue("@Note", vendorOrderLineItem.Note);
                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 FrmUpdateVendorOrderLineItem(VendorOrderLineItem item, string vendorName, int vendorID, AccessToken acctkn)
        {
            InitializeComponent();
            var RoleAccess = new RoleAccess(acctkn, this);

            this.item = item;
            txtLineItemProductID.Text = item.ProductID.ToString();
            txtLineItemProductName.Text = item.Name;
            txtLineItemQuantityOrdered.Text = item.QtyOrdered.ToString();
            upDownQuantityDamaged.Value = 0;
            upDownQuantityReceived.Value = 0;
            txtLineItemVendorID.Text = vendorID.ToString();
            txtLineItemVendorOrderID.Text = item.VendorOrderId.ToString();
            txtLineItemVendorName.Text = vendorName;
            txtLineItemVendorName.ReadOnly = true;
            txtLineItemProductID.ReadOnly = true;
            txtLineItemProductName.ReadOnly = true;
            txtLineItemVendorID.ReadOnly = true;
            txtLineItemVendorOrderID.ReadOnly = true;
            txtLineItemQuantityOrdered.ReadOnly = true;
        }
 public static bool UpdateNote(VendorOrderLineItem lineItem, SqlConnection myConnection)
 {
     myConnection = myConnection ?? GetInventoryDbConnection();
     try
     {
         var mySqlCommand = new SqlCommand("proc_UpdateVendorOrderLineItemNote", myConnection)
         {
             CommandType = CommandType.StoredProcedure
         };
         mySqlCommand.Parameters.AddWithValue("@vendorOrderId", lineItem.VendorOrderId);
         mySqlCommand.Parameters.AddWithValue("@productId", lineItem.ProductID);
         mySqlCommand.Parameters.AddWithValue("@note", lineItem.Note);
         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 true;
 }
        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;
        }
        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 DeleteLineItem(VendorOrderLineItem item)
 {
     if (item == null) throw new ApplicationException("Cannot delete a null item");
     //need to check and see if stored procedure exsists
     return true;
 }
 public bool UpdateLineItem(VendorOrderLineItem item, int newQtyOrdered)
 {
     if (item == null) throw new ApplicationException("VendorOrderLineItem cannot be null");
     if (newQtyOrdered == null) newQtyOrdered = 0;
     var oldLineItem = item;
     item.QtyOrdered = newQtyOrdered;
     var result = VendorOrderLineItemDAL.Update(oldLineItem, item, _connection);
     return result;
 }
Beispiel #16
0
 public void AddLineItem(VendorOrderLineItem lineItem)
 {
     _lineItems.Add(lineItem);
 }
Beispiel #17
0
 public void RemoveLineItem(VendorOrderLineItem lineItem)
 {
     if (_lineItems.Contains(lineItem))
     {
         _lineItems.Remove(lineItem);
     }
     else
     {
         //not sure if we need to throw this.
         throw new ApplicationException("line item doesn't exsist");
     }
 }
Beispiel #18
0
 public void AddLineItem(VendorOrderLineItem lineItem)
 {
     _lineItems.Add(lineItem);
 }
Beispiel #19
0
        private void btnUpdateOrder_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection selectedVendorOrderLineItem = this.lvReceiving.SelectedItems;
            if (selectedVendorOrderLineItem.Count > 0)
            {
                //int vendorID = Convert.ToInt32(selectedVendor[0].SubItems[0].Text);
                //Vendor thisVendor = _myVendorManager.GetVendor(vendorID);
                //FrmVendorAddUpdate frm = new FrmVendorAddUpdate(_myAccessToken, thisVendor);
                //frm.ShowDialog();
                //findActiveSelection();
                VendorManager _vendorManager = new VendorManager();
                int productID = Convert.ToInt32(selectedVendorOrderLineItem[0].SubItems[0].Text);
                int id = Convert.ToInt32(txtVendorOrderID.Text);
                string vendorName = txtVendorName.Text;
                int vendorID = Convert.ToInt32(txtVendorID.Text);

                VendorOrderLineItem item = new VendorOrderLineItem(id, productID);
                item.ProductID = productID;
                item.Name = selectedVendorOrderLineItem[0].SubItems[1].Text;
                item.QtyOrdered = Convert.ToInt32(selectedVendorOrderLineItem[0].SubItems[2].Text);
                item.QtyReceived = Convert.ToInt32(selectedVendorOrderLineItem[0].SubItems[3].Text);
                item.QtyDamaged = Convert.ToInt32(selectedVendorOrderLineItem[0].SubItems[4].Text);
                item.Note = selectedVendorOrderLineItem[0].SubItems[5].Text;

                _frmUpdateVendorOrderLineItem = new FrmUpdateVendorOrderLineItem(item, vendorName, vendorID, _myAccessToken);
                _frmUpdateVendorOrderLineItem.ShowDialog();
                populateListView();
            }
        }