Ejemplo n.º 1
0
        public override void Export(object students)
        {
            Sheet sheet = wbPart.Workbook.Descendants <Sheet>().First();

            if (sheet != null)
            {
                DAOStudent studentdao = DatabaseFactory.getInstance().getDAOStudent();
                Worksheet  ws         = ((WorksheetPart)(wbPart.GetPartById(sheet.Id))).Worksheet;
                int        rowNumber  = 2;
                foreach (int studentnumber in (int[])students)
                {
                    BarometerDataAccesLayer.User student = studentdao.getStudentInfo(studentnumber);
                    if (student != null)
                    {
                        string numberAdress = "A" + rowNumber;
                        InsertCellInWorksheet(ws, numberAdress);
                        UpdateValue("Blad1", numberAdress, student.student_number.ToString(), 0, false);

                        string firstNameAdress = "B" + rowNumber;
                        InsertCellInWorksheet(ws, firstNameAdress);
                        UpdateValue("Blad1", firstNameAdress, student.firstname, 0, true);

                        string lastNameAdress = "C" + rowNumber;
                        InsertCellInWorksheet(ws, lastNameAdress);
                        UpdateValue("Blad1", lastNameAdress, student.lastname, 0, true);

                        string emailAdress = "D" + rowNumber;
                        InsertCellInWorksheet(ws, emailAdress);
                        UpdateValue("Blad1", emailAdress, student.email, 0, true);

                        string groupsString = "";
                        foreach (BarometerDataAccesLayer.ProjectGroup group in studentdao.getStudentGroup((int)student.student_number))
                        {
                            groupsString += group.group_code + ",";
                        }
                        string groupAdress = "E" + rowNumber;
                        InsertCellInWorksheet(ws, groupAdress);
                        UpdateValue("Blad1", groupAdress, groupsString, 0, true);
                    }
                    else
                    {
                        string numberAdress = "A" + rowNumber;
                        InsertCellInWorksheet(ws, numberAdress);
                        UpdateValue("Blad1", numberAdress, studentnumber.ToString(), 0, false);

                        string lastNameAdress = "C" + rowNumber;
                        InsertCellInWorksheet(ws, lastNameAdress);
                        UpdateValue("Blad1", lastNameAdress, "Bestaat niet!", 0, true);
                    }
                    rowNumber++;
                }
                document.Close();
            }
        }
Ejemplo n.º 2
0
        public ActionResult AddStudent(FormCollection collection)
        {
            int        studentIdToAdd = int.Parse(collection.GetValue("student").AttemptedValue);
            int        projectId      = int.Parse(collection.GetValue("projectID").AttemptedValue);
            int        groupId        = int.Parse(collection.GetValue("groupID").AttemptedValue);
            DAOStudent studentdao     = DatabaseFactory.getInstance().getDAOStudent();
            DAOProject projectdao     = DatabaseFactory.getInstance().getDAOProject();

            BarometerDataAccesLayer.User studentUser = studentdao.getStudentInfo(studentIdToAdd);
            IEnumerable <BarometerDataAccesLayer.ProjectMember> member = studentUser.ProjectMembers.Where(pm => pm.project_group_id == groupId);

            if (member.Count() == 0)
            {
                BarometerDataAccesLayer.ProjectMember pMember = new BarometerDataAccesLayer.ProjectMember();
                pMember.User             = studentUser;
                pMember.project_group_id = groupId;
                BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext();
                context.ProjectMembers.InsertOnSubmit(pMember);
                context.SubmitChanges();
            }

            return(RedirectToAction("ProjectGroups", new { groupId = groupId }));
        }
