コード例 #1
0
 public void Dispose()
 {
     if (!IsRun)
     {
         Rollback();
     }
     if (TransactionIndex == 1)
     {
         TransactionMain.Dispose();
     }
 }
コード例 #2
0
 public void Rollback()
 {
     if (IsRun)
     {
         throw new LnskyDBException("该事务已提交或者回滚过不可再提交");
     }
     IsRun = true;
     if (TransactionIndex == 1)
     {
         TransactionMain.Rollback();
     }
 }
コード例 #3
0
 public void Complete()
 {
     if (IsRun)
     {
         throw new LnskyDBException("该事务已提交或者回滚过不可再提交");
     }
     IsRun = true;
     if (TransactionIndex == 1)
     {
         TransactionMain.Commit();
     }
 }
コード例 #4
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            var a = new TransactionMain();
            var l = new List<TransactionDetail>();
            a.transaction_id = transaction_id;
            a.transaction_comment = txtComments.Text;
            a.transaction_date = txtTransactionDate.Text == "" ? DateTime.Now : Convert.ToDateTime(txtTransactionDate.Text);
            a.transaction_title = txtTitle.Text;
            a.account_id = account_id;
            a.amount = 0;
            a.is_active = chkIsActive.Checked ? "1" : "0";
            {//gather transaction details, so we'll have the amount on the main transaction record, we'll save the details afteward
                foreach (EditText et in amounts)
                {
                    var td = new TransactionDetail();
                    td.account_id = account_id;
                    td.fund_id = Convert.ToString(et.Tag);
                    td.comment = et.Text;
                    var s = Misc.ValSum(et.Text);
                    td.amount = a.is_active == "1" ? s : 0;
                    a.amount += s;
                    l.Add(td);
                }
            }
            if (a.transaction_id == "")
            {
                a.transaction_id = Guid.NewGuid().ToString();
                transaction_id = a.transaction_id;

                Db.AddTransaction(a);
            }
            else
            {
                Db.UpdateTransaction(a);
            }
            foreach (var li in l)
                li.transaction_id = transaction_id;
            Db.AddTransactionDetails(l);
            SetResult(Result.Ok);
            Finish();
        }