private void addPhoto_Click(object sender, RoutedEventArgs e)
        {
            // Create a new PhotoInfo object.
            PhotoInfo newPhotoEntity = new PhotoInfo();

            // Ceate an new PhotoDetailsWindow instance with the current
            // context and the new photo entity.
            PhotoDetailsWindow addPhotoWindow =
                new PhotoDetailsWindow(newPhotoEntity, context);

            addPhotoWindow.Title = "Select a new photo to upload...";

            // We need to have the new entity tracked to be able to
            // call DataServiceContext.SetSaveStream.
            trackedPhotos.Add(newPhotoEntity);

            // If we successfully created the new image, then display it.
            if (addPhotoWindow.ShowDialog() == true)
            {
                // Set the index to the new photo.
                photoComboBox.SelectedItem = newPhotoEntity;
            }
            else
            {
                // Remove the new entity since the add operation failed.
                trackedPhotos.Remove(newPhotoEntity);
            }
        }
        private void HandleDeleteConstParam(ConstantParam a)
        {
            var delmodel = _selectedConstantParam;
            var msg      = new DialogMessage(string.Format("确定要删除参数:{0}吗?", delmodel.ParamName), result =>
            {
                if (result == System.Windows.MessageBoxResult.Yes)
                {
                    try
                    {
                        _constantParams.Remove(delmodel);
                        _allParams.Remove(delmodel);
                    }
                    catch (Exception ex)
                    {
                        Messenger.Default.Send <Exception>(ex);
                    }
                }
            });

            msg.Caption = "确定要删除吗?";
            msg.Button  = MessageBoxButton.YesNo;
            msg.Icon    = MessageBoxImage.Question;

            Messenger.Default.Send <DialogMessage>(msg);
        }
Beispiel #3
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> dsc = new DataServiceCollection <Customer>(context);

            try
            {
                dsc.Add(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                Assert.NotNull(e);
            }

            try
            {
                dsc.Remove(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                Assert.NotNull(e);
            }

            this.EnqueueTestComplete();
        }
Beispiel #4
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);

            try
            {
                DSC.Add(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Add");
            }

            try
            {
                DSC.Remove(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Remove");
            }

            this.EnqueueTestComplete();
        }
Beispiel #5
0
        private void HandleDeleteApp(App model)
        {
            model = _selectedApp;
            var msg = new DialogMessage(string.Format("确定要删除测点:{0}吗?", model.AppName), result =>
            {
                if (result == System.Windows.MessageBoxResult.Yes)
                {
                    try
                    {
                        _currentApps.Remove(model);
                        DbContext.SaveChanges();

                        //从视图中删除
                    }
                    catch (Exception ex)
                    {
                        Messenger.Default.Send <Exception>(ex);
                    }
                }
            });

            msg.Caption = "确定要删除吗?";
            msg.Button  = MessageBoxButton.YesNo;
            msg.Icon    = MessageBoxImage.Question;

            Messenger.Default.Send <DialogMessage>(msg);
        }
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            if (customerIDComboBox.SelectedItem != null)
            {
                // Get the Orders binding collection.
                DataServiceCollection <Order> trackedOrders =
                    ((Customer)(customerIDComboBox.SelectedItem)).Orders;

                // Remove the currently selected order.
                trackedOrders.Remove((Order)(ordersDataGrid.SelectedItem));
            }
        }
Beispiel #7
0
 private static void SelectFunctionItems(RoleDTO role, DataServiceCollection<FunctionItemDTO> functionItems)
 {
     for (int i = functionItems.Count - 1; i >= 0; i--)
     {
         var temp = functionItems[i];
         if (role.RoleFunctions.All(p => p.FunctionItemId != temp.Id))
         {
             functionItems.Remove(temp);
             continue;
         }
         SelectFunctionItems(role, temp.SubFunctionItems);
     }
 }
Beispiel #8
0
        public void AddDeleteEntitySave()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            dsc.Add(c);
            dsc.Remove(c);
            Assert.True(VerifyCtxCount(context, 0, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
Beispiel #9
0
        public void RemoveEntityTwice()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };
            Customer c2 = new Customer {
                CustomerId = 1003
            };

            DSC.Add(c);
            DSC.Add(c2);
            DSC.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            DSC.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));

            this.EnqueueTestComplete();
        }
