コード例 #1
0
ファイル: AccountManager.cs プロジェクト: weatherdata/opencbs
        public void DeleteAccount(Account account)
        {
            using (SqlConnection conn = GetConnection())
            {
                OpenCbsCommand cmd = new OpenCbsCommand
                {
                    Connection  = conn,
                    CommandText =
                        @"DELETE FROM dbo.ChartOfAccounts
                                               WHERE lft >= @lft AND rgt <= @rgt"
                };
                cmd.AddParam("@lft", account.Left);
                cmd.AddParam("@rgt", account.Right);
                cmd.ExecuteNonQuery();

                cmd.ResetParams();
                cmd.CommandText =
                    @"UPDATE dbo.ChartOfAccounts
                                SET lft = lft - @diff, rgt = rgt - @diff
                                WHERE lft > @lft";
                cmd.AddParam("@diff", account.Right - account.Left + 1);
                cmd.AddParam("@lft", account.Left);
                cmd.ExecuteNonQuery();
            }
        }
コード例 #2
0
ファイル: LoanManager.cs プロジェクト: TalasZh/opencbs
        private void _SetLoanShareAmount(Loan pLoan, SqlTransaction pSqlTransac)
        {
            // Get group id
            int group_id;
            const string q = @"SELECT p.tiers_id
                FROM dbo.Projects AS p
                LEFT JOIN dbo.Contracts AS c ON c.project_id = p.id
                WHERE c.id = @contract_id";
            using (OpenCbsCommand c = new OpenCbsCommand(q, pSqlTransac.Connection, pSqlTransac))
            {
                c.AddParam("@contract_id", pLoan.Id);
                group_id = Convert.ToInt32(c.ExecuteScalar());
            }

            const string sqlText = @"INSERT INTO LoanShareAmounts (person_id, group_id, contract_id, amount)
                                     VALUES (@person_id, @group_id, @contract_id, @amount)";

            using(OpenCbsCommand c = new OpenCbsCommand(sqlText, pSqlTransac.Connection, pSqlTransac))
            {
                foreach (LoanShare ls in pLoan.LoanShares)
                {
                    c.ResetParams();
                    c.AddParam("@person_id", ls.PersonId);
                    c.AddParam("@group_id", group_id);
                    c.AddParam("@contract_id", pLoan.Id);
                    c.AddParam("@amount", ls.Amount.Value);

                    c.ExecuteNonQuery();
                }
            }
        }
コード例 #3
0
ファイル: AccountManager.cs プロジェクト: jay3126/opencbs
        public void DeleteAccount(Account account)
        {
            using (SqlConnection conn = GetConnection())
            {
                OpenCbsCommand cmd = new OpenCbsCommand
                                         {
                                             Connection = conn,
                                             CommandText =
                                                 @"DELETE FROM dbo.ChartOfAccounts
                                               WHERE lft >= @lft AND rgt <= @rgt"
                                         };
                cmd.AddParam("@lft", account.Left);
                cmd.AddParam("@rgt", account.Right);
                cmd.ExecuteNonQuery();

                cmd.ResetParams();
                cmd.CommandText =
                    @"UPDATE dbo.ChartOfAccounts
                                SET lft = lft - @diff, rgt = rgt - @diff
                                WHERE lft > @lft";
                cmd.AddParam("@diff", account.Right - account.Left + 1);
                cmd.AddParam("@lft", account.Left);
                cmd.ExecuteNonQuery();
            }
        }