Example #1
0
        private void removeBanch_Click(object sender, RoutedEventArgs e)
        {
            BranchClass brancheselect = new BranchClass();

            brancheselect = branch.SelectedItem as BranchClass;


            var query =
                (from branch in context3.branches
                 where branch.Name == brancheselect.Name
                 select branch).FirstOrDefault();


            branch branchesupdated = context3.branches.Where(em => em.Name == query.Name).FirstOrDefault();

            context3.branches.Remove(branchesupdated);
            context3.SaveChanges();
        }
Example #2
0
        private void AddBranch_Click(object sender, RoutedEventArgs e)
        {
            BranchClass newBracnh = new BranchClass();

            newBracnh.Name = BranchLocation_textbox.Text.ToString();
            newBracnh.Year = branchdate.DisplayDate;
            var counter = 1;
            var BranchAddedToDataBase = new branch
            {
                BranchId = (++counter),
                Name     = newBracnh.Name,
                Year     = newBracnh.Year,
            };

            context3.branches.Add(BranchAddedToDataBase);
            context3.SaveChanges();
            branch.Items.Add(BranchAddedToDataBase);
        }
Example #3
0
        private void updateBranch_Click(object sender, RoutedEventArgs e)
        {
            BranchClass branchselect = new BranchClass();

            branchselect = branch.SelectedItem as BranchClass;


            var query =
                (from branch in context3.branches
                 where branch.Name == branchselect.Name
                 select branch).FirstOrDefault();


            branch branchesupdated = context3.branches.Where(em => em.Name == query.Name).FirstOrDefault();

            branchesupdated.Name = (BranchLocation_textbox.Text.ToString());
            branchesupdated.Year = DateTime.Now;
            context3.SaveChanges();
        }
        private void removeBanch_Click(object sender, RoutedEventArgs e)
        {
            try {
                BranchClass brancheselect = new BranchClass();
                brancheselect = branch.SelectedItem as BranchClass;


                var query =
                    (from branch in context3.branches
                     where branch.Name == brancheselect.Name
                     select branch).FirstOrDefault();


                branch branchesupdated = context3.branches.Where(em => em.Name == query.Name).FirstOrDefault();
                context3.branches.Remove(branchesupdated);
                context3.SaveChanges();
            }
            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");
            }
        }