public void IsNumber_WhenString_ThenReturnBool(string testStr, bool expected) { bool actual = ValidationData.IsNumber(testStr); Assert.AreEqual(expected, actual); }
private void AddProduct_Click(object sender, RoutedEventArgs e) { string quantity = textBoxQuaunity.Text.Trim(); string orderDate = datePicker.Text; isAdding = true; if (!(ValidationData.IsNumber(quantity) || !(ValidationData.IsValidStringLenght(quantity, validCharQuantity: 53)))) { textBoxQuaunity.ToolTip = "Введите цифры в формате ХХХ или ХХХ,ХХ"; textBoxQuaunity.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(comboBoxClient.Text.Trim()))) { comboBoxClient.ToolTip = "Необходимо выбрать один из вариантов в списке"; comboBoxClient.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(comboBoxProduct.Text.Trim()))) { comboBoxProduct.ToolTip = "Необходимо выбрать один из вариантов в списке"; comboBoxProduct.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(comboBoxStatus.Text.Trim()))) { comboBoxStatus.ToolTip = "Необходимо выбрать один из вариантов в списке"; comboBoxStatus.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(orderDate))) { datePicker.ToolTip = "Выберите дату"; datePicker.Background = Brushes.Tomato; isAdding = false; } if (isAdding) { ProductInOrderModel productInOrderModel = new ProductInOrderModel() { Articul = productInfoModel.Articul, ProductId = productInfoModel.Id, ProductTitle = productInfoModel.Title, Price = productInfoModel.Price, Quantity = Convert.ToDouble(quantity), MeasureUnitId = productInfoModel.MeasureUnitId, MeasureUnitTitle = productInfoModel.MeasureUnit, GroupTitle = productInfoModel.Group, SubgroupTitle = productInfoModel.Subgroup, Rate = -1 }; string measureUnitTitle = productInfoModel.MeasureUnit; int measureUnitId = (from m in _measureUnitInfoModels where m.Title.Equals(measureUnitTitle) select m.Id) .FirstOrDefault(); FeedbackModel newfeedbackModel = new FeedbackModel() { ProductId = productInfoModel.Id, Description = string.Empty, Rate = -1 }; _productInOrderModels.Add(productInOrderModel); _feedbackModels.Add(newfeedbackModel); totalPrice += productInOrderModel.Price * productInOrderModel.Quantity; textBoxTotalPrice.Text = totalPrice.ToString(); gridProductsInOrder.Items.Add(productInOrderModel); datePicker.Background = Brushes.Transparent; } }
private void SaveProductButton_Click(object sender, RoutedEventArgs e) { string articul = ArticulTextBox.Text; string title = TitelTextBox.Text; string quantity = QuantityTextBox.Text; string price = PriceTextBox.Text; bool isAdding = true; bool isTitleNotUnique = false; List <ProductsSubgropModel> _products = _controller.GetProductsSubgroupModels(); foreach (UIElement item in AddProductGrid.Children) { if (item is TextBox) { TextBox textBox = (TextBox)item; textBox.Background = Brushes.Transparent; } } foreach (var product in _products) { isTitleNotUnique = product.ProductTitle.Contains(title); if (isTitleNotUnique) { break; } } if (!(ValidationData.IsValidStringLenght(articul, 255))) { ArticulTextBox.ToolTip = "Превышено количество символов"; ArticulTextBox.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsValidStringLenght(title, 255)) || !(ValidationData.IsStringNotNull(title)) || (isTitleNotUnique)) { TitelTextBox.ToolTip = "Превышено количество символов или название продукта уже существует"; TitelTextBox.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsNumber(quantity)) || !(ValidationData.IsStringNotNull(quantity))) { QuantityTextBox.ToolTip = "Введите цифры в формате ХХХ или ХХХ,ХХ"; QuantityTextBox.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsNumber(price)) || !(ValidationData.IsStringNotNull(price))) { PriceTextBox.ToolTip = "Введите цифры в формате ХХХ или ХХХ,ХХ"; PriceTextBox.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(SubgroupComboBox.Text.Trim()))) { SubgroupComboBox.ToolTip = "Необходимо выбрать один из вариантов в списке"; SubgroupComboBox.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(GroupComboBox.Text.Trim()))) { GroupComboBox.ToolTip = "Необходимо выбрать один из вариантов в списке"; GroupComboBox.Background = Brushes.Tomato; isAdding = false; } if (!(ValidationData.IsStringNotNull(MeasureUnitComboBox.Text.Trim()))) { MeasureUnitComboBox.ToolTip = "Необходимо выбрать один из вариантов в списке"; MeasureUnitComboBox.Background = Brushes.Tomato; isAdding = false; } if (isAdding) { MeasureUnitInfoModel measureUnitModel = measureUnitInfoModels[MeasureUnitComboBox.SelectedIndex]; SubgroupInfoModel subgroupModel = subgroupInfoModels[SubgroupComboBox.SelectedIndex]; AddingProductModel addingProductModel = new AddingProductModel() { Articul = articul, Title = title, Quantity = Convert.ToDouble(quantity), Price = Convert.ToDouble(price), MeasureId = measureUnitModel.Id, SubgroupId = subgroupModel.Id }; _controller.AddProduct(addingProductModel); foreach (UIElement element in AddProductGrid.Children) { if (element is TextBox) { TextBox textBox = (TextBox)element; textBox.Background = Brushes.Transparent; textBox.Clear(); } if (element is ComboBox) { ComboBox comboBox = (ComboBox)element; comboBox.Text = string.Empty; } } MessageBox.Show("Товар успешно добавлен"); } }