Example #1
0
        private void removetrack_Click(object sender, RoutedEventArgs e)
        {
            TrackClass trackeselect = new TrackClass();

            trackeselect = track.SelectedItem as TrackClass;


            var query =
                (from track in context3.tracks
                 where track.TrackName == trackeselect.TrackName
                 select track).FirstOrDefault();


            track tracksupdated = context3.tracks.Where(em => em.TrackName == query.TrackName).FirstOrDefault();

            context3.tracks.Remove(tracksupdated);
            context3.SaveChanges();
        }
Example #2
0
        private void Trackadd_Click(object sender, RoutedEventArgs e)
        {
            TrackClass newTrack = new TrackClass();

            newTrack.TrackName = tracKName_textbOX.Text.ToString();
            newTrack.Year      = trackdate.DisplayDate;
            var counter = 1;
            var trackAddedToDataBase = new track
            {
                TrackId   = (++counter),
                TrackName = newTrack.TrackName,
                Year      = newTrack.Year,
            };

            context3.tracks.Add(trackAddedToDataBase);
            context3.SaveChanges();
            track.Items.Add(trackAddedToDataBase);
        }
Example #3
0
        private void updatetrack_Click(object sender, RoutedEventArgs e)
        {
            TrackClass trackselect = new TrackClass();

            trackselect = track.SelectedItem as TrackClass;


            var query =
                (from track in context3.tracks
                 where track.TrackName == trackselect.TrackName
                 select track).FirstOrDefault();


            track tracksupdated = context3.tracks.Where(em => em.TrackName == query.TrackName).FirstOrDefault();

            tracksupdated.TrackName = (tracKName_textbOX.Text.ToString());
            tracksupdated.Year      = DateTime.Now;
            context3.SaveChanges();
        }
        private void removetrack_Click(object sender, RoutedEventArgs e)
        {
            try {
                TrackClass trackeselect = new TrackClass();
                trackeselect = track.SelectedItem as TrackClass;


                var query =
                    (from track in context3.tracks
                     where track.TrackName == trackeselect.TrackName
                     select track).FirstOrDefault();


                track tracksupdated = context3.tracks.Where(em => em.TrackName == query.TrackName).FirstOrDefault();
                context3.tracks.Remove(tracksupdated);
                context3.SaveChanges();
            }
            catch (Exception f)
            {
                MessageBox.Show("invalid inputs");
            }
        }
 private void Trackadd_Click(object sender, RoutedEventArgs e)
 {
     try {
         TrackClass newTrack = new TrackClass();
         newTrack.TrackName = tracKName_textbOX.Text.ToString();
         newTrack.Year      = trackdate.DisplayDate;
         var counter = 1;
         var trackAddedToDataBase = new track
         {
             TrackId   = (++counter),
             TrackName = newTrack.TrackName,
             Year      = newTrack.Year,
         };
         context3.tracks.Add(trackAddedToDataBase);
         context3.SaveChanges();
         track.Items.Add(trackAddedToDataBase);
     }
     catch (Exception f)
     {
         MessageBox.Show("invalid inputs");
     }
 }
        private void addstudent_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                track  addtrackstudent      = new track();
                intake addintakstudent      = new intake();
                branch addbranchstudent     = new branch();
                user   studentuser          = new user();
                rel_branch_track_intake ITb = new rel_branch_track_intake();

                student newstudent = new student();
                newstudent.StuId             = int.Parse(idstudent.Text.ToString());
                newstudent.FirstName         = studentFirstName.Text.ToString();
                newstudent.LastName          = lastnamestudent.Text.ToString();
                newstudent.BirthDate         = datestudent.DisplayDate;
                newstudent.StuEmail          = emailstudent.Text.ToString();
                newstudent.MatrailStatus     = "single";
                newstudent.JoinDate          = DateTime.Now;
                addbranchstudent.Year        = DateTime.Now;
                addbranchstudent.Name        = branchstudent.SelectedItem.ToString();
                addtrackstudent.Year         = DateTime.Now;
                addtrackstudent.TrackName    = tracksstudent.SelectedItem.ToString();
                addintakstudent.IntakeNumber = int.Parse(intakestudent.SelectedItem.ToString());
                addintakstudent.Year         = DateTime.Now;
                ShowStudentData newstudentwasadded = new ShowStudentData();
                newstudentwasadded.StuId     = int.Parse(idstudent.Text.ToString());
                newstudentwasadded.StuEmail  = emailstudent.Text.ToString();
                newstudentwasadded.FirstName = studentFirstName.Text.ToString();
                newstudentwasadded.LastName  = lastnamestudent.Text.ToString();
                newstudentwasadded.Track     = tracksstudent.SelectedItem.ToString();
                newstudentwasadded.Intake    = int.Parse(intakestudent.SelectedItem.ToString());
                newstudentwasadded.Branch    = branchstudent.SelectedItem.ToString();
                newstudentwasadded.BirthDate = DateTime.Now;

                studentuser.Email    = newstudent.StuEmail;
                studentuser.Password = passswordstudent.Text.ToString();
                studentuser.Type     = "student";


                int branchFindId
                    = (from branches in context3.branches
                       where branches.Name == addbranchstudent.Name
                       select branches.BranchId).FirstOrDefault();

                int trackFindId
                    =
                        (from trackID in context3.tracks
                         where trackID.TrackName == addtrackstudent.TrackName
                         select trackID.TrackId).FirstOrDefault();

                int intakeFindId
                    =
                        (from intakeId in context3.intakes
                         where intakeId.IntakeNumber == addintakstudent.IntakeNumber
                         select intakeId.IntakeNo
                        ).FirstOrDefault();

                ITb.intack   = intakeFindId;
                ITb.trackID  = trackFindId;
                ITb.branchID = branchFindId;


                int findITB =
                    (
                        from TIB in context3.rel_branch_track_intake
                        where TIB.branchID == branchFindId && TIB.trackID == trackFindId && TIB.intack == intakeFindId
                        select TIB.id
                    ).Count();
                int lastindexOfTIB;
                lastindexOfTIB =
                    (from lastindexes in context3.rel_branch_track_intake
                     select lastindexes).Count();
                MessageBox.Show(lastindexOfTIB.ToString());
                if (findITB > 0)
                {
                    int findITB2 =
                        (
                            from TIB in context3.rel_branch_track_intake
                            where TIB.branchID == branchFindId && TIB.trackID == trackFindId && TIB.intack == intakeFindId
                            select TIB.id
                        ).FirstOrDefault();
                    newstudent.ITBid = findITB2;
                    context3.users.Add(studentuser);
                    context3.students.Add(newstudent);
                    context3.SaveChanges();
                    lvUsers.Items.Add(newstudentwasadded);
                }
                else
                {
                    newstudent.ITBid = lastindexOfTIB;
                    ITb.id           = lastindexOfTIB;
                    context3.rel_branch_track_intake.Add(ITb);
                    context3.SaveChanges();
                    context3.users.Add(studentuser);
                    context3.students.Add(newstudent);
                    context3.SaveChanges();
                    lvUsers.Items.Add(newstudentwasadded);
                }
            }
            catch (Exception d)
            {
                MessageBox.Show("invalid inputs");
            }
        }