欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

winfrom 在业务层实现事务控制的小例子

程序员文章站 2023-12-10 17:49:28
复制代码 代码如下:try    { using (transactionscope tr = new transactionsco...

复制代码 代码如下:

try
    {
 using (transactionscope tr = new transactionscope())
 {
     int i = this.customermanager.addcustomer(customer);
     int j = this.homestatusmanager.updatehomestatus(homestatus);
     if ((i * j) > 0)
     {
  messagebox.show("记录插入成功!", "消息", messageboxbuttons.ok, messageboxicon.information);
  empty();
  tr.complete();
     }
     else
     {
  messagebox.show("记录插入失败!联系管理员!", "消息", messageboxbuttons.ok, messageboxicon.information);
  empty();
     }
     tr.dispose();
 }

    }
    catch(exception err)
    {
 messagebox.show("记录插入失败" +err.tostring(), "消息", messageboxbuttons.ok, messageboxicon.information);
    }