Exemple #1
0
		public void Test2()
		{
			using (DbManager db = new DbManager())
			{
				db.BeginTransaction(/*[a]*/IsolationLevel.ReadCommitted/*[/a]*/);

				// ...

				db.CommitTransaction();
			}
		}
Exemple #2
0
		public void Test1()
		{
			using (DbManager db = new DbManager())
			{
				db./*[a]*/BeginTransaction()/*[/a]*/;

				// ...

				db./*[a]*/CommitTransaction()/*[/a]*/;
			}
		}
Exemple #3
0
		public void Test()
		{
			List<Person> list = new List<Person>
			{
				new Person { FirstName = "John", LastName = "Smith", Gender = Gender.Male   },
				new Person { FirstName = "Jane", LastName = "Smith", Gender = Gender.Female }
			};

			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Prepare command.
				//
				db
					.SetSpCommand("Person_Insert",
						db.CreateParameters(list[0]))
					./*[a]*/Prepare/*[/a]*/();

				// Insert.
				//
				foreach (Person person in list)
				{
					db./*[a]*/AssignParameterValues/*[/a]*/(person);
					db.ExecuteNonQuery();
				}

				// Check the result.
				//
				list = db
					.SetCommand(
						"SELECT * FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					.ExecuteList<Person>();

				Assert.GreaterOrEqual(2, list.Count);

				// Cleanup.
				//
				db
					.SetCommand(
						"DELETE FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					.ExecuteNonQuery();

				db.CommitTransaction();
			}
		}
		public void Test()
		{
			List<Person> list = new List<Person>
			{
				new Person { FirstName = "John", LastName = "Smith", Gender = Gender.Male   },
				new Person { FirstName = "Jane", LastName = "Smith", Gender = Gender.Female }
			};

			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Execute.
				//
				db
					.SetSpCommand("Person_Insert")
					./*[a]*/ExecuteForEach/*[/a]*/<Person>(list);

				// Check the result.
				//
				list = db
					.SetCommand(
						"SELECT * FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					.ExecuteList<Person>();

				Assert.GreaterOrEqual(2, list.Count);

				// Cleanup.
				//
				db
					.SetCommand(
						"DELETE FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					.ExecuteNonQuery();

				db.CommitTransaction();
			}
		}
		public void Test()
		{
			Person person = new Person();

			person.FirstName = "John";
			person.LastName  = "Smith";
			person.Gender    = Gender.Male;

			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Execute.
				//
				db
					.SetSpCommand("Person_Insert", db.CreateParameters(person))
					./*[a]*/ExecuteNonQuery/*[/a]*/();

				// Check the result.
				//
				person = db
					.SetCommand(
						"SELECT * FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					.ExecuteObject<Person>();

				Assert.IsNotNull(person);

				// Cleanup.
				//
				db
					.SetCommand(
						"DELETE FROM Person WHERE LastName = @lastName",
						db.Parameter("@lastName", "Smith"))
					./*[a]*/ExecuteNonQuery/*[/a]*/();

				db.CommitTransaction();
			}
		}
        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");
            }
        }
        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");

                }
            }
        }
        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");

                    }
                }

            }
        }
Exemple #9
0
		public void Test3()
		{
			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Insert.
				//
				Person person = CreatePerson(db);

				Assert.IsNotNull(person);

				// Update.
				//
				Assert.AreEqual(Gender.Male, person.Gender);

				person.Gender = Gender.Female;

				person = UpdatePerson(db, person);

				Assert.AreEqual(Gender.Female, person.Gender);

				// Delete.
				//
				person = DeletePerson(db, person);

				Assert.IsNull(person);

				db.CommitTransaction();
			}
		}
Exemple #10
0
		public void CreateParametersTest()
		{
			Person person = new Person();

			person.FirstName = "John";
			person.LastName  = "Smith";
			person.Gender    = Gender.Male;

			using (DbManager db = new DbManager())
			{
				db.BeginTransaction();

				// Prepare command.
				//
				int id = db
					.SetSpCommand("Person_Insert",
						db./*[a]*/CreateParameters/*[/a]*/(person))
					.ExecuteScalar<int>();

				// Check the result.
				//
				person = db
					.SetCommand(
						"SELECT * FROM Person WHERE PersonID = @id",
						db.Parameter("@id", id))
					.ExecuteObject<Person>();

				Assert.IsNotNull(person);

				// Cleanup.
				//
				db
					.SetCommand(
						"DELETE FROM Person WHERE PersonID = @id",
						db.Parameter("@id", id))
					.ExecuteNonQuery();

				db.CommitTransaction();
			}
		}
Exemple #11
0
    private void _btnDelete_Click(object sender, EventArgs e)
    {
      if (_gvItems.CurrentRow != null)
      {
        DialogResult dr =
          MessageBox.Show(
            "Are you sure to delete the item?",
            "Warning",
            MessageBoxButtons.OKCancel,
            MessageBoxIcon.Question);

        if (dr == DialogResult.Cancel)
          return;

        GridItem gridItem = (GridItem)_gvItems.CurrentRow.DataBoundItem;

        try
        {
          UseWaitCursor = true;
          using (DbManager db = new DbManager())
          {
            db.BeginTransaction();
            new OrderAccessor().Delete(db, gridItem.Item);
            db.CommitTransaction();
          }
          UseWaitCursor = false;

          objectBinder.List.Remove(gridItem);
        }
        catch (Exception ex)
        {
          UseWaitCursor = false;
          MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
      }
    }
Exemple #12
0
    bool Save()
    {
      _order.OrderDateTime = _date.Value.Date;
      try
      {
        UseWaitCursor = true;

        using (DbManager db = new DbManager())
        {
          db.BeginTransaction();

          if (_new)
            new OrderAccessor().Insert(db, _order);
          else
            new OrderAccessor().Update(db, _order);

          OrderInventoryAccessor acc = new OrderInventoryAccessor();
          foreach (GridItem item in _gridItems)
          {
            item.Item.OrderId = _order.Id;
            if (_gridItems.NewItems.Contains(item))
              acc.Insert(db, item.Item);
            else
              acc.Update(db, item.Item);
          }

          foreach (GridItem item in _gridItems.DelItems)
            acc.Delete(db, item.Item);

          db.CommitTransaction();
        }

        UseWaitCursor = false;

      }
      catch (Exception ex)
      {
        UseWaitCursor = false;
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      return true;
    }