Exemplo n.º 1
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();
            }
        }