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

📄 deliveries.cs

📁 微软的行业应用解决方案示例
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using HardwareDistributor.Business;
using HardwareDistributor.Properties;
using HardwareDistributor.Synchronization;
using Microsoft.WindowsMobile.Status;

namespace HardwareDistributor.UI
{
    /// <summary>
    /// UI layer form that displays deliveries that need to be made
    /// </summary>
    public partial class Deliveries : Form
    {
        #region Members
        private HardwareDistributor.Controls.GradientHeaders header;
        private SystemState rotation = null;


        private const int INDEX_DISPLAYID = 0;
        private const int INDEX_CUSTOMERNAME = 1;
        private const int INDEX_DELIVERYDATE = 2;
        private const int INDEX_ORDERSTATE = 3;
        private const int INDEX_CUSTOMERID = 4;
        private const int INDEX_GUID = 5;


        #endregion

        #region Contructors

        public Deliveries()
        {
            InitializeComponent();

            // Need to adjust the column width, so that we automatically adjust to different screen
            // sizes and orientations.
            AdjustColumns();

            // We are removing both the Control Box and the Minimize Box, so that we don't
            // have to handle these in our code. This is not necessary in Windows Mobile Standard,
            // but we are writing this code so that it works on all platforms without any changes
            // or any recompiling.
            this.ControlBox = false;
            this.MinimizeBox = false;

            AttachHeader();

            HandleBackgroundSync();
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// attach handlers for the synchronization events
        /// </summary>
        private void HandleBackgroundSync()
        {
            ClientSyncAgent.Instance.BakgroundSyncBegin += new EventHandler(ClientSyncAgent_SyncBegin);
            ClientSyncAgent.Instance.BakgroundSyncEnd += new EventHandler(ClientSyncAgent_SyncEnd);
        }

        /// <summary>
        /// Locks the screen and waits for the synchronization to end
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ClientSyncAgent_SyncBegin(object sender, EventArgs e)
        {
            //to deal with background thread
            this.Invoke((EventHandler)delegate(object senderInner, EventArgs eInner)
            {
                Application.DoEvents();
                Cursor.Current = Cursors.WaitCursor;

                this.DisplayStatus(Resources.SyncDbMessage, 0);
                Application.DoEvents();
            }

            );

        }

        /// <summary>
        /// refreshes the orders and unlocks the screen 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ClientSyncAgent_SyncEnd(object sender, EventArgs e)
        {
            this.Invoke((EventHandler)delegate(object sender1, EventArgs e1)
            {
                //refresh on-screen data 
                Application.DoEvents();
                RefreshOrdersListView();
                Application.DoEvents();

                //clear the message
                ClearStatus();

                //reset the cursor back to the usual
                Cursor.Current = Cursors.Default;
                Application.DoEvents();
            });

        }


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

        /// <summary>
        /// Synchronize Client with Server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemSync_Click(object sender, EventArgs e)
        {

            try
            {
                //change the cursor icon to wait
                Cursor.Current = Cursors.WaitCursor;

                //check if network available
                DisplayStatus(Resources.CheckNetworkMessage, 0);
                bool connectionAvailable = Business.Services.GetConnectionStatus();
                Application.DoEvents();

                if (connectionAvailable)
                {
                    //Test to see if Replication URL is reachable
                    DisplayStatus(Resources.checkIisMessage, 0); ;
                    bool replicationAvailable = Business.Services.CheckSynchronizationUrl();
                    Application.DoEvents();

                    if (replicationAvailable)
                    {
                        //synchronize data with server
                        DisplayStatus(Resources.SyncDbMessage, 0);
                        Synchronize();
                        Application.DoEvents();

                        //refresh ui to reflect any changes
                        RefreshOrdersListView();
                    }
                    else
                    {
                        //Replication URL isn't reachable
                        DisplayStatus(Resources.IisUnavailableMessage, 1000);
                    }
                }
                else
                {
                    //Network isn't available
                    DisplayStatus(Resources.NetworkUnavailableMessage, 1000);
                }

            }
            catch (Utilities.WrapperException wex)
            {
                Cursor.Current = Cursors.Default;

                Business.Services.LogErrors(wex.InnerException);
                MessageBox.Show(wex.UserDisplayMessage, Resources.SystemError);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;

                Business.Services.LogErrors(ex);
                MessageBox.Show(Resources.SystemError, Resources.SystemError);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                ClearStatus();
            }

        }

        private void Synchronize()
        {
            try
            {
                //Log Application and Device Metrics
                Business.Services.LogAppState();
                Business.Services.SyncWithDataSource();

            }
            catch (Exception ex)
            {
                throw new Utilities.WrapperException(Resources.SyncDbError, ex);

            }
        }

        private ListViewItem GetSelectedOrder()
        {
            ListViewItem selectedOrder = null;

            //Retrieve a collection of items from the list view control
            ListView.ListViewItemCollection selectedItems = OrdersListView.Items;

            //Iterate through the collection
            foreach (ListViewItem item in selectedItems)
            {
                //Determine of item is selected
                if (item.Selected)
                {
                    selectedOrder = item;

                    break;
                }
            }

            return selectedOrder;
        }



        /// <summary>
        /// Launch the Delivery form and pass in the
        /// OrderId and CustomerId
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemDeliver_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem selectedItem = GetSelectedOrder();

                if (selectedItem != null)
                {
                    //Get OrderId and CustomerId and pass to Delivery Screen
                    Guid _orderId = new Guid(selectedItem.SubItems[INDEX_GUID].Text);
                    int _customerId = int.Parse(selectedItem.SubItems[INDEX_CUSTOMERID].Text);

                    //Update the Orders table to reflect a new Order State of Out for Delivery (4)                        
                    Business.Order myOrder = Business.Services.GetOrder(_orderId);
                    myOrder.OrderState = Business.OrderState.OutForDelivery;
                    Business.Services.SaveOrder(myOrder);

                    //Create the new Delivery form
                    Delivery delivery = new Delivery(_orderId, _customerId);
                    delivery.ShowDialog();
                    //Free the resources of the Delivery form
                    delivery.Dispose();

                    //get back focus
                    this.Activate();

                    //Refresh the list view when the Delivery form closes
                    RefreshOrdersListView();
                }

            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show(Resources.DeliveryScreenLoadError, Resources.SystemError);
            }

        }

        /// <summary>
        /// Retrieve a route map from MapPoint
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemGetDirections_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem selectedItem = GetSelectedOrder();

                if (selectedItem != null)
                {
                    //Get CustomerId 
                    int _customerId = int.Parse(selectedItem.SubItems[INDEX_CUSTOMERID].Text);

                    //check if we have network connectivity
                    DisplayStatus(Resources.CheckNetworkMessage, 0);
                    Application.DoEvents();
                    bool networkAvailable = Business.Services.GetConnectionStatus();
                    Application.DoEvents();

                    //try to sync only if network is available
                    if (networkAvailable)

⌨️ 快捷键说明

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