本文整理汇总了C#中UnitOfWork.CommitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.CommitTransaction方法的具体用法?C# UnitOfWork.CommitTransaction怎么用?C# UnitOfWork.CommitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.CommitTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowsInvalidOperationExceptionWhenCalledWhenNotInTransaction
public void ThrowsInvalidOperationExceptionWhenCalledWhenNotInTransaction()
{
using (var uow = new UnitOfWork<TestDbContextContainer>())
{
ExceptionTester.CallMethodAndExpectException<InvalidOperationException>(() => uow.CommitTransaction());
}
}
示例2: btnCancelPurchOrderQty_Click
private void btnCancelPurchOrderQty_Click(object sender, EventArgs e)
{
if (InitExcel("Sheet1") == false)
return;
UnitOfWork uow = new UnitOfWork();
int row = 3;
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
string poNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
float cancelQty = ExcelHelper.GetCellFloatValue(xlSht, row, 2);
PurchOrderLine poLine = PurchOrderLine.Find(uow, poNo);
if (poLine != null)
{
if (poLine.BalQty >= cancelQty)
{
poLine.ChangeCancelQty(cancelQty);
poLine.Save();
xlSht.Cells[row, 3] = "ok";
}
}
row++;
}
xlWb.Save();
uow.CommitTransaction();
ReleaseExcel();
}
示例3: ReturnsTrueWhenInTransaction
public void ReturnsTrueWhenInTransaction()
{
using (var uow = new UnitOfWork<TestDbContextContainer>())
{
Assert.IsFalse(uow.IsInTransaction);
uow.BeginTransaction();
Assert.IsTrue(uow.IsInTransaction);
uow.CommitTransaction();
Assert.IsFalse(uow.IsInTransaction);
}
}
示例4: btnDeductFromWarehouse_Click
private void btnDeductFromWarehouse_Click(object sender, EventArgs e)
{
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
foreach (int row in gridView1.GetSelectedRows())
{
PurchOrderLine poLine = (PurchOrderLine)gridView1.GetRow(row);
if (poLine.OrderStatus != PurchOrderLine.PurchOrderStatus.Complete)
{
XtraMessageBox.Show(string.Format("退货单 {0} 不能扣数 !!", poLine.PurchOrderNo));
}
else
{
DialogResult dialResult = XtraMessageBox.Show(string.Format("请问是否扣以下退货数{0}\n注意 : 你需要在采购入仓确认内过帐. ", poLine.PurchOrderNo), "确认扣数", MessageBoxButtons.YesNo);
if (dialResult == DialogResult.Yes)
{
PurchOrderReceive pOrderReceive = new PurchOrderReceive(uow);
PurchOrderLine poLine2 = uow.FindObject<PurchOrderLine>(CriteriaOperator.Parse(string.Format("Oid = '{0}'", poLine.Oid)));
pOrderReceive.PurchOrderLine = poLine2;
pOrderReceive.Qty = poLine2.NeedQty * -1;
pOrderReceive.Remark = "";
pOrderReceive.Warehouse = poLine2.Warehouse;
pOrderReceive.VendorDN = "";
pOrderReceive.FreeSpareQty = 0;
pOrderReceive.Save();
pOrderReceive.Post();
}
}
}
uow.CommitTransaction();
initGrid();
}
示例5: btnJia_Click
private void btnJia_Click(object sender, EventArgs e)
{
if (InitExcel("夹具") == false)
return;
UnitOfWork uow = new UnitOfWork();
int row = 2;
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
string gageNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
string gageName = ExcelHelper.GetCellStringValue(xlSht, row, 2);
Jia jia = new Jia(uow);
jia.JiaNo = gageNo;
jia.JiaDescription = gageName;
jia.Save();
xlSht.Cells[row, 5] = "ok";
row++;
}
uow.CommitTransaction();
xlWb.Save();
ReleaseExcel();
}
示例6: btnFixSupplier_Click
private void btnFixSupplier_Click(object sender, EventArgs e)
{
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
XPCollection<PurchOrderLine> purchOrderLines = new XPCollection<PurchOrderLine>(uow);
foreach (PurchOrderLine poLine in purchOrderLines)
{
if (poLine.Vendor.No.Substring(poLine.Vendor.No.Length - 2, 2) == "-d")
{
string originalVendorNo = poLine.Vendor.No.Substring(0, poLine.Vendor.No.Length - 2);
Vendor vendor = Vendor.FindVendor(uow, originalVendorNo);
if (vendor != null)
{
poLine.updateTimeStamp = false;
poLine.Vendor = vendor;
poLine.Save();
}
}
}
XPCollection<PriceDisc> priceDiscs = new XPCollection<PriceDisc>(uow);
foreach (PriceDisc priceDisc in priceDiscs)
{
if (priceDisc.Type == PriceDisc.PriceType.Purch)
{
if (priceDisc.ExternalContact != null)
{
if (priceDisc.ExternalContact.No.Substring(priceDisc.ExternalContact.No.Length - 2, 2) == "-d")
{
string originalVendorNo = priceDisc.ExternalContact.No.Substring(0, priceDisc.ExternalContact.No.Length - 2);
Vendor vendor = Vendor.FindVendor(uow, originalVendorNo);
if (vendor != null)
{
priceDisc.updateTimeStamp = false;
priceDisc.ExternalContact = vendor;
priceDisc.Save();
}
}
}
}
}
XPCollection<Item> items = new XPCollection<Item>(uow);
foreach (Item item in items)
{
if (item.MainVendor != null)
{
if (item.MainVendor.No.Substring(item.MainVendor.No.Length - 2, 2) == "-d")
{
string originalVendorNo = item.MainVendor.No.Substring(0, item.MainVendor.No.Length - 2);
Vendor vendor = Vendor.FindVendor(uow, originalVendorNo);
if (vendor != null)
{
item.MainVendor = vendor;
item.IsConfirming = true;
item.updateTimeStamp = false;
item.Save();
}
}
}
}
uow.CommitTransaction();
}
示例7: CorrectlyRollbacksTransactionWhenAnErrorOccursWhileSaving
public void CorrectlyRollbacksTransactionWhenAnErrorOccursWhileSaving()
{
using (var uow = new UnitOfWork<TestDbContextContainer>())
{
var orderRepository = uow.GetRepository<IDbContextOrderRepository>();
uow.BeginTransaction();
var order = new DbContextOrder { Amount = 1, CustomerId = 999, ProductId = 999 };
orderRepository.Add(order);
try
{
uow.CommitTransaction();
Assert.Fail("Expected an exception");
}
catch (Exception)
{
Assert.IsFalse(uow.IsInTransaction);
}
}
}
示例8: btnMassInput_Click
private void btnMassInput_Click(object sender, EventArgs e)
{
// 产品编码, 产品类别, 价钱类别, 销售价钱,
StringBuilder sb = new StringBuilder();
sb.AppendLine("EXCEL页的格式亦请按照下指示 :");
sb.AppendLine("页名 : Sheet1");
sb.AppendLine("栏 A : 销售单号");
sb.AppendLine("栏 B : 人客");
sb.AppendLine("栏 C : 产品编码");
sb.AppendLine("栏 D : 单种类");
sb.AppendLine("栏 E : 要求交期");
sb.AppendLine("栏 F : 要求数量");
XtraMessageBox.Show(sb.ToString(), "注意 !!");
if (InitExcel("Sheet1") == false)
return;
UnitOfWork uow = new UnitOfWork();
bool isAdmin = SecurityHelper.IsAdministrator();
int row = 2;
StringBuilder sbMsg = new StringBuilder();
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
Customer customer = Customer.Find(uow, ExcelHelper.GetCellStringValue(xlSht, row, 2));
if (customer == null)
{
xlSht.Cells[row, 7] = "Cannot find customer.";
}
else
{
string soNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
string itemNo = ExcelHelper.GetCellStringValue(xlSht, row, 3);
string orderTypeName = ExcelHelper.GetCellStringValue(xlSht, row, 4);
SalesOrder so = SalesOrder.Create(soNo, customer, uow);
uow.CommitChanges();
DateTime needDate = ExcelHelper.GetCellDateTimeValue(xlSht, row, 5);
int needQty = ExcelHelper.GetCellIntValue(xlSht, row, 6);
createWO(itemNo, orderTypeName, needDate, needQty, so, true, uow, sbMsg);
xlSht.Cells[row, 7] = "ok";
}
row++;
}
xlWb.Save();
uow.CommitTransaction();
ReleaseExcel();
}
示例9: UpdateSOQty
public static void UpdateSOQty(SubSalesOrderLine SubSOLine)
{
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
SubSalesOrderLine soLine = uow.FindObject<SubSalesOrderLine>(new BinaryOperator("Oid", SubSOLine.Oid));
soLine.UpdateQty();
soLine.Save();
uow.CommitTransaction();
}
示例10: btnIssueCMSO_Click
private void btnIssueCMSO_Click(object sender, EventArgs e)
{
txtItemNo.Text = txtItemNo.Text.Trim();
txtSalesOrderNo.Text = txtSalesOrderNo.Text.Trim();
txtQty.Text = txtQty.Text.Trim();
if (txtItemNo.Text == "" || txtSalesOrderNo.Text == "" || txtQty.Text == "0")
{
txtMessage.Text = "错误!! 请输入销售单号 , 产品编码 及 数量 !";
PlayErrorSound();
return;
}
UnitOfWork uow = new UnitOfWork();
XPCollection<SalesOrderLine> SalesOrderLines = new XPCollection<SalesOrderLine>(uow);
SalesOrderLines.Criteria = CriteriaOperator.Parse(string.Format("CustomerItemNo == '{0}' AND SalesOrder.OrderNo == '{1}' AND OrderStatus == '{2}' ", txtItemNo.Text.Trim(), txtSalesOrderNo.Text.Trim(), SalesOrderLine.SalesOrderStatus.Active));
SortingCollection sorting = new SortingCollection();
ShipmentSetting sSetting = ShipmentSetting.GetInstance(uow);
if (sSetting.SortBy == ShipmentSetting.SortType.DatePriority)
{
sorting.Add(new SortProperty("NeedDate", DevExpress.Xpo.DB.SortingDirection.Ascending));
sorting.Add(new SortProperty("Priority", DevExpress.Xpo.DB.SortingDirection.Descending));
}
else
{
sorting.Add(new SortProperty("Priority", DevExpress.Xpo.DB.SortingDirection.Descending));
sorting.Add(new SortProperty("NeedDate", DevExpress.Xpo.DB.SortingDirection.Ascending));
}
SalesOrderLines.Sorting = sorting;
float shipQty = float.Parse(txtQty.Text);
uow.BeginTransaction();
foreach (SalesOrderLine soLine in SalesOrderLines)
{
if (soLine.LackQty > 0)
{
if (soLine.LackQty >= shipQty)
{
Shipment so = soLine.CreateShipment(uow, shipQty);
if (so != null)
{
so.ChangeStatusToReady();
shipQty = 0;
break;
}
}
else
{
float tmpLackQty = soLine.LackQty;
Shipment so = soLine.CreateShipment(uow, soLine.LackQty);
if (so != null)
{
so.ChangeStatusToReady();
shipQty = shipQty - tmpLackQty;
}
}
}
}
uow.CommitTransaction();
if (shipQty == 0)
{
PlayOKSound();
txtMessage.Text = "OK";
}
else
{
PlayErrorSound();
txtMessage.Text = string.Format("还有余数{0}", shipQty);
}
RefreshShipment();
}
示例11: btnRemoveCH_Execute
private void btnRemoveCH_Execute(object sender, SimpleActionExecuteEventArgs e)
{
if (View.CurrentObject == null)
return;
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
OutlookSystemItem olItem = new OutlookSystemItem();
foreach (Item tmpItem in View.SelectedObjects)
{
string itemNo = tmpItem.ItemNo;
Item item = Item.FindItem(uow, itemNo);
if (item.ItemNo.Substring(0, 2) == "CH")
{
item.ItemNo = item.ItemNo.Replace("CH", "");
olItem.SaveToOutlookSystem(item);
item.IsConfirming = true;
item.Save();
uow.CommitChanges();
}
}
uow.CommitTransaction();
}
示例12: btnGage_Click
private void btnGage_Click(object sender, EventArgs e)
{
if (InitExcel("量具") == false)
return;
UnitOfWork uow = new UnitOfWork();
int row = 2;
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
string gageNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
string gageName = ExcelHelper.GetCellStringValue(xlSht, row, 2);
Gage gage = new Gage(uow);
gage.GageNo = gageNo;
gage.Name = gageName;
gage.Save();
xlSht.Cells[row, 5] = "ok";
row++;
}
uow.CommitTransaction();
xlWb.Save();
ReleaseExcel();
}
示例13: DeductBySalesOrder
void DeductBySalesOrder(string SalesOrderNo, string ItemNo, Single shipQty)
{
UnitOfWork uow = new UnitOfWork();
uow.BeginTransaction();
XPCollection<Shipment> shipments = new XPCollection<Shipment>(uow);
shipments.Criteria = CriteriaOperator.Parse(string.Format("Item.ItemNo == '{0}' AND SalesOrderLine.SalesOrder.OrderNo == '{1}' AND Status == '{2}' ", ItemNo, SalesOrderNo, Shipment.PackStatus.Ready));
foreach (Shipment shipment in shipments)
{
if (shipment.UnPackedQty < shipQty)
{
shipQty = shipQty - shipment.UnPackedQty;
shipment.AddPackedQty(shipment.UnPackedQty);
shipment.AddCartonNo(txtCartonNo.Text);
}
else
{
shipment.AddPackedQty(shipQty);
shipment.AddCartonNo(txtCartonNo.Text);
shipQty = 0;
break;
}
}
uow.CommitTransaction();
if (shipQty > 0)
{
PlayErrorSound();
txtMessage.Text = string.Format("还有余数 {0} 只 ", shipQty);
}
else
{
PlayOKSound();
txtMessage.Text = "OK";
}
}
示例14: btnItem_Click
private void btnItem_Click(object sender, EventArgs e)
{
if (InitExcel("Item") == false)
return;
UnitOfWork uow = new UnitOfWork();
Item item;
String itemNo;
int row = 3;
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
itemNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
item = Item.FindItem(uow, itemNo);
if (item != null && ItemExist.SelectedIndex == 0 || item == null)
{
if (item == null)
item = new Item(uow);
item.ItemNo = itemNo;
item.ItemName = ExcelHelper.GetCellStringValue(xlSht, row, 2);
item.ItemType = GetItemType(ExcelHelper.GetCellStringValue(xlSht, row, 3), uow);
item.CustomerItemNo = ExcelHelper.GetCellStringValue(xlSht, row, 4);
item.Material = GetMaterial(ExcelHelper.GetCellStringValue(xlSht, row, 5), uow);
if (ExcelHelper.GetCellStringValue(xlSht, row, 6) != "")
{
Lot lot = GetLot(ExcelHelper.GetCellStringValue(xlSht, row, 6), uow);
item.Lot = lot;
}
if (ExcelHelper.GetCellStringValue(xlSht, row, 7) != "")
item.PriceCategory = uow.FindObject<PriceCategory>(new BinaryOperator("PriceCategoryNo", ExcelHelper.GetCellStringValue(xlSht, row, 7)));
if (ExcelHelper.GetCellStringValue(xlSht, row, 8) != "")
item.ItemCategory = uow.FindObject<ItemCategory>(new BinaryOperator("ItemCategoryNo", ExcelHelper.GetCellStringValue(xlSht, row, 8)));
//item.Source = Item.ItemSource.None;
item.Warehouse = uow.FindObject<WareHouse>(new BinaryOperator("WarehouseName", ExcelHelper.GetCellStringValue(xlSht, row, 10)));
item.DrawingNo = ExcelHelper.GetCellStringValue(xlSht, row, 11);
item.Save();
uow.CommitChanges();
}
row++;
}
uow.CommitTransaction();
ReleaseExcel();
}
示例15: btnCancelSORemain_Click
private void btnCancelSORemain_Click(object sender, EventArgs e)
{
if (InitExcel("Shipment") == false)
return;
UnitOfWork uow = new UnitOfWork();
int row = 3;
uow.BeginTransaction();
while (ExcelHelper.GetCellStringValue(xlSht, row, 1) != "")
{
string soNo = ExcelHelper.GetCellStringValue(xlSht, row, 1);
int soIndex = ExcelHelper.GetCellIntValue(xlSht, row, 2);
SalesOrderLine soLine = SalesOrderLine.Find(uow, soNo, soIndex);
soLine.ChangeCancelQty(soLine.BalQty + soLine.CancelQty);
soLine.Save();
row++;
}
uow.CommitTransaction();
ReleaseExcel();
}