Ejemplo n.º 1
0
        public void RegisterChangeOrderObject(OrderObject newObj)
        {
            Logger.info("Пользователь изменил оборудование", Logger.LoggerSource.objectsContext);
            try {
                if (!CurrentUser.AllowEditTree)
                {
                    throw new Exception("У вас нет прав редактировать оборудование");
                }
                VotGESOrdersEntities context = new VotGESOrdersEntities();

                IQueryable <OrderObjects> objectsDB = (from o in context.OrderObjects where o.objectID == newObj.ObjectID select o);
                OrderObjects objDB = null;
                if (objectsDB.Count() == 0)
                {
                    Logger.info("===Новое оборудование", Logger.LoggerSource.objectsContext);
                    objDB = new OrderObjects();
                    context.OrderObjects.AddObject(objDB);
                }
                else
                {
                    objDB = objectsDB.First();
                }
                objDB.objectName     = newObj.ObjectName;
                objDB.parentID       = newObj.ParentObjectID;
                objDB.showInFullName = newObj.ShowInFullName;

                context.SaveChanges();

                newObj.ObjectID   = objDB.objectID;
                newObj.ObjectName = objDB.objectName;
                OrderObject.init();
                newObj.FullName = OrderObject.getByID(newObj.ObjectID).getFullName();
                Logger.info("===Сохранено", Logger.LoggerSource.objectsContext);
            } catch (Exception e) {
                Logger.error(String.Format("===Ошибка при изменении оборудования: {0}", e), Logger.LoggerSource.objectsContext);
                if (e is Exception)
                {
                    throw e;
                }
                throw new Exception("Ошибка при изменении/создании оборудования");
            }
        }
