⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picking.cs

📁 微软的行业应用解决方案实例!非常优秀的Windows Mobile开发案例
💻 CS
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace HardwareDistributor.UI
{
    /// <summary>
    /// UI layer form that facilitate the picking of items
    /// </summary>
    public partial class Picking : Form
    {
        private int _orderId;
        private Business.OrderDetailsCollection _orderDetails = null;
        private Business.InventoryCollection _inventory = null;


        /// <summary>
        /// The OrderId is passed into the constructor
        /// </summary>
        /// <param name="orderId"></param>
        public Picking(int orderId)
        {
            InitializeComponent();

            this._orderId = orderId;
        }


        /// <summary>
        /// Cancels picking operation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem1_Click(object sender, EventArgs e)
        {
            //Close form
            this.Close();
        }


        /// <summary>
        /// Load the picking form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Picking_Load(object sender, EventArgs e)
        {
            try
            {
                //Retrieve OrderDetailsCollection
                _orderDetails = Business.Services.GetOrderDetails(_orderId);

                //Retrieve InventoryCollection
                _inventory = Business.Services.GetInventory();

                int _quantity;
                int _orderDetailId;
                int _inventoryId;
                string _hardwareName = string.Empty;
                int _inStock = 0;
                int _bin = 0;


                //Iterate through OrderDetailsCollection
                foreach (Business.OrderDetails orderDetailsItem in _orderDetails)
                {
                    //Get OrderDetailId
                    _orderDetailId = orderDetailsItem.OrderDetailsId;

                    //Get InventoryId
                    _inventoryId = orderDetailsItem.InventoryId;

                    //Get Quantity
                    _quantity = orderDetailsItem.Quantity;

                    //Iterate through InventoryCollection
                    foreach (Business.Inventory inventoryItem in _inventory)
                    {
                        //Search based on InventoryId
                        if (_inventoryId == inventoryItem.InventoryId)
                        {
                            //Get Hardware Name
                            _hardwareName = inventoryItem.InventoryName;

                            //Get In Stock Amount
                            _inStock = inventoryItem.InStock;

                            //Get Bin Location
                            _bin = inventoryItem.Bin;

                            break;
                        }
                    }

                    //Add Quantity
                    ListViewItem lvi = new ListViewItem(_quantity.ToString());
                    //Add Hardware Name
                    lvi.SubItems.Add(_hardwareName);
                    //Add In Stock Amount
                    lvi.SubItems.Add(_inStock.ToString());
                    //Add Bin Location
                    lvi.SubItems.Add("Bin #: " + _bin.ToString());
                    //Add Inventory Id
                    lvi.SubItems.Add(_inventoryId.ToString());
                    //Add ListView Items to ListView
                    listView1.Items.Add(lvi);

                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error displaying inventory items to pick", "System Error");
            }

        }


        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                //Retrieve a collection of items from the list view control
                ListView.ListViewItemCollection checkedItems = listView1.Items;
                //Iterate through the collection
                foreach (ListViewItem item in checkedItems)
                {
                    //Determine of item is checked
                    if (item.Checked)
                    {
                        int _quantity = int.Parse(item.SubItems[0].Text);
                        string _hardwareName = item.SubItems[1].Text;
                        int _inStock = int.Parse(item.SubItems[2].Text);
                        int _inventoryId = int.Parse(item.SubItems[4].Text);

                        //Update In Stock Amount
                        int _newInStock = _inStock - _quantity;

                        //Add item to Staged Items List View

                        //Add Quantity
                        ListViewItem lvi = new ListViewItem(_quantity.ToString());
                        //Add Hardware Name
                        lvi.SubItems.Add(_hardwareName);
                        //Add In Updated Stock Amount
                        lvi.SubItems.Add(_newInStock.ToString());
                        //Add Inventory Id
                        lvi.SubItems.Add(_inventoryId.ToString());
                        //Add ListView Items to ListView
                        listView2.Items.Add(lvi);
                        
                        //Remove item from list
                        listView1.Items.Remove(item);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error picking hardware items", "System Error");
            }
        }


        /// <summary>
        /// This menu completes the picking operation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemFinish_Click(object sender, EventArgs e)
        {
            try
            {
                //Ensure that listview1 is empty and listview2 is greater than zero before proceeding
                if (listView1.Items.Count == 0 && listView2.Items.Count > 0)
                {
                    //Update the Orders table to reflect a new Order State of Picked (2)
                    Business.Services.UpdateOrderState(_orderId, Business.OrderState.Picked);

                    //Iterate through the Staged list view to update the in-stock amounts
                    ListView.ListViewItemCollection items = listView2.Items;
                    //Iterate through the collection
                    foreach (ListViewItem item in items)
                    {
                        //Get In-Stock amount
                        int _inStock = int.Parse(item.SubItems[2].Text);
                        //Get InventoryId
                        int _inventoryId = int.Parse(item.SubItems[3].Text);
                        //Update the in-stock inventory
                        Business.Services.UpdateInStockAmount(_inventoryId, _inStock);
                    }

                    //Set Notification Balloon caption
                    notification1.Caption = "Picked Order";
                    //Set Notification Balloon text
                    notification1.Text = "An order has been picked.  Please synchronize your device to inform the forklift driver that an order is ready to load.";
                    //Set duration that Notification Balloon will be visible
                    notification1.InitialDuration = 5;
                    //Set Notification Balloon to visible
                    Application.DoEvents();
                    notification1.Visible = true;
                    Application.DoEvents();

                    //Close form
                    this.Close();
                }
                else
                {
                    MessageBox.Show("All picked items must be staged", "Picking Error");
                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error updating status of staged hardware items", "System Error");
            }
        }

       
        /// <summary>
        /// Launch Help
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabelHelp_Click_1(object sender, EventArgs e)
        {
            try
            {
                //Show Picking Help
                Help.ShowHelp(this, @Business.GlobalCache.Instance.AppPath + "HardwareHelp.htm#picking");
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error displaying Help", "System Error");
            }

        }


        /// <summary>
        /// This event fires when the state of the Notification Balloon changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notification1_BalloonChanged(object sender, Microsoft.WindowsCE.Forms.BalloonChangedEventArgs e)
        {
            //If Balloon is not visible
            if (!e.Visible)
            {
                //Dispose of that Notification Balloon object
                ((Microsoft.WindowsCE.Forms.Notification)sender).Dispose();
            } 
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -