Exemplo n.º 1
0
        public new string CreateTable()
        {
            DBExtend     helper = dbHelper;
            ITransaction obj1   = new ITransaction();
            //IAccountRecord obj2 = new IAccountRecord();
            string msg = obj1.CreateTable(helper);
            //msg += obj2.CreateTable(helper);
            ILockRecord rec = new ILockRecord();

            msg += rec.CreateTable(helper);
            return(msg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 锁定一定金额
        /// </summary>
        public bool LockAmount(ILockRecord record, out int id, out string message)
        {
            message = "";
            if (record.Amount <= 0)
            {
                id      = 0;
                message = "amount格式不正确";
                return(false);
            }
            string key = string.Format("LockAmount_{0}_{1}_{2}_{3}", record.AccountId, 0, record.Remark, 0);

            if (!CoreHelper.ConcurrentControl.Check(key, 3))
            {
                throw new Exception("同时提交了多次相同的参数" + key);
            }
            DBExtend helper = dbHelper;
            string   sql    = "update $IAccountDetail set LockedAmount=LockedAmount+@LockedAmount where id=@AccountId and CurrentBalance-(abs(LockedAmount)+@LockedAmount)>=0";

            //sql = FormatTable(sql);
            helper.AddParam("LockedAmount", Math.Abs(record.Amount));
            helper.AddParam("AccountId", record.AccountId);
            helper.BeginTran();
            try
            {
                int n = helper.Execute(sql, typeof(IAccountDetail));
                if (n == 0)
                {
                    message = "余额不足";
                    id      = 0;
                    helper.RollbackTran();
                    return(false);
                }
                //helper.Clear();
                id = helper.InsertFromObj(record);
                helper.CommitTran();
            }
            catch (Exception ero)
            {
                message = "提交事物时发生错误:" + ero.Message;
                helper.RollbackTran();
                CoreHelper.ConcurrentControl.Remove(key);
                CoreHelper.EventLog.Log("LockAmount 执行出错" + ero, true);
                throw ero;
            }
            bool ok = id > 0;

            if (!ok)
            {
                CoreHelper.ConcurrentControl.Remove(key);
            }
            return(ok);
        }