/// <summary>
        /// Отображение/скрытие соответсвующих полей окна, загрузка списов из БД (если нужно)
        /// </summary>
        private void AdditionalInitializeComponent()
        {
            const Visibility show = Visibility.Visible;
            const Visibility hide = Visibility.Collapsed;

            // Отображение/скрытие полей
            PeriodWrapperGrid.Visibility                           = _isPeriod ? show : hide;
            MonthOrYearWrapperGrid.Visibility                      = _isMonthOrYear ? show : hide;
            DateWrapperGrid.Visibility                             = _isDate ? show : hide;
            DatePeriodWrapperGrid.Visibility                       = _isDatePeriod ? show : hide;
            KoefTWrapperGrid.Visibility                            = _isKoefT ? show : hide;
            KoefZWrapperGrid.Visibility                            = _isKoefZ ? show : hide;
            CehWrapperGrid.Visibility                              = _isWorkGuild ? show : hide;
            AreaWrapperGrid.Visibility                             = _isArea ? show : hide;
            WorkGuildSpecifiedOrAllWrapperGrid.Visibility          = _isWorkGuildSpecifiedOrAll ? show : hide;
            ProductWrapperGrid.Visibility                          = _isProduct ? show : hide;
            DetailWrapperGrid.Visibility                           = _isDetail ? show : hide;
            ProductSpecifiedOrAllWrapperGrid.Visibility            = _isProductSpecifiedOrAll ? show : hide;
            AssemblyUnitWrapperGrid.Visibility                     = _isAssemblyUnit ? show : hide;
            MonthYearWrapperGrid.Visibility                        = _isMonthYear ? show : hide;
            TimeFundWrapperGrid.Visibility                         = _isTimeFund ? show : hide;
            ProcentageOfLossTimeWrapperGrid.Visibility             = _isProcentageOfLossTime ? show : hide;
            ProcentageOfPerformanceStandartsWrapperGrid.Visibility = _isProcentageOfPerformanceStandarts ? show : hide;
            AreaSpecifiedOrAllWrapperGrid.Visibility               = _isAreaSpecifiedOrAll ? show : hide;

            MessageLabel.Content = _hintMessage;

            // Если вводится [Дата] - значение по-умолчанию сегодняшняя
            if (_isDate)
            {
                DatePicker.SelectedDate = DateTime.Today;
            }

            if (_isWorkGuild)
            {
                try
                {
                    WorkGuildsComboBox.ItemsSource = WorkGuildsService.GetAll();
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                }
            }

            // Если вводится [Изделие] - загрузка списка из БД и заполнение Textbox
            if (_isProductSpecifiedOrAll)
            {
                try
                {
                    _searchProductStorage             = ProductsService.GetProducts();
                    SearchProductDataGrid.ItemsSource = _searchProductStorage;
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                    return;
                }
                ProductAllRadioButton.IsChecked = true;
            }

            // Если вводится [Цех] - загрузка списка из БД и заполнение ComboBox
            if (_isWorkGuildSpecifiedOrAll)
            {
                try
                {
                    WorkguildSpecifiedComboBox.ItemsSource = WorkGuildsService.GetAll();
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                    return;
                }
                WorkguildAllRadioButton.IsChecked = true;
            }

            // Если вводится [Участок] - загрузка списка из БД и заполнение ComboBox
            if (_isAreaSpecifiedOrAll)
            {
                try
                {
                    AreaSpecifiedComboBox.ItemsSource = AreasService.GetAll();
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                    return;
                }

                AreaAllRadioButton.IsChecked = true;
            }

            if (_isArea)
            {
                try
                {
                    AreaComboBox.ItemsSource = AreasService.GetAll();
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                }
            }

            // Если вводится [Изделие] - загрузка списка из БД и заполнение Textbox
            if (_isProduct)
            {
                try
                {
                    _searchProductStorage             = ProductsService.GetProducts();
                    SearchProductDataGrid.ItemsSource = _searchProductStorage;
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                }
            }

            // Если вводится [Деталь] - загрузка списка из БД и заполнение Textbox
            if (_isDetail)
            {
                try
                {
                    _searchDetailStorage             = DetailsService.GetAll();
                    SearchDetailDataGrid.ItemsSource = _searchDetailStorage;
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                }
            }

            // Если вводится [Сборочноя еденица] - загрузка списка из БД и заполнение Textbox
            if (_isAssemblyUnit)
            {
                try
                {
                    _searchProductStorage = ProductsService.GetAssemblyUnits();
                    SearchAssemblyUnitDataGrid.ItemsSource = _searchProductStorage;
                }
                catch (StorageException ex)
                {
                    Common.ShowDetailExceptionMessage(ex);
                }
            }

            // Если вводится [Месяц/Год] - получение Dictionary месяцев и заполнение ComboBox, год текущий
            // ReSharper disable once InvertIf
            if (_isMonthYear)
            {
                const int monthOffset = 1;
                var       today       = DateTime.Today;
                MonthComboBox.ItemsSource   = Common.MonthsFullNames();
                MonthComboBox.SelectedIndex = today.Month - monthOffset;
                YearIntegerUpDown.Value     = today.Year;
            }

            ConfirmButton.Focus();
        }
Пример #2
0
        public ActionResult AreasManagement(int page = 1, int pageSize = 50, string title = "")
        {
            ViewBag.Title         = "";
            ViewBag.MessageStatus = TempData["MessageStatus"];
            ViewBag.Message       = TempData["Message"];
            if (pageSize == 1)
            {
                pageSize = CMSHelper.pageSizes[0];
            }
            @ViewBag.PageSizes = CMSHelper.pageSizes;
            int              CurrentUserId = WebMatrix.WebData.WebSecurity.CurrentUserId;
            string           userName      = User.Identity.Name;
            int              skip          = (page - 1) * pageSize;
            int              totalRows     = 0;
            List <AreaModel> list          = new List <AreaModel>();

            if (userName == "administrator")
            {
                list = areasService.GetAll(skip, pageSize, out int totalRow, title).AsEnumerable().Select(item => new AreaModel
                {
                    Id         = item.Id,
                    Name       = item.Name,
                    Latitude   = item.Latitude,
                    Longtitude = item.Longtitude,
                    CreateDay  = item.CreateDay,
                    NguoiTao   = userProfileService.userProfileResponsitory.Single(item.CreateBy).FullName,
                    IsActive   = item.IsActive,
                    GroupsName = groupService.groupResponsitory.Single(item.Group_Id).Name
                }).ToList();
                totalRows = totalRow;
            }
            else
            {
                int groupId = userProfileService.userProfileResponsitory.Single(CurrentUserId).Group_Id.Value;
                list = areasService.GetAll(skip, pageSize, out int totalRow, title, groupId).AsEnumerable().Select(item => new AreaModel
                {
                    Id         = item.Id,
                    Name       = item.Name,
                    Latitude   = item.Latitude,
                    Longtitude = item.Longtitude,
                    CreateDay  = item.CreateDay,
                    NguoiTao   = userProfileService.userProfileResponsitory.Single(item.CreateBy).FullName,
                    IsActive   = item.IsActive,
                    GroupsName = groupService.groupResponsitory.Single(item.Group_Id).Name
                }).ToList();
                totalRows = totalRow;
            }


            #region Lấy dữ liệu

            #endregion

            #region Hiển thị dữ liệu và phân trang
            AreaViewModel viewModel = new AreaViewModel
            {
                Areas      = new StaticPagedList <AreaModel>(list, page, pageSize, totalRows),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = totalRows
                }
            };
            #endregion

            return(View(viewModel));
        }