Beispiel #10
0
        public void AddDeleteEntitySave()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            DSC.Add(c);
            DSC.Remove(c);
            Assert.True(VerifyCtxCount(context, 0, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
Beispiel #11
0
        public void DeletingInUnchangedState()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer unchanged = new Customer {
                CustomerId = 1002
            };

            DSC.Add(unchanged);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            this.CheckState(context, EntityStates.Unchanged, unchanged);
            VerifyCtxCount(context, 1, 0);
            DSC.Remove(unchanged);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Beispiel #12
0
        public void DeletingInDeletedState()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> dsc = new DataServiceCollection <Customer>(context);
            Customer deleted = new Customer {
                CustomerId = 1004
            };

            dsc.Add(deleted);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            context.DeleteObject(deleted);
            this.CheckState(context, EntityStates.Deleted, deleted);
            VerifyCtxCount(context, 1, 0);
            dsc.Remove(deleted);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Beispiel #13
0
        public void AddSaveRemoveSaveEntity()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> dsc = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            dsc.Add(c);
            this.CheckState(context, EntityStates.Added, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 1, 0));
            dsc.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
Beispiel #14
0
        public void RemoveParentEntityWithLinks()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            DSC.Add(c);
            Order o = new Order {
                OrderId = 2001, Customer = c, CustomerId = 1002
            };

            c.Orders.Add(o);
            VerifyCtxCount(context, 2, 1);
            DSC.Remove(c);
            VerifyCtxCount(context, 0, 0);
            SaveChanges(context);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Beispiel #15
0
        public void DeletingInDeletedState()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            Customer deleted = new Customer { CustomerId = 1004 };
            DSC.Add(deleted);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            context.DeleteObject(deleted);
            this.CheckState(context, EntityStates.Deleted, deleted);
            VerifyCtxCount(context, 1, 0);
            DSC.Remove(deleted);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Beispiel #16
0
        public void AddSaveRemoveSaveEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            DSC.Add(c);
            this.CheckState(context, EntityStates.Added, c);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));
            DSC.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.IsTrue(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
Beispiel #17
0
        public void RemoveEntityTwice()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            Customer c2 = new Customer { CustomerId = 1003 };
            dsc.Add(c);
            dsc.Add(c2);
            dsc.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            dsc.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));

            this.EnqueueTestComplete();
        }
Beispiel #18
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            try
            {
                DSC.Add(null);
                Assert.Fail("Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
#if !PORTABLELIB && !SILVERLIGHT
                 StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Add" );
#else
                Assert.IsNotNull(e);
#endif

            }

            try
            {
                DSC.Remove(null);
                Assert.Fail("Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
#if !PORTABLELIB && !SILVERLIGHT
                StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Remove");
#else
                Assert.IsNotNull(e);
#endif
                
                }

            this.EnqueueTestComplete();
        }
        private void HandleDeleteCalcDate(object a)
        {
            var delDate = CurrentDate;
            var msg     = new DialogMessage(string.Format("确定要删该时间点{0}的公式吗?", delDate.ToString("u")), result =>
            {
                if (result == System.Windows.MessageBoxResult.Yes)
                {
                    try
                    {
                        DateTimeOffset prefixDate = (from i in _dates
                                                     where i < CurrentDate
                                                     orderby i descending
                                                     select i).FirstOrDefault();
                        //当没有之前的时间时,preDate为DateTime.MinDate
                        DateTimeOffset suffixDate = (from i in _dates
                                                     where i > CurrentDate
                                                     orderby i ascending
                                                     select i).FirstOrDefault();

                        if (suffixDate == DateTimeOffset.MinValue)
                        {
                            //没有后缀的时间,要删除的项为最为一个时刻
                            suffixDate = Hammergo.GlobalConfig.PubConstant.OverTime;
                        }

                        //删除
                        var delList = (from i in _allFormulae
                                       where i.StartDate == CurrentDate
                                       select i).ToList();

                        foreach (var delItem in delList)
                        {
                            _allFormulae.Remove(delItem);
                        }

                        //修正前一个时刻点的公式结束时刻
                        var modifyList = (from i in _allFormulae
                                          where i.StartDate == prefixDate
                                          select i).ToList();

                        foreach (var modifyItem in modifyList)
                        {
                            modifyItem.EndDate = suffixDate;
                        }

                        Dates.Remove(CurrentDate);
                        //让当前时刻为第一个
                    }
                    catch (Exception ex)
                    {
                        Messenger.Default.Send <Exception>(ex);
                    }
                }
            });

            msg.Caption = "确定要删除吗?";
            msg.Button  = MessageBoxButton.YesNo;
            msg.Icon    = MessageBoxImage.Question;

            Messenger.Default.Send <DialogMessage>(msg);
        }
Beispiel #20
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            try
            {
                dsc.Add(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                Assert.NotNull(e);
            }

            try
            {
                dsc.Remove(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                Assert.NotNull(e);
            }

            this.EnqueueTestComplete();
        }
Beispiel #21
0
        public void DeletingInUnchangedState()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer unchanged = new Customer { CustomerId = 1002 };
            dsc.Add(unchanged);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            this.CheckState(context, EntityStates.Unchanged, unchanged);
            VerifyCtxCount(context, 1, 0);
            dsc.Remove(unchanged);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Beispiel #22
0
        public void RemoveChildEntityWithLinks()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            DataServiceCollection<Order> dscOrder = new DataServiceCollection<Order>(context);
            Customer c = new Customer { CustomerId = 1002 };
            dsc.Add(c);
            Order o = new Order { OrderId = 2001, Customer = c, CustomerId = 1002 };
            c.Orders.Add(o);
            VerifyCtxCount(context, 2, 1);
            dscOrder.Remove(o);
            VerifyCtxCount(context, 1, 0);
            SaveChanges(context);
            VerifyCtxCount(context, 1, 0);

            this.EnqueueTestComplete();
        }