Ejemplo n.º 1
0
        private void button1_MouseClick(object sender, MouseEventArgs e)
        {
            var temp = listBox2.SelectedItem;

            if (temp != null)
            {
                var forma = new StudentEdit();
                var t     = (Student)temp;
                forma.Put(t);

                var rezult = forma.ShowDialog();
                if (rezult == DialogResult.OK)
                {
                    t = forma.Get();
                    listBox2.Items.Remove(temp);

                    if ((databaseservis.dbContext.students.SingleOrDefault <Student>(n => n.Id == t.Id)) != null) // возвращаем или null если ничего не нашли или указатель на объект
                    {
                        (databaseservis.dbContext.students.SingleOrDefault <Student>(n => n.Id == t.Id)).Name  = t.Name;
                        (databaseservis.dbContext.students.SingleOrDefault <Student>(n => n.Id == t.Id)).Age   = t.Age;
                        (databaseservis.dbContext.students.SingleOrDefault <Student>(n => n.Id == t.Id)).Group = t.Group;

                        listBox2.Items.Add(t);
                        listBox2.Refresh();
                    }

                    databaseservis.Save();
                }
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var forma = new StudentEdit();

            string  s    = File.ReadAllText(@"C:\Temp\spisok.json");
            Student stud = System.Text.Json.JsonSerializer.Deserialize <Student>(s);

            forma.Put(stud);


            //var stud = new Student();
            //stud = forma.Get();
            var rezult = forma.ShowDialog();

            if (rezult == DialogResult.OK)
            {
                // var stud = new Student();
                stud = forma.Get();
                File.WriteAllText(@"C:\Temp\spisok.json", System.Text.Json.JsonSerializer.Serialize(stud));
            }
        }