当前位置: 首页>>代码示例>>C#>>正文


C# TransactionScope类代码示例

本文整理汇总了C#中TransactionScope的典型用法代码示例。如果您正苦于以下问题:C# TransactionScope类的具体用法?C# TransactionScope怎么用?C# TransactionScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TransactionScope类属于命名空间,在下文中一共展示了TransactionScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddEquipment

        public SigmaResultType AddEquipment(TypeEquipment objEquipment)
        {
            TypeUserInfo userinfo = AuthMgr.GetUserInfo();

            SigmaResultType result = new SigmaResultType();
            TransactionScope scope = null;

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            List<SqlParameter> paramList = new List<SqlParameter>();
            paramList.Add(new SqlParameter("@EquipmentCodeMain", objEquipment.EquipmentCodeMain.Trim()));
            paramList.Add(new SqlParameter("@EquipmentCodeSub", objEquipment.EquipmentCodeSub.Trim()));
            paramList.Add(new SqlParameter("@Description", objEquipment.Description.Trim()));
            paramList.Add(new SqlParameter("@ThirdLevel", objEquipment.ThirdLevel.Trim()));
            paramList.Add(new SqlParameter("@Spec", objEquipment.Spec.Trim()));
            paramList.Add(new SqlParameter("@EquipmentType", objEquipment.EquipmentType.Trim()));
            paramList.Add(new SqlParameter("@CreatedBy", userinfo.SigmaUserId.Trim()));
            paramList.Add(new SqlParameter("@ModelNumber", objEquipment.ModelNumber.Trim()));
            SqlParameter outParam = new SqlParameter("@NewId", SqlDbType.Int);
            outParam.Direction = ParameterDirection.Output;
            paramList.Add(outParam);

            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddEquipment", paramList.ToArray());
                result.IsSuccessful = true;
                result.ScalarValue = (int)outParam.Value;

                scope.Complete();
            }

            return result;
        }
开发者ID:paraneye,项目名称:WebService,代码行数:34,代码来源:EquipmentMgr.cs

示例2: AddCWA

        public SigmaResultType AddCWA(TypeCWA objCWA)
        {
            TypeUserInfo userinfo = AuthMgr.GetUserInfo();

            TransactionScope scope = null;
            SigmaResultType result = new SigmaResultType();

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            List<SqlParameter> paramList = new List<SqlParameter>();
            paramList.Add(new SqlParameter("@ProjectId", Utilities.ToInt32(userinfo.CurrentProjectId.ToString().Trim())));
            paramList.Add(new SqlParameter("@Name", objCWA.Name.Trim()));
            paramList.Add(new SqlParameter("@Area", objCWA.Area));
            paramList.Add(new SqlParameter("@Description", objCWA.Description.Trim()));
            paramList.Add(new SqlParameter("@CreatedBy", userinfo.SigmaUserId.Trim()));
            SqlParameter outParam = new SqlParameter("@NewId", SqlDbType.Int);
            outParam.Direction = ParameterDirection.Output;
            paramList.Add(outParam);

            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddCWA", paramList.ToArray());
                result.IsSuccessful = true;
                result.ScalarValue = (int)outParam.Value;

                scope.Complete();
            }

            return result;
        }
开发者ID:paraneye,项目名称:WebService,代码行数:31,代码来源:CWAMgr.cs

示例3: CreateMessage

        /// <summary>
        /// 作者:Vincen
        /// 时间:2014.04.30
        /// 描述:创建消息
        /// </summary>
        /// <param name="model"></param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public static bool CreateMessage(MessageModel model, int loginUserId)
        {
            try
            {
                using (var tran = new TransactionScope())
                {
                    using (var edb = new EmeEntities())
                    {
                        var msg = new Message()
                        {
                            MessageType = model.MessageType,
                            Subject = model.Subject,
                            MContent = model.MContent,
                            Receivers = model.Receiver.Count,
                            Openers = 0,
                            Status = ConvertEnum.StatusTypeForActive,
                            CreateBy = model.CreateBy,
                            CreateTime = model.CreateTime
                        };

                        edb.Entry(msg).State = EntityState.Added;
                        edb.SaveChanges();

                        var receiver = from a in model.Receiver
                                       select new MessageReceiver()
                                           {
                                               MessageId = msg.Id,
                                               Receiver = a,
                                               IsRead = false,
                                               Status = ConvertEnum.StatusTypeForActive,
                                               CreateBy = model.CreateBy,
                                               CreateTime = model.CreateTime
                                           };
                        foreach (var messageReceiver in receiver)
                        {
                            edb.Entry(messageReceiver).State = EntityState.Added;
                        }

                        var result = edb.SaveChanges() > 0;

                        tran.Complete();
                        return result;
                    }
                }
            }
            catch (Exception e)
            {
                // 异常日志消息队列
                Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                {
                    ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                    Message = string.Format("EmeBLL-CreateMessage:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                    IsTreat = false,
                    CreateBy = loginUserId,
                    CreateTime = DateTime.Now
                });

                return false;
            }
        }
