コード例 #1
0
        private void instructorss_Loaded(object sender, RoutedEventArgs e)
        {
            var query =
                (from instructorInfo in context3.instructors
                 select instructorInfo).ToList();

            List <showInstrctor> instructorclass = new List <showInstrctor>();
            var query2 =
                (from c in context3.branches
                 select c).ToList();

            foreach (var item in query)
            {
                showInstrctor inst = new showInstrctor();
                inst.Salary    = item.Salary;
                inst.Branchid  = item.Branchid;
                inst.FirstName = item.FirstName;

                foreach (var item2 in query2)
                {
                    if (item.Branchid == item2.BranchId)
                    {
                        inst.Branchname = item2.Name;
                    }
                }
                instructorclass.Add(inst);
            }



            foreach (var item in instructorclass)
            {
                instructorss.Items.Add(item);
            }
        }
コード例 #2
0
        private void removeinstructor_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                decimal x = decimal.Parse(salaryName.Text.ToString());

                int query =
                    (from c in context3.branches
                     where c.Name == branchName.SelectedItem.ToString()
                     select c.BranchId).FirstOrDefault();

                instructor deleteinstructor =
                    (from ins in context3.instructors
                     where ins.FirstName == instructorname.Text.ToString() && ins.Salary == x &&
                     ins.Branchid == query
                     select ins).FirstOrDefault();

                context3.instructors.Remove(deleteinstructor);
                context3.SaveChanges();
                showInstrctor removeFromList = new showInstrctor();
                removeFromList.FirstName  = instructorname.Text.ToString();
                removeFromList.Branchname = branchName.SelectedItem.ToString();
                removeFromList.Salary     = x;


                instructorss.Items.Remove(removeFromList);
            }
            catch (Exception d)

            {
                MessageBox.Show("invalid inputs");
            }
        }
コード例 #3
0
        private void updateinstructor_Click(object sender, RoutedEventArgs e)
        {
            showInstrctor updated = new showInstrctor();

            updated = instructorss.SelectedItem as showInstrctor;

            int query =
                (from c in context3.branches
                 where c.Name == branchName.SelectedItem.ToString()
                 select c.BranchId).FirstOrDefault();

            int query2 =
                (from c in context3.branches
                 where c.Name == updated.Branchname
                 select c.BranchId).FirstOrDefault();

            instructor deleteinstructor =
                (from ins in context3.instructors
                 where ins.FirstName == updated.FirstName && ins.Salary == updated.Salary &&
                 ins.Branchid == query2
                 select ins).FirstOrDefault();

            decimal x = decimal.Parse(salaryName.Text.ToString());

            deleteinstructor.FirstName = instructorname.Text.ToString();
            deleteinstructor.Salary    = x;
            deleteinstructor.Branchid  = query;

            context3.SaveChanges();
        }
コード例 #4
0
        private void instructorss_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            showInstrctor up = new showInstrctor();

            up = instructorss.SelectedItem as showInstrctor;
            instructorname.Text     = up.FirstName;
            branchName.SelectedItem = up.Branchname;
            salaryName.Text         = up.Salary.ToString();
        }
コード例 #5
0
        private void addinstructor_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                showInstrctor newinst = new showInstrctor();
                newinst.FirstName  = instructorname.Text.ToString();
                newinst.Branchname = branchName.SelectedItem.ToString();
                newinst.Salary     = decimal.Parse(salaryName.Text.ToString());

                instructor NewInstructorWasAdded = new instructor();
                user       NewUserWasAdded       = new user();

                NewUserWasAdded.Password = newinst.FirstName;
                NewUserWasAdded.Type     = "instructor";
                NewUserWasAdded.Email    = newinst.FirstName + "@gmail.com";
                context3.users.Add(NewUserWasAdded);
                context3.SaveChanges();

                int query =
                    (from c in context3.branches
                     where c.Name == newinst.Branchname
                     select c.BranchId).FirstOrDefault();
                instructor newInstructorIsAdded = new instructor();
                newInstructorIsAdded.InsEmail = NewUserWasAdded.Email;

                newInstructorIsAdded.ManagerId     = 1;
                newInstructorIsAdded.FirstName     = newinst.FirstName;
                newInstructorIsAdded.LastName      = newinst.FirstName;
                newInstructorIsAdded.MaritalStatus = "married";
                newInstructorIsAdded.BirthDate     = DateTime.Now;
                newInstructorIsAdded.HireDate      = DateTime.Now;
                newInstructorIsAdded.Job           = "instructor";
                newInstructorIsAdded.Salary        = newinst.Salary;
                newInstructorIsAdded.Branchid      = query;
                context3.instructors.Add(newInstructorIsAdded);
                context3.SaveChanges();
                instructorss.Items.Add(newinst);
            }
            catch (Exception u)
            {
                MessageBox.Show("inavlid inputs");
            }
        }