Exemplo n.º 1
0
 /// <summary>
 /// Создание нового объекта Material.
 /// </summary>
 /// <param name="id">Исходное значение свойства Id.</param>
 /// <param name="materialType_Id">Исходное значение свойства MaterialType_Id.</param>
 /// <param name="name">Исходное значение свойства Name.</param>
 public static Material CreateMaterial(global::System.Int32 id, global::System.Int32 materialType_Id, global::System.String name)
 {
     Material material = new Material();
     material.Id = id;
     material.MaterialType_Id = materialType_Id;
     material.Name = name;
     return material;
 }
        private void SavePerson(int PID)
        {
            model1.Persons.First(o => o.Id == PID).Surname = surnameTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Name = nameTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Patronymic = patronymicTextBox.Text;
            model1.Persons.First(o => o.Id == PID).BirthDate = birthDateTextBox.Text;
            model1.Persons.First(o => o.Id == PID).PlaceOfBirth = placeOfBirthTextBox.Text;
            model1.Persons.First(o => o.Id == PID).DeathDate = deathDateTextBox.Text;
            model1.Persons.First(o => o.Id == PID).CauseOfDeath = causeOfDeathTextBox.Text;
            model1.Persons.First(o => o.Id == PID).PlaceOfDeath = placeOfDeathTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Nationality = nationalityTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Physique = physiqueTextBox.Text;
            model1.Persons.First(o => o.Id == PID).MentalHealth = mentalHealthTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Religion = religionTextBox.Text;
            model1.Persons.First(o => o.Id == PID).PoliticalViews = politicalViewsTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Education = educationTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Rank = rankTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Rewards = rewardsTextBox.Text;
            model1.Persons.First(o => o.Id == PID).FinancialPosition = financialPositionTextBox.Text;
            model1.Persons.First(o => o.Id == PID).Gender = genderComboBox.SelectedIndex;

            if (model1.Persons.First(o => o.Id == PID).Materials.Where(o => o.MaterialType_Id == 1).Count() > 0)
            {
                if (image1.Tag == null) model1.Materials.DeleteObject(model1.Persons.First(o => o.Id == PID).Materials.First(o => o.MaterialType_Id == 1));
                else if (image1.Tag != "db")
                {
                    byte[] buffer = File.ReadAllBytes(image1.Tag.ToString());
                    model1.Persons.First(o => o.Id == PID).Materials.First(o => o.MaterialType_Id == 1).Data = buffer;
                }
            }
            else if (image1.Tag != null && image1.Tag.ToString()!= "db")
            {
                Material m = new Material();
                byte[] buffer = File.ReadAllBytes(image1.Tag.ToString());
                m.Data = buffer;
                m.Name = "Фотография карточки";
                m.Persons.Add(model1.Persons.First(o => o.Id == PID));
                m.MaterialType_Id = 1;
                m.FileName = image1.Tag.ToString().Substring(image1.Tag.ToString().LastIndexOf('\\')+1);
                m.MaterialTypes = model1.MaterialTypes.First(o => o.Id == m.MaterialType_Id);
                model1.Materials.AddObject(m);
            }
            model1.SaveChanges();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Устаревший метод для добавления новых объектов в набор EntitySet Materials. Взамен можно использовать метод .Add связанного свойства ObjectSet&lt;T&gt;.
 /// </summary>
 public void AddToMaterials(Material material)
 {
     base.AddObject("Materials", material);
 }
        private void addMaterialButton_Click(object sender, RoutedEventArgs e)
        {
            CreateMaterialWindow createMaterialWindow1 = new CreateMaterialWindow();
            createMaterialWindow1.ShowDialog();

            if (createMaterialWindow1.MyDialogResult == true)
            {
                byte[] buffer = File.ReadAllBytes(createMaterialWindow1.pathTextBox.Text);
                Material m = new Material();
                m.Name = createMaterialWindow1.titleTextBox.Text;
                m.Description = createMaterialWindow1.descriptionTextBox.Text;
                m.Data = buffer;
                
                m.MaterialType_Id = createMaterialWindow1.MaterialType_Id;
                m.MaterialTypes = model1.MaterialTypes.First(o => o.Id == m.MaterialType_Id);
                m.FileName = createMaterialWindow1.pathTextBox.Text.Substring(createMaterialWindow1.pathTextBox.Text.LastIndexOf('\\') + 1);
                foreach (Person x in createMaterialWindow1.PersonsToAdd)
                {
                    m.Persons.Add(x);
                }
                Person p; p = model1.Persons.First(o => o.Id == Person_Id);
                materialsDataGrid.ItemsSource = p.Materials.Select(o => new { Id = o.Id, Название = o.Name, Описание = o.Description, Data = o.Data, }).ToList();
            }
        }