예제 #1
0
        public CreateNewItemWindow(IControllerBase databaseController, bool isChange = false, int UID = -1)
        {
            this.databaseController = databaseController;
            this.isChange           = isChange;
            this.UID = UID;

            InitializeComponent();
            AddCategoriesToSelector();

            if (isChange)
            {
                MainLabel.Content = "Изменение товара";
                prevItemData      = databaseController.GetFullItemData(UID);
                CategoryComboBox.SelectedIndex = FindComboBoxIndexWithCategory(prevItemData.Category).Value;
                NameTextBox.Text        = prevItemData.Name;
                PriceTextBox.Text       = prevItemData.Price.ToString();
                DescriptionTextBox.Text = prevItemData.Description;
                for (var i = 0; i < CategoryParamsListBox.Items.Count; i++)
                {
                    ((TextBox)((Grid)CategoryParamsListBox.Items[i]).Children[1]).Text = prevItemData.Params[i];
                }
            }
        }
예제 #2
0
        private void OnClickSaveButton(object sender, RoutedEventArgs e)
        {
            void disableHighlight()
            {
                NameTextBox.BorderBrush = new SolidColorBrush(new Color {
                    R = 171, G = 173, B = 179
                });
                PriceTextBox.BorderBrush = new SolidColorBrush(new Color {
                    R = 171, G = 173, B = 179
                });
                foreach (Grid grid in CategoryParamsListBox.Items)
                {
                    ((TextBox)grid.Children[1]).BorderBrush = new SolidColorBrush(new Color {
                        R = 171, G = 173, B = 179
                    });
                }
            }

            bool canCreate = true;

            disableHighlight();
            if (CategoryComboBox.SelectedItem == null)
            {
                canCreate = false;
            }
            if (NameTextBox.Text == "")
            {
                canCreate = false;
                NameTextBox.BorderBrush = Brushes.Red;
            }
            if (PriceTextBox.Text == "")
            {
                canCreate = false;
                PriceTextBox.BorderBrush = Brushes.Red;
            }

            var paramsList = new List <string>();

            foreach (Grid grid in CategoryParamsListBox.Items)
            {
                var paramBox = (TextBox)grid.Children[1];
                //var paramName = (string)paramBox.Tag;
                var paramValue = paramBox.Text;
                if (paramValue == "")
                {
                    paramBox.BorderBrush = Brushes.Red;
                    canCreate            = false;
                }
                //paramsDict.Add(paramName, paramValue);
                paramsList.Add(paramValue);
            }

            if (canCreate)
            {
                if (isChange)
                {
                    var fullItemData = new FullItemData
                    {
                        Category    = ((TextBlock)CategoryComboBox.SelectedItem).Text,
                        Name        = NameTextBox.Text,
                        Params      = paramsList.ToArray(),
                        Price       = int.Parse(PriceTextBox.Text),
                        Description = DescriptionTextBox.Text,
                        Count       = prevItemData.Count
                    };
                    databaseController.SetItemDataForUID(UID, fullItemData);
                }
                else
                {
                    databaseController.CreateNewItem(((TextBlock)CategoryComboBox.SelectedItem).Text, NameTextBox.Text, paramsList.ToArray(), int.Parse(PriceTextBox.Text), DescriptionTextBox.Text);
                    ((ViewerWindow)this.Owner).UpdateCategoryCreateCategoryList();
                }
                ((ViewerWindow)this.Owner).UpdateItemsList();
                ((ViewerWindow)this.Owner).UpdateStatisticItemsList();
                this.Close();
            }
        }