Example #1
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());
            //}
        }
        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 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());
            }
        }