Inheritance: Account.Entity.BaseEntiy
        private void GetManifestsCompleted(Task <List <Manifest> > task)
        {
            if (task.Exception != null)
            {
                this.RefreshingVisibility = Visibility.Collapsed;
                MessageBox.Show("获取消费明细出错!");
                return;
            }
            List <Manifest> list = task.Result;

            if (list == null || list.Count == 0)
            {
                this.RefreshingVisibility = Visibility.Collapsed;
                if (this._showNotFoundMessage)
                {
                    MessageBox.Show("未查询到相关消费明细!");
                }
                return;
            }
            ManifestModel model;

            foreach (Manifest m in list)
            {
                model = new ManifestModel(m);
                this._manifests.Add(model);
            }
            this.RefreshingVisibility = Visibility.Collapsed;
        }
        private void AddOrUpdate_HandleCompleted(object sender, EntityEventArgs e)
        {
            bool          isAdd  = e.IsAdd;
            ManifestModel entity = e.Entity as ManifestModel;

            if (isAdd)
            {
                if (this.Manifests.Count == 0)
                {
                    this.Manifests.Add(entity);
                    this._eventAggregator.GetEvent <ManifestRefreshEvent>().Publish(this.SelectedItem);
                    return;
                }
                if (entity.Date < this.Manifests.FirstOrDefault().Date)
                {
                    this.Manifests.Insert(0, entity);
                }
                else if (entity.Date > this.Manifests.Last().Date)
                {
                    this.Manifests.Add(entity);
                }
                else
                {
                    int           index  = -1;
                    var           items1 = this.Manifests.Where(x => x.Date == entity.Date);
                    ManifestModel item;
                    if (items1 != null)
                    {
                        item = items1.Where(x => x.Cost > entity.Cost).FirstOrDefault();
                        if (item == null)
                        {
                            item  = items1.LastOrDefault();
                            index = this.Manifests.IndexOf(item);
                            index++;
                        }
                        else
                        {
                            index = this.Manifests.IndexOf(item);
                        }
                    }
                    else
                    {
                        item  = this.Manifests.Where(x => x.Date > entity.Date).First();
                        index = this.Manifests.IndexOf(item);
                    }

                    this.Manifests.Insert(index, entity);
                }
            }
            else
            {
                ManifestModel item  = this.Manifests.Where(x => x.ID == entity.ID).First();
                int           index = this.Manifests.IndexOf(item);
                this.Manifests[index] = entity;
            }
            this.SelectedItem = entity;
            this._eventAggregator.GetEvent <ManifestRefreshEvent>().Publish(this.SelectedItem);
        }
 public AddOrUpdateManifest(ManifestModel model)
 {
     InitializeComponent();
     this.ViewModel = new VMAddOrUpdateManifest(model);
     this.ViewModel.HandleCompleted += new EventHandler<EntityEventArgs>(ViewModel_HandleCompleted);
     if (model == null)
     {
         this.Title = "添加消费明细";
     }
     else
     {
         this.Title = "编辑消费明细";
     }
 }
示例#4
0
 public VMAddOrUpdateManifest(ManifestModel model)
 {
     this._isAdd = model == null;
     if (_isAdd)
     {
         _model = new ManifestModel()
         {
             Date = DateTime.Now.Date
         };
     }
     else
     {
         _model = new ManifestModel()
         {
             ID     = model.ID,
             Date   = model.Date,
             Cost   = model.Cost,
             Remark = model.Remark
         };
     }
     this.Save             = new DelegateCommand(ExecuteSave);
     this._manifestManager = UnityContainerFactory.GetUnityContainer().Resolve <IManifestManager>();
 }