示例#1
0
        private void button2_Click(object sender, EventArgs s)
        {
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult      result  = MessageBox.Show("Are you sure you want to delete this student?", "Confirm Delete", buttons);

            if (result == DialogResult.Yes)
            {
                try
                {
                    int delete   = listBox1.SelectedIndex;
                    var employee = stu[delete];
                    using (var db = new CodeFirstContext())
                    {
                        db.Students.Attach(employee);
                        db.Students.Remove(employee);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Unable to Delete - Contact your administrator");
                }
            }
            listBox1.DataSource = Student.displayStudents();
        }
示例#2
0
        public static List <Employee> getAll()
        {
            var employees = new List <Employee>();

            using (var db = new CodeFirstContext())
            {
                var e = db.Employees.ToList();
                foreach (Employee em in e)
                {
                    employees.Add(em);
                }
            }
            return(employees);
        }
示例#3
0
        public static List <String> displayEmployees()
        {
            var list = new List <string>();

            using (var db = new CodeFirstContext())
            {
                var emp = db.Employees.ToList();
                foreach (var employee in emp)
                {
                    list.Add("ID: " + employee.Id + " | " + employee.Name + " | $" + employee.Salary + ".00 | " + employee.JobTitle);
                }
            }
            return(list);
        }
示例#4
0
        public static List <Student> getAll()
        {
            var students = new List <Student>();

            using (var db = new CodeFirstContext())
            {
                var s = db.Students.ToList();
                foreach (Student st in s)
                {
                    students.Add(st);
                }
            }
            return(students);
        }
示例#5
0
        public static List <String> displayStudents()
        {
            var list = new List <string>();

            using (var db = new CodeFirstContext())
            {
                var stu = db.Students.ToList();
                foreach (var students in stu)
                {
                    list.Add("ID: " + students.Id + " | " + students.Name + " | $" + students.tuition + " | " + students.Major);
                }
            }
            return(list);
        }
示例#6
0
 private void button1_Click_1(object sender, EventArgs s)
 {
     // THIS IS THE ADD BUTTON
     try
     {
         using (var db = new CodeFirstContext())
         {
             Student objStudent = new Student();
             objStudent.Name    = textBox2.Text;
             objStudent.tuition = int.Parse(textBox3.Text);
             objStudent.Major   = textBox4.Text;
             db.Students.Add(objStudent);
             db.SaveChanges();
         }
         MessageBox.Show("New student has been added to the database.", "Success!");
         textBox2.Clear();
         textBox3.Clear();
         textBox4.Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Oops - Something went wrong.");
     }
 }
示例#7
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     // THIS IS THE ADD BUTTON
     try
     {
         using (var db = new CodeFirstContext())
         {
             Employee objEmployee = new Employee();
             objEmployee.Name     = textBox2.Text;
             objEmployee.Salary   = int.Parse(textBox3.Text);
             objEmployee.JobTitle = textBox4.Text;
             db.Employees.Add(objEmployee);
             db.SaveChanges();
         }
         MessageBox.Show("New employee has been added to the database.", "Success!");
         textBox2.Clear();
         textBox3.Clear();
         textBox4.Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Oops - Something went wrong.");
     }
 }