Ejemplo n.º 1
0
        public static void UpdateActualFinancesValueAndDescription(int ActualId,
                                                                   decimal Value, string Description)
        {
            int AccountId;
            int ObjectTypeId, ObjectId;

            using (IDataReader reader = DBFinance.GetActualFinances(ActualId))
            {
                reader.Read();
                AccountId    = (int)reader["AccountId"];
                ObjectTypeId = (int)reader["ObjectTypeId"];
                ObjectId     = (int)reader["ObjectId"];
            }

            if (!CanWork(ObjectTypeId, ObjectId))
            {
                throw new AccessDeniedException();
            }

            using (DbTransaction tran = DbTransaction.Begin())
            {
                DBFinance.UpdateActualFinancesValueAndDescription(ActualId, Value, Description, Security.CurrentUser.UserID);

                RecalculateActualAccounts(AccountId);

                tran.Commit();
            }
        }
Ejemplo n.º 2
0
        public static void DeleteActualFinances(int ActualId)
        {
            int AccountId;
            int ObjectTypeId, ObjectId;

            using (IDataReader reader = DBFinance.GetActualFinances(ActualId))
            {
                reader.Read();
                AccountId    = (int)reader["AccountId"];
                ObjectTypeId = (int)reader["ObjectTypeId"];
                ObjectId     = (int)reader["ObjectId"];
            }

            if (!CanWork(ObjectTypeId, ObjectId))
            {
                throw new AccessDeniedException();
            }

            using (DbTransaction tran = DbTransaction.Begin())
            {
                DBFinance.DeleteActualFinances(ActualId);
                RecalculateActualAccounts(AccountId);

                tran.Commit();
            }
        }
Ejemplo n.º 3
0
        internal static void RecalculateActualAccounts(int AccountId)
        {
            // Пересчитаем текущий счёт
            DBFinance.RecalculateACurAccount(AccountId, Security.CurrentUser.UserID);

            RecalculateParentAccounts(AccountId, false);
        }
Ejemplo n.º 4
0
        public static void RenameAccount(int AccountId, string Title)
        {
            if (!CanWork(AccountId))
            {
                throw new AccessDeniedException();
            }

            DBFinance.RenameAccount(AccountId, Title, Security.CurrentUser.UserID);
        }
Ejemplo n.º 5
0
        private static void RecalculateParentAccountWithPreserving(int AccountId)
        {
            int ParentId = DBFinance.GetParentAccountId(AccountId);

            if (ParentId > 0)
            {
                DBFinance.RecalculateParentAccountWithPreserving(ParentId, Security.CurrentUser.UserID);
            }
        }
Ejemplo n.º 6
0
        public static int AddChildAccount(int ParentId, string Title)
        {
            if (!CanWork(ParentId))
            {
                throw new AccessDeniedException();
            }

            return(DBFinance.AddChildAccount(ParentId, Title, Security.CurrentUser.UserID));
        }
Ejemplo n.º 7
0
        public static DataTable GetListActualFinancesByProject(int ProjectId, bool checkAccess)
        {
            if (checkAccess && !Project.CanViewFinances(ProjectId))
            {
                throw new AccessDeniedException();
            }

            return(DBFinance.GetListActualFinancesByProject(ProjectId, Security.CurrentUser.TimeZoneId));
        }
Ejemplo n.º 8
0
        public static bool CanWork(int AccountId)
        {
            int ProjectId = -1;

            using (IDataReader reader = DBFinance.GetAccount(AccountId))
            {
                reader.Read();
                ProjectId = (int)reader["ProjectId"];
            }

            return(Project.CanEditFinances(ProjectId));
        }
Ejemplo n.º 9
0
        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();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// AccountId, ProjectId, Title, OutlineLevel, OutlineNumber, IsSummary, IsCollapsed,
        /// TTotal, TCur, TSub,
        /// ETotal, ECur, ESub,
        /// ATotal, ACur, ASub
        /// </summary>
        /// <returns></returns>
        public static DataTable GetListAccountsByProjectCollapsed(int project_id)
        {
            DataTable dt = DBFinance.GetListAccountsByProjectCollapsed(project_id, Security.CurrentUser.UserID);

            // Удалим невидимые строки
            int       OldOutlineLevel = 1;
            bool      OldIsCollapsed  = false;
            Hashtable htT             = new Hashtable();
            Hashtable htE             = new Hashtable();

            foreach (DataRow dr in dt.Rows)
            {
                int  OutlineLevel = (int)dr["OutlineLevel"];
                bool IsCollapsed  = (bool)dr["IsCollapsed"];

                if (OldIsCollapsed && OldOutlineLevel < OutlineLevel)
                {
                    dr.Delete();
                }
                else
                {
                    OldOutlineLevel = OutlineLevel;
                    OldIsCollapsed  = IsCollapsed;

                    // Выставим значения для TParent и EParent
                    htT[OutlineLevel] = (decimal)dr["TCur"];
                    htE[OutlineLevel] = (decimal)dr["ECur"];

                    if (OutlineLevel == 1)
                    {
                        dr["TParent"] = decimal.MaxValue;
                        dr["EParent"] = decimal.MaxValue;
                    }
                    else
                    {
                        dr["TParent"] = (decimal)htT[OutlineLevel - 1] + (decimal)dr["TTotal"];
                        dr["EParent"] = (decimal)htE[OutlineLevel - 1] + (decimal)dr["ETotal"];
                    }
                }
            }
            return(dt);
        }