Ejemplo n.º 3
0
        private void FillDatabase(Dictionary<int, object[]> rowData, Project insertProject)
        {
            BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext();
            foreach (KeyValuePair<int, object[]> cell in rowData)
            {
                bool userExists = false;

                if (cell.Key != 0 && cell.Value[0].ToString() != "")
                {
                    int studentNumber = int.Parse(cell.Value[0].ToString());
                    BarometerDataAccesLayer.User insertUser = null;
                    var existingUser =
                        from u in context.Users
                        where u.student_number == studentNumber
                        select u;

                    int test = 0;
                    if (!existingUser.Any())
                    {
                        //If doesnt exist, create empty one
                        insertUser = new BarometerDataAccesLayer.User();
                    }
                    else
                    {
                        //If exists, get user
                        userExists = true;
                        insertUser = existingUser.First();
                    }

                    insertUser.student_number = int.Parse(cell.Value[0].ToString());
                    insertUser.firstname = cell.Value[1].ToString();
                    insertUser.lastname = cell.Value[2].ToString();
                    insertUser.email = cell.Value[3].ToString();

                    if (cell.Value[4].ToString() != "")
                    {
                        string[] groups = cell.Value[4].ToString().Split(',');
                        foreach (string groupcode in groups)
                        {
                            bool groupExists = false;
                            var currentGroup =
                                from pg in context.ProjectGroups
                                where pg.group_code == groupcode
                                select pg;

                            ProjectGroup newGroup = null;
                            if (currentGroup.Count() == 0)
                            {
                                //Groep bestaat nog niet, aanmaken
                                newGroup = new ProjectGroup();
                                newGroup.group_code = groupcode;
                            }
                            else
                            {
                                groupExists = true;
                                newGroup = currentGroup.First();
                            }
                            if (insertProject != null)
                            {
                                newGroup.Project = insertProject;
                            }

                            ProjectMember member = new ProjectMember();
                            member.student_user_id = insertUser.id;
                            member.ProjectGroup = newGroup;
                            if (!groupExists)
                            {
                                context.ProjectGroups.InsertOnSubmit(newGroup);
                            }
                            context.ProjectMembers.InsertOnSubmit(member);
                        }
                    }
                    if (!userExists)
                    {
                        context.Users.InsertOnSubmit(insertUser);
                    }
                }
            }
            context.SubmitChanges();
        }
Ejemplo n.º 4
0
        private void FillDatabase(Dictionary <int, object[]> rowData, Project insertProject)
        {
            BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext();
            foreach (KeyValuePair <int, object[]> cell in rowData)
            {
                bool userExists = false;

                if (cell.Key != 0 && cell.Value[0].ToString() != "")
                {
                    int studentNumber = int.Parse(cell.Value[0].ToString());
                    BarometerDataAccesLayer.User insertUser = null;
                    var existingUser =
                        from u in context.Users
                        where u.student_number == studentNumber
                        select u;

                    int test = 0;
                    if (!existingUser.Any())
                    {
                        //If doesnt exist, create empty one
                        insertUser = new BarometerDataAccesLayer.User();
                    }
                    else
                    {
                        //If exists, get user
                        userExists = true;
                        insertUser = existingUser.First();
                    }

                    insertUser.student_number = int.Parse(cell.Value[0].ToString());
                    insertUser.firstname      = cell.Value[1].ToString();
                    insertUser.lastname       = cell.Value[2].ToString();
                    insertUser.email          = cell.Value[3].ToString();

                    if (cell.Value[4].ToString() != "")
                    {
                        string[] groups = cell.Value[4].ToString().Split(',');
                        foreach (string groupcode in groups)
                        {
                            bool groupExists  = false;
                            var  currentGroup =
                                from pg in context.ProjectGroups
                                where pg.group_code == groupcode
                                select pg;

                            ProjectGroup newGroup = null;
                            if (currentGroup.Count() == 0)
                            {
                                //Groep bestaat nog niet, aanmaken
                                newGroup            = new ProjectGroup();
                                newGroup.group_code = groupcode;
                            }
                            else
                            {
                                groupExists = true;
                                newGroup    = currentGroup.First();
                            }
                            if (insertProject != null)
                            {
                                newGroup.Project = insertProject;
                            }

                            ProjectMember member = new ProjectMember();
                            member.student_user_id = insertUser.id;
                            member.ProjectGroup    = newGroup;
                            if (!groupExists)
                            {
                                context.ProjectGroups.InsertOnSubmit(newGroup);
                            }
                            context.ProjectMembers.InsertOnSubmit(member);
                        }
                    }
                    if (!userExists)
                    {
                        context.Users.InsertOnSubmit(insertUser);
                    }
                }
            }
            context.SubmitChanges();
        }