Exemple #1
0
        void ProcessTag(TagAndData tag)
        {
            var entity = InventoryData.AddEntity(tag, out bool isNewly);

            var info = entity.Tag as ProcessInfo;

            if (info == null)
            {
                info       = new ProcessInfo();
                entity.Tag = info;
            }

            if (isNewly)
            {
                App.Invoke(new Action(() =>
                {
                    _entities.Add(entity);
                }));
            }

            if (string.IsNullOrEmpty(entity.PII) == false &&
                string.IsNullOrEmpty(info.State))
            {
                info.State = "processing";
                InventoryData.AppendList(entity);
                InventoryData.ActivateInventory();
            }
        }
Exemple #2
0
 private void clearList_Click(object sender, RoutedEventArgs e)
 {
     App.Invoke(new Action(() =>
     {
         _entities.Clear();
     }));
     InventoryData.Clear();
 }
Exemple #3
0
 void ClearList()
 {
     App.Invoke(new Action(() =>
     {
         _entities.Clear();
     }));
     InventoryData.Clear();
     InventoryData.CurrentShelfNo = null;
 }
Exemple #4
0
 void RemoveEntity(Entity entity)
 {
     // 删除这个事项,以便后面可以重新处理
     App.Invoke(new Action(() =>
     {
         _entities.Remove(entity);
     }));
     InventoryData.RemoveEntity(entity);
 }
Exemple #5
0
        private void PageInventory_Loaded(object sender, RoutedEventArgs e)
        {
            App.NewTagChanged        += CurrentApp_NewTagChanged;
            App.IsPageInventoryActive = true;

            _ = Task.Run(() =>
            {
                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();
                    }));
                }
            });
        }
Exemple #6
0
        public static Entity AddEntity(TagAndData tag, out bool isNewly)
        {
            if (_entityTable.ContainsKey(tag.OneTag.UID))
            {
                // TODO: 更新 tagInfo
                isNewly = false;
                Entity result = _entityTable[tag.OneTag.UID] as Entity;
                InventoryData.NewEntity(tag, result, false);
                return(result);
            }

            var entity = InventoryData.NewEntity(tag, null, false);

            _entityTable[entity.UID] = entity;
            isNewly = true;
            return(entity);
        }
Exemple #7
0
        void ProcessTag(BaseChannel <IRfid> channel, TagAndData tag)
        {
            var entity = InventoryData.AddEntity(tag, out bool isNewly);

            var info = entity.Tag as ProcessInfo;

            if (info == null)
            {
                info       = new ProcessInfo();
                entity.Tag = info;
            }

            if (isNewly)
            {
                App.Invoke(new Action(() =>
                {
                    _entities.Add(entity);
                }));
            }

            FillEntity(channel, entity);
        }
Exemple #8
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();
                        }));
                    }
                }
            });
        }
