Exemplo n.º 1
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            var source = this.DataGrid.ItemsSource as ObservableCollection <GroupBuyingCategoryInfo>;

            if (ValidationManager.Validate(this.GridMaintain))
            {
                if ((this.VM.SysNo ?? 0) > 0)
                {
                    facade.UpdateGroupBuyingCategory(this.VM, (o, a) =>
                    {
                        if (a.FaultsHandle())
                        {
                            return;
                        }

                        var item = source.FirstOrDefault(p => p.SysNo == VM.SysNo);
                        if (item != null)
                        {
                            int index = source.IndexOf(item);
                            source.RemoveAt(index);
                            source.Insert(index, a.Result);
                        }
                        //this.Window.Alert("保存成功!");
                        this.Window.Alert(ResGroupBuyingCategoryQuery.Info_SaveSuccess);
                    });
                }
                else
                {
                    facade.CreateGroupBuyingCategory(this.VM, (o, a) =>
                    {
                        if (a.FaultsHandle())
                        {
                            return;
                        }
                        if (source != null)
                        {
                            source.Add(a.Result);
                        }
                        //this.VM.SysNo = a.Result.SysNo;
                        this.VM = new GroupBuyingCategoryVM();
                        //this.Window.Alert("保存成功!");
                        this.Window.Alert(ResGroupBuyingCategoryQuery.Info_SaveSuccess);
                    });
                }
            }
        }