Ejemplo n.º 11
0
        private static int AddActualFinances(int AccountId, int ObjectTypeId, int ObjectId, string Description, decimal Value)
        {
            if (!CanWork(ObjectTypeId, ObjectId))
            {
                throw new AccessDeniedException();
            }

            int retval = -1;

            using (DbTransaction tran = DbTransaction.Begin())
            {
                retval = DBFinance.AddActualFinances(AccountId, ObjectTypeId, ObjectId, DateTime.UtcNow, Description, Value, Security.CurrentUser.UserID);

                RecalculateActualAccounts(AccountId);

                tran.Commit();
            }

            return(retval);
        }
Ejemplo n.º 12
0
        // Перенумерация OutlineNumber и OutlineLevel
        private static void ProcessRenumber(int AccountId, ArrayList children)
        {
            string OutlineNumber;
            int    OutlineLevel;

            using (IDataReader reader = DBFinance.GetAccount(AccountId))
            {
                reader.Read();
                OutlineNumber = reader["OutlineNumber"].ToString();
                OutlineLevel  = (int)reader["OutlineLevel"];
            }

            int pos = 0;

            foreach (int childId in children)
            {
                // Найдём всех внуков
                ArrayList grandChildren = new ArrayList();
                using (IDataReader reader = DBFinance.GetListChildrenAccounts(childId))
                {
                    while (reader.Read())
                    {
                        grandChildren.Add((int)reader["AccountId"]);
                    }
                }

                // Обновим OutlineNumber
                pos++;
                string newNumber = String.Format("{0}.{1}", OutlineNumber, pos);
                DBFinance.UpdateOutlineLevelAndNumber(childId, OutlineLevel + 1, newNumber);

                // Рекурсия
                if (grandChildren.Count > 0)
                {
                    ProcessRenumber(childId, grandChildren);
                }
            }
        }
Ejemplo n.º 13
0
        private static void RecalculateParentAccounts(int AccountId, bool IncludeCurrent)
        {
            ArrayList parentAccounts = new ArrayList();

            if (IncludeCurrent)
            {
                parentAccounts.Add(AccountId);
            }

            // Найдём всех родителей
            using (IDataReader reader = DBFinance.GetListParentAccounts(AccountId))
            {
                while (reader.Read())
                {
                    parentAccounts.Add(reader["AccountId"]);
                }
            }

            // Пересчитаем родителей
            foreach (int parentAccountId in parentAccounts)
            {
                DBFinance.RecalculateParentAccount(parentAccountId, Security.CurrentUser.UserID);
            }
        }
