public static void DeleteAccount(int AccountId) { if (!CanWork(AccountId)) { throw new AccessDeniedException(); } int ParentId = DBFinance.GetParentAccountId(AccountId); if (ParentId <= 0) { throw new AccessDeniedException(); } using (DbTransaction tran = DbTransaction.Begin()) { // Улалим счёт и всех его детей DBFinance.DeleteAccount(AccountId); // Найдём всех сестёр ArrayList siblings = new ArrayList(); using (IDataReader reader = DBFinance.GetListChildrenAccounts(ParentId)) { while (reader.Read()) { siblings.Add((int)reader["AccountId"]); } } if (siblings.Count == 0) { DBFinance.UpdateIsSummary(ParentId, false); } else { ProcessRenumber(ParentId, siblings); } // Пересчёт вверх по иерархии RecalculateParentAccounts(AccountId, false); tran.Commit(); } }