Example #1
0
        static async Task ProcessingAsync()
        {
            var list = CopyList();

            foreach (var entity in list)
            {
                // 获得册记录和书目摘要
                // .Value
                //      -1  出错
                //      0   没有找到
                //      1   找到
                var result = await LibraryChannelUtil.GetEntityDataAsync(entity.PII, "network");

                if (result.Value == -1)
                {
                    entity.AppendError(result.ErrorInfo, "red", result.ErrorCode);
                }
                else
                {
                    if (string.IsNullOrEmpty(result.Title) == false)
                    {
                        entity.Title = PageBorrow.GetCaption(result.Title);
                    }
                    if (string.IsNullOrEmpty(result.ItemXml) == false)
                    {
                        entity.SetData(result.ItemRecPath, result.ItemXml);
                    }
                }
            }

            // 把处理过的 entity 从 list 中移走
            RemoveList(list);
        }
Example #2
0
        public static void DetectLibraryNetwork()
        {
            // 探测和 dp2library 服务器的通讯是否正常
            // return.Value
            //      -1  本函数执行出现异常
            //      0   网络不正常
            //      1   网络正常
            var detect_result = LibraryChannelUtil.DetectLibraryNetwork();

            if (detect_result.Value == 1)
            {
                _libraryNetworkCondition = "OK";
                PageMenu.PageShelf?.SetBackColor(Brushes.Black);
            }
            else
            {
                _libraryNetworkCondition = "Bad";
                PageMenu.PageShelf?.SetBackColor(Brushes.DarkBlue);
            }
        }