Ejemplo n.º 14
0
 public static DataTable GetListAccountsDataTable(int ProjectId)
 {
     return(DBFinance.GetListAccountsDataTable(ProjectId));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Reader returns fields:
 ///		AccountId, ProjectId, Title, AccountNum, OutlineLevel, OutlineNumber, IsSummary
 /// </summary>
 public static IDataReader GetListAccounts(int ProjectId)
 {
     return(DBFinance.GetListAccounts(ProjectId));
 }
Ejemplo n.º 16
0
 public static void CollapseAccount(int AccountId)
 {
     DBFinance.AddCollapsedAccount(Security.CurrentUser.UserID, AccountId);
 }
Ejemplo n.º 17
0
 /// <summary>
 ///		ActualId, AccountId, Title, OutlineLevel, ActualDate, Description, AValue,
 ///		LastEditorId, LastSavedDate
 /// </summary>
 private static DataTable GetListActualFinancesByObject(int ObjectTypeId, int ObjectId)
 {
     return(DBFinance.GetListActualFinancesByObject(ObjectTypeId, ObjectId, Security.CurrentUser.TimeZoneId));
 }
Ejemplo n.º 18
0
        public static void MoveAccount(int AccountId, int NewParentId)
        {
            // Проверка на соответствие проектов:
            int oldProjectId = -1;
            int newProjectId = -1;

            using (IDataReader reader = DBFinance.GetAccount(AccountId))
            {
                reader.Read();
                oldProjectId = (int)reader["ProjectId"];
            }
            using (IDataReader reader = DBFinance.GetAccount(NewParentId))
            {
                reader.Read();
                newProjectId = (int)reader["ProjectId"];
            }
            if (oldProjectId != newProjectId)
            {
                throw new AccessDeniedException();
            }

            // Проверка на права
            if (!Project.CanEditFinances(newProjectId))
            {
                throw new AccessDeniedException();
            }

            // Проверка на дочерние элементы
            bool CanMove = false;

            using (IDataReader reader = DBFinance.GetListAccountsForMove(AccountId))
            {
                while (reader.Read())
                {
                    if ((int)reader["AccountId"] == NewParentId)
                    {
                        CanMove = true;
                        break;
                    }
                }
            }
            if (!CanMove)
            {
                throw new AccessDeniedException();
            }

            // Предварительная работа
            int oldParentId = DBFinance.GetParentAccountId(AccountId);

            // Найдём всех детей (для перенумерации)
            ArrayList children = new ArrayList();

            using (IDataReader reader = DBFinance.GetListChildrenAccounts(AccountId))
            {
                while (reader.Read())
                {
                    children.Add((int)reader["AccountId"]);
                }
            }

            // Обработка
            using (DbTransaction tran = DbTransaction.Begin())
            {
                // Move
                DBFinance.MoveAccount(AccountId, NewParentId);

                // Найдём всех бывших сестёр (для перенумерации)
                ArrayList siblings = new ArrayList();
                using (IDataReader reader = DBFinance.GetListChildrenAccounts(oldParentId))
                {
                    while (reader.Read())
                    {
                        siblings.Add((int)reader["AccountId"]);
                    }
                }

                // Перенумеруем новую ветку
                ProcessRenumber(AccountId, children);

                // Обработаем старую ветку
                if (siblings.Count == 0)
                {
                    DBFinance.UpdateIsSummary(oldParentId, false);
                }
                else
                {
                    ProcessRenumber(oldParentId, siblings);
                }

                // Пересчитаем новую ветку
                RecalculateParentAccounts(AccountId, false);

                // Пересчитаем старую ветку
                RecalculateParentAccounts(oldParentId, true);

                tran.Commit();
            }
        }
Ejemplo n.º 19
0
 public static void ExpandAccount(int AccountId)
 {
     DBFinance.DeleteCollapsedAccount(Security.CurrentUser.UserID, AccountId);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Reader returns fields:
 ///		AccountId, Title, OutlineLevel, OutlineNumber, IsSummary
 /// </summary>
 public static IDataReader GetListAccountsForMove(int AccountId)
 {
     return(DBFinance.GetListAccountsForMove(AccountId));
 }
Ejemplo n.º 21
0
 public static DataTable GetListAccountsForMoveDataTable(int AccountId)
 {
     return(DBFinance.GetListAccountsForMoveDataTable(AccountId));
 }
Ejemplo n.º 22
0
        public static void UpdateEstimatedAccount(int AccountId, decimal TotalValue, bool PreserveParentValue)
        {
            if (!CanWork(AccountId))
            {
                throw new AccessDeniedException();
            }

            decimal ESub   = 0;
            decimal ETotal = 0;

            using (IDataReader reader = DBFinance.GetAccount(AccountId))
            {
                reader.Read();
                ESub   = (decimal)reader["ESub"];                       // сумма дочерних
                ETotal = (decimal)reader["ETotal"];                     // старый общий итог
            }

            // Новый итог не может быть меньше суммы старых дочерних значений
            if (TotalValue < ESub)
            {
                throw new WrongDataException();
            }

            // Oleg Rylin [5/23/2006]
            // Проверка на то, чтобы не вылезти из родительского диапазона
            // Т.е. разница между тем, что было (ETotal) и тем, что стало (TotalValue),
            // не должна быть больше ECur родителя (parentECur)
            if (PreserveParentValue)
            {
                decimal parentECur = 0;
                int     ParentId   = DBFinance.GetParentAccountId(AccountId);
                if (ParentId > 0)
                {
                    using (IDataReader reader = DBFinance.GetAccount(ParentId))
                    {
                        reader.Read();
                        parentECur = (decimal)reader["ECur"];                                   // настолько можно изменить значение
                    }
                    if (TotalValue - ETotal > parentECur)
                    {
                        throw new WrongDataException();
                    }
                }
            }

            decimal ECur = TotalValue - ESub;

            using (DbTransaction tran = DbTransaction.Begin())
            {
                DBFinance.UpdateAccountECur(AccountId, ECur, Security.CurrentUser.UserID);

                if (PreserveParentValue)
                {
                    RecalculateParentAccountWithPreserving(AccountId);
                }
                else
                {
                    RecalculateParentAccounts(AccountId, false);
                }

                tran.Commit();
            }
        }