本文整理汇总了C#中PetaPoco.Database.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# Database.BeginTransaction方法的具体用法?C# Database.BeginTransaction怎么用?C# Database.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PetaPoco.Database
的用法示例。
在下文中一共展示了Database.BeginTransaction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnReView_ItemClick
void btnReView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var et = gcloginfail.GetFocusedDataSource<t_loginfail>();
if (null == et)
return;
if (MsgBox.ShowYesNoMessage(null,
string.Format("确定要将 {0} MAC:{1} 审核通过吗?", et.UserName, et.LoginMAC)) == System.Windows.Forms.DialogResult.No)
return;
var usr = GetCurUser<t_user>();
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Delete("t_loginfail", "Id", et, et.Id);
db.Execute(sql_addmac, et.LoginMAC, usr.UserName, usr.Guid);
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
#if DEBUG
throw;
#endif
}
}
using (var db = new Database()) {
var etfail = db.Fetch<t_loginfail>("select * from t_loginfail");
gcloginfail.DataSource = etfail;
gcloginfail.RefreshDataSource();
var etmac = db.Fetch<t_loginfail>("select * from t_mac");
gcMac.DataSource = etmac;
gcMac.RefreshDataSource();
}
}
示例2: btnOK_Click
private void btnOK_Click(object sender, EventArgs e)
{
if (!dxValidationProvider1.Validate())
return;
var odrs = gcOrder.GetDataSource<t_order>();
if (odrs == null || odrs.Count < 1) {
MsgBox.ShowMessage("提示", "没有添加商品不能保存!");
return;
}
if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.New) {
var trdnew = new t_trade() {
Guid = GuidKey,
ReceiverName = memgcEdt.GetSelectedValue().ReceiverName,
ReceiverMobile = memgcEdt.GetSelectedValue().ReceiverMobile,
ReceiverAddress = memgcEdt.GetSelectedValue().ReceiverAddress,
MemberGuid = memgcEdt.GetSelectedValue().Guid,
DeliveryDate = dateDeliveryDate.DateTime,
CreateDate = TimeSync.Default.CurrentSyncTime,
Creator = this.CurUser,
};
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Save(trdnew);
odrs.ForEach(k => db.Save(k));
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
} else if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit) {
using (var db = new Database()) {
var trd = db.FirstOrDefault<t_trade>(" where [email protected]", GuidKey);
trd.ReceiverName = memgcEdt.GetSelectedValue().ReceiverName;
trd.ReceiverMobile = txtMobile.Text;
trd.ReceiverAddress = txtReceiverAddress.Text;
trd.MemberGuid = memgcEdt.GetSelectedValue().Guid;
trd.DeliveryDate = TimeSync.Default.CurrentSyncTime;
trd.DeliveryDate = dateDeliveryDate.DateTime;
try {
db.BeginTransaction();
db.Save(trd);
db.Execute("delete t_order where [email protected]", trd.Guid);
odrs.ForEach(k => {
k.Id = 0;
db.Save(k);
});
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}
DialogResult = System.Windows.Forms.DialogResult.OK;
Close();
}
示例3: ResetDatabase
protected override void ResetDatabase()
{
using (var database = new Database("SQLiteTest"))
{
database.BeginTransaction();
database.Execute(new Sql("DELETE FROM Entity"));
database.Execute(new Sql("DELETE FROM sqlite_sequence WHERE name = @0", "Entity"));
database.CompleteTransaction();
}
}
示例4: btnOK_Click
private void btnOK_Click(object sender, EventArgs e)
{
if (MsgBox.ShowYesNoMessage(null, string.Format("确定要保存对角色:{0} 的修改吗?", roleGridEdit2.SelectedValue.Name))
== System.Windows.Forms.DialogResult.No)
return;
var role = roleGridEdit2.SelectedValue;
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Execute("delete from t_roleuser where [email protected]", role.Id);
var ets = gridalloc.GetDataSource<t_user>();
if (null != ets && ets.Count > 0)
foreach (var k in ets)//.ForEach(k =>
{
db.Insert(new t_roleuser {
Guid = Guid.NewGuid(),
RoleId = role.Id,
UserId = k.Id,
IsUsing = true,
Creator = this.CurUser,
CreateDate = TimeSync.Default.CurrentSyncTime
});
};
db.CompleteTransaction();
} catch (Exception ex) {
db.AbortTransaction();
throw;
}
}
MsgBox.ShowMessage(null, "保存成功!");
}
示例5: btnOK_Click
private void btnOK_Click(object sender, EventArgs e)
{
if (!dxValidationProvider1.Validate())
return;
var odrs = gcOrder.GetDataSource<t_retorder>();
if (odrs == null || odrs.Count < 1) {
MsgBox.ShowMessage("提示", "没有退货商品不能保存退货单!");
return;
}
if (odrs.Any(k=>string.IsNullOrEmpty(k.LocName))) {
MsgBox.ShowMessage("提示", "所有商品都必须选择库位!");
return;
}
if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.New) {
var rettrd = this.Trade;
rettrd.Guid = Guid.NewGuid();
rettrd.Id = 0;
rettrd.IsAudit = false;
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Save(rettrd);
odrs.ForEach(k => {
k.Guid = Guid.NewGuid();
k.Id = 0;
k.TradeGuid = rettrd.Guid;
db.Save(k);
});
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
} else if (EditMode == Ultra.Web.Core.Enums.EnViewEditMode.Edit) {
using (var db = new Database()) {
var trd = db.FirstOrDefault<t_rettrade>(" where [email protected]", GuidKey);
trd.ReceiverName = Trade.ReceiverName;
trd.ReceiverMobile = txtMobile.Text;
trd.ReceiverAddress = txtReceiverAddress.Text;
trd.MemberGuid = Trade.Guid;
trd.DeliveryDate = TimeSync.Default.CurrentSyncTime;
trd.DeliveryDate = dateDeliveryDate.DateTime;
try {
db.BeginTransaction();
db.Save(trd);
db.Execute("delete t_retorder where [email protected]", trd.Guid);
odrs.ForEach(k => {
k.Id = 0;
db.Save(k);
});
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}
DialogResult = System.Windows.Forms.DialogResult.OK;
Close();
}
示例6: btnOK_Click
private void btnOK_Click(object sender, EventArgs e)
{
var items = gcItem.GetDataSource<t_instockitem>();
if (items == null || items.Count < 1) {
MsgBox.ShowMessage("", "没有商品信息,不能保存!");
return;
}
if (items.Any(K => string.IsNullOrEmpty(K.ItemNo))) {
MsgBox.ShowMessage("", "商品信息不完整!");
return;
}
if (EditMode == Web.Core.Enums.EnViewEditMode.Edit) {
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Execute("delete t_instockitem where [email protected]", InStockNo);
InStock.Remark = txtRemark.Text;
InStock.Num = items.Sum(k => k.Num);
InStock.OuterNo = txtOuterNo.Text;
db.Save(InStock);
items.ForEach(k => { k.Id = 0; db.Save(k); });
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
} else {
InStock = new t_instock();
InStock.Remark = txtRemark.Text;
InStock.Guid = GuidKey;
InStock.InStockNo = InStockNo;
InStock.OuterNo = txtOuterNo.Text;
InStock.Creator = this.CurUser;
InStock.AuditDate = InStock.CreateDate = TimeSync.Default.CurrentSyncTime;
InStock.Num = items.Sum(k => k.Num);
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Save(InStock);
items.ForEach(k => db.Save(k));
db.CompleteTransaction();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}
DialogResult = DialogResult.OK;
Close();
}
示例7: btnReView_ItemClick
void btnReView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var trd = gcUnAudit.GetFocusedDataSource<t_rettrade>();
if (trd == null)
return;
using (var db = new Database()) {
try {
db.BeginTransaction();
//入库更新库存
db.Execute("exec p_retgoodsupdateinvt @0", trd.Guid);
db.Execute("update t_rettrade set isaudit=1 where [email protected]", trd.Guid);
db.CompleteTransaction();
gcUnAudit.RemoveSelected();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}
示例8: Transaction
public Transaction(Database db)
{
_db = db;
_db.BeginTransaction();
}
示例9: btnReView_ItemClick
void btnReView_ItemClick(object sender, ItemClickEventArgs e)
{
var et=gcUnAudit.GetFocusedDataSource<t_instock>();
if (et == null)
return;
using (var db = new Database()) {
try {
db.BeginTransaction();
db.Execute(" update t_instock set isaudit=1,auditdate=getdate() where [email protected]", et.InStockNo);
//更新库存
db.Execute("exec p_instockupdateinvt @0", et.InStockNo);
db.CompleteTransaction();
gcUnAudit.RemoveSelected();
} catch (Exception) {
db.AbortTransaction();
throw;
}
}
}