Example #3
0
        public static Paragraph BuildParagraph(
            ActionInfo action,
            int index,
            double baseFontSize,
            string style)
        {
            // 是否显示 transfer (in) 条目。注意,即便 false, 也要显示 transfer (out) 条目的
            bool display_transfer = StringUtil.IsInList("transfer", style);

            if (action.Action.StartsWith("transfer") && action.TransferDirection == "in" &&
                display_transfer == false)
            {
                return(null);
            }

            var p = new Paragraph();

            p.FontFamily = new FontFamily("微软雅黑");
            p.FontSize   = baseFontSize;
            // p.FontStyle = FontStyles.Italic;
            p.TextAlignment = TextAlignment.Left;
            p.Foreground    = Brushes.Gray;
            // p.LineHeight = 18;
            p.TextIndent = -20;
            p.Margin     = new Thickness(10, 0, 0, 8); // 10,0,0,8
            p.Tag        = new ParagraphInfo {
                Action = action, Index = index
            };                                                              // 记忆下来后面刷新事项的时候可以用到

            // 序号
            p.Inlines.Add(new Run($"{(index + 1).ToString()}) "));

            Brush back = Brushes.Transparent;

            // 状态
            {
                // 等待动画
                if (string.IsNullOrEmpty(action.State))
                {
                    var image = new FontAwesome.WPF.ImageAwesome();
                    image.Icon         = FontAwesome.WPF.FontAwesomeIcon.Spinner;
                    image.Spin         = true;
                    image.SpinDuration = 5;
                    image.Height       = baseFontSize * 2.0;
                    image.Foreground   = Brushes.DarkGray;
                    var container = new InlineUIContainer(image);
                    container.Name = "image_id";
                    p.Inlines.Add(container);
                }
                else if (action.SyncErrorCode == "overflow")
                {
                    back = Brushes.DarkRed;
                    p.Inlines.Add(new Run
                    {
                        Text       = " 超额 ",
                        Background = back,
                        Foreground = Brushes.White
                    });
                }
                else if (action.State == "sync")
                {
                    back = Brushes.DarkGreen;
                    p.Inlines.Add(new Run
                    {
                        Text       = " 成功 ",
                        Background = back,
                        Foreground = Brushes.White
                    });
                }
                else if (action.SyncErrorCode == "skipped")
                {
                    back = Brushes.DeepSkyBlue;
                    p.Inlines.Add(new Run
                    {
                        Text       = $" 暂时跳过同步 ",
                        Background = back,
                        Foreground = Brushes.White
                    });
                }
                else if (action.State == "commerror" || action.State == "normalerror")
                {
                    if (ShelfData.LibraryNetworkCondition == "Bad")
                    {
                        back = Brushes.DeepSkyBlue;
                    }
                    else
                    {
                        back = Brushes.DarkRed;
                    }
                    p.Inlines.Add(new Run
                    {
                        Text       = $" 同步失败({action.State}) ",
                        Background = back,
                        Foreground = Brushes.White
                    });
                }
                else if (action.State == "dontsync")
                {
                    back = Brushes.DarkBlue;
                    p.Inlines.Add(new Run
                    {
                        Text       = $" 不再同步 ",
                        Background = back,
                        Foreground = Brushes.White
                    });
                }
                else
                {
                    back = Brushes.DarkRed;
                    p.Inlines.Add(new Run
                    {
                        Text       = $" {action.State} ",
                        Background = back,
                        Foreground = Brushes.White
                    });
                }
            }

            // 转移方向
            if (action.Action.StartsWith("transfer")
                /*&& string.IsNullOrEmpty(action.TransferDirection) == false*/)
            {
                p.Inlines.Add(new Run
                {
                    Text       = GetTransferDirCaption(action.TransferDirection, action.Location) + " ",
                    Foreground = Brushes.White
                });
            }
            else
            {
                // 操作名称
                p.Inlines.Add(new Run
                {
                    Text       = GetOperationCaption(action.Action) + " ",
                    Foreground = Brushes.White
                });
            }

            string title = "";

            if (action.Entity != null)
            {
                title = MessageDocument.ShortTitle(action.Entity.Title);
                // 2020/5/6
                // 尝试从本地缓存中获取书目摘要
                if (string.IsNullOrEmpty(title))
                {
                    title = LibraryChannelUtil.GetBiblioSummaryFromLocal(action.Entity.GetOiPii(true));
                }
                if (string.IsNullOrEmpty(title))
                {
                    title = ShelfData.GetPiiString(action.Entity);
                }
                else
                {
                    // 2020/7/22
                    title = $"[{ShelfData.GetPiiString(action.Entity)}] {title}";
                }
            }
            else
            {
                title = "(action.Entity 为空)";
            }

            // 书目摘要
            if (string.IsNullOrEmpty(title) == false)
            {
                Run run = new Run(title);

                /*
                 * run.FontSize = 14;
                 * run.FontStyle = FontStyles.Normal;
                 * run.Background = Brushes.DarkRed;
                 * run.Foreground = Brushes.White;
                 */

                p.Inlines.Add(run);
            }

            // 对于上架/下架来说,还要补充显示一些细节信息:location 去向;和 currentLocation 去向
            if (action.Action.StartsWith("transfer"))
            {
                List <string> details = new List <string>();
                if (string.IsNullOrEmpty(action.Location) == false)
                {
                    details.Add($"调拨到:{action.Location}");
                }
                if (string.IsNullOrEmpty(action.CurrentShelfNo) == false)
                {
                    details.Add($"新架位:{action.CurrentShelfNo}");
                }
                p.Inlines.Add(new Run
                {
                    Text       = " " + StringUtil.MakePathList(details, " ") + " ",
                    Foreground = Brushes.Green
                });
            }

            // 错误码和错误信息
            if (string.IsNullOrEmpty(action.SyncErrorInfo) == false &&
                (action.State != "sync" || action.SyncErrorCode == "overflow"))
            {
                p.Inlines.Add(new Run
                {
                    Text       = "\r\n" + action.SyncErrorInfo,
                    Background = back,
                    Foreground = Brushes.White
                });
            }

            return(p);
        }
Example #4
0
        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();
                        }));
                    }
                }
            });
        }