Пример #1
0
        public void RemoveJournalItem()
        {
            if (CanRemoveItem && null != selectedItem &&
                MessageBox.Show(string.Format("Ви впевнені що хочете вилучити позицію \"{0}\"?",selectedItem.Name), "вилучення", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (DbManager db = new DbManager())
                {
                    db.BeginTransaction();
                    try
                    {
                        if (selectedItem.Tovar != null && !selectedItem.IsRent)
                        {
                            //add ostatok in tovar
                            selectedItem.Tovar.Ostatok += (int)selectedItem.Amount;
                            SqlQuery<Tovar> query2 = new SqlQuery<Tovar>(db);
                            query2.Update(selectedItem.Tovar);
                        }
                        //insert new journal item
                        SqlQuery<Journal> query = new SqlQuery<Journal>(db);
                        query.Delete(selectedItem);
                        db.CommitTransaction();
                    }
                    catch
                    {
                        db.RollbackTransaction();
                        throw;
                    }

                }
                PropertyChange("JournalList");
                PropertyChange("DaySum");
                PropertyChange("InKasaSum");
            }
        }
Пример #2
0
        public void AddReduceItem()
        {
            if (selectedReduce != null)
            {
                Journal newJournal = new Journal()
                {
                    Amount = 1,
                    Discount = 0,
                    ID_Partner = selectedReduce.ID_Partner,
                    Partner = selectedReduce,
                    User = User.CurrentUser,
                    ID_User = User.CurrentUser.ID_User,
                    Price = 0,
                    SaleDate = CurrentDate
                };

                JournalItemView view = new JournalItemView();
                view.DataContext = new JournalItemViewModel() { Item = newJournal };
                if (view.ShowDialog() == true)
                {
                    using (DbManager db = new DbManager())
                    {
                        db.BeginTransaction();
                        try
                        {
                            //inser new journal item
                            SqlQuery<Journal> query = new SqlQuery<Journal>(db);
                            query.Insert(newJournal);
                            db.CommitTransaction();
                        }
                        catch
                        {
                            db.RollbackTransaction();
                            throw;
                        }

                    }
                    PropertyChange("JournalList");
                    PropertyChange("DaySum");
                    PropertyChange("InKasaSum");

                }
            }
        }
Пример #3
0
		public void NonUpdatableOnInsert()
		{
			using (var db = new DbManager())
			{
				db.BeginTransaction();

				new SqlQuery<Person1>().Insert(db, new Person1
				{
					FirstName  = "TestOnInsert",
					LastName   = "",
					MiddleName = "1",
					Gender     = 'M'
				});

				var p = db.GetTable<Person1>().Single(_ => _.FirstName == "TestOnInsert");

				Assert.AreNotEqual("1", p.MiddleName);

				db.RollbackTransaction();
			}
		}
Пример #4
0
        public void AddJournalItem()
        {
            if (!CanAddItem)
                return;
            FindWindow findWindow = new FindWindow();
            FindViewModel viewModel = new FindViewModel();
            //viewModel.SelectedTovar = viewModel.TovarList[0];
            findWindow.DataContext = viewModel;
            if (findWindow.ShowDialog() == true)
            {
                if (viewModel.SelectedTovar != null)
                {
                    Journal newJournal = new Journal()
                    {
                        Amount = 1,
                        Discount = 0,
                        ID_Tovar = viewModel.SelectedTovar.ID_Tovar,
                        Tovar = viewModel.SelectedTovar,
                        User = User.CurrentUser,
                        ID_User = User.CurrentUser.ID_User,
                        Price = viewModel.SelectedTovar.CinaProdazh,
                        SaleDate = CurrentDate
                    };
                    JournalItemView view = new JournalItemView();
                    view.DataContext = new JournalItemViewModel() { Item = newJournal };
                    if (view.ShowDialog() == true)
                    {
                        using (DbManager db = new DbManager())
                        {
                            db.BeginTransaction();
                            try
                            {
                                //inser new journal item
                                SqlQuery<Journal> query = new SqlQuery<Journal>(db);
                                query.Insert(newJournal);

                                if (!newJournal.IsRent) // if it's rent - reduce amount is not needed
                                {
                                    //reduce ostatok in tovar
                                    newJournal.Tovar.Ostatok -= (int) newJournal.Amount;
                                    SqlQuery<Tovar> query2 = new SqlQuery<Tovar>(db);
                                    query2.Update(newJournal.Tovar);
                                }
                                db.CommitTransaction();
                            }
                            catch {
                                db.RollbackTransaction();
                                throw;
                            }

                        }
                        PropertyChange("JournalList");
                        PropertyChange("DaySum");
                        PropertyChange("InKasaSum");

                    }
                }

            }
        }
Пример #5
0
		public void NonUpdatableOnUpdate()
		{
			using (var db = new DbManager())
			{
				db.BeginTransaction();

				var person = new Person1
				{
					FirstName  = "TestOnInsert",
					LastName   = "",
					MiddleName = "1",
					Gender     = 'M'
				};

				var sqlQuery = new SqlQuery<Person1>();

				sqlQuery.Insert(db, person);

				var p = db.GetTable<Person1>().Single(_ => _.FirstName == "TestOnInsert");

				Assert.AreEqual(person.MiddleName, p.MiddleName);

				person.PersonID   = p.PersonID;
				person.MiddleName = "should not be updated";

				sqlQuery.Update(db, person);

				p = db.GetTable<Person1>().Single(_ => _.FirstName == "TestOnInsert");

				Assert.AreNotEqual(person.MiddleName, p.MiddleName);
				
				db.RollbackTransaction();
			}
		}