Ejemplo n.º 2
0
        public void refreshOrderFromDB(Orders dbOrder, OrdersUser currentUser, bool readRelated, List <Order> listOrders)
        {
            if (listOrders != null)
            {
                if (!listOrders.Contains(this))
                {
                    listOrders.Add(this);
                }
            }

            OrderOperation = OrderOperationEnum.none;
            checkPremissions(dbOrder, currentUser);


            SelOrderObject = OrderObject.getByID(dbOrder.orderObjectID);

            OrderNumber = dbOrder.orderNumber;
            if (dbOrder.orderYearNumber.HasValue)
            {
                OrderYearNumber = dbOrder.orderYearNumber.Value;
            }
            else
            {
                OrderYearNumber = OrderNumber;
            }

            OrderType = (OrderTypeEnum)Enum.Parse(typeof(OrderTypeEnum), dbOrder.orderType, true);
            ReadyTime = dbOrder.readyTime;

            CreateText         = dbOrder.createText;
            ReviewText         = dbOrder.reviewText;
            OpenText           = dbOrder.openText;
            CloseText          = dbOrder.closeText;
            CompleteText       = dbOrder.completeText;
            CancelText         = dbOrder.cancelText;
            OrderObjectAddInfo = dbOrder.orderObjectAddInfo;

            OrderText         = dbOrder.orderText;
            AgreeText         = dbOrder.agreeText;
            AgreeUsersIDSText = dbOrder.agreeUsersIDS;
            refreshAgreeUsers();

            FaktStartDate    = dbOrder.faktStartDate;
            FaktStopDate     = dbOrder.faktStopDate;
            FaktCompleteDate = dbOrder.faktCompleteDate;
            PlanStartDate    = dbOrder.planStartDate;
            PlanStopDate     = dbOrder.planStopDate;

            OrderDateReview   = dbOrder.orderDateReview;
            OrderDateClose    = dbOrder.orderDateClose;
            OrderDateOpen     = dbOrder.orderDateOpen;
            OrderDateCreate   = dbOrder.orderDateCreate;
            OrderDateComplete = dbOrder.orderDateComplete;
            OrderDateCancel   = dbOrder.orderDateCancel;

            ExpiredReglamentHours = dbOrder.expiredReglamentHours;
            ExpiredOpenHours      = dbOrder.expiredOpenHours;
            ExpiredCompleteHours  = dbOrder.expiredCompleteHours;
            ExpiredCloseHours     = dbOrder.expiredCloseHours;

            OrderIsExpiredClose     = ExpiredCloseHours.HasValue && ExpiredCloseHours.Value < 0;
            OrderIsExpiredOpen      = ExpiredOpenHours.HasValue && ExpiredOpenHours.Value < 0;
            OrderIsExpriredComplete = ExpiredCompleteHours.HasValue && ExpiredCompleteHours.Value < 0;
            OrderIsExpiredReglament = ExpiredReglamentHours.HasValue && ExpiredReglamentHours.Value < 0;


            CommentsText = dbOrder.commentsText;
            HasComments  = !String.IsNullOrEmpty(CommentsText) || !String.IsNullOrEmpty(CreateText);


            UserCreateOrder = OrdersUser.loadFromCache(dbOrder.userCreateOrderID);

            if (dbOrder.userReviewOrderID != null)
            {
                UserReviewOrder = OrdersUser.loadFromCache(dbOrder.userReviewOrderID.Value);
            }
            if (dbOrder.userCloseOrderID != null)
            {
                UserCloseOrder = OrdersUser.loadFromCache(dbOrder.userCloseOrderID.Value);
            }
            if (dbOrder.userCancelOrderID != null)
            {
                UserCancelOrder = OrdersUser.loadFromCache(dbOrder.userCancelOrderID.Value);
            }
            if (dbOrder.userOpenOrderID != null)
            {
                UserOpenOrder = OrdersUser.loadFromCache(dbOrder.userOpenOrderID.Value);
            }
            if (dbOrder.userCompleteOrderID != null)
            {
                UserCompleteOrder = OrdersUser.loadFromCache(dbOrder.userCompleteOrderID.Value);
            }



            if (OrderExtended || OrderAskExtended || OrderCompletedWithoutEnter)
            {
                if (readRelated)
                {
                    ChildOrder = GetOrder(dbOrder.childOrderNumber.Value, currentUser, readRelated, listOrders);
                }
                else
                {
                    ChildOrderNumber = dbOrder.childOrderNumber.Value;
                }
                ChildOrderYearNumber = Math.Floor(OrderYearNumber) + ChildOrderNumber - Math.Floor(ChildOrderNumber);
            }
            else
            {
                ChildOrderNumber     = 0;
                ChildOrderYearNumber = 0;
            }


            if (OrderIsExtend || OrderIsFixErrorEnter)
            {
                if (readRelated)
                {
                    ParentOrder = GetOrder(dbOrder.parentOrderNumber.Value, currentUser, readRelated, listOrders);
                }
                else
                {
                    ParentOrderNumber = dbOrder.parentOrderNumber.Value;
                }
                ParentOrderYearNumber = Math.Floor(OrderYearNumber) + ParentOrderNumber - Math.Floor(ParentOrderNumber);
            }
            else
            {
                ParentOrderNumber     = 0;
                ParentOrderYearNumber = 0;
            }

            OrderYearNumber       = checkOrderNumber(OrderYearNumber);
            ParentOrderYearNumber = checkOrderNumber(ParentOrderYearNumber);
            ChildOrderYearNumber  = checkOrderNumber(ChildOrderYearNumber);

            if (OrderIsExtend || OrderIsFixErrorEnter)
            {
                try {
                    OrderYear = GetOrder(Math.Floor(OrderNumber), currentUser, false, null).OrderDateCreate.Year;
                } catch (Exception e) {
                    OrderYear = OrderDateCreate.Year;
                }
            }
            else
            {
                OrderYear = OrderDateCreate.Year;
            }
            OrderNumberFloor = Math.Floor(OrderNumber).ToString();
            OrderNumberExp   = Math.Round(((OrderNumber - Math.Floor(OrderNumber)) * 100)).ToString();
            if (OrderNumberExp.Length == 1)
            {
                OrderNumberExp = "0" + OrderNumberExp;
            }
            IsCurrentYear       = OrderYear == DateTime.Now.Year;
            OrderHasChildOrder  = ChildOrderNumber > 0;
            OrderHasParentOrder = ParentOrderNumber > 0;
            checkTimeToOpen();
        }