using Aurora.Api; using Aurora.View; using VisionCommon; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Reactive.Linq; using System.Windows; namespace VisionUI.Pattern { /// /// 바코드 로그 뷰 모델 /// public class BcrLogViewModel : NotifyPropertyChangedBase { private Logger _Logger = new Logger("BcrLogViewModel"); private ObservableCollection bcrResultItems; /// 바코드 결과 아이템 컬렉션 public ObservableCollection BcrResultItems { get => bcrResultItems; set => SetProperty(ref bcrResultItems, value); } private string dislayName; /// 디스플레이 이름 public string DisplayName { get => dislayName; set => SetProperty(ref dislayName, value); } private DateTime selectedDate; /// 선택 날짜 public DateTime SelectedDate { get => selectedDate; set { SetProperty(ref selectedDate, value); CalendarChanged(value); } } private SubSysInfo _SubSysInfo; private SubSysRecipe _SubSysRecipe; private CsvManager _CsvManager = new CsvManager(); /// /// 생성자 /// /// 서브 시스템 정보 public BcrLogViewModel(SubSysInfo subSysInfo) { _SubSysInfo = subSysInfo; _SubSysRecipe = VisionRecipeManager.GetSubSysRecipe(_SubSysInfo); DisplayName = _SubSysInfo.SubSysName + " " + _SubSysRecipe.FovRecipes[0].CamRecipe.CamId; BcrResultItems = new ObservableCollection(); SelectedDate = DateTime.Now.Date; SetObservable(); } private void SetObservable() { VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.UPDATE_BCR_RESULT). Where(x => x.From == _SubSysInfo.GetKey()).Subscribe(patternResult => UpdateBcrResult(patternResult)); } /// /// 바코드 결과 값 업데이트 /// /// 이벤트 메세지 public void UpdateBcrResult(EventMessage msg) { Application.Current.Dispatcher.BeginInvoke( new Action(() => { BcrResultItems.Add(BcrResultItemManager.GetBcrResultItem(_SubSysInfo, msg.Param as PatternResult)); })); } private void CalendarChanged(DateTime dateTime) { LoadCsv(dateTime); } private void LoadCsv(DateTime dateTime) { try { BcrResultItems?.Clear(); List items = _CsvManager.LoadCsv(_SubSysInfo, dateTime, eSaveDataType.BCR); if (items != null) { // 로드할 파일이 없으면 items가 null임. foreach (BcrResultItem item in items) { BcrResultItems.Add(item); } } } catch (Exception e) { _Logger.FuncE(e.Message); } } } }