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

📄 loading.cs

📁 微软的行业应用解决方案示例
💻 CS
📖 第 1 页 / 共 2 页
字号:

            try
            {
                //Ensure that listview1 is empty and listview2 is greater than zero before proceeding

                Cursor.Current = Cursors.WaitCursor;

                //Update the Orders table to reflect a new Order State of Loaded
                DisplayStatus(Resources.UpdateOrderMsg, 0);
                Application.DoEvents();
                UpdateOrder();
                Application.DoEvents();

                localDBUpdated = true;

                 //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)
                {
                    //Test to see if Replication URL is reachable
                    DisplayStatus(Resources.checkIisMessage, 0); ;
                    bool replicationAvailable = Business.Services.CheckSynchronizationUrl();
                    Application.DoEvents();

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

                        //send notification to next role in workflow
                        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();
                }


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

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

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

            }
            finally
            {
                //reset the cursor
                Cursor.Current = Cursors.Default;
                ClearStatus();

                if (localDBUpdated)
                    this.Close();

            }
        }


        /// <summary>
        /// Synchronizes local db with server DB
        /// </summary>
        private void Synchronize()
        {
            try
            {
                Business.Services.SyncWithDataSource();
            }
            catch (Exception ex)
            {
                throw new Utilities.WrapperException(Resources.SyncDbError, ex);
            }

        }

        /// <summary>
        /// sends notification to the warehouse role that the order has been placed
        /// </summary>
        private void SendNotification()
        {
            try
            {
                Business.Services.SendNotification("Delivery Driver");
            }
            catch (Exception ex)
            {
                throw new Utilities.WrapperException(Resources.NotificationError, ex);
            }
        }

        #endregion

        #region Methods

        private void ShowNotification()
        {
			HtmlFormEx notificationsForm = new HtmlFormEx(Resources.Loading,
                                                Resources.OrderLoaded,
                                                Resources.SyncAfterLoadMessage,
                                                    string.Empty);
			notificationsForm.ShowDialog();
			notificationsForm.Dispose();

            //bring back focus
            this.Activate();
        }

        private void RefreshItemsToLoadList()
        {
            //Retrieve OrderDetailsCollection
            List<OrderDetail> orderDetailsList = Services.GetOrderDetails(_orderId);

            //Iterate through OrderDetailsCollection
            foreach (OrderDetail orderDetailsItem in orderDetailsList)
            {
                //Add Quantity
                ListViewItem lvi = new ListViewItem(orderDetailsItem.Quantity.ToString());

                //Add Hardware Name
                lvi.SubItems.Add(orderDetailsItem.Inventory.InventoryName);

                //Add Inventory Id
                lvi.SubItems.Add(orderDetailsItem.Inventory.InventoryId.ToString());

                //Add ListView Items to ListView
                ItemsToLoadListView.Items.Add(lvi);
            }
        }

        private void SetTruckInfo()
        {
            Truck truckToLoad = Services.GetTruckToLoad(_orderId);

            if (null != truckToLoad)
            {
                StringBuilder sb = new StringBuilder();

                //build the display string
                sb.Append(Resources.TruckNumber);
                sb.Append(": ");
                sb.Append(truckToLoad.TruckId);
                sb.Append(ControlChars.CrLf);
                sb.Append("License: ");
                sb.Append(truckToLoad.LicenseNumber);
                sb.Append(ControlChars.CrLf);
                sb.Append("State/Province: ");
                sb.Append(truckToLoad.LicenseStateProvince);

                truckInfoTextBox.Text = sb.ToString();
            }
        }

        private void UpdateOrder()
        {
            try
            {
                Order myOrder = Business.Services.GetOrder(_orderId);
                myOrder.OrderState = OrderState.Loaded;
                Business.Services.SaveOrder(myOrder);
            }
            catch (Exception ex)
            {
                throw new Utilities.WrapperException(Resources.UpdateOrderMsg, ex);
            }

        }

        private bool AllItemsLoaded()
        {
            return ItemsToLoadListView.Items.Count == 0 && _loadedItemsForm.Count > 0;
        }

        private void ShowHelpScreen()
        {
            try
            {
                //Show Loading Help
                OnlineHelper myHelp = new OnlineHelper("loading");
                myHelp.ShowDialog();

                //Free the resources of the help form
                myHelp.Dispose();

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

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

        #endregion

    }
}

⌨️ 快捷键说明

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