コード例 #1
0
ファイル: PageInventory.xaml.cs プロジェクト: zgren/dp2
        private void PageInventory_Loaded(object sender, RoutedEventArgs e)
        {
            App.NewTagChanged        += CurrentApp_NewTagChanged;
            App.IsPageInventoryActive = true;

            RefreshActionModeMenu();

            _ = Task.Run(() =>
            {
                // 获得馆藏地列表
                GetLocationListResult get_result = LibraryChannelUtil.GetLocationList();
                if (get_result.Value == -1)
                {
                    App.SetError("inventory", $"获得馆藏地列表时出错: {get_result.ErrorInfo}");
                }

                string batchNo = "inventory_" + DateTime.Now.ToShortDateString();

                bool slow_mode     = false;
                bool dialog_result = false;
                // “开始盘点”对话框
                App.Invoke(new Action(() =>
                {
                    App.PauseBarcodeScan();
                    try
                    {
                        BeginInventoryWindow dialog = new BeginInventoryWindow();
                        dialog.TitleText            = $"开始盘点";
                        // dialog.Text = $"如何处理以上放入 {door_names} 的 {collection.Count} 册图书?";
                        dialog.Owner = App.CurrentApp.MainWindow;
                        // dialog.BatchNo = batchNo;
                        dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        App.SetSize(dialog, "tall");
                        dialog.location.ItemsSource = get_result.List;  // result.List;
                        dialog.BatchNo    = batchNo;
                        dialog.ActionMode = ActionMode;
                        dialog.ShowDialog();
                        if (dialog.DialogResult == false)
                        {
                            dialog_result = false;
                        }
                        else
                        {
                            dialog_result = true;

                            {
                                _actionMode = dialog.ActionMode;
                                RefreshActionModeMenu();
                            }

                            CurrentLocation = dialog.Location;
                            CurrentBatchNo  = dialog.BatchNo;
                            slow_mode       = dialog.SlowMode;
                        }
                    }
                    finally
                    {
                        App.ContinueBarcodeScan();
                    }
                }));

                ClearList();

                if (dialog_result == true && slow_mode == false)
                {
                    CancellationTokenSource cancel = new CancellationTokenSource();

                    ProgressWindow progress = null;
                    App.Invoke(new Action(() =>
                    {
                        progress                       = new ProgressWindow();
                        progress.TitleText             = "dp2SSL -- 盘点";
                        progress.MessageText           = "正在获取 UID 对照信息,请稍候 ...";
                        progress.Owner                 = Application.Current.MainWindow;
                        progress.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        progress.Closed               += (s, e1) =>
                        {
                            cancel.Cancel();
                        };
                        progress.okButton.Visibility = Visibility.Collapsed;
                        // progress.okButton.Content = "停止";
                        App.SetSize(progress, "middle");
                        progress.BackColor = "green";
                        progress.Show();
                    }));

                    try
                    {
                        Hashtable uid_table = new Hashtable();
                        var result          = InventoryData.DownloadUidTable(
                            null,
                            uid_table,
                            (text) =>
                        {
                            App.Invoke(new Action(() =>
                            {
                                progress.MessageText = text;
                            }));
                        },
                            cancel.Token);
                        InventoryData.SetUidTable(uid_table);
                    }
                    catch (Exception ex)
                    {
                        WpfClientInfo.WriteErrorLog($"准备册记录过程出现异常: {ExceptionUtil.GetDebugText(ex)}");
                    }
                    finally
                    {
                        App.Invoke(new Action(() =>
                        {
                            progress.Close();
                        }));
                    }
                }
            });
        }