예제 #1
0
        private void editstudent_Click(object sender, RoutedEventArgs e)
        {
            ShowStudentData studentSelected = new ShowStudentData();

            studentSelected = lvUsers.SelectedItem as ShowStudentData;

            studentSelected.StuId     = int.Parse(idstudent.Text.ToString());
            studentSelected.FirstName = studentFirstName.Text.ToString();
            studentSelected.LastName  = lastnamestudent.Text.ToString();
            studentSelected.BirthDate = datestudent.DisplayDate;
            studentSelected.StuEmail  = emailstudent.Text.ToString();
            studentSelected.Branch    = branchstudent.SelectedItem.ToString();

            studentSelected.Track  = tracksstudent.SelectedItem.ToString();
            studentSelected.Intake = int.Parse(intakestudent.SelectedItem.ToString());
            rel_branch_track_intake newaddedstudent = new rel_branch_track_intake();

            var getIntack =
                (from Ik in context3.intakes
                 select Ik).ToList();
            var getTrack =
                (from Ik in context3.tracks
                 select Ik).ToList();
            var getBracnh =
                (from Ik in context3.branches
                 select Ik).ToList();

            // but intake id in table intak student

            foreach (var item2 in getIntack)
            {
                if (studentSelected.Intake == item2.IntakeNumber)
                {
                    studentSelected.IntakeID = item2.IntakeNo;
                }
            }


            // put track name in class track


            foreach (var item2 in getTrack)
            {
                if (studentSelected.Track == item2.TrackName)
                {
                    studentSelected.TrackID = item2.TrackId;
                }
            }

            // put branch name in class branch


            foreach (var item2 in getBracnh)
            {
                if (studentSelected.Branch == item2.Name)
                {
                    studentSelected.BranchID = item2.BranchId;
                }
            }



            int findITB =
                (
                    from TIB in context3.rel_branch_track_intake
                    where TIB.branchID == studentSelected.BranchID && TIB.trackID == studentSelected.TrackID &&
                    TIB.intack == studentSelected.IntakeID
                    select TIB.id
                ).Count();


            int lastindexOfTIB;


            lastindexOfTIB =
                (from lastindexes in context3.rel_branch_track_intake
                 select lastindexes).Count();



            student updateStudentInformation =
                (from std in context3.students

                 where std.StuId == studentSelected.StuId
                 select std
                ).FirstOrDefault();


            user newstudentuser = context3.users.Where(em => em.Email == studentSelected.StuEmail.ToString()).FirstOrDefault();

            newstudentuser.Email    = updateStudentInformation.StuEmail;
            newstudentuser.Password = passswordstudent.Text.ToString();

            context3.SaveChanges();

            int findITB3 =
                (
                    from TIB in context3.rel_branch_track_intake
                    where TIB.branchID == studentSelected.BranchID && TIB.trackID == studentSelected.TrackID &&
                    TIB.intack == studentSelected.IntakeID
                    select TIB.id
                ).FirstOrDefault();

            if (findITB > 0)
            {
                updateStudentInformation.StuEmail      = studentSelected.StuEmail;
                updateStudentInformation.StuId         = studentSelected.StuId;
                updateStudentInformation.FirstName     = studentSelected.FirstName;
                updateStudentInformation.LastName      = studentSelected.LastName;
                updateStudentInformation.BirthDate     = DateTime.Now;
                updateStudentInformation.JoinDate      = DateTime.Now;
                updateStudentInformation.MatrailStatus = "single";

                updateStudentInformation.ITBid = findITB3;
                context3.SaveChanges();
            }
            else
            {
                updateStudentInformation.StuEmail      = studentSelected.StuEmail;
                updateStudentInformation.StuId         = studentSelected.StuId;
                updateStudentInformation.FirstName     = studentSelected.FirstName;
                updateStudentInformation.LastName      = studentSelected.LastName;
                updateStudentInformation.BirthDate     = DateTime.Now;
                updateStudentInformation.JoinDate      = DateTime.Now;
                updateStudentInformation.MatrailStatus = "single";
                newaddedstudent.trackID  = studentSelected.TrackID;
                newaddedstudent.branchID = studentSelected.BranchID;
                newaddedstudent.intack   = studentSelected.IntakeID;
                context3.rel_branch_track_intake.Add(newaddedstudent);
                updateStudentInformation.ITBid = newaddedstudent.id;
                context3.SaveChanges();
            }
        }
예제 #2
0
        private void addstudent_Click(object sender, RoutedEventArgs e)
        {
            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);
            }
        }