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

📄 warehouse.cs

📁 微软的行业应用解决方案示例
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    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);
                    Application.DoEvents();
                }

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

            }
        }

        /// <summary>
        /// Display status in form. Wait for the specified timeout so that the user can see the message
        /// before returning
        /// </summary>
        /// <param name="statusText"></param>
        /// <param name="timeout"></param>
        private void DisplayStatus(string statusText, int timeout)
        {
            //Network isn't available
            statusBarLabel.Visible = true;
            statusBarLabel.Text = statusText;

            Application.DoEvents();
            System.Threading.Thread.Sleep(timeout);
            Application.DoEvents();

        }

        public void ClearStatus()
        {
            statusBarLabel.Visible = false;
            statusBarLabel.Text = string.Empty;
        }

        private bool LastItemSelected()
        {
            return (placedOrdersListView.SelectedIndices.Count > 0 &&
                (placedOrdersListView.SelectedIndices[0] == (placedOrdersListView.Items.Count - 1)));
        }

        private bool FirstItemSelected()
        {
            return (placedOrdersListView.SelectedIndices.Count > 0 && placedOrdersListView.SelectedIndices[0] == 0);
        }

        private bool ListViewEmpty()
        {
            return (placedOrdersListView.Items.Count == 0);
        }

        private void SendNotification()
        {

            //get the address for Warehouse role
            List<Role> roles = Business.Services.GetRoles();

            //find the email address for the WareHouse role
            string emailAddress = string.Empty;
            foreach (Role role in roles)
            {
                if (role.RoleName.Trim().CompareTo("Warehouse") == 0)
                {
                    emailAddress = role.EmailAddress;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(emailAddress))
            {
                NotificationAgent.Instance.SendMessage(emailAddress, "SYNC", null);
            }
            else
            {
                throw new ApplicationException("Could not find email address for next role");
            }

        }


        /// <summary>
        /// bring up the help screen for this form
        /// </summary>
        private static void ShowHelpScreen()
        {
            try
            {
                //Show Warehouse Help
                OnlineHelper myHelp = new OnlineHelper("warehouse");
                myHelp.ShowDialog();

                //Free the resources of the help form
                myHelp.Dispose();
            }
            catch (Exception ex)
            {
                Business.Services.LogErrors(ex);
                MessageBox.Show(Resources.HelpDisplayError, Resources.SystemError);
            }
        }

        /// <summary>
        /// Bring up the loading form 
        /// </summary>
        /// <param name="orderId">valid order id</param>
        private void ShowLoadingForm(Guid orderId)
        {
            //Load the Loading screen and pass in the OrderId
            Loading loading = new Loading(orderId);
            loading.ShowDialog();


            //Release Loading screen's resources
            loading.Dispose();


            this.Activate();
        }

        /// <summary>
        /// gets the picked order id
        /// </summary>
        /// <returns></returns>
        private Guid GetPickedOrder()
        {
            Guid orderId = Guid.Empty;

            if (pickedOrdersCombobox.Items.Count > 0)
            {
                //Get OrderId from combo selection
                orderId = new Guid(pickedOrdersCombobox.SelectedValue.ToString());
            }

            return orderId;
        }

        /// <summary>
        /// Fill Orders to Pick listview and
        /// Order to Load combo box
        /// </summary>
        private void RefreshOrdersListView()
        {
            RefreshPickedOrders();

            RefreshPlacedOrders();
        }

        /// <summary>
        /// insert order item into the listview
        /// </summary>
        /// <param name="currentOrder">order object</param>
        private void InsertOrderIntoList(Order currentOrder)
        {
            //Display Id
            ListViewItem item = new ListViewItem(currentOrder.DisplayId.ToString());

            //CustomerId
            item.SubItems.Add(currentOrder.Customer.CustomerName.Trim());

            //Order State
            item.SubItems.Add(Business.Services.TranslateOrderState(currentOrder.OrderState));

            //Delivery Date
            item.SubItems.Add(currentOrder.DeliveryDate.Value.ToShortDateString());

            //Order Id
            item.SubItems.Add(currentOrder.OrderId.ToString());

            //insert order 
            placedOrdersListView.Items.Add(item);
        }


        /// <summary>
        /// Refresh Placed Orders
        /// </summary>
        private void RefreshPlacedOrders()
        {
            //Retrieve OrderCollection of Orders to Pick
            List<Order> placedOrders = Business.Services.GetOrders(true, Business.OrderState.Placed);

            //Fill listview with Orders to Load
            placedOrdersListView.Items.Clear();

            //Iterate through OrderCollection
            foreach (Order orderItem in placedOrders)
            {
                InsertOrderIntoList(orderItem);
            }
        }

        /// <summary>
        /// Refresh Picked Orders
        /// </summary>
        private void RefreshPickedOrders()
        {
            //Retrieve OrderCollection of Orders to Load
            List<Order> pickedOrders = Business.Services.GetOrders(false, Business.OrderState.Picked);

            //Databind Orders to Load to combo box
            pickedOrdersCombobox.DisplayMember = "DisplayIdCustomer";
            pickedOrdersCombobox.ValueMember = "OrderId";
            pickedOrdersCombobox.DataSource = pickedOrders;
        }

        /// <summary>
        /// bring up the picking form 
        /// </summary>
        /// <param name="orderId">valid order id</param>
        private void ShowPickingDialog(Guid orderId)
        {
            Picking picking = new Picking(orderId);
            picking.ShowDialog();

            picking.Dispose();

            //bring back focus 
            this.Activate();

        }

        /// <summary>
        /// finds the selected order in the list and returns its Id.
        /// If no order is seleceted, returns Guid.Empty
        /// </summary>
        /// <returns>orderId Guid</returns>
        private Guid GetSelectedOrder()
        {
            Guid selectedOrderId = Guid.Empty;

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

            //Iterate through the collection
            foreach (ListViewItem item in selectedItems)
            {
                //Determine of item is selected
                if (item.Selected)
                {
                    //Get OrderId and pass to Picking Screen
                    selectedOrderId = new Guid(item.SubItems[INDEX_GUID].Text);
                    break;
                }
            }

            return selectedOrderId;
        }

        /// <summary>
        /// hook up the gradient header 
        /// </summary>
        private void AttachHeader()
        {
            // Create instance of the gradient header
            header = new HardwareDistributor.Controls.GradientHeaders();
            // Attach it to the listview
            header.Attach(ref placedOrdersListView);
            this.Controls.Add(header);
        }

 
    }
}

⌨️ 快捷键说明

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