private void oButton_SaveTobacco_Click(object sender, RoutedEventArgs e)
        {
            // strings for messageBox
            string           sMassage = "Wollen Sie die Pfeife wirklich speichern?", sCaption = "Speichern";
            MessageBoxResult eResult = MessageBox.Show(sMassage, sCaption, MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (bTobaccoEditAddMode == false)
            {
                oClickedTobacco = oTobacco;
            }
            if (eResult == MessageBoxResult.Yes)
            {
                if (oTextBox_TobaccoName.Text == "")
                {
                    MessageBox.Show("Bitte Name eingeben!");
                    return;
                }
                else
                {
                    oClickedTobacco.Name = oTextBox_TobaccoName.Text;
                }

                oClickedTobacco.Description    = oTextBox_Description.Text;
                oClickedTobacco.Note           = oTextBox_Note.Text;
                oClickedTobacco.TobaccoAmount  = Convert.ToInt32(oSlider_TobaccoAmount.Value);
                oClickedTobacco.Brand          = oTextBox_Brand.Text;
                oClickedTobacco.Cut            = oTextBox_Cut.Text;
                oClickedTobacco.Flavoring      = oTextBox_Flavoring.Text;
                oClickedTobacco.getTotalGramms = oClickedTobacco.TobaccoAmount * 50;
                try {
                    oClickedTobacco.Price = Convert.ToDouble(oTextBox_Price.Text);
                } catch (Exception ex) {
                    MessageBox.Show("Bitte eine numerische Zahl eingeben", "Preis Fehler!!!");
                    return;
                }
                oClickedTobacco.Strength = oComboBox_Strength.SelectionBoxItem.ToString();
                if (bTobaccoEditAddMode == true)
                {
                    oParentWindow.iniTobaccoBinding();
                    int iIndex = oUser.lTobaccos.Count - 1;
                    oParentWindow.oListBox_Tobacco.SelectedIndex = iClickedIndex;
                    oParentWindow.iniDashboard();
                }
                else
                {
                    oUser.lTobaccos.Add(oClickedTobacco);
                    oParentWindow.iniTobaccoBinding();
                    int iIndex = oUser.lTobaccos.Count - 1;
                    oParentWindow.oListBox_Tobacco.SelectedIndex = iIndex;
                    oParentWindow.iniDashboard();
                }
                this.Owner.Visibility = Visibility.Visible;
                this.Close();
            }
        }
Example #2
0
        /// <summary>
        /// When user has no items ins list an default item
        /// will be added on each List for testing
        /// </summary>
        private void noItemsExist()
        {
            if (oUser.lPipes.Count == 0)
            {
                Pipe oDefaultPipe = new Pipe();
                oUser.lPipes.Add(oDefaultPipe);
            }

            if (oUser.lTobaccos.Count == 0)
            {
                Tobacco oDefaultTobacco = new Tobacco();
                oUser.lTobaccos.Add(oDefaultTobacco);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            oTobacco = new Tobacco();
            if (bTobaccoEditAddMode == true)
            {
                oClickedTobacco = oUser.lTobaccos[iClickedIndex];

                oTextBox_TobaccoName.Text   = oClickedTobacco.Name;
                oTextBox_Brand.Text         = oClickedTobacco.Brand;
                oTextBox_Description.Text   = oClickedTobacco.Description;
                oTextBox_Note.Text          = oClickedTobacco.Note;
                oTextBox_Cut.Text           = oClickedTobacco.Cut;
                oTextBox_Flavoring.Text     = oClickedTobacco.Flavoring;
                oTextBox_Price.Text         = oClickedTobacco.Price.ToString();
                oSlider_TobaccoAmount.Value = oClickedTobacco.TobaccoAmount;
                oTextBlock_Rating_1.Text    = oClickedTobacco.UniCode1;
                oTextBlock_Rating_2.Text    = oClickedTobacco.UniCode2;
                oTextBlock_Rating_3.Text    = oClickedTobacco.UniCode3;
                oTextBlock_Rating_4.Text    = oClickedTobacco.UniCode4;
                oTextBlock_Rating_5.Text    = oClickedTobacco.UniCode5;
                oTextBlock_Title.Text       = "Tabak Bearbeiten";
                BitmapImage oImage = new BitmapImage();
                try {
                    var uriPipe = oClickedTobacco.profileUri;
                    if (uriPipe == "")
                    {
                        try {
                            uriPipe = sPathImages + "profilePic.jpg";
                        } catch (Exception) {
                            uriPipe = "";
                        }
                    }
                    using (FileStream oStream = File.OpenRead(uriPipe)) {
                        oImage.BeginInit();
                        oImage.StreamSource = oStream;
                        oImage.CacheOption  = BitmapCacheOption.OnLoad;
                        oImage.EndInit();
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message, "Error");
                    //return;
                }
                oImage_PipePicture.Source = oImage;
            }
            else
            {
                oTextBlock_Rating_1.Text = "\u2606"; oTextBlock_Rating_2.Text = "\u2606"; oTextBlock_Rating_3.Text = "\u2606"; oTextBlock_Rating_4.Text = "\u2606"; oTextBlock_Rating_5.Text = "\u2606";
            }
        }
        private void oTextBlock_Rating_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var       oTextBlock = (sender as TextBlock);
            var       sStarName  = oTextBlock.Name;
            int       iStarIndex = 0;
            const int iMaxStars  = 6;

            try {
                iStarIndex = Convert.ToInt32(sStarName.Substring(sStarName.LastIndexOf("_") + 1));
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }

            if (bTobaccoEditAddMode == false)
            {
                oClickedTobacco = oTobacco;
            }
            oClickedTobacco.Rating = iStarIndex;
            List <TextBlock> lRating = new List <TextBlock>();

            for (int i = 0; i < iStarIndex + 1; i++)
            {
                if (i != 0)
                {
                    var s = oStackPanel_Rating.FindName("oTextBlock_Rating_" + i);
                    lRating.Add(s as TextBlock);
                    switch (i)
                    {
                    case 1:
                        oClickedTobacco.UniCode1 = "\u2605";
                        break;

                    case 2:
                        oClickedTobacco.UniCode2 = "\u2605";
                        break;

                    case 3:
                        oClickedTobacco.UniCode3 = "\u2605";
                        break;

                    case 4:
                        oClickedTobacco.UniCode4 = "\u2605";
                        break;

                    case 5:
                        oClickedTobacco.UniCode5 = "\u2605";
                        break;

                    default:
                        break;
                    }
                }
            }
            List <TextBlock> lRatingBlank = new List <TextBlock>();

            for (int i = iStarIndex + 1; i < iMaxStars; i++)
            {
                var s = oStackPanel_Rating.FindName("oTextBlock_Rating_" + i);
                lRatingBlank.Add(s as TextBlock);
                switch (i)
                {
                case 1:
                    oClickedTobacco.UniCode1 = "\u2606";
                    break;

                case 2:
                    oClickedTobacco.UniCode2 = "\u2606";
                    break;

                case 3:
                    oClickedTobacco.UniCode3 = "\u2606";
                    break;

                case 4:
                    oClickedTobacco.UniCode4 = "\u2606";
                    break;

                case 5:
                    oClickedTobacco.UniCode5 = "\u2606";
                    break;

                default:
                    break;
                }
            }

            foreach (var oStar in lRating)
            {
                oStar.Text = "\u2605";
            }
            foreach (var oStarBlank in lRatingBlank)
            {
                oStarBlank.Text = "\u2606";
            }
        }