开发者ID:kylin589,项目名称:EmePro,代码行数:68,代码来源:EmeBLL.cs

示例4: Create

        /// <summary>
        /// 创建报表文件格式
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public int Create(ReportsEntity entity,List<ReportParamsEntity> list)
        {
            if (!entity.ReportNum.IsEmpty())
            {
                return Update(entity,list);
            }
            int line = 0;
            using (TransactionScope ts = new TransactionScope())
            {
                entity.ReportNum = entity.ReportNum.IsEmpty() ? SequenceProvider.GetSequence(typeof(ReportsEntity)) : entity.ReportNum;
                entity.IncludeAll();
                line += this.Reports.Add(entity);

                if (!list.IsNullOrEmpty())
                {
                    foreach (ReportParamsEntity item in list)
                    {
                        item.ParamNum = item.ParamNum.IsEmpty() ? SequenceProvider.GetSequence(typeof(ReportParamsEntity)) : item.ParamNum;
                        item.ReportNum = entity.ReportNum;
                        item.IncludeAll();
                    }
                    this.ReportParams.Add(list);
                }
                ts.Complete();
            }

            return line;
        }
开发者ID:ZhangHanLong,项目名称:gitwms,代码行数:34,代码来源:ReportProvider.cs

示例5: UpdateData

        public string[] UpdateData(IEntityBase value)
        {
            EConfigHoraSet objE = (EConfigHoraSet)value;
             object[] objRet = null;

             try
             {

            using (TransactionScope tx = new TransactionScope())
            {

               this.DeleteDetail(objE.ColConfigHora, true);

               //objRet = this.UpdateMaster(objE.EConfigHora);

               this.UpdateDetail(objE.ColConfigHora, objRet);

               tx.Complete();

            }

            if (objRet == null)
               return null;

            return new String[] { objRet[0].ToString() };

             }
             catch (Exception ex)
             {

            throw ex;

             }
        }
开发者ID:ArquitecturaSoftware,项目名称:texfinadev,代码行数:34,代码来源:ConfigHora.cs

