Ejemplo n.º 1
0
 private void LoadboxSelectionChanged( object sender, RoutedEventArgs e )
 {
     if (_loadBox.SelectedItem != null)
     {
         _loadedAlien = (Aliens) _loadBox.SelectedItem;
         _loadWindow.Close();
         LoadAlien();
     }
 }
Ejemplo n.º 2
0
        private void btSave_Click( object sender, RoutedEventArgs e )
        {
            using (var context = new Db1Entities())
            {
                var dbAlien = new Aliens
                {
                    Name = TbName.Text,
                    chemicalBasis = CbChemicalBasis.SelectedValue.ToString(),
                    LandOrWater = CbLandOrWater.SelectedValue.ToString(),
                    LandHabitat = CbLandHabitat.SelectedValue.ToString(),
                    WaterHabitat = CbWaterHabitat.SelectedValue.ToString(),
                    TrophicDiet = CbThrophicDiet.SelectedValue.ToString(),
                    PrimaryLocomotion = CbPrimaryLocomotion.SelectedValue.ToString(),
                    SecondaryLocomotion = CbSecondaryLocomotion.SelectedValue.ToString(),
                    hasSecondaryLocomotuib = CheckHasSecondaryLocmotion.IsChecked,
                    Gravity = null,
                    SizeClass = CbSizeClass.SelectedValue.ToString(),
                    Size = double.Parse(CbSize.Text),
                    Symmetry = CbSymmetry.SelectedValue.ToString(),
                    Sides = int.Parse(CbSides.Text),
                    LimbSegments = int.Parse(CbLimbSegments.Text),
                    Tail = CbTails.SelectedValue.ToString(),
                    Manipulators = int.Parse(CbManipulators.Text),
                    Skeleton = CbSkeleton.SelectedValue.ToString(),
                    SkinClass = CbSkinClass.SelectedValue.ToString(),
                    Skin = CbSkin.SelectedValue.ToString(),
                    Breathing = CbBreathing.SelectedValue.ToString(),
                    Temperatur = CbTemperture.SelectedValue.ToString(),
                    Growth = CbGrowthRate.SelectedValue.ToString(),
                    Sex = CbSexes.SelectedValue.ToString(),
                    Gestation = CbGestation.SelectedValue.ToString(),
                    Strategy = CbStrategy.SelectedValue.ToString(),
                    OffspringCount = int.Parse(CbOffspringCount.Text),
                    PrimarySense = CbPrimarySense.SelectedValue.ToString(),
                    Vision = CbVision.SelectedValue.ToString(),
                    Hearing = CbHearing.SelectedValue.ToString(),
                    Touch = CbTouch.SelectedValue.ToString(),
                    TasteSmell = CbTasteSmell.SelectedValue.ToString(),
                    Intelligence = CbIntelligence.SelectedValue.ToString(),
                    IntelligenceValue = int.Parse(CbIntelligenceValue.Text),
                    MatingBehaviour = CbMatingBehaviour.SelectedValue.ToString(),
                    SocialOrganization = CbSocialOrganization.SelectedValue.ToString(),
                    SocialGroupSize = int.Parse(CbSocialGroupSize.Text),
                    Concentration = CbConcentration.SelectedValue.ToString(),
                    Curiosity = CbCuriosity.SelectedValue.ToString(),
                    Egoism = CbEgoism.SelectedValue.ToString(),
                    Empathy = CbEmpathy.SelectedValue.ToString(),
                    Gegariousness = CbGegariousness.SelectedValue.ToString(),
                    Imagination = CbImagination.SelectedValue.ToString(),
                    Chauvinism = CbChauvinism.SelectedValue.ToString(),
                    Suspicion = CbSuspicion.SelectedValue.ToString(),
                    Playfulness = CbPlayfulness.SelectedValue.ToString(),
                    Image = BuildByteArrayFromImage(_raceBitmapImage)
                };
                //FIXME

                //if (RaceImageWindow.Source != null)
                //{
                //    byte[] buffer;
                //    FileStream fileStream = new FileStream(_imagePath, FileMode.Open, FileAccess.Read);
                //    try
                //    {
                //        int length = (int)fileStream.Length;  // get file length
                //        buffer = new byte[length];            // create buffer
                //        int count;                            // actual number of bytes read
                //        int sum = 0;                          // total number of bytes read

                //        // read until Read method returns 0 (end of the stream has been reached)
                //        while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
                //            sum += count;  // sum is a buffer offset for next reading
                //    }
                //    finally
                //    {
                //        fileStream.Close();
                //    }
                //    DBAlien.image = buffer;
                //}

                context.Aliens.Add(dbAlien);
                context.SaveChanges();
            }

            MessageBox.Show("The Alien '" + TbName.Text + "' has been saved in the Database");
        }