예제 #1
0
        private void OkRequestButton_Click(object sender, RoutedEventArgs e)
        {
            if (FactoryComboBox.SelectedValue == null || WorkUnitsComboBox.SelectedValue == null ||
                WorkSectionsComboBox.SelectedValue == null || string.IsNullOrEmpty(RequestNoteTextBox.Text))
            {
                return;
            }

            var factoryId     = Convert.ToInt32(FactoryComboBox.SelectedValue);
            var workUnitId    = Convert.ToInt32(WorkUnitsComboBox.SelectedValue);
            var workSectionId = Convert.ToInt32(WorkSectionsComboBox.SelectedValue);
            var requestNote   = RequestNoteTextBox.Text;
            var requestDate   = App.BaseClass.GetDateFromSqlServer();

            var newId = _tpr.AddNewRequest(factoryId, workUnitId, workSectionId, requestDate,
                                           _curWorkerId, requestNote);

            AdministrationClass.AddNewAction(17);

            var newsText = string.Format(RequestText, newId.ToString("00000"),
                                         new IdToWorkSectionConverter().Convert(workSectionId, typeof(string), string.Empty,
                                                                                new CultureInfo("ru-RU")),
                                         new IdToWorkUnitConverter().Convert(workUnitId, typeof(string), string.Empty, new CultureInfo("ru-RU")),
                                         requestNote);
            var newsStatus = factoryId == 1 ? 6 : 7;

            NewsHelper.AddNews(requestDate, newsText, newsStatus, _curWorkerId);

            _mw = Window.GetWindow(this) as MainWindow;
            if (_mw != null)
            {
                var techProbPage = _mw.MainFrame.Content as XamlFiles.TechnologyProblemPage;
                if (techProbPage != null)
                {
                    techProbPage.SelectNewTableRow(newId);
                }
            }

            CancelRequestButton_Click(null, null);
        }