Exemple #9
0
        void FillEntity(BaseChannel <IRfid> channel,
                        Entity entity,
                        delegate_speakLocation func_speakLocation)
        {
            var info = entity.Tag as ProcessInfo;

            // 是否强迫获取标签内容
            bool force = info.GetTagInfoError == "errorGetTagInfo" ||
                         StringUtil.IsInList("verifyEAS", ActionMode);

            // bool force = info.GetTagInfoError == "errorGetTagInfo"; // testing

            // 2020/10/7
            // 尝试获取 PII
            if (string.IsNullOrEmpty(entity.PII) ||
                force)
            {
                if (InventoryData.UidExsits(entity.UID, out string pii) &&
                    force == false)
                {
                    entity.PII = pii;
                    var set_result = SetTargetCurrentLocation(info);
                    if (set_result.Value == -1 && set_result.ErrorCode == "noCurrentShelfNo")
                    {
                        // 删除这个事项,以便后面可以重新处理
                        RemoveEntity(entity);
                    }
                }
                else
                {
                    string error = null;
                    if (channel.Started == false)
                    {
                        error = "22 RFID 通道尚未启动";
                    }
                    else
                    {
                        var get_result = channel.Object.GetTagInfo(entity.ReaderName, entity.UID, Convert.ToUInt32(entity.Antenna), "quick");

                        /*
                         * // testing
                         * get_result.Value = -1;
                         * get_result.ErrorInfo = "GetTagInfo() error error 1234 error 1345";
                         */

                        if (get_result.Value == -1)
                        {
                            SoundMaker.ErrorSound();

                            // 朗读出错 entity 数量
                            var count = InventoryData.AddErrorEntity(entity, out bool changed);
                            if (changed == true)
                            {
                                App.CurrentApp.SpeakSequence(count.ToString());
                            }

                            info.GetTagInfoError = "errorGetTagInfo";
                            info.ErrorCount++;
                            error = get_result.ErrorInfo;

                            // TODO: 当有一行以上 GetTagInfo() 出错时,要不断发出响声警告。
                            entity.Error = error;

                            if (info.ErrorCount > 5)
                            {
                                if (func_speakLocation?.Invoke(entity) == true)
                                {
                                    info.ErrorCount = 0;
                                }
                            }
                        }
                        else
                        {
                            entity.Error = null;

                            // 把 PII 显示出来
                            InventoryData.UpdateEntity(entity,
                                                       get_result.TagInfo,
                                                       out string type);
                            info.GetTagInfoError = "";

                            // 层架标
                            if (type == "location")
                            {
                                info.IsLocation = true;
                                if (string.IsNullOrEmpty(entity.PII) == false)
                                {
                                    // 设置当前层架标
                                    SwitchCurrentShelfNo(entity);
                                }
                            }
                            else
                            {
                                var set_result = SetTargetCurrentLocation(info);
                                if (set_result.Value == -1 && set_result.ErrorCode == "noCurrentShelfNo")
                                {
                                    // 删除这个事项,以便后面可以重新处理
                                    RemoveEntity(entity);
                                }
                            }

                            // 朗读出错 entity 数量
                            var count = InventoryData.RemoveErrorEntity(entity, out bool changed);
                            if (changed == true)
                            {
                                App.CurrentApp.SpeakSequence(count.ToString());
                            }

                            if (StringUtil.IsInList("blankTag", entity.ErrorCode))
                            {
                                App.CurrentApp.SpeakSequence(entity.Error);
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        // 筛选出需要 GetTagInfo() 的那些标签
        async Task FilterTags(BaseChannel <IRfid> channel, List <TagAndData> tags)
        {
            // PII 尚为空的那些 entities
            List <Entity> empty_piis = new List <Entity>();

            // 其他 entities
            List <Entity> rests = new List <Entity>();

            foreach (var tag in tags)
            {
                var entity = InventoryData.AddEntity(tag, out bool isNewly);
                var info   = entity.Tag as ProcessInfo;
                if (info == null)
                {
                    info       = new ProcessInfo();
                    entity.Tag = info;
                }

                if (isNewly)
                {
                    App.Invoke(new Action(() =>
                    {
                        _entities.Add(entity);
                    }));
                }

                if (string.IsNullOrEmpty(entity.PII))
                {
                    empty_piis.Add(entity);
                }
                else
                {
                    // 对 PII 不为空的,但有任务没有完成的,要加入列表寻求再次被后台处理
                    rests.Add(entity);

                    /*
                     * if (info.IsLocation == false)
                     * {
                     *  InventoryData.AppendList(entity);
                     *  InventoryData.ActivateInventory();
                     * }
                     */
                }

                // 如果发现 PII 不为空的层架标,要用于切换当前 CurrentShelfNo
                if (info != null && info.IsLocation == true)
                {
                    SwitchCurrentShelfNo(entity);
                    if (isNewly == false)
                    {
                        App.Invoke(new Action(() =>
                        {
                            _entities.MoveToTail(entity);
                        }));
                    }
                }
            }

            // 准备音阶
            SoundMaker.InitialSequence(empty_piis.Count);

            bool speaked = false;

            // 集中 GetTagInfo()
            foreach (var entity in empty_piis)
            {
                var info = entity.Tag as ProcessInfo;

                SoundMaker.NextSound();

                FillEntity(channel, entity,
                           (e) =>
                {
                    // 说过一次便不再说
                    if (speaked == true)
                    {
                        return(false);
                    }
                    speaked = SpeakLocation(e);
                    return(speaked);
                });

                // 进入后台队列
                if (string.IsNullOrEmpty(entity.PII) == false &&
                    info.IsLocation == false)
                {
                    InventoryData.AppendList(entity);
                    InventoryData.ActivateInventory();
                }
            }

            // 停止音阶响声
            SoundMaker.StopCurrent();

            // 其余的也要进入后台队列
            foreach (var entity in rests)
            {
                var info = entity.Tag as ProcessInfo;
                if (info.IsLocation == true)
                {
                    continue;
                }

                // 尝试重新赋予目标 location 和 currentLocation,观察参数是否发生变化、重做后台任务
                var old_targetLocation        = info.TargetLocation;
                var old_targetShelfNo         = info.TargetShelfNo;
                var old_targetCurrentLocation = info.TargetCurrentLocation;
                var result = SetTargetCurrentLocation(info);
                if (result.Value != -1)
                {
                    if (old_targetLocation != info.TargetLocation ||
                        old_targetShelfNo != info.TargetShelfNo ||
                        old_targetCurrentLocation != info.TargetCurrentLocation)
                    {
                        // 删除条目,这样可以迫使用新 target 重做后台任务
                        info.SetTaskInfo("setLocation", null);
                        // 视觉上移动到最末行,让操作者意识到发生了重做后台任务
                        App.Invoke(new Action(() =>
                        {
                            _entities.MoveToTail(entity);
                        }));
                    }
                }

                if (string.IsNullOrEmpty(entity.PII) == false &&
                    info.IsLocation == false)
                {
                    InventoryData.AppendList(entity);
                    InventoryData.ActivateInventory();
                }
            }

            // 2020/11/9
            // 执行修改 EAS 任务
            foreach (var entity in rests)
            {
                var info = entity.Tag as ProcessInfo;

                // 如果有以前尚未执行成功的修改 EAS 的任务,则尝试再执行一次
                if (info != null &&
                    info.TargetEas != null &&
                    info.ContainTask("changeEAS") == true &&
                    info.IsTaskCompleted("changeEAS") == false)
                {
                    try
                    {
                        if (info.TargetEas == "?")
                        {
                            await InventoryData.VerifyEasAsync(entity);
                        }
                        else
                        {
                            // TODO: 记载轮空和出错的次数。
                            // result.Value
                            //      -1  出错
                            //      0   标签不在读卡器上所有没有执行
                            //      1   成功执行修改
                            await InventoryData.TryChangeEasAsync(entity, info.TargetEas == "on");
                        }
                    }
                    catch (Exception ex)
                    {
                        WpfClientInfo.WriteErrorLog($"FilterTags() 出现异常: {ExceptionUtil.GetDebugText(ex)}");
                        App.SetError("processing", $"FilterTags() 出现异常: {ex.Message}");
                    }
                }
            }
        }
Exemple #11
0
        void FillEntity(BaseChannel <IRfid> channel,
                        Entity entity,
                        delegate_speakLocation func_speakLocation)
        {
            var info = entity.Tag as ProcessInfo;

            // 2020/10/7
            // 尝试获取 PII
            if (string.IsNullOrEmpty(entity.PII))
            {
                if (InventoryData.UidExsits(entity.UID, out string pii))
                {
                    entity.PII = pii;
                }
                else
                {
                    string error = null;
                    if (channel.Started == false)
                    {
                        error = "RFID 通道尚未启动";
                    }
                    else
                    {
                        var get_result = channel.Object.GetTagInfo(entity.ReaderName, entity.UID, Convert.ToUInt32(entity.Antenna), "quick");

                        /*
                         * // testing
                         * get_result.Value = -1;
                         * get_result.ErrorInfo = "GetTagInfo() error error 1234 error 1345";
                         */

                        if (get_result.Value == -1)
                        {
                            SoundMaker.ErrorSound();

                            // 朗读出错 entity 数量
                            var count = InventoryData.AddErrorEntity(entity, out bool changed);
                            if (changed == true)
                            {
                                App.CurrentApp.SpeakSequence(count.ToString());
                            }

                            info.State = "errorGetTagInfo";
                            info.ErrorCount++;
                            error = get_result.ErrorInfo;

                            // TODO: 当有一行以上 GetTagInfo() 出错时,要不断发出响声警告。
                            entity.Error = error;

                            if (info.ErrorCount > 5)
                            {
                                if (func_speakLocation?.Invoke(entity) == true)
                                {
                                    info.ErrorCount = 0;
                                }
                            }
                        }
                        else
                        {
                            entity.Error = null;

                            // 把 PII 显示出来
                            InventoryData.UpdateEntity(entity, get_result.TagInfo);
                            info.State = "";

                            // 朗读出错 entity 数量
                            var count = InventoryData.RemoveErrorEntity(entity, out bool changed);
                            if (changed == true)
                            {
                                App.CurrentApp.SpeakSequence(count.ToString());
                            }

                            if (StringUtil.IsInList("blankTag", entity.ErrorCode))
                            {
                                App.CurrentApp.SpeakSequence(entity.Error);
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(entity.PII) == false &&
                string.IsNullOrEmpty(info.State))
            {
                info.State = "processing";  // 正在获取册信息
                InventoryData.AppendList(entity);
                InventoryData.ActivateInventory();
            }
        }
Exemple #12
0
        // 筛选出需要 GetTagInfo() 的那些标签
        void FilterTags(BaseChannel <IRfid> channel, List <TagAndData> tags)
        {
            List <Entity> entities1 = new List <Entity>();
            List <Entity> all       = new List <Entity>();

            foreach (var tag in tags)
            {
                var entity = InventoryData.AddEntity(tag, out bool isNewly);
                var info   = entity.Tag as ProcessInfo;
                if (info == null)
                {
                    info       = new ProcessInfo();
                    entity.Tag = info;
                }

                if (isNewly)
                {
                    App.Invoke(new Action(() =>
                    {
                        _entities.Add(entity);
                    }));
                }

                if (string.IsNullOrEmpty(entity.PII))
                {
                    entities1.Add(entity);
                }

                all.Add(entity);
            }

            // 准备音阶
            SoundMaker.InitialSequence(entities1.Count);

            bool speaked = false;

            // 集中 GetTagInfo()
            foreach (var entity in entities1)
            {
                SoundMaker.NextSound();

                FillEntity(channel, entity,
                           (e) =>
                {
                    // 说过一次便不再说
                    if (speaked == true)
                    {
                        return(false);
                    }
                    speaked = SpeakLocation(e);
                    return(speaked);
                });
            }

            // 停止音阶响声
            SoundMaker.StopCurrent();

            // 获取题名等
            foreach (var entity in all)
            {
                var info = entity.Tag as ProcessInfo;

                if (string.IsNullOrEmpty(entity.PII) == false &&
                    string.IsNullOrEmpty(info.State))
                {
                    info.State = "processing";  // 正在获取册信息
                    InventoryData.AppendList(entity);
                    InventoryData.ActivateInventory();
                }
            }
        }