private void UpdateMember()
        {
            using (var context = new KucsaManagementDatabaseEntities())
            {
                var memberToUpdate = context.TblMembers.SingleOrDefault(member => member.MemberId == memId);
                if (memberToUpdate != null)
                {
                    memberToUpdate.MemberName = memberName;

                    //did not want to make it possible to change the registration number
                    memberToUpdate.MemberRegistration = memberToUpdate.MemberRegistration;
                    memberToUpdate.Password           = memberPass;
                    memberToUpdate.MemberThumbnail    = bigPicture;
                    memberToUpdate.MemberBigPicture   = bigPicture;
                    memberToUpdate.RoleId             = Convert.ToInt32(MetroComboBoxRole.SelectedValue);
                    memberToUpdate.CourseId           = Convert.ToInt32(MetroComboBoxMemberCourse.SelectedValue);
                    memberToUpdate.ModuleId           = Convert.ToInt32(MetroComboBoxMemberModule.SelectedValue);
                }
                try
                {
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    MetroMessageBox.Show(this, "Could not update the user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                MetroMessageBox.Show(this, memberName + " Updated Successfully but registration number remained!", "Successful Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void Login_Load(object sender, EventArgs e)
        {
            //Cursor.Current = Cursors.WaitCursor;

            try
            {
                Application.UseWaitCursor = true;
                using (var context = new KucsaManagementDatabaseEntities())
                {
                    MetroComboBoxUser.DataSource    = context.TblMembers.ToList();
                    MetroComboBoxUser.DisplayMember = "MemberName";
                    MetroComboBoxUser.ValueMember   = "MemberId";
                }
                MetroButtonLogin.Enabled = true;
                //Cursor.Current = Cursors.WaitCursor;
            }
            catch (Exception)
            {
                Application.UseWaitCursor = false;
                MetroMessageBox.Show(this, "Either the database has been moved, we cannot find it.", "Database Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
                MetroButtonLogin.Enabled = false;
            }
            finally
            {
                Application.UseWaitCursor = false;
                //Cursor.Current = Cursors.WaitCursor;
            }
        }
 public void LoadMembers()
 {
     using (var context = new KucsaManagementDatabaseEntities())
     {
         var members = from mem in context.TblMembers select new
         {
             mem.MemberId,
             mem.MemberName,
             mem.MemberRegistration,
             mem.Password,
             //mem.MemberThumbnail,
             //mem.MemberBigPicture,
             TblCourse = mem.TblCourse.CourseName,
             TblModule = mem.TblModule.Title,
             TblRole   = mem.TblRole.RoleName,
             //mem.TimeJoined
         };
         try
         {
             MetroGridMembers.DataSource = members.ToList();
         }
         catch (Exception es)
         {
             MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 4
0
        private void MetroButtonSaveModule_Click(object sender, EventArgs e)
        {
            int    modId        = Convert.ToInt32(metroLabelModuleId.Text);
            string moduleName   = metroTextBoxModuleTitle.Text;
            string moduleLeader = metroTextBoxModuleLeader.Text;

            //validate not to duplicate modules
            if (!IsValidModule(moduleName))
            {
                MetroMessageBox.Show(this, "Module with the name " + moduleName + " already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (moduleName != "")
            {
                using (var context = new KucsaManagementDatabaseEntities())
                {
                    if (modId == 0)
                    {
                        TblModule module = new TblModule
                        {
                            Title        = moduleName,
                            ModuleLeader = moduleLeader
                        };
                        context.TblModules.Add(module);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception es)
                        {
                            MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        MetroMessageBox.Show(this, moduleName + " Module Added Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        var moduleToUpdate = context.TblModules.SingleOrDefault(module => module.ModuleId == modId);
                        if (moduleToUpdate != null)
                        {
                            moduleToUpdate.Title        = moduleName;
                            moduleToUpdate.ModuleLeader = moduleLeader;
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception es)
                        {
                            MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        MetroMessageBox.Show(this, moduleName + " Updated Successfully!", "Successful Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }

                InitializeModuleList();
            }
        }
Esempio n. 5
0
        private void MetroButtonSaveCourse_Click(object sender, EventArgs e)
        {
            int    cosId       = Convert.ToInt32(metroLabelCourseId.Text);
            string courseName  = metroTextBoxCourseName.Text;
            string facultyName = metroTextBoxFaculty.Text;

            //validate not to duplicate modules
            if (!IsValidCourse(courseName))
            {
                MetroMessageBox.Show(this, "Course with the name " + metroTextBoxCourseName.Text + " already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (courseName != "")
            {
                using (var context = new KucsaManagementDatabaseEntities())
                {
                    if (cosId == 0)
                    {
                        TblCourse course = new TblCourse
                        {
                            CourseName    = courseName,
                            CourseFaculty = facultyName
                        };
                        context.TblCourses.Add(course);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception es)
                        {
                            MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        MetroMessageBox.Show(this, courseName + " Course Added Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        var courseToUpdate = context.TblCourses.SingleOrDefault(course => course.CourseId == cosId);
                        if (courseToUpdate != null)
                        {
                            courseToUpdate.CourseName    = courseName;
                            courseToUpdate.CourseFaculty = facultyName;
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception es)
                        {
                            MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        MetroMessageBox.Show(this, courseName + " Updated Successfully!", "Successful Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }

                InitializeCourseList();
            }
        }
        private void MetroButtonSaveRole_Click(object sender, EventArgs e)
        {
            int    rolId    = Convert.ToInt32(metroLabelRoleId.Text);
            string roleName = MetroTextBoxRoleName.Text;

            //validate not to duplicate Roles
            if (!IsValidRole(roleName))
            {
                MetroMessageBox.Show(this, "Role with the name " + roleName + " already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (roleName != "")
            {
                using (var context = new KucsaManagementDatabaseEntities())
                {
                    if (rolId == 0)
                    {
                        TblRole role = new TblRole
                        {
                            RoleName = roleName
                        };
                        context.TblRoles.Add(role);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception es)
                        {
                            MetroMessageBox.Show(this, es.ToString(), "Entity Framework Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        MetroMessageBox.Show(this, roleName + " Role Added Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        var roleToUpdate = context.TblRoles.SingleOrDefault(role => role.RoleId == rolId);
                        if (roleToUpdate != null)
                        {
                            roleToUpdate.RoleName = roleName;
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception es)
                        {
                            MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        MetroMessageBox.Show(this, roleName + " Updated Successfully!", "Successful Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }

                InitializeRoleList();
            }
        }
 private void InitializeCourseList()
 {
     using (var context = new KucsaManagementDatabaseEntities())
     {
         MetroComboBoxMemberCourse.DataSource    = context.TblCourses.ToList();
         MetroComboBoxMemberCourse.DisplayMember = "CourseName";
         MetroComboBoxMemberCourse.ValueMember   = "CourseId";
     }
 }
 private void InitializeModuleList()
 {
     using (var context = new KucsaManagementDatabaseEntities())
     {
         MetroComboBoxMemberModule.DataSource    = context.TblModules.ToList();
         MetroComboBoxMemberModule.DisplayMember = "Title";
         MetroComboBoxMemberModule.ValueMember   = "ModuleId";
     }
 }
 private bool IsValidRole(string title)
 {
     using (var context = new KucsaManagementDatabaseEntities())
     {
         if (context.TblRoles.Any(role => role.RoleName == title))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 10
0
 private bool IsValidModule(string title)
 {
     using (var context = new KucsaManagementDatabaseEntities())
     {
         if (context.TblModules.Any(module => module.Title == title))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 11
0
 private bool IsValidCourse(string title)
 {
     using (var context = new KucsaManagementDatabaseEntities())
     {
         if (context.TblCourses.Any(course => course.CourseName == title))
         {
             return(false);
         }
     }
     return(true);
 }
        private bool isValidDelete(int deleteID)
        {
            //Method to check if an entry is used as a foreign key, it should return false
            using (var context = new KucsaManagementDatabaseEntities())
            {
                var roleToDelete = context.TblMembers.SingleOrDefault(role => role.RoleId == deleteID);
                if (roleToDelete != null)
                {
                    return(false);
                }
            }

            return(true);
        }
        private void InitializeRoleList()
        {
            using (var context = new KucsaManagementDatabaseEntities())
            {
                var roles = from rol in context.TblRoles
                            select new
                {
                    rol.RoleId,
                    rol.RoleName,
                };

                MetroGridRoles.DataSource = roles.ToList();
            }
        }
Esempio n. 14
0
        private void InitializeModuleList()
        {
            using (var context = new KucsaManagementDatabaseEntities())
            {
                var modules = from mod in context.TblModules
                              select new
                {
                    mod.ModuleId,
                    mod.Title,
                    mod.ModuleLeader
                };

                metroGridModules.DataSource = modules.ToList();
            }
        }
Esempio n. 15
0
        private void InitializeCourseList()
        {
            using (var context = new KucsaManagementDatabaseEntities())
            {
                var courses = from cos in context.TblCourses
                              select new
                {
                    cos.CourseId,
                    cos.CourseName,
                    cos.CourseFaculty
                };

                MetroGridCourses.DataSource = courses.ToList();
            }
        }
 private bool isValidRegistrationNo(string RegNo)
 {
     try
     {
         using (var context = new KucsaManagementDatabaseEntities())
         {
             var regExists = context.TblMembers.SingleOrDefault(member => member.MemberRegistration == RegNo);
             if (regExists != null)
             {
                 return(false);
             }
         }
     }
     catch (Exception)
     {
     }
     return(true);
 }
        private bool isValidDelete(int deleteID)
        {
            //Method to check if an entry is used as a foreign key, it should return false
            using (var context = new KucsaManagementDatabaseEntities())
            {
                var memberToDelete = context.TblProjects.SingleOrDefault(member => member.MemberId == deleteID);
                if (memberToDelete != null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            //return true;
        }
        private void MetroButtonDelete_Click(object sender, EventArgs e)
        {
            int deleteID = Convert.ToInt32(metroLabelMemberId.Text);

            if (metroLabelMemberId.Text != "0" && metroLabelMemberId.Text != null && isValidDelete(deleteID))
            {
                using (var context = new KucsaManagementDatabaseEntities())
                {
                    var delUser = new TblMember {
                        MemberId = deleteID
                    };
                    context.TblMembers.Attach(delUser);
                    context.TblMembers.Remove(delUser);
                    context.SaveChanges();
                    MetroMessageBox.Show(this, delUser.MemberName + " Removed Successfully from the system!", "Successful Removal", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    LoadMembers();
                }
            }
        }
Esempio n. 19
0
        private void MetroButtonLogin_Click(object sender, EventArgs e)
        {
            //nothing much has been done here, login implementation deserves more than this

            int    userName = Convert.ToInt32(MetroComboBoxUser.SelectedValue);
            string password = MetroTextBoxPassword.Text;

            try
            {
                this.Enabled       = false; //optional, better target a panel or specific controls
                this.UseWaitCursor = true;  //from the Form/Window instance
                using (var context = new KucsaManagementDatabaseEntities())
                {
                    var user = context.TblMembers.SingleOrDefault(member => member.MemberId == userName);
                    if (user != null)
                    {
                        string useLoggedIn = user.MemberName;
                        MetroMessageBox.Show(this, useLoggedIn, "User's name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        FormMain fm = new FormMain()
                        {
                        };
                        fm.Show();
                        this.Hide();
                    }
                    else
                    {
                        MetroMessageBox.Show(this, "Not logged in", "User's name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            catch (Exception es)
            {
                MetroMessageBox.Show(this, es.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Enabled       = true;//optional
                this.UseWaitCursor = false;
            }
        }
        private void AddNewMember()
        {
            using (var context = new KucsaManagementDatabaseEntities())
            {
                TblMember member = new TblMember
                {
                    MemberName         = memberName,
                    MemberRegistration = memberReg,
                    Password           = memberPass,
                    MemberThumbnail    = bigPicture,
                    MemberBigPicture   = bigPicture,
                    RoleId             = Convert.ToInt32(MetroComboBoxRole.SelectedValue),
                    CourseId           = Convert.ToInt32(MetroComboBoxMemberCourse.SelectedValue),
                    ModuleId           = Convert.ToInt32(MetroComboBoxMemberModule.SelectedValue)
                };

                if (!isValidRegistrationNo(memberReg))
                {
                    MetroMessageBox.Show(this, "The registration number entered already exists!", "Unsuccessful Operation!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    context.TblMembers.Add(member);

                    try
                    {
                        context.SaveChanges();
                        MetroMessageBox.Show(this, memberName + " Added Successfully as a member!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    catch (Exception)
                    {
                        MetroMessageBox.Show(this, "Could not save a new user", "Unsuccessful Operation!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }