Ejemplo n.º 1
0
        /// <summary>
        /// Валидация, сохранение и выход к списку сущностей
        /// </summary>
        private void SaveAndExit()
        {
            // Получение значений и подписей полей

            var workGuildId    = WorkGuildIdLongUpDown.Value.ToString();
            var parcelId       = ParcelIdLongUpDown.Value.ToString();
            var signMaterial   = SignMaterialLongUpDown.Value.ToString();
            var unitValidation = NormUnitLongUpDown.Value.ToString();
            var auxiliaryMaterialConsumptionRate = AuxiliaryMaterialConsumptionRateTextBox.Text.Trim();
            var flowRate = FlowRateTextBox.Text.Trim();

            // Валидация полей
            var isValidFields = IsValidFieldsWithShowMessageOtherwise();

            if (!isValidFields)
            {
                return;
            }

            try
            {
                // нормализация параметров
                var realWorkGuildId = workGuildId;
                while (realWorkGuildId.Length < 2)
                {
                    realWorkGuildId = "0" + realWorkGuildId;
                }

                var realParcelId = parcelId;
                while (realParcelId.Length < 2)
                {
                    realParcelId = "0" + realParcelId;
                }

                var realUnitValidation = unitValidation;
                while (realUnitValidation.Length < 4)
                {
                    realUnitValidation = "0" + realUnitValidation;
                }

                var realOldWorkGuildId = string.Empty;
                var realOldParcelId    = string.Empty;

                // Если режим редактирования
                if (_editedMaterial != null)
                {
                    realOldWorkGuildId = _editedMaterial.WorkGuildId;
                    while (realOldWorkGuildId.Length < 2)
                    {
                        realOldWorkGuildId = "0" + realOldWorkGuildId;
                    }

                    realOldParcelId = _editedMaterial.ParcelId;
                    while (realOldParcelId.Length < 2)
                    {
                        realOldParcelId = "0" + realOldParcelId;
                    }
                }

                if (_editedMaterial == null || (realOldWorkGuildId != realWorkGuildId ||
                                                realOldParcelId != realParcelId))
                {
                    // Проверка на уникальность
                    var flag = Nu65Service.IsDublicate(_editedProduct.Id, _selectedMaterial.Id, realWorkGuildId,
                                                       realParcelId);
                    if (flag)
                    {
                        const string dublicatePattern = "Материал [{0}] с кодом цеха [{1}] и кодом участка [{2}] " +
                                                        "уже имеется у изделия [{3}]";
                        const string header  = PageLiterals.HeaderInformationOrWarning;
                        var          message = string.Format(dublicatePattern, _selectedMaterial.CodeMaterial, realWorkGuildId,
                                                             realParcelId, _editedProduct.DisplayCodeString);
                        const MessageBoxButton buttons        = MessageBoxButton.OK;
                        const MessageBoxImage  messageBoxType = MessageBoxImage.Exclamation;
                        MessageBox.Show(message, header, buttons, messageBoxType);
                        return;
                    }
                }

                var id = _editedMaterial == null
                    ? Nu65Service.Insert(_editedProduct.Id, _editedProduct.DisplayCodeString, _selectedMeasure.Id,
                                         _selectedMeasure.DisplayOldDbCodeString, _selectedMaterial.Id,
                                         _selectedMaterial.DisplayCodeString, auxiliaryMaterialConsumptionRate, realWorkGuildId,
                                         signMaterial, realParcelId, realUnitValidation, DateTime.Today, flowRate)
                    : Nu65Service.Update(_editedMaterial.Nu65TableId, _editedProduct.Id, _editedProduct.DisplayCodeString,
                                         _selectedMeasure.Id, _selectedMeasure.DisplayOldDbCodeString, _selectedMaterial.Id,
                                         _selectedMaterial.DisplayCodeString, auxiliaryMaterialConsumptionRate, realWorkGuildId, signMaterial,
                                         realParcelId, realUnitValidation, DateTime.Today, flowRate, realOldWorkGuildId,
                                         realOldParcelId);

                _selectedMaterial.Nu65TableId = id != 0 ? id : _selectedMaterial.Nu65TableId;
                _selectedMaterial.AuxiliaryMaterialConsumptionRate = auxiliaryMaterialConsumptionRate;
                _selectedMaterial.WorkGuildId            = realWorkGuildId;
                _selectedMaterial.SignMaterial           = signMaterial;
                _selectedMaterial.ParcelId               = realParcelId;
                _selectedMaterial.UnitValidation         = realUnitValidation;
                _selectedMaterial.Date                   = DateTime.Today;
                _selectedMaterial.FlowRate               = flowRate;
                _selectedMaterial.ServiceMappedMeasureId = _selectedMeasure.Id;
            }
            catch (StorageException ex)
            {
                Common.ShowDetailExceptionMessage(ex);
            }

            DialogResult = true;
            Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Нажатие кнопки [Копировать]
        /// </summary>
        private void CopyButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_selectedMaterial == null)
            {
                MessageBox.Show($"Вы не выбрали материал для копирования, копирование отменено!",
                                PageLiterals.HeaderInformationOrWarning, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            var result = MessageBox.Show($"Вы действительно желаете скопировать материал [{_selectedMaterial.CodeMaterial}] на каждое из указанных изделий?",
                                         PageLiterals.HeaderConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.No)
            {
                return;
            }
            if (_selectedProductList.Count > 0)
            {
                //Сохраняем значение ProgressBar
                double value = 0;

                //Создаем новый экземпляр делегата для ProgressBar
                // который показывает на метод ProgressBar.SetValue
                var updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar.SetValue);

                ProgressBarLabel.Content   = "Копирование:";
                ProgressBarGrid.Visibility = Visibility.Visible;
                ProgressBar.Maximum        = _selectedProductList.Count;
                ProgressBar.Value          = value;

                try
                {
                    var productsId = ProductsStorageMssql.GetProductsIdWhereMaterial(_selectedMaterial);
                    foreach (var selectedProduct in _selectedProductList)
                    {
                        var isHave = false;
                        foreach (var productId in productsId)
                        {
                            if (selectedProduct.Id == productId)
                            {
                                isHave = true;
                                break;
                            }
                        }

                        if (!isHave)
                        {
                            Nu65Service.Insert(selectedProduct.Id, selectedProduct.DisplayCodeString,
                                               _selectedMaterial.ServiceMappedMeasureId,
                                               _selectedMaterial.Measure.DisplayOldDbCodeString, _selectedMaterial.Id, _selectedMaterial.DisplayCodeString,
                                               _selectedMaterial.AuxiliaryMaterialConsumptionRate, _selectedMaterial.WorkGuildId, _selectedMaterial.SignMaterial, _selectedMaterial.ParcelId,
                                               _selectedMaterial.UnitValidation, DateTime.Today, _selectedMaterial.FlowRate);
                        }

                        value += 1;
                        Dispatcher?.Invoke(updatePbDelegate, DispatcherPriority.Background, ProgressBar.ValueProperty,
                                           value);
                    }

                    ProgressBarGrid.Visibility = Visibility.Collapsed;
                    MessageBox.Show($"Копирование успешно произведено!",
                                    PageLiterals.HeaderInformationOrWarning, MessageBoxButton.OK, MessageBoxImage.Information);

                    _selectedProductList            = new List <Product>();
                    ProductListDataGrid.ItemsSource = _selectedProductList;
                    ProductListDataGrid.Items.Refresh();
                    ShowCountItemsPageDataGrid();
                }
                catch (DbException ex) // DbException - суперкласс для SqlException и OleDbException
                {
                    throw DbControl.HandleKnownDbFoxProAndMssqlServerExceptions(ex);
                }
            }
            else
            {
                MessageBox.Show($"Вы не выбрали куда копировать, копирование отменено!",
                                PageLiterals.HeaderInformationOrWarning, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Валидация, сохранение и выход к списку сущностей
        /// </summary>
        private void CopyAndExit()
        {
            _resultMaterials = new List <Material>();

            ProgressBarLabel.Content = "Подготовка:";
            ProgressBar.Maximum      = _selectedMaterials.Count;
            ProgressBar.Value        = 0;

            //Сохраняем значение ProgressBar
            double value = 0;

            //Создаем новый экземпляр делегата для ProgressBar
            // который показывает на метод ProgressBar.SetValue
            var updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar.SetValue);


            foreach (var selected in _selectedMaterials)
            {
                value += 1;

                bool flag = false;
                foreach (var edited in _editedMaterials)
                {
                    if (selected.CodeMaterial == edited.CodeMaterial &&
                        selected.ParcelId == edited.ParcelId &&
                        selected.WorkGuildId == edited.WorkGuildId)
                    {
                        flag = true;
                        break;
                    }
                }

                if (!flag)
                {
                    _resultMaterials.Add(selected);
                }

                Dispatcher?.Invoke(updatePbDelegate, DispatcherPriority.Background, ProgressBar.ValueProperty,
                                   value);
            }

            ProgressBarLabel.Content = "Копирование:";
            ProgressBar.Maximum      = _resultMaterials.Count;
            value             = 0;
            ProgressBar.Value = value;

            try
            {
                foreach (var item in _resultMaterials)
                {
                    value += 1;

                    var id = Nu65Service.Insert(_editedProduct.Id, _editedProduct.DisplayCodeString,
                                                item.ServiceMappedMeasureId,
                                                item.Measure.DisplayOldDbCodeString, item.Id, item.DisplayCodeString,
                                                item.AuxiliaryMaterialConsumptionRate, item.WorkGuildId, item.SignMaterial, item.ParcelId,
                                                item.UnitValidation, DateTime.Today, item.FlowRate);
                    item.Nu65TableId = id != 0 ? id : item.Nu65TableId;

                    Dispatcher?.Invoke(updatePbDelegate, DispatcherPriority.Background, ProgressBar.ValueProperty,
                                       value);
                }
            }
            catch (DbException ex) // DbException - суперкласс для SqlException и OleDbException
            {
                throw DbControl.HandleKnownDbFoxProAndMssqlServerExceptions(ex);
            }

            DialogResult = true;
            Close();
        }