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

📄 customerservice.cs

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

using HardwareDistributor.Properties;
using HardwareDistributor.Business;
using HardwareDistributor.Synchronization;


namespace HardwareDistributor.UI
{
    /// <summary>
    /// UI layer form that deals with Customer Service issues
    /// </summary>
    public partial class CustomerService : Form
    {
        #region Members

        HardwareDistributor.Controls.GradientHeaders header;


        #endregion

        #region Constants

        private const string HELP_FILE = "CustomerService";

        private const int INDEX_DISPLAYID = 0;
        private const int INDEX_CUSTOMERID = 1;
        private const int INDEX_ORDERSTATE = 2;
        private const int INDEX_DELIVERYDATE = 0;
        private const int INDEX_GUID = 4;
        
        #endregion

        #region Constructor

        public CustomerService()
        {
            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 EventHandlers

        private void CustomerService_Closing(object sender, CancelEventArgs e)
        {
            //unhook the synchronization handlers
            ClientSyncAgent.Instance.BakgroundSyncBegin -= ClientSyncAgent_SyncBegin;
            ClientSyncAgent.Instance.BakgroundSyncEnd -= ClientSyncAgent_SyncEnd;
        }

        /// <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)
        {
            //bring up the new order form 
            ShowNewOrderForm();

            //Refresh the orders data once we are back from new order
            RefreshOrdersListView();

        }

        /// <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
                RefreshOrdersListView();
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show(Resources.DisplayOrderError, Resources.SystemError);
            }
        }

        /// <summary>
        /// Cancel a selected order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemCancelOrder_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Application.DoEvents();

                ListViewItem orderToCancel = GetSelectedOrder();

                if (null != orderToCancel)
                {

                    Guid orderId = new Guid(orderToCancel.SubItems[INDEX_GUID].Text);

                    //update the status in the local db
                    DisplayStatus(Resources.UpdateOrderMsg, 0);
                    Application.DoEvents();
                    UpdateOrder(orderId);
                    Application.DoEvents();

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

                    //try to sync only if network is available
                    if (networkAvailable)
                    {
						//Test to see if Replication URL is reachable
				        DisplayStatus(Resources.checkIisMessage, 0); ;
			            bool replicationAvailable = Business.Services.CheckSynchronizationUrl();
		                Application.DoEvents();

						if (replicationAvailable)
						{
							//send this update to server DB
							DisplayStatus(Resources.SyncDbMessage, 0);
							Application.DoEvents();
							Synchronize();
							Application.DoEvents();

							//inform the next role that the order has been cancelled
							DisplayStatus(Resources.SendingNotificationMessage, 0);
							Application.DoEvents();
							SendNotification();
							Application.DoEvents();
						}
						else
						{
							//Replication URL isn't reachable
							DisplayStatus(Resources.IisUnavailableMessage, 1000);
						}
                    }
                    else
                    {
                        DisplayStatus(Resources.NetworkUnavailableMessage, 1000);
                        Application.DoEvents();
                    }

                    //Refresh UI
                    RefreshOrdersListView();
                }
            }
            catch (Utilities.WrapperException wex)
            {
                Cursor.Current = Cursors.Default;
                Application.DoEvents();

                Business.Services.LogErrors(wex.InnerException);
                MessageBox.Show(wex.Message, Resources.SystemError);

            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                Application.DoEvents();

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

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

        }

        /// <summary>
        /// Launch Help
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabelHelp_Click(object sender, EventArgs e)
        {
            DisplayHelp();
        }

        /// <summary>
        /// View a selected order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemViewOrder_Click(object sender, EventArgs e)
        {
            //identify selected order item
            ListViewItem item = GetSelectedOrder();

            if (null != item)
            {
                //extract details 
                Guid orderId = new Guid(item.SubItems[INDEX_GUID].Text);
                string customer = item.SubItems[INDEX_CUSTOMERID].Text;
                string state = item.SubItems[INDEX_ORDERSTATE].Text;
                string displayId = item.SubItems[INDEX_DISPLAYID].Text;

                DisplayOrderDetails(orderId, customer, state);

            }

        }

        /// <summary>
        /// Handle the key down event for the listview, so that we can set focus to the next control
        /// when we hit the first or last item in the list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OrdersListView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up &&
                            (OrdersListView.Items.Count == 0 ||
                            (OrdersListView.SelectedIndices.Count > 0 && OrdersListView.SelectedIndices[0] == 0)))
            {
                e.Handled = true;
                this.SelectNextControl(OrdersListView, false, true, false, true);
            }
            else if (e.KeyCode == Keys.Down &&
                            (OrdersListView.Items.Count == 0 ||
                            (OrdersListView.SelectedIndices.Count > 0 &&
                            (OrdersListView.SelectedIndices[0] == (OrdersListView.Items.Count - 1)))))
            {
                e.Handled = true;
                this.SelectNextControl(OrdersListView, true, true, false, true);
            }
        }

        // <summary>
        /// Custom Handling for the back key
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BackKeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == System.Windows.Forms.Keys.Back))
            {
                // Back

                // if the back key is hit, close the dialog
                this.Close();
            }
        }

        /// <summary>
        /// Handles the repaint command for the dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomerService_Paint(object sender, PaintEventArgs e)
        {
            // if the width of the listview no longer matches the width of the 
            // headers, then a rotation happened, so we need to adjust the

⌨️ 快捷键说明

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