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

📄 delivery.cs

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

namespace HardwareDistributor.UI
{
    /// <summary>
    /// UI layer form that presents final delivery information
    /// </summary>
    public partial class Delivery : Form
    {
        int _orderId;
        int _customerId;
        int _itemsToDeliver;
        private Business.OrderDetailsCollection _orderDetails = null;
        private Business.InventoryCollection _inventory = null;
          

        /// <summary>
        /// Capture OrderId and CustomerId in constructor
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="customerId"></param>
        public Delivery(int orderId, int customerId)
        {
            InitializeComponent();

            this._orderId = orderId;
            this._customerId = customerId;
        }


        /// <summary>
        /// Close form and roll back state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemCancel_Click(object sender, EventArgs e)
        {
            //Update the Orders table to reflect a reversion to an Order State of Loaded (3)
            Business.Services.UpdateOrderState(_orderId, Business.OrderState.Loaded);
            //Close form
            this.Close();
        }


        /// <summary>
        /// Clears the signature capture control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabelClear_Click(object sender, EventArgs e)
        {
            try
            {
                //Clear the control
                signatureCapture1.Clear();
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error clearing signature", "System Error");
            }
        }


        /// <summary>
        /// Completes order delivery
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemFinish_Click(object sender, EventArgs e)
        {
            try
            {
                //Test to see if any items exist in list view
                if (listView1.Items.Count > 0)
                {
                    //Count all the items that have been checked
                    ListView.ListViewItemCollection orderItems = listView1.Items;
                    int _checkedItems = 0;
                    foreach (ListViewItem item in orderItems)
                    {
                        if (item.Checked)
                        {
                            _checkedItems++;

                        }
                    }

                    //If the items checked equals the number of items to deliver then proceed
                    if (_checkedItems == _itemsToDeliver)
                    {
                        //Save the signature as a GIF file
                        signatureCapture1.Save(Business.GlobalCache.Instance.AppPath + "signature.gif");

                        //Insert GIF into database
                        Business.Services.SaveGifToDatabase(Business.GlobalCache.Instance.AppPath + "signature.gif", _orderId);

                        //Update the Orders table to reflect final Order State of Delivered (5)
                        Business.Services.UpdateOrderState(_orderId, Business.OrderState.Delivered);

                        //Set Notification Balloon caption
                        notification1.Caption = "Order Delivered";
                        //Set Notification Balloon text
                        notification1.Text = "An order has been delivered.  Please synchronize your device to make this delivery status available to everyone else.";
                        //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 items must be checked by customer before completing delivery.", "Delivery Error");
                    }
                }
                else
                {
                    MessageBox.Show("There are no items to deliver", "Delivery Error");
                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error completing delivery", "System Error");
            }
        }


        /// <summary>
        /// Load the Delivery form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Delivery_Load(object sender, EventArgs e)
        {
            try
            {
                //If not a square screen
                if (this.Height > 200)
                {
                    //Increase the height of the signature control
                    signatureCapture1.Height = 80;
                }

                //Retrieve Customer Collection
                Business.CustomerCollection _customers = Business.GlobalCache.Instance.Customers;

                //Iterate through Customer Collection
                foreach (Business.Customer _customerItem in _customers)
                {
                    //If the Customer object matches the CustomerId
                    if (_customerItem.CustomerId == _customerId)
                    {
                        //Build a list of customer information
                        StringBuilder sb = new StringBuilder();
                        sb.Append("Name: " + _customerItem.CustomerName + ControlChars.CrLf);
                        sb.Append("Street: " + _customerItem.StreetAddress + ControlChars.CrLf);
                        sb.Append("City: " + _customerItem.City + ControlChars.CrLf);
                        sb.Append("State: " + _customerItem.StateProvince + ControlChars.CrLf);
                        sb.Append("Postal Code: " + _customerItem.PostalCode + ControlChars.CrLf);
                        sb.Append("Contact Name: " + _customerItem.ContactName + ControlChars.CrLf);
                        sb.Append("Contact Phone: " + _customerItem.ContactPhone);

                        //Set address textbox equal to the stringbuilder contents
                        txtAddress.Text = sb.ToString();
                        break;
                    }
                }

                //Retrieve OrderDetailsCollection
                _orderDetails = Business.Services.GetOrderDetails(_orderId);

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

                int _quantity;
                int _inventoryId;
                string _hardwareName = string.Empty;
                decimal _price = 0;
                decimal _subTotal = 0;
                decimal _totalPrice = 0;

                //Iterate through OrderDetailsCollection
                foreach (Business.OrderDetails orderDetailsItem in _orderDetails)
                {
                    //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 Hardware Price
                            _price = inventoryItem.Price;
                            //Get a subtotal based on price times quantity
                            _subTotal = _price * _quantity;

                            break;
                        }
                    }

                    //Add the subtotals to get the total price for the order
                    _totalPrice += _subTotal;

                    //Add Quantity
                    ListViewItem lvi = new ListViewItem(_quantity.ToString());
                    //Add Hardware Name
                    lvi.SubItems.Add(_hardwareName);
                    //Add Price
                    lvi.SubItems.Add(_subTotal.ToString());
                    //Add Inventory Id
                    lvi.SubItems.Add(_inventoryId.ToString());
                    //Add ListView Items to ListView
                    listView1.Items.Add(lvi);
                    //Update column header
                    listView1.Columns[1].Text = "Item $" + _totalPrice.ToString();

                }

                //This number will be compared later to see if order is complete
                _itemsToDeliver = listView1.Items.Count;
            
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error displaying customer data", "System Error");
            }
        }


        /// <summary>
        /// Launch Help
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabelHelp_Click_2(object sender, EventArgs e)
        {
            try
            {
                //Show Delivery Help
                Help.ShowHelp(this, @Business.GlobalCache.Instance.AppPath + "HardwareHelp.htm#delivery");
            }
            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 + -