Ejemplo n.º 1
0
        public override void Execute(ListLogicalView view)
        {
            var category = view.Current as TaskOrCategory;
            if (category.IsTaskRO)
            {
                category = category.TreeParent as TaskOrCategory;
            }

            var task = view.CreateNewItem() as TaskOrCategory;

            var weeksCount = task.MonthPlan.WeeksCountRO;
            for (int i = 0; i < weeksCount; i++)
            {
                task.WeekCompletionList.Add(new WeekCompletion
                {
                    Index = i + 1
                });
            }

            task.WeightInCategory = 1;
            task.Score = 0;
            task.ObjectiveNum = 1;//放在添加 WeekCompletionList 之后

            category.TreeChildren.Add(task);

            view.RefreshControl();

            view.Current = task;

            CommandsHelper.EditCurrent(view);
        }
Ejemplo n.º 2
0
        public override void Execute(ListLogicalView view)
        {
            var barcode = BarcodeTextBoxGenerator.GetTextBoxParameter(this);

            if (!string.IsNullOrEmpty(barcode))
            {
                var list = view.Data;
                var item = list.Cast<ProductRefItem>().FirstOrDefault(i => i.Product.Barcode == barcode);
                if (item != null)
                {
                    item.Amount++;
                }
                else
                {
                    var product = RF.Concrete<ProductRepository>().GetByBarcode(barcode);
                    if (product == null)
                    {
                        App.MessageBox.Show(string.Format("没有找到对应 {0} 的商品".Translate(), barcode), MessageBoxImage.Error);
                        return;
                    }

                    item = view.CreateNewItem().CastTo<ProductRefItem>();
                    item.Product = product;
                    item.Amount = 1;
                    list.Add(item);
                    view.RefreshControl();
                }

                view.Current = item;
            }
        }
Ejemplo n.º 3
0
        public override void Execute(ListLogicalView view)
        {
            var category = view.CreateNewItem() as TaskOrCategory;

            category.MonthPercent = 0;
            category.MonthScore = 0;

            view.Data.Add(category);

            view.RefreshControl();

            view.Current = category;

            CommandsHelper.EditCurrent(view);
        }
Ejemplo n.º 4
0
        public override void Execute(ListLogicalView view)
        {
            //创建一个临时的拷贝数据
            var tmp = view.CreateNewItem();

            var evm = view.Meta;
            var result = PopupEditingDialog(evm, tmp, w =>
            {
                w.Title = this.Meta.Label.Translate() + " " + evm.Label.Translate();
            });

            //如果没有点击确定,则删除刚才添加的记录。
            if (result == WindowButton.Yes)
            {
                //先添加一行记录
                var curEntity = view.AddNew(false);

                var oldTreeCode = string.Empty;
                object oldTreePId = null;
                if (evm.EntityMeta.IsTreeEntity)
                {
                    oldTreeCode = curEntity.TreeIndex;
                    oldTreePId = curEntity.TreePId;
                }

                curEntity.Clone(tmp, new CloneOptions(
                    CloneActions.NormalProperties | CloneActions.RefEntities
                    ));

                //如果用户没有设置树型编码,则把树型编码还原到 Clone 之前系统自动生成的编码
                if (!string.IsNullOrEmpty(oldTreeCode) &&
                    string.IsNullOrEmpty(curEntity.TreeIndex) &&
                    view.Data.AutoTreeIndexEnabled)
                {
                    curEntity.TreeIndex = oldTreeCode;
                    curEntity.TreePId = oldTreePId;
                }

                this.OnDataCloned(curEntity, tmp);

                view.RefreshControl();
                view.Current = curEntity;
            }
        }
Ejemplo n.º 5
0
        public override void Execute(ListLogicalView view)
        {
            //创建一个临时的拷贝数据
            var tmpEntity = view.CreateNewItem();

            //弹出窗体显示详细面板
            this.Template.EntityType = view.EntityType;
            var ui = this.Template.CreateUI();

            var detailView = ui.MainView.CastTo<DetailLogicalView>();
            detailView.Data = tmpEntity;

            App.Windows.ShowDialog(ui.Control, w =>
            {
                w.Buttons = ViewDialogButtons.YesNo;
                w.Title = this.Meta.Label.Translate() + " " + view.Meta.Label.Translate();

                //验证
                w.ValidateOperations += (o, e) =>
                {
                    var broken = tmpEntity.Validate();
                    if (broken.Count > 0)
                    {
                        App.MessageBox.Show(broken.ToString(), "属性错误".Translate(), MessageBoxButton.OK, MessageBoxImage.Error);
                        e.Cancel = true;
                    }
                };

                //焦点
                w.Loaded += (o, e) =>
                {
                    var txt = w.GetVisualChild<TextBox>();
                    if (txt != null) { Keyboard.Focus(txt); }
                };

                //窗口在数据改变后再关闭窗口,需要提示用户是否保存。
                tmpEntity.MarkSaved();
                w.Closing += (o, e) =>
                {
                    if (w.DialogResult != true)
                    {
                        if (tmpEntity.IsDirty)
                        {
                            var res = App.MessageBox.Show("直接退出将不会保存数据,是否退出?".Translate(), MessageBoxButton.YesNo, MessageBoxImage.Warning);
                            e.Cancel = res == MessageBoxResult.No;
                        }
                    }
                    else
                    {
                        //如果保存的过程中发生异常,不要关闭当前窗口
                        try
                        {
                            this.OnServiceInvoking(detailView, e);
                            if (e.Cancel) return;

                            tmpEntity.PersistenceStatus = PersistenceStatus.New;

                            this.Service.Item = tmpEntity;
                            this.Service.Invoke();

                            App.MessageBox.Show(this.Service.Result.Message.Translate());

                            if (!this.Service.Result.Success)
                            {
                                e.Cancel = true;
                            }
                            else
                            {
                                tmpEntity.Id = this.Service.NewId;
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.Alert();
                            e.Cancel = true;
                        }

                        if (!e.Cancel)
                        {
                            view.DataLoader.ReloadDataAsync(() =>
                            {
                                view.Current = view.Data.FirstOrDefault(en => en.Id == tmpEntity.Id);
                            });
                        }
                    }
                };
            });
        }
Ejemplo n.º 6
0
        public override void Execute(ListLogicalView view)
        {
            var list = view.Data;
            if (list == null) throw new ArgumentNullException("list");

            var current = view.Current;

            var newEntity = view.CreateNewItem();

            var parentList = GetParentList(current);
            var index = parentList.IndexOf(current);
            parentList.Insert(index, newEntity);

            view.RefreshControl();
            view.Current = newEntity;
        }