1、orm框架+sql组合事务
/// <summary> /// 删除功能事务 /// </summary> /// <param name="strFPutPlanNo"></param> /// <returns></returns> public bool DoDeleteStatus(string strFPutPlanNo) { _UserManualControlTrans = true;//自己控制事务 try { this.BeginTransaction(); //启用事务 string sql3 = string.Format(@"update MY_SP_LiTiKuWarehousingPlan set FDelete=1 WHERE FPutPlanNo='{0}' and FDelete=0", strFPutPlanNo);//删除本地表计划 int ret3 = _Database.ExecuteTrans(_CurrentTrans, sql3); string sql4 = string.Format(@"update t_business_asrs_inttmp_erp set wms_status=0,exchange_status=0,sync_status=0,delete_status=1 where in_bill_no='{0}' and sync_status=1 and delete_status=0", strFPutPlanNo);//删除MQ表计划 int ret4 = _Database.ExecuteTrans(_CurrentTrans, sql4); string sql5 = string.Format(@"update t_business_asrs_odc_interface set delete_status=1,exchange_status=0 where billId='{0}' and sync_status=1 and delete_status=0", strFPutPlanNo);//删除计划下的箱码明细,明旭无需下发 int ret5 = _Database.ExecuteTrans(_CurrentTrans, sql5); this.CommitTransaction();//提交事务 _UserManualControlTrans = false; return true; } catch (Exception ex) { this.RollbackTransaction();//事务回滚 throw ex; } }
2、sql事务
/// <summary> /// 删除功能事务 /// </summary> /// <param name="strFPutPlanNo"></param> /// <returns></returns> public bool DoDeleteStatus(string strFPutPlanNo) { _UserManualControlTrans = true;//自己控制事务 try { this.BeginTransaction(); //启用事务 string sql3 = string.Format(@"begin tran update MY_SP_LiTiKuWarehousingPlan set FDelete=1 WHERE FPutPlanNo='{0}' and FDelete=0; update t_business_asrs_inttmp_erp set wms_status=0,exchange_status=0,sync_status=0,delete_status=1 where in_bill_no='{1}' and sync_status=1 and delete_status=0; update t_business_asrs_odc_interface set delete_status=1,exchange_status=0 where billId='{2}' and sync_status=1 and delete_status=0; if @@error = 0 commit tran else rollback tran go", strFPutPlanNo, strFPutPlanNo, strFPutPlanNo); int ret5 = _Database.ExecuteTrans(_CurrentTrans, sql3); return true; } catch (Exception ex) { this.RollbackTransaction();//事务回滚 throw ex; } }