Ejemplo n.º 1
0
        public void FillPage(EmployeePeriodsInfoDs periodsDs, DateTime _startPeriod, DateTime _endPeriod,
                             int currentPage, int rowsPerPage)
        {
            //foreach (EmployeePeriodsInfoDs.СотрудникиRow row in periodsDs.Сотрудники.Rows)
            _sourceTable.Rows.Clear();
            CountEmployee = periodsDs.Сотрудники.Rows.Count;
            var startPosition = currentPage * rowsPerPage - rowsPerPage;
            var endPosition   = currentPage * rowsPerPage;

            if (endPosition >= CountEmployee)
            {
                endPosition = CountEmployee;
            }
            for (var i = startPosition; i < endPosition; i++)
            {
                var row         = (EmployeePeriodsInfoDs.СотрудникиRow)periodsDs.Сотрудники.Rows[i];
                var periodsInfo = new EmployeeTimePeriodsInfo(_startPeriod, _endPeriod, row.КодСотрудника,
                                                              PrimaryEmployeeCalc, periodsDs.ПроходыСотрудников);
                var empName = _sourcePage.IsRusLocal ? row.Сотрудник : row.Employee;

                var strEntranceTime   = "";
                var strExitTime       = "";
                var isEnterAfterExit  = "";
                var isEnterAfterExit2 = "";

                if (periodsInfo.ExitTime != null)
                {
                    strExitTime = ((DateTime)periodsInfo.ExitTime).ToString("HH:mm:ss");
                }


                if (periodsInfo.EntranceTime != null)
                {
                    strEntranceTime = ((DateTime)periodsInfo.EntranceTime).ToString("HH:mm:ss");
                }

                if (periodsInfo.ExitTime != null && periodsInfo.EntranceTime != null &&
                    (DateTime)periodsInfo.EntranceTime > (DateTime)periodsInfo.ExitTime)
                {
                    isEnterAfterExit  = "<div>00:00:00</div><hr />";
                    isEnterAfterExit2 = "<hr /><div>24:00:00</div>";
                }

                if (periodsInfo.ExitTime == null && periodsInfo.EntranceTime == null &&
                    periodsInfo.ExitTimePrevDay != null && periodsInfo.EnterTimeNextDay != null)
                {
                    //strExitTime = String.Format("{0}-{1}-{2} {3}:{4}:{5}", ((DateTime)periodsInfo.ExitTimePrevDay).Year.ToString(CultureInfo.InvariantCulture),
                    //    ((DateTime)periodsInfo.ExitTimePrevDay).Month.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.ExitTimePrevDay).Day.ToString(CultureInfo.InvariantCulture),
                    //    ((DateTime)periodsInfo.ExitTimePrevDay).Hour.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.ExitTimePrevDay).Minute.ToString(CultureInfo.InvariantCulture),
                    //    ((DateTime)periodsInfo.ExitTimePrevDay).Second.ToString(CultureInfo.InvariantCulture));
                    strExitTime = ((DateTime)periodsInfo.ExitTimePrevDay).ToString("HH:mm:ss");
                    //strEntranceTime = String.Format("{0}-{1}-{2} {3}:{4}:{5}", ((DateTime)periodsInfo.EnterTimeNextDay).Year.ToString(CultureInfo.InvariantCulture),
                    //    ((DateTime)periodsInfo.EnterTimeNextDay).Month.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.EnterTimeNextDay).Day.ToString(CultureInfo.InvariantCulture),
                    //    ((DateTime)periodsInfo.EnterTimeNextDay).Hour.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.EnterTimeNextDay).Minute.ToString(CultureInfo.InvariantCulture),
                    //    ((DateTime)periodsInfo.EnterTimeNextDay).Second.ToString(CultureInfo.InvariantCulture));
                    strEntranceTime   = ((DateTime)periodsInfo.EnterTimeNextDay).ToString("HH:mm:ss");
                    isEnterAfterExit  = "<div>00:00:00</div><hr />";
                    isEnterAfterExit2 = "<hr /><div>24:00:00</div>";
                }

                if (periodsInfo.ExitTime == null && periodsInfo.EntranceTime != null &&
                    periodsInfo.EnterTimeNextDay != null)
                {
                    strExitTime = "24:00:00";
                }
                if (periodsInfo.ExitTime != null && periodsInfo.EntranceTime == null &&
                    periodsInfo.ExitTimePrevDay != null)
                {
                    strEntranceTime = "00:00:00";
                }

                object absentTime;

                var periodsInfoTotalAbsentTime = periodsInfo.TotalAbsentTime;
                if ((int)periodsInfoTotalAbsentTime.TotalSeconds != 0)
                {
                    absentTime = string.Format("{0}:{1}:{2}",
                                               periodsInfoTotalAbsentTime.Hours + periodsInfoTotalAbsentTime.Days * 24,
                                               periodsInfoTotalAbsentTime.Minutes.ToString("D2"),
                                               periodsInfoTotalAbsentTime.Seconds.ToString("D2"));
                }
                else
                {
                    absentTime = "";
                }

                object workTime;
                var    periodsInfoTotalWorkTime = periodsInfo.TotalWorkTime;
                if ((int)periodsInfoTotalWorkTime.TotalSeconds != 0)
                {
                    workTime = string.Format("{0}:{1}:{2}",
                                             periodsInfoTotalWorkTime.Hours + periodsInfoTotalWorkTime.Days * 24,
                                             periodsInfoTotalWorkTime.Minutes.ToString("D2"),
                                             periodsInfoTotalWorkTime.Seconds.ToString("D2"));
                }
                else
                {
                    workTime = "";
                }

                if (periodsInfo.HasErrors)
                {
                    workTime = workTime + " *";
                }

                _sourceTable.Rows.Add(row.КодСотрудника, row.КодЛица, null, null, strEntranceTime, strExitTime,
                                      absentTime, workTime, periodsInfoTotalAbsentTime, periodsInfoTotalWorkTime, empName,
                                      periodsInfo.HasErrors ? "errorRow" : "singleRow", "", "", isEnterAfterExit, isEnterAfterExit2);
                if (periodsInfo.HasErrors && !IsError)
                {
                    IsError = true;
                }
            }
        }
        /// <summary>
        ///     Получение списка дней за выбранный период
        /// </summary>
        /// <param name="startPeriodParam">Дата начала</param>
        /// <param name="endPeriodParam">Дата конца</param>
        /// <param name="semplId">ID сотрудника</param>
        /// <param name="stz">Таймзона</param>
        public void CompleteDaysTable(DateTime?startPeriodParam, DateTime?endPeriodParam, string semplId, string stz)
        {
            int tz, emplId;

            try
            {
                tz = Convert.ToInt32(stz);
            }
            catch
            {
                tz = 0;
            }

            try
            {
                emplId = Convert.ToInt32(semplId);
            }
            catch
            {
                emplId = 0;
            }

            //bool hasNewIds = _needCheckIndex && (EmployeeTimePeriodsInfo.GetMaxId(_startDate, _endDate, _emplId, -tz) != _maxIndex);
            //bool sourceChanged = (_startDate == DateTime.MinValue) || (_endDate == DateTime.MinValue) || hasNewIds;
            //bool sourceChanged = true;
            var startPeriod = startPeriodParam ?? DateTime.MinValue;
            var endPeriod   = endPeriodParam ?? DateTime.MinValue;

            //if (emplId != _emplId || sourceChanged)
            //{
            //    ClearCash();
            //}
            ClearCash();
            if (startPeriod != _startDate || endPeriod != _endDate)
            {
                IsError   = false;
                _holidays = CompleteHolidaysInfoDs(startPeriod, endPeriod);
                var minDate = DateTime.MaxValue;
                var maxDate = DateTime.MinValue;

                var temp = _sourceTable.Clone();

                foreach (DataRow row in _sourceTable.Rows)
                {
                    if (((DateTime)row["DAY_VALUE"]).Date <= endPeriod.Date &&
                        ((DateTime)row["DAY_VALUE"]).Date >= startPeriod.Date)
                    {
                        if (minDate > ((DateTime)row["DAY_VALUE"]).Date)
                        {
                            minDate = ((DateTime)row["DAY_VALUE"]).Date;
                        }

                        if (maxDate < ((DateTime)row["DAY_VALUE"]).Date)
                        {
                            maxDate = ((DateTime)row["DAY_VALUE"]).Date;
                        }

                        temp.ImportRow(row);
                    }
                }

                _sourceTable.Rows.Clear();
                _sourceTable = temp.Copy();

                EmployeePeriodsInfoDs periodsDs;

                if (maxDate < minDate)
                {
                    _startDate = DateTime.MinValue;
                    _endDate   = DateTime.MinValue;
                    periodsDs  = new ExecQuery().CompleteEmployeePeriodsInfoDs(emplId, startPeriod.Date, endPeriod.Date,
                                                                               -tz);
                }
                else
                {
                    if (minDate.Date != startPeriod.Date && maxDate.Date != endPeriod.Date)
                    {
                        periodsDs = new ExecQuery().CompleteEmployeePeriodsInfoDs(emplId, startPeriod.Date,
                                                                                  minDate.Date, maxDate.Date, endPeriod.Date.AddDays(1));
                    }
                    else if (minDate.Date != startPeriod.Date)
                    {
                        periodsDs = new ExecQuery().CompleteEmployeePeriodsInfoDs(emplId, startPeriod.Date,
                                                                                  minDate.Date, -tz);
                    }
                    else if (maxDate.Date != endPeriod.Date)
                    {
                        periodsDs = new ExecQuery().CompleteEmployeePeriodsInfoDs(emplId, maxDate.Date, endPeriod.Date,
                                                                                  -tz);
                    }
                    else
                    {
                        periodsDs = new EmployeePeriodsInfoDs();
                    }

                    _startDate = minDate;
                    _endDate   = maxDate;
                }

                if (periodsDs.Сотрудники.Rows.Count > 0)
                {
                    _empNameRus = ((EmployeePeriodsInfoDs.СотрудникиRow)periodsDs.Сотрудники.Rows[0]).Сотрудник;
                    _empNameLat = ((EmployeePeriodsInfoDs.СотрудникиRow)periodsDs.Сотрудники.Rows[0]).Employee;
                }

                var dayIntervals = new EmployeeTimeInervals();

                for (var curentDay = startPeriod; curentDay <= endPeriod; curentDay = curentDay.AddDays(1))
                {
                    dayIntervals.Add(new TimeInterval(curentDay.Date, curentDay.Date.AddDays(1), -1));
                }
                var isEnterPrevDayByDay = false;
                foreach (TimeInterval curInterval in dayIntervals)
                {
                    if (curInterval.StartTime.Date >= _startDate.Date &&
                        curInterval.StartTime.Date <= _endDate.Date)
                    {
                        continue;
                    }

                    var periodsInfo = new EmployeeTimePeriodsInfo(curInterval.StartTime, curInterval.EndTime, emplId,
                                                                  PrimaryEmployeeCalc, periodsDs.ПроходыСотрудников, true, isEnterPrevDayByDay);
                    isEnterPrevDayByDay = periodsInfo.IsEnterPrevDayByDay;
                    var internetAccessInfo =
                        new EmployeeInternetAccessInfo(curInterval.StartTime, curInterval.EndTime, emplId);

                    object linkCell = null;

                    if (periodsInfo.EntranceTime != null || periodsInfo.ExitTime != null ||
                        periodsInfo.ExitTimePrevDay != null && periodsInfo.EnterTimeNextDay != null)
                    {
                        linkCell = string.Format(
                            "<A href=\"#\" onclick=\"cmd('cmd', 'openDetails', 'id', '{0}', 'from', '{1}', 'to', '{2}');\"><IMG src=\"{3}detail.GIF\" border=\"0\" title=\"{4}\"></A>",
                            emplId, curInterval.StartTime, curInterval.EndTime, Global.Styles,
                            _resx.GetString("hPageSubTitleDetails2"));
                    }

                    var totalWorkTime   = periodsInfo.TotalWorkTime;
                    var totalAbsentTime = periodsInfo.TotalAbsentTime;

                    var strEntranceTime   = "";
                    var strExitTime       = "";
                    var isEnterAfterExit  = "";
                    var isEnterAfterExit2 = "";

                    if (periodsInfo.ExitTime != null)
                    {
                        strExitTime = ((DateTime)periodsInfo.ExitTime).ToString("HH:mm:ss");
                    }

                    if (periodsInfo.EntranceTime != null)
                    {
                        strEntranceTime = ((DateTime)periodsInfo.EntranceTime).ToString("HH:mm:ss");
                    }

                    if (periodsInfo.ExitTime != null && periodsInfo.EntranceTime != null &&
                        (DateTime)periodsInfo.EntranceTime > (DateTime)periodsInfo.ExitTime)
                    {
                        isEnterAfterExit  = "<div>00:00:00</div><hr />";
                        isEnterAfterExit2 = "<hr /><div>24:00:00</div>";
                    }

                    if (periodsInfo.ExitTime == null && periodsInfo.EntranceTime == null &&
                        periodsInfo.ExitTimePrevDay != null && periodsInfo.EnterTimeNextDay != null)
                    {
                        //strExitTime = String.Format("{0}-{1}-{2} {3}:{4}:{5}", ((DateTime)periodsInfo.ExitTimePrevDay).Year.ToString(CultureInfo.InvariantCulture),
                        //    ((DateTime)periodsInfo.ExitTimePrevDay).Month.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.ExitTimePrevDay).Day.ToString(CultureInfo.InvariantCulture),
                        //    ((DateTime)periodsInfo.ExitTimePrevDay).Hour.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.ExitTimePrevDay).Minute.ToString(CultureInfo.InvariantCulture),
                        //    ((DateTime)periodsInfo.ExitTimePrevDay).Second.ToString(CultureInfo.InvariantCulture));
                        strExitTime = ((DateTime)periodsInfo.ExitTimePrevDay).ToString("HH:mm:ss");
                        //strEntranceTime = String.Format("{0}-{1}-{2} {3}:{4}:{5}", ((DateTime)periodsInfo.EnterTimeNextDay).Year.ToString(CultureInfo.InvariantCulture),
                        //    ((DateTime)periodsInfo.EnterTimeNextDay).Month.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.EnterTimeNextDay).Day.ToString(CultureInfo.InvariantCulture),
                        //    ((DateTime)periodsInfo.EnterTimeNextDay).Hour.ToString(CultureInfo.InvariantCulture), ((DateTime)periodsInfo.EnterTimeNextDay).Minute.ToString(CultureInfo.InvariantCulture),
                        //    ((DateTime)periodsInfo.EnterTimeNextDay).Second.ToString(CultureInfo.InvariantCulture));
                        strEntranceTime   = ((DateTime)periodsInfo.EnterTimeNextDay).ToString("HH:mm:ss");
                        isEnterAfterExit  = "<div>00:00:00</div><hr />";
                        isEnterAfterExit2 = "<hr /><div>24:00:00</div>";
                    }

                    if (periodsInfo.ExitTime == null && periodsInfo.EntranceTime != null &&
                        periodsInfo.EnterTimeNextDay != null)
                    {
                        strExitTime = "24:00:00";
                    }
                    if (periodsInfo.ExitTime != null && periodsInfo.EntranceTime == null &&
                        periodsInfo.ExitTimePrevDay != null)
                    {
                        strEntranceTime = "00:00:00";
                    }

                    object absentTime = null;
                    object workTime   = null;

                    if (totalAbsentTime.TotalSeconds > 0)
                    {
                        absentTime = string.Format("{0}:{1}:{2}", totalAbsentTime.Hours + totalAbsentTime.Days * 24,
                                                   totalAbsentTime.Minutes.ToString("D2"), totalAbsentTime.Seconds.ToString("D2"));
                    }

                    if (totalWorkTime.TotalSeconds > 0)
                    {
                        //workTime = String.Format("<P align=\"center\">{0}:{1}:{2}</P>", totalWorkTime.Hours + (totalWorkTime.Days * 24), totalWorkTime.Minutes.ToString("D2"),
                        //    totalWorkTime.Seconds.ToString("D2"));
                        workTime = string.Format("{0}:{1}:{2}", totalWorkTime.Hours + totalWorkTime.Days * 24,
                                                 totalWorkTime.Minutes.ToString("D2"), totalWorkTime.Seconds.ToString("D2"));
                        if (periodsInfo.HasErrors)
                        {
                            workTime = workTime + " *";
                        }
                    }

                    var internetAccessInfoCount = internetAccessInfo.Count;
                    var internetAccessCount     = "";
                    if (internetAccessInfoCount != 0)
                    {
                        internetAccessCount = internetAccessInfoCount.ToString(CultureInfo.InvariantCulture);
                    }

                    string internetAccessTotal;
                    var    internetAccessInfoTotal = internetAccessInfo.Total;
                    if (internetAccessInfoTotal == 0)
                    {
                        internetAccessTotal = "";
                    }
                    else
                    {
                        internetAccessTotal = new TimeSpan(0, 0, internetAccessInfoTotal).ToString();
                    }

                    _sourceTable.Rows.Add(linkCell, curInterval.StartTime, strEntranceTime, strExitTime, absentTime,
                                          workTime, totalAbsentTime, totalWorkTime, periodsInfo.HasErrors ? "errorRow" : "singleRow",
                                          internetAccessCount, internetAccessTotal, isEnterAfterExit, isEnterAfterExit2);
                    if (periodsInfo.HasErrors && !IsError)
                    {
                        IsError = true;
                    }
                }

                _emplId    = emplId;
                _startDate = startPeriod;
                _endDate   = endPeriod;
                //_maxIndex = EmployeeTimePeriodsInfo.GetMaxId(_startDate, _endDate, _emplId, -tz);
                //_needCheckIndex = (_maxIndex == EmployeeTimePeriodsInfo.GetMaxId(_emplId)) || (_maxIndex == -1);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Расчет проходов сотрудников
        /// </summary>
        /// <param name="startPeriod"></param>
        /// <param name="endPeriod"></param>
        /// <param name="filterEmployee"></param>
        /// <param name="filterCompany"></param>
        /// <param name="filterPost"></param>
        /// <param name="filterSubdiv"></param>
        /// <param name="filterTimeExitActive"></param>
        /// <param name="tm"></param>
        /// <param name="filterActiveOnly"></param>
        /// <param name="stz"></param>
        /// <param name="isReversCompany"></param>
        /// <param name="isReversSubdivision"></param>
        /// <param name="isReversPosition"></param>
        /// <param name="isReversPerson"></param>
        /// <param name="currentPage"> </param>
        /// <param name="rowsPerPage"> </param>
        /// <param name="subEmpl"> </param>
        public void CompleteEmplTable(DateTime?startPeriod, DateTime?endPeriod, string filterEmployee,
                                      string filterCompany, string filterPost, string filterSubdiv,
                                      bool filterTimeExitActive, DateTime tm, bool filterActiveOnly, string stz, string isReversCompany,
                                      string isReversSubdivision, string isReversPosition, string isReversPerson,
                                      int currentPage, int rowsPerPage, bool subEmpl)
        {
            int tz;

            try
            {
                tz = Convert.ToInt32(stz);
            }
            catch
            {
                tz = 0;
            }

            var hasNewIds    = _needCheckId && EmployeeTimePeriodsInfo.GetMaxId(_startDate, _endDate, -tz) != _maxIndex;
            var isChanged    = _startDate == DateTime.MinValue || _endDate == DateTime.MinValue || hasNewIds;
            var _startPeriod = startPeriod ?? new DateTime(1753, 1, 2);
            var _endPeriod   = endPeriod ?? new DateTime(1753, 1, 2);

            if (startPeriod != _startDate || endPeriod != _endDate || !filterEmployee.Equals(_filterEmployee) ||
                !filterCompany.Equals(_filterCompany) || !filterPost.Equals(_filterPost) ||
                !filterSubdiv.Equals(_filterSubdiv) || isChanged || _filterActiveOnly != filterActiveOnly ||
                _isReversCompany != isReversCompany || _isReversSubdivision != isReversSubdivision ||
                _isReversPosition != isReversPosition || _isReversPerson != isReversPerson ||
                _subEmpl != subEmpl)
            {
                ClearCash();
                IsError   = false;
                periodsDs = new ExecQuery().CompleteEmployeePeriodsInfoDs(filterEmployee, filterCompany, filterPost,
                                                                          filterSubdiv, _startPeriod, _endPeriod,
                                                                          _sourcePage.IsRusLocal, -tz, filterTimeExitActive, tm, filterActiveOnly, isReversCompany,
                                                                          isReversSubdivision, isReversPosition, isReversPerson, subEmpl);

                FillPage(periodsDs, _startPeriod, _endPeriod, currentPage, rowsPerPage);

                _startDate           = _startPeriod;
                _endDate             = _endPeriod;
                _filterEmployee      = filterEmployee;
                _filterCompany       = filterCompany;
                _filterPost          = filterPost;
                _filterActiveOnly    = filterActiveOnly;
                _filterSubdiv        = filterSubdiv;
                _isReversCompany     = isReversCompany;
                _isReversSubdivision = isReversSubdivision;
                _isReversPosition    = isReversPosition;
                _isReversPerson      = isReversPerson;
                _maxIndex            = EmployeeTimePeriodsInfo.GetMaxId(_startDate, _endDate, -tz);
                _needCheckId         = _maxIndex == EmployeeTimePeriodsInfo.GetMaxId() || _maxIndex == -1;
                _currentPage         = currentPage;
                _rowsPerPage         = rowsPerPage;
                _subEmpl             = subEmpl;
            }
            else if (currentPage != _currentPage || rowsPerPage != _rowsPerPage)
            {
                FillPage(periodsDs, _startPeriod, _endPeriod, currentPage, rowsPerPage);
                _currentPage = currentPage;
                _rowsPerPage = rowsPerPage;
            }
        }