本文整理汇总了C#中BLToolkit.Data.DbManager.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# DbManager.BeginTransaction方法的具体用法?C# DbManager.BeginTransaction怎么用?C# DbManager.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLToolkit.Data.DbManager
的用法示例。
在下文中一共展示了DbManager.BeginTransaction方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test2
public void Test2()
{
using (DbManager db = new DbManager())
{
db.BeginTransaction(/*[a]*/IsolationLevel.ReadCommitted/*[/a]*/);
// ...
db.CommitTransaction();
}
}
示例2: Test1
public void Test1()
{
using (DbManager db = new DbManager())
{
db./*[a]*/BeginTransaction()/*[/a]*/;
// ...
db./*[a]*/CommitTransaction()/*[/a]*/;
}
}
示例3: Test
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();
}
}
示例4: Test
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();
}
}
示例5: Test
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();
}
}
示例6: RemoveJournalItem
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");
}
}
示例7: AddReduceItem
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");
}
}
}
示例8: AddJournalItem
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");
}
}
}
}
示例9: NonUpdatableOnInsert
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();
}
}
示例10: NonUpdatableOnUpdate
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();
}
}
示例11: Test3
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();
}
}
示例12: CreateParametersTest
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();
}
}
示例13: _btnDelete_Click
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);
}
}
}
示例14: Save
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;
}