示例6: Bug

		public void Bug()
		{
			string connectionString = cfg.GetProperty("connection.connection_string");
			int id = -1;
			
			using (TransactionScope ts = new TransactionScope())
			{
				// Enlisting DummyEnlistment as a durable resource manager will start
				// a DTC transaction
				System.Transactions.Transaction.Current.EnlistDurable(
					DummyEnlistment.Id,
					new DummyEnlistment(),
					EnlistmentOptions.None);
				
				using (IDbConnection connection = new SqlConnection(connectionString))
				{
					connection.Open();
					using (ISession s = Sfi.OpenSession(connection))
					{
						id = (int)s.Save(new MyTable() { String = "hello!" });
					}
					connection.Close();
				}
				
				// Prior to the patch, an InvalidOperationException exception would occur in the
				// TransactionCompleted delegate at this point with the message, "Disconnect cannot
				// be called while a transaction is in progress". Although the exception can be
				// seen reported in the IDE, NUnit fails to see it, and the test passes. The
				// TransactionCompleted event fires *after* the transaction is committed and so
				// it doesn't affect the success of the transaction
				ts.Complete();
			}
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:33,代码来源:Fixture.cs

示例7: Abandon

        public void Abandon(int masterSysNo, int userSysNo)
        {
            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {

                //�����dz�ʼ״̬
                POInfo dbInfo = LoadPO(masterSysNo);
                if ( dbInfo == null )
                    throw new BizException("does not exist this po sysno");
                if ( dbInfo.Status != (int)AppEnum.POStatus.Origin )
                    throw new BizException("status is not origin now, abandon failed");

                //���� ���š�״̬�������
                Hashtable ht = new Hashtable(4);

                ht.Add("SysNo", masterSysNo);
                ht.Add("Status", (int)AppEnum.POStatus.Abandon);
                if ( 1!=new PODac().UpdateMaster(ht))
                    throw new BizException("expected one-row update failed, verify failed ");

                ProductIDManager.GetInstance().AbandonProductIDsByPO(masterSysNo);

                scope.Complete();
            }
        }
开发者ID:ue96,项目名称:ue96,代码行数:29,代码来源:PurchaseManager.cs

示例8: UpdateClient

        public void UpdateClient(Client client)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                Db.ExecuteNonQuery("usp_Client_UpdateClient", CommandType.StoredProcedure,
                    new DbParameter[] {
                               Db.CreateParameter("ClientId", client.ClientId),
                               Db.CreateParameter("ClientName", client.ClientName),
                               Db.CreateParameter("ContactName", client.ContactName),
                               Db.CreateParameter("Phone", client.Phone),
                               Db.CreateParameter("Email", client.Email),
                               Db.CreateParameter("TIN", client.TIN),
                               Db.CreateParameter("PrivateClientDetails", client.PrivateClientDetails),
                               Db.CreateParameter("OtherClientDetails", client.OtherClientDetails),
                               Db.CreateParameter("BillingAddress", client.BillingAddress),
                               Db.CreateParameter("City", client.City),
                               Db.CreateParameter("StateCode", client.StateCode),
                               Db.CreateParameter("Zip", client.Zip),
                               Db.CreateParameter("Country", client.Country),
                               Db.CreateParameter("ShipToDifferentAddress", client.ShipToDifferentAddress),
                               Db.CreateParameter("ShippingAddress", client.ShippingAddress),
                               Db.CreateParameter("ShippingCity", client.ShippingCity),
                               Db.CreateParameter("ShippingStateCode", client.ShippingStateCode),
                               Db.CreateParameter("ShippingZip", client.ShippingZip),
                               Db.CreateParameter("ShippingCountry", client.ShippingCountry)

                 });
                scope.Complete();
            }
        }
开发者ID:UmeshTayade,项目名称:SleekBill,代码行数:30,代码来源:ClientDBHelper.cs

示例9: Capnhatgia

        public static ActionResult Capnhatgia(long id, decimal don_gia, byte cachtinh_gia)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var sh = new SharedDbConnectionScope())
                    {

                        new Update(NoitruPhanbuonggiuong.Schema)
                                             .Set(NoitruPhanbuonggiuong.Columns.DonGia).EqualTo(don_gia)
                                             .Set(NoitruPhanbuonggiuong.Columns.CachtinhGia).EqualTo(cachtinh_gia)
                                             .Where(NoitruPhanbuonggiuong.Columns.Id).IsEqualTo(id).Execute();
                    }
                    scope.Complete();
                    return ActionResult.Success;

                }
            }
            catch (Exception exception)
            {
                Utility.CatchException(exception);
                return ActionResult.Error;
            }
        }
开发者ID:khaha2210,项目名称:CodeNewHis,代码行数:25,代码来源:noitru_nhapvien.cs

示例10: DeletedDirectDebit

        public static Boolean DeletedDirectDebit(DirectDebit debit)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                Boolean bol = false;
                using (var context = new SycousCon())
                {
                    try
                    {
                        var Update = context.DirectDebits.Where(c => c.ID == debit.ID&& c.IsDeleted==0&&c.IsApproved==0);

                        foreach (DirectDebit p in Update)
                        {
                            p.IsDeleted = 2;
                            p.ModifyBy = debit.ModifyBy;
                            p.ModifyDate = DateTime.Now;

                        }//
                        context.SaveChanges();
                        context.AcceptAllChanges();
                        scope.Complete();
                        context.Dispose();
                        bol = true;
                    }
                    catch (Exception ex)
                    {
                        context.Dispose();
                        throw;
                    }

                }// using
                return bol;
            } //trans
        }
开发者ID:arnabknd4,项目名称:scs0400915,代码行数:34,代码来源:DALDirectDebit.cs

