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

📄 warehouse.cs

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

namespace HardwareDistributor.UI
{
    /// <summary>
    /// UI layer form that displays order to pick and load
    /// </summary>
    public partial class Warehouse : Form
    {
		private HardwareDistributor.Controls.GradientHeaders header;
		private SystemState rotation = null;

        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;

        /// <summary>
        /// help class used to populate the combo box
        /// </summary>
        private class OrderComboBoxItem {

            OrderComboBoxItem(string customerName, string orderId)
            {
                CustomerName = customerName;
                OrderId = orderId;
            }
            public string CustomerName;
            public string OrderId;
        }

        public Warehouse()
        {
            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();
        }



        /// <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>
		/// Automatically adjust the column widths based on the width of the screen
		/// if the screen can show extra columns, show them.
		/// </summary>
		private void AdjustColumns()
		{
			System.Drawing.Graphics gx = this.CreateGraphics();
			int header1Size;
			int header2Size;
			int header3Size;
			int header4Size;
			int spacing;

			spacing = 20;

			header1Size = gx.MeasureString(columnHeaderOrderId.Text, placedOrdersListView.Font).ToSize().Width + spacing;
			header2Size = gx.MeasureString(columnHeaderCustomer.Text, placedOrdersListView.Font).ToSize().Width + spacing;
			header3Size = gx.MeasureString(columnHeaderState.Text, placedOrdersListView.Font).ToSize().Width + spacing;
			header4Size = gx.MeasureString(columnHeaderDelivery.Text, placedOrdersListView.Font).ToSize().Width + spacing;

			columnHeaderDelivery.Width = 0;
			columnHeaderState.Width = 0;

			if (placedOrdersListView.Width > header1Size + header2Size + header3Size + header4Size + 4)
			{
				columnHeaderOrderId.Width = header1Size;
				columnHeaderState.Width = header3Size;
				columnHeaderDelivery.Width = header4Size;
				columnHeaderCustomer.Width = placedOrdersListView.Width - header1Size - header3Size - header4Size - 4;
			}
			else if (placedOrdersListView.Width > header1Size + header2Size + header3Size + 4)
			{
				columnHeaderOrderId.Width = header1Size;
				columnHeaderState.Width = header3Size;
				columnHeaderCustomer.Width = placedOrdersListView.Width - header1Size - header3Size - 4;
			}
			else
			{
				this.columnHeaderCustomer.Width = this.placedOrdersListView.Width - this.columnHeaderOrderId.Width - 4;
			}
		}

        /// <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>
        /// 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 this dialog
                this.Close();
            }
        }

        /// <summary>
        /// Check an Order to Pick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemPick_Click(object sender, EventArgs e)
        {
            Guid orderId = GetSelectedOrder();

            if (orderId != Guid.Empty)
            {

                ShowPickingDialog(orderId);

                RefreshOrdersListView();
            }
        }

        /// <summary>
        /// Launches the Loading screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItemLoad_Click(object sender, EventArgs e)
        {
            Guid orderId = GetPickedOrder();

            if (orderId != Guid.Empty)
            {

                ShowLoadingForm(orderId);

                //Refill listview and combo box when 
                //Loading screen is closed
                RefreshOrdersListView();

            }
        }

        /// <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 placedOrdersListView_KeyDown(object sender, KeyEventArgs e)
        {

            if (
                    e.KeyCode == Keys.Up
                && (ListViewEmpty() || FirstItemSelected())
                )
            {
                e.Handled = true;
                this.SelectNextControl(placedOrdersListView, false, true, false, true);
            }
            else if (
                        e.KeyCode == Keys.Down
                        && (ListViewEmpty() || LastItemSelected())
                    )
            {
                e.Handled = true;
                this.SelectNextControl(placedOrdersListView, true, true, false, true);
            }
        }

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

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

        /// <summary>
        /// Loads Warehouse form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Warehouse_Load(object sender, EventArgs e)
        {
            try
            {
                //Fill the listview and combo box controls
                RefreshOrdersListView();
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show(Resources.DisplayOrderError, Resources.SystemError);
            }

        }

		/// <summary>
		/// Handles the repaint command for the dialog
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void Warehouse_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
			// width of all the columns
			if (placedOrdersListView.Width != header.Width)
			{
				AdjustColumns();
			}
		}
        /// <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

⌨️ 快捷键说明

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