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

📄 customerservice.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 deals with Customer Service issues
    /// </summary>
    public partial class CustomerService : Form
    {
        private Business.OrderDetailsCollection _orderDetails = null;
        private Business.InventoryCollection _inventory = null;
        private Microsoft.WindowsCE.Forms.Notification notify = null;

        public CustomerService()
        {
            InitializeComponent();
        }
        

        /// <summary>
        /// Exit the CustomerService form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemExit_Click(object sender, EventArgs e)
        {
            //Close form
            this.Close();
        }


        /// <summary>
        /// Launch the New Order form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemCreateOrder_Click(object sender, EventArgs e)
        {
            //Create the New Order form
            NewOrder newOrder = new NewOrder();
            newOrder.ShowDialog();

            //Refresh the list view when the New Order form closes
            FillListView();

            //Free the resources of the New Order form
            newOrder.Dispose();
        }


        /// <summary>
        /// Load the Customer Service form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomerService_Load(object sender, EventArgs e)
        {
            try
            {
                //Fill the list view control with order status
                FillListView();
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error displaying orders", "System Error");
            }
        }


        /// <summary>
        /// Fill the list view control with orders
        /// and their associated status
        /// </summary>
        private void FillListView()
        {
            //Retrieve OrderCollection
            Business.OrderCollection _orders = Business.Services.GetOrders(false, Business.OrderState.All);

            //Verify there are orders before displaying
            if (_orders.Count > 0)
            {
                //Clear the list view before filling
                listView1.Items.Clear();

                //Iterate through the Orders Collection with a for loop
                for (int i = 0; i < _orders.Count; i++)
                {
                    //Add OrderId
                    ListViewItem lvi = new ListViewItem(_orders[i].OrderId.ToString());
                    //Add CustomerId
                    lvi.SubItems.Add(_orders[i].CustomerName);
                    //Add Delivery Date
                    lvi.SubItems.Add(_orders[i].DeliveryDate.ToShortDateString());
                    //Add Order State
                    lvi.SubItems.Add(_orders[i].OrderState);
                    //Add ListView Items to ListView
                    listView1.Items.Add(lvi);
                }
            }
        }


        /// <summary>
        /// Cancel a checked order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemCancelOrder_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)
                    {
                        //Cancel Order by setting OrderState to zero
                        int _orderId = int.Parse(item.SubItems[0].Text);
                        Business.Services.UpdateOrderState(_orderId, Business.OrderState.Cancelled);

                        //Remove item from list
                        listView1.Items.Remove(item);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error removing orders", "System Error");
            }
        }


        /// <summary>
        /// Replicate with SQL Server 2005
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemSync_Click(object sender, EventArgs e)
        {
            Application.DoEvents();
            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();

            try
            {
                //Test to see if Network is available
                Application.DoEvents();
                statusBar1.Text = "Checking network connectivity...";
                Application.DoEvents();
                if (Business.Services.GetConnectionStatus())
                {
                    //Test to see if Replication URL is reachable
                    Application.DoEvents();
                    statusBar1.Text = "Testing IIS server...";
                    Application.DoEvents();
                    if (Business.Services.CheckReplicationUrl())
                    {
                        //Log Application and Device Metrics
                        Business.Services.LogAppState();

                        //Synchronize database changes
                        Application.DoEvents();
                        statusBar1.Text = "Synchronizing database...";
                        Application.DoEvents();
                        Business.Services.SyncWithDataSource();

                        //Refill list view with new data
                        FillListView();
                    }
                    else
                    {
                        //Replication URL isn't reachable
                        Application.DoEvents();
                        statusBar1.Text = "IIS server isn't available...";
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                else
                {
                    //Network isn't available
                    Application.DoEvents();
                    statusBar1.Text = "Network isn't available...";
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error synchronizing database", "System Error");
            }

            Application.DoEvents();
            statusBar1.Text = "";
            Cursor.Current = Cursors.Default;
            Application.DoEvents();
        }


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


        /// <summary>
        /// View a checked order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemViewOrder_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)
                    {
                        //View Order based on OrderId
                        int _orderId = int.Parse(item.SubItems[0].Text);

                        string _customer = item.SubItems[1].Text;

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

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

                        int _quantity;
                        int _inventoryId;
                        string _hardwareName = string.Empty;
                        int _inStock = 0;
                        StringBuilder sb = new StringBuilder();

                        //Create a Notification Balloon
                        notify = new Microsoft.WindowsCE.Forms.Notification();
                        //Create a Notification Balloon event handler 
                        notify.BalloonChanged += new Microsoft.WindowsCE.Forms.BalloonChangedEventHandler(notify_BalloonChanged);

                        //Set Notification Balloon caption to customer name
                        notify.Caption = _customer;

                        //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 In Stock Amount
                                    _inStock = inventoryItem.InStock;

                                    break;
                                }
                            }

                            //Add quantity, hardware item, and in stock amount to stringbuilder
                            sb.Append("Qty: " + _quantity.ToString());
                            sb.Append(" Item: " + _hardwareName);
                            sb.Append(" Stock: " + _inStock.ToString() + "<br>");

                        }

                        //Set Notification Balloon text
                        notify.Text = sb.ToString();
                        //Set duration that Notification Balloon will be visible
                        notify.InitialDuration = 5;
                        //Set Notification Balloon to visible
                        Application.DoEvents();
                        notify.Visible = true;
                        Application.DoEvents();

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show("Error viewing orders", "System Error");
            }
        }

        
        /// <summary>
        /// This event fires when the state of the Notification Balloon changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void notify_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 + -