コード例 #1
0
    private void SaveSendInfo()
    {
        #region 事务开启

        TransactionOptions transactionOption = new TransactionOptions();
        transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
        using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOption))
        {
            #endregion

            Model.WxSendInfoModel model = new WxSendInfoModel();
            BLL.WxBLL             bll   = new BLL.WxBLL();
            model.WxSendId = ReDecimal("WxSendId", 0);

            if (model.WxSendId == 0)
            {
                model.WxPtId = ReDecimal("WxPtId");
            }
            else
            {
                //如果是修改, 选取出原来的数据
                model = bll.GetWxSendModel(model.WxSendId);
            }
            model.WxSendTitle   = ReStr("WxSendTitle");
            model.WxSendType    = ReStr("WxSendType");
            model.WxSendClassId = ReInt("WxSendClassId");
            model.Memo          = ReStr("Memo");
            model.FmImgId       = ReStr("FmImgId");
            model.WxSuCaiId     = ReDecimal("WxSuCaiId", 0);
            model.SendContent   = ReStrDeCode("SendContent");
            bll.SaveSendInfo(model);



            DataTable dtKeys = ReTable("KeysAreray");

            if (dtKeys.Rows.Count == 0)
            {
                throw new Exception("没有添加激发时间, 这个回应没有触发将没有意义!");
            }


            DAL.WxKeyDAL keyDal = new DAL.WxKeyDAL();
            keyDal.DeleteList(" WxSendId='" + model.WxSendId + "' ");  //首先删除所有的key关联关系

            foreach (DataRow drKeys in dtKeys.Rows)
            {
                if (model.WxSendId == 0)
                {
                    throw new Exception("在执行插入之后,WxSendId不能为0!");
                }

                Model.WxKeyModel KeyModel = new WxKeyModel();
                KeyModel.WxSendId        = model.WxSendId;
                KeyModel.KeyTitle        = drKeys["KeyTitle"].ToString();
                KeyModel.KeyTypeId       = drKeys["KeyTypeId"].ToString();
                KeyModel.KeyTypeDetailId = drKeys["KeyTypeDetailId"].ToString();
                keyDal.Add(KeyModel);   //逐个添加新的关联关系
            }

            ReDict.Add("WxSendId", model.WxSendId);
            #region 事务关闭

            transactionScope.Complete();
        }
        #endregion


        ReTrue();
    }