Exemplo n.º 1
0
        public void AddLatestClosedWorkEvent(TimeSpan duration, WorkEventType eventType)
        {
            var mainWorkEvent = GetMainWorkEvent(DateTime.Today);

            if (mainWorkEvent == null)
                throw new Exception("There is no main work event.");

            if (mainWorkEvent.BeginTime > DateTime.Now)
                throw new Exception("Can't open work event outside main work event.");

            // Получим все события за сегодня отсортированные по дате создания.
            var workEvents = WorkEvent.GetEventsOfDate(m_UserID, DateTime.Today).
                OrderByDescending(workEvent => workEvent.BeginTime).ToList();

            var startDate = mainWorkEvent.BeginTime;
            var endDate = mainWorkEvent.IsOpen
                                   	? DateTime.Now
                                   	: mainWorkEvent.EndTime;

            foreach (var workEvent in workEvents)
            {
                var isMainWorkEvent = WorkEvent.IsMainWorkEvent(workEvent.EventTypeID);

                if (workEvent.IsOpen && !isMainWorkEvent)
                {
                    endDate = workEvent.BeginTime;
                    continue;
                }

                startDate = isMainWorkEvent
                                ? workEvent.BeginTime
                                : workEvent.EndTime;

                if (endDate - startDate >= duration)
                    break;

                endDate = workEvent.BeginTime;
            }

            if (endDate - startDate >= duration)
                WorkEvent.CreateEvent(endDate - duration, endDate, m_UserID, (int) WorkEventType.TimeOff);
            else
                throw new Exception("Cannot add closed interval. Not enough time.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens work or break event.
        /// </summary>
        /// <param name="eventType">Work event type.</param>
        public void OpenWorkBreakEvent(WorkEventType eventType)
        {
            if (WorkEvent.IsMainWorkEvent((int) eventType))
                throw new ArgumentException("Event type is incorrect.");

            if (WorkEvent.IsLunchEvent((int) eventType))
                throw new ArgumentException("Event type is incorrect.");

            if (!WorkEvent.IsWorkEvent((int) eventType) && !WorkEvent.IsBreakEvent((int) eventType))
                throw new ArgumentException("Event type is incorrect.");

            WorkEvent mainWorkEvent = GetMainWorkEvent(DateTime.Today);

            if (mainWorkEvent == null)
                throw new Exception("There is no main work event.");

            if (!mainWorkEvent.IsOpen)
                throw new Exception("There is no open main work event.");

            if (mainWorkEvent.BeginTime > DateTime.Now)
                throw new Exception("Can't open work event outside main work event.");

            // Закрыть все открытые в рамках текущего MW события.
            foreach (WorkEvent workEvent in WorkEvent.GetEventsOfDate(m_UserID, DateTime.Today))
            {
                if (!workEvent.IsOpen || WorkEvent.IsMainWorkEvent(workEvent.EventTypeID))
                    continue;

                if (WorkEvent.IsWorkEvent(workEvent.EventTypeID))
                {
                    CloseWorkBreakEvent();
                }
                else if (WorkEvent.IsLunchEvent(workEvent.EventTypeID))
                {
                    CloseLunchEvent();
                }
                else if (WorkEvent.IsBreakEvent(workEvent.EventTypeID))
                {
                    CloseWorkBreakEvent();
                }
            }

            WorkEvent.CreateEvent(DateTime.Now, DateTime.Now,
                                  m_UserID, (int) eventType);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates absence event for current date.
 /// </summary>
 /// <param name="eventType">Absence event type.</param>
 /// <exception cref="Exception">There already is open main work event.</exception>
 public void CreateAbsenceEvent( WorkEventType eventType )
 {
     CreateAbsenceEvent(eventType, DateTime.Today);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates absence event for given date.
        /// </summary>
        /// <param name="eventType">Absence event type.</param>
        /// <param name="date">Date of absence.</param>
        /// <exception cref="Exception">There already is open main work event.</exception>
        public void CreateAbsenceEvent(WorkEventType eventType, DateTime date)
        {
            if (!WorkEvent.IsAbsenceEvent((int) eventType))
                throw new ArgumentException("Event type is incorrect.");

            LogUserWorkEvent(m_UserID, "Absence", true);

            date = date.Date.AddHours(12);

            WorkEvent.CreateEvent(date,
                                  date + Globals.Settings.WorkTime.DefaultWorkTime +
                                  Globals.Settings.WorkTime.MaxLunchTime,
                                  m_UserID, (int) eventType);
        }
Exemplo n.º 5
0
    private void setUserWorkEvent(bool isOpenAction, WorkEventType eventType)
    {
        if (!WebHelpers.IsRequestIPAllowed())
            return;

        SLService.SLService service = new SLService.SLService();
        service.SetUserWorkEvent(Page.CurrentUser.ID.Value, isOpenAction, eventType);
    }
Exemplo n.º 6
0
        public WorkEvent[] SetUserWorkEvent(int userID, bool isOpenAction, WorkEventType eventType)
        {
            try
            {
                var userWorkEvents = new UserWorkEvents(userID);

                switch (eventType)
                {
                    case WorkEventType.MainWork:
                        {
                            if (isOpenAction)
                                userWorkEvents.OpenMainWorkEvent();
                            else
                                userWorkEvents.CloseMainWorkEvent();

                            break;
                        }

                    case WorkEventType.TimeOff:
                        {
                            if (isOpenAction)
                                userWorkEvents.OpenWorkBreakEvent(WorkEventType.TimeOff);
                            else
                                userWorkEvents.CloseWorkBreakEvent();
                            break;
                        }

                    case WorkEventType.LanchTime:
                        {
                            if (isOpenAction)
                                userWorkEvents.OpenLunchEvent();
                            else
                                userWorkEvents.CloseLunchEvent();
                            break;
                        }

                    case WorkEventType.StudyEnglish:
                        {
                            if (isOpenAction)
                                userWorkEvents.OpenWorkBreakEvent(WorkEventType.StudyEnglish);
                            else
                                userWorkEvents.CloseWorkBreakEvent();

                            break;
                        }
                }
                return GetTodayWorkEventsOfUser(userID);
            }
            catch
            {
                return null;
            }
        }
Exemplo n.º 7
0
    /// <summary>
    /// Create absence event for user.
    /// </summary>
    /// <param name="sender">Image button.</param>
    /// <param name="eventType">Type of event.</param>
    private void createAbsenceEvent(Object sender, WorkEventType eventType)
    {
        try
        {
            if (!(sender is ImageButton))
                return;

            var b = (ImageButton)sender;

            int userID;
            if (!Int32.TryParse(b.CommandArgument, out userID))
                return;

            var userEvents = new UserWorkEvents(userID);
            userEvents.CreateAbsenceEvent(eventType, Date);

            FillUsersGrid();
        }
        catch (Exception ex)
        {
            lblException.Text = ex.Message;
            lblException.Visible = true;
        }
    }
Exemplo n.º 8
0
        /// <summary>
        /// Writes information about event.
        /// </summary>
        /// <param name="userCode">3-symbol code of user.</param>
        /// <param name="eventBegin">Beginning time.</param>
        /// <param name="eventEnd">Ending time.</param>
        /// <param name="eventType">Event type.</param>
        private void WriteEvent( string userCode, DateTime eventBegin, DateTime eventEnd, WorkEventType eventType )
        {
            if( string.IsNullOrEmpty( userCode ))
                throw new ArgumentNullException( "userCode" );

            Debug.Assert( m_ReportTable != null );

            string beginTime = eventBegin.ToString( "HH:mm" );
            string endTime = eventEnd.ToString( "HH:mm" );

            DataRow row = m_ReportTable.NewRow();
            row[ "RecordID" ] = string.Empty;
            row[ "RegDate" ] = eventBegin.ToString( "dd.MM.yyyy" );
            row[ "USICode" ] = userCode;

            switch( eventType )
            {
                case WorkEventType.BusinessTrip:
                    row[ "DaySign" ] = 3;
                    row[ "ComeTime" ] = beginTime;
                    row[ "LeaveTime" ] = endTime;
                    break;
                case WorkEventType.Ill:
                    row[ "DaySign" ] = 4;
                    row[ "ComeTime" ] = string.Empty;
                    row[ "LeaveTime" ] = string.Empty;
                    break;
                case WorkEventType.LanchTime:
                    break;
                case WorkEventType.MainWork:
                    row[ "DaySign" ] = 1;
                    row[ "ComeTime" ] = beginTime;
                    row[ "LeaveTime" ] = endTime;
                    break;
                case WorkEventType.OfficeOut:
                    row[ "DaySign" ] = 8;
                    row[ "ComeTime" ] = beginTime;
                    row[ "LeaveTime" ] = endTime;
                    break;
                case WorkEventType.StudyEnglish:
                    break;
                case WorkEventType.TimeOff:
                    break;
                case WorkEventType.TrustIll:
                    row[ "DaySign" ] = 5;
                    row[ "ComeTime" ] = string.Empty;
                    row[ "LeaveTime" ] = string.Empty;
                    break;
                case WorkEventType.Vacation:
                    row[ "DaySign" ] = 2;
                    row[ "ComeTime" ] = string.Empty;
                    row[ "LeaveTime" ] = string.Empty;
                    break;
            }

            row[ "Notes" ] = string.Empty;
            row[ "Absense" ] = 0;

            m_ReportTable.Rows.Add( row );
        }
Exemplo n.º 9
0
 /// <summary>
 /// Возвращает имя типа события.
 /// </summary>
 /// <param name="eventType">Тип события.</param>
 /// <returns>Имя типа события.</returns>
 private string GetEventName(WorkEventType eventType)
 {
     return Enum.GetName( typeof( WorkEventType ), eventType );
 }