示例11: CreateDirectDebit

        public static Boolean CreateDirectDebit(DirectDebit mdirectdebit)
        {
            Boolean flag = false;

                using (TransactionScope scope = new TransactionScope())
                {
                    using (var context = new SycousCon())
                    {
                        try
                        {
                            context.DirectDebits.AddObject(mdirectdebit);
                            context.SaveChanges();
                            scope.Complete();
                            context.AcceptAllChanges();
                            flag = true;
                        }
                        catch (Exception ex)
                        {
                            context.Dispose();
                            throw;
                        }
                    }
                }

            return flag;
        }
开发者ID:arnabknd4,项目名称:scs0400915,代码行数:26,代码来源:DALDirectDebit.cs

示例12: DeleteData

        public int DeleteData(IEntityBase value)
        {
            EProcPlani objE = (EProcPlani)value;

             try
             {

            using (TransactionScope tx = new TransactionScope())
            {

               //this.DeleteDetail(objE.EProcPlani, false);
               this.DeleteMaster(objE);

               tx.Complete();

            }

            return 1;

             }
             catch
             {
            return 0;
             }
        }
开发者ID:ArquitecturaSoftware,项目名称:texfinadev,代码行数:25,代码来源:ProcPlani.cs

示例13: Save

		/// <summary>
		/// データ登録
		/// </summary>
		/// <param name="query">SQL文字列</param>
		/// <param name="args">パラメータ</param>
		/// <returns>True:正常終了 / False:エラー</returns>
		public static int Save(string query, params SQLiteParameter[] args)
		{
			using (var connector = new SqliteConnector())
			using (var command = new SQLiteCommand(query, connector.Connection))
			{
				SqliteCommander.SetParameters(command, args);

				connector.Open();
                
                int result = 0;

                using (var tran = new TransactionScope())
                {
                    result = command.ExecuteNonQuery();

                    if (0 < result)
                    {
                        tran.Complete();
                    }
                }

				connector.Close();

				return result;
			}
		}
开发者ID:KentaYamada,项目名称:KntLibrary.SQLiteDAO,代码行数:32,代码来源:SqliteCommander.cs

示例14: CreateEnergy

        public static Boolean CreateEnergy(Energy energy)
        {
            Boolean flag = false;
              if (!(IsExistingEnergy(energy)))
              {
              using (TransactionScope scope = new TransactionScope())
              {
                  using (var context = new SycousCon())
                  {
                      try
                      {
                          context.Energies.AddObject(energy);
                          context.SaveChanges();
                          scope.Complete();
                          context.AcceptAllChanges();
                          flag = true;
                      }
                      catch (Exception ex)
                      {
                          context.Dispose();
                          throw;
                      }
                  }//
              }// using
              }//if

              return flag;
        }
开发者ID:arnabknd4,项目名称:scs0400915,代码行数:28,代码来源:DALEnergy.cs

示例15: AddSigmaUserSigmaRole

        public SigmaResultType AddSigmaUserSigmaRole(TypeSigmaUserSigmaRole objSigmaUserSigmaRole)
        {
            TypeUserInfo userinfo = AuthMgr.GetUserInfo();
            objSigmaUserSigmaRole.CreatedBy = userinfo.SigmaUserId;
            //objSigmaUserSigmaRole.ProjectId = userinfo.CurrentProjectId;

            TransactionScope scope = null;
            SigmaResultType result = new SigmaResultType();

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            List<SqlParameter> paramList = new List<SqlParameter>();
            paramList.Add(new SqlParameter("@SigmaRoleId", objSigmaUserSigmaRole.SigmaRoleId));
            paramList.Add(new SqlParameter("@SigmaUserId", objSigmaUserSigmaRole.SigmaUserId));
            paramList.Add(new SqlParameter("@ReportTo", objSigmaUserSigmaRole.ReportTo));
            paramList.Add(new SqlParameter("@ReportToRole", objSigmaUserSigmaRole.ReportToRole));
            paramList.Add(new SqlParameter("@IsDefault", objSigmaUserSigmaRole.IsDefault));
            paramList.Add(new SqlParameter("@ProjectId", objSigmaUserSigmaRole.ProjectId));
            paramList.Add(new SqlParameter("@CreatedBy", objSigmaUserSigmaRole.CreatedBy));

            using (scope = new TransactionScope(TransactionScopeOption.Required))
            {
                result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddSigmaUserSigmaRole", paramList.ToArray());
                result.IsSuccessful = true;

                scope.Complete();
            }

            return result;
        }
开发者ID:paraneye,项目名称:WebService,代码行数:31,代码来源:SigmaUserMgr.cs


注:本文中的TransactionScope类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。