예제 #2
0
        private void OnSaveButtonClick(object sender, RoutedEventArgs e)
        {
            #region Check for empty fields

            var hasEmptyField = false;
            var errorBrush    = Resources["RedForeground"] != null
                ? Resources["RedForeground"] as SolidColorBrush
                : Brushes.IndianRed;
            var defaultBrush = Resources["AdditTextBlackBrush"] != null
                ? Resources["AdditTextBlackBrush"] as SolidColorBrush
                : Brushes.LightGray;

            if (RequestTypeComboBox.SelectedItem == null)
            {
                RequestTypeDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                RequestTypeDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (SalarySaveTypeComboBox.SelectedItem == null)
            {
                SalarySaveTypeDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                SalarySaveTypeDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (IntervalTypeComboBox.SelectedItem == null)
            {
                IntervalTypeDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                IntervalTypeDescriptionTextBlock.Foreground = defaultBrush;
                var intTypeId = Convert.ToInt32(IntervalTypeComboBox.SelectedValue);
                switch ((IntervalType)intTypeId)
                {
                case IntervalType.DurringSomeHours:
                {
                    if (DuringTheDayRequestDatePicker.SelectedDate == null ||
                        RequestFromTimeControl.TotalTime == TimeSpan.Zero ||
                        RequestToTimeControl.TotalTime == TimeSpan.Zero)
                    {
                        IntervalTypeDescriptionTextBlock.Foreground = errorBrush;
                        hasEmptyField = true;
                    }
                }
                break;

                case IntervalType.DurringWorkingDay:
                {
                    if (DuringTheDayRequestDatePicker.SelectedDate == null)
                    {
                        IntervalTypeDescriptionTextBlock.Foreground = errorBrush;
                        hasEmptyField = true;
                    }
                }
                break;

                case IntervalType.DurringSomeDays:
                {
                    if (RequestFromDatePicker.SelectedDate == null ||
                        RequestToDatePicker.SelectedDate == null)
                    {
                        IntervalTypeDescriptionTextBlock.Foreground = errorBrush;
                        hasEmptyField = true;
                    }
                }
                break;
                }
            }

            if (string.IsNullOrEmpty(RequestReasonCompleteComboBox.Text))
            {
                RequestReasonDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                RequestReasonDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (WorkingOffTypeComboBox.SelectedItem == null)
            {
                WorkingOffTypeDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                WorkingOffTypeDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (InitiativeTypeComboBox.SelectedItem == null)
            {
                InitiativeTypeDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                InitiativeTypeDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (_selectedMainWorkerId == null)
            {
                MainWorkerDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                MainWorkerDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (_selectedWorkerId == null)
            {
                WorkerDescriptionTextBlock.Foreground = errorBrush;
                hasEmptyField = true;
            }
            else
            {
                WorkerDescriptionTextBlock.Foreground = defaultBrush;
            }

            if (hasEmptyField)
            {
                return;
            }

            #endregion

            var requestType     = (RequestType)Convert.ToInt32(RequestTypeComboBox.SelectedValue);
            var salarySaveType  = (SalarySaveType)Convert.ToInt32(SalarySaveTypeComboBox.SelectedValue);
            var intervalType    = (IntervalType)Convert.ToInt32(IntervalTypeComboBox.SelectedValue);
            var requestDateFrom = new DateTime();
            var requestDateTo   = new DateTime();
            switch (intervalType)
            {
            case IntervalType.DurringSomeHours:
            {
                requestDateFrom =
                    DuringTheDayRequestDatePicker.SelectedDate.Value.Date.Add(RequestFromTimeControl.TotalTime);
                requestDateTo =
                    DuringTheDayRequestDatePicker.SelectedDate.Value.Date.Add(RequestToTimeControl.TotalTime);
            }
            break;

            case IntervalType.DurringWorkingDay:
            {
                requestDateFrom = DuringTheDayRequestDatePicker.SelectedDate.Value;
                requestDateTo   = DuringTheDayRequestDatePicker.SelectedDate.Value;
            }
            break;

            case IntervalType.DurringSomeDays:
            {
                requestDateFrom = RequestFromDatePicker.SelectedDate.Value;
                requestDateTo   = RequestToDatePicker.SelectedDate.Value;
            }
            break;
            }
            var requestReason   = RequestReasonCompleteComboBox.Text;
            var initiativeType  = (InitiativeType)Convert.ToInt32(InitiativeTypeComboBox.SelectedValue);
            var workingOffType  = (WorkingOffType)Convert.ToInt32(WorkingOffTypeComboBox.SelectedValue);
            var currentDate     = App.BaseClass.GetDateFromSqlServer();
            var currentWorkerId = AdministrationClass.CurrentWorkerId;

            var workerRequestId = _workerRequestsClass.AddWorkerRequest(requestType, _selectedWorkerId.Value, requestDateFrom,
                                                                        requestDateTo, salarySaveType, initiativeType, intervalType, workingOffType, currentDate, currentWorkerId, requestReason,
                                                                        _selectedMainWorkerId.Value);

            if (_initializeMode == InitializeMode.FromSender)
            {
                AdministrationClass.AddNewAction(79);
            }
            else
            {
                AdministrationClass.AddNewAction(80);
            }

            NotificationManager.AddNotification((int)_selectedMainWorkerId.Value, AdministrationClass.Modules.WorkerRequests, (int)workerRequestId);

            var newsText = string.Format("Заявка на {0}, составлена на: {1} \nПериод: {2} \nПричина: {3} \nСоставитель заявки: {4} \nКому на подтверждение: {5}",
                                         new WorkerRequestConverter().Convert((int)requestType, typeof(string), "RequestTypeName", CultureInfo.InvariantCulture).ToString().ToLower(),
                                         new IdToNameConverter().Convert(_selectedWorkerId.Value, "FullName"),
                                         WorkerRequestDurationConverter.GetDateDuration(intervalType, requestDateFrom, requestDateTo) + " (" + WorkerRequestDurationConverter.GetTimeDuration(intervalType, requestDateFrom, requestDateTo) + ")",
                                         requestReason,
                                         new IdToNameConverter().Convert(currentWorkerId, "ShortName"),
                                         new IdToNameConverter().Convert(_selectedMainWorkerId.Value, "ShortName"));

            string globalId = null;
            var    rows     = _workerRequestsClass.WorkerRequestsTable.Select(string.Format("WorkerRequestID = {0}", workerRequestId));
            if (rows.Any())
            {
                globalId = rows.First()["GlobalID"].ToString();
            }
            NewsHelper.AddNews(currentDate, newsText, 9, (int)_selectedWorkerId.Value, globalId);

            OnClosePageButtonClick(null, null);
        }
예제 #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (GroupComboBox.SelectedValue == DBNull.Value || WorkUnitsComboBox.SelectedValue == DBNull.Value ||
                WorkSectionsComboBox.SelectedValue == DBNull.Value ||
                WorkSubSectionsComboBox.SelectedValue == DBNull.Value ||
                string.IsNullOrEmpty(RequestNoteTextBox.Text) || RequestTypeComboBox.SelectedValue == null ||
                (_unitToFactory && FactoryComboBox.SelectedValue == DBNull.Value))
            {
                return;
            }

            int    requestTypeId    = Convert.ToInt32(RequestTypeComboBox.SelectedValue);
            int    groupId          = Convert.ToInt32(GroupComboBox.SelectedValue);
            int    workUnitId       = Convert.ToInt32(WorkUnitsComboBox.SelectedValue);
            int    workSectionId    = Convert.ToInt32(WorkSectionsComboBox.SelectedValue);
            int    workSubSectionId = Convert.ToInt32(WorkSubSectionsComboBox.SelectedValue);
            string requestNote      = RequestNoteTextBox.Text;
            var    requestDate      = App.BaseClass.GetDateFromSqlServer();
            int    newCrashId;
            string newsText;
            int    newsStatus = 6;

            if (_unitToFactory)
            {
                int factoryId = Convert.ToInt32(FactoryComboBox.SelectedValue);
                newCrashId = _sec.AddNewRequest(groupId, factoryId, workUnitId, workSectionId, workSubSectionId,
                                                requestDate,
                                                _curWorkerId, requestNote, requestTypeId);

                newsStatus = factoryId == 1 ? 6 : 7;
            }
            else
            {
                newCrashId = _sec.AddNewRequest(groupId, 1, workUnitId, workSectionId, workSubSectionId, requestDate,
                                                _curWorkerId, requestNote, requestTypeId);
            }

            if (requestTypeId == 1)
            {
                AdministrationClass.AddNewAction(7);
            }
            else
            {
                AdministrationClass.AddNewAction(8);
            }

            if (requestTypeId == 1)
            {
                newsText = string.Format(CrashRequestText, newCrashId.ToString("00000"),
                                         _workSubSectionConverter.Convert(workSubSectionId, typeof(string), string.Empty,
                                                                          new CultureInfo("ru-RU")),
                                         _workUnitConverter.Convert(workUnitId, typeof(string), string.Empty, new CultureInfo("ru-RU")),
                                         _workSectionConverter.Convert(workSectionId, typeof(string), string.Empty, new CultureInfo("ru-RU")),
                                         requestNote);
            }
            else
            {
                newsText = string.Format(ProblemRequestText, newCrashId.ToString("00000"),
                                         _workSubSectionConverter.Convert(workSubSectionId, typeof(string), string.Empty,
                                                                          new CultureInfo("ru-RU")),
                                         _workUnitConverter.Convert(workUnitId, typeof(string), string.Empty, new CultureInfo("ru-RU")),
                                         _workSectionConverter.Convert(workSectionId, typeof(string), string.Empty, new CultureInfo("ru-RU")),
                                         requestNote);
            }

            NewsHelper.AddNews(requestDate, newsText, newsStatus, _curWorkerId);


            _mw = Window.GetWindow(this) as MainWindow;
            if (_mw != null)
            {
                var servEquipPage = _mw.MainFrame.Content as XamlFiles.ServiceEquipmentPage;
                if (servEquipPage != null)
                {
                    servEquipPage.SelectNewTableRow(newCrashId);
                }
            }

            CancelRequestButton_Click(null, null);
        }