示例#1
0
        public static scout getScout(int idNumber)
        {
            scout Scout = new scout();

            using (var ctx = new SALAHContext())
            {
                var query = from data in ctx.Scouts     //create a query to find the groupIDs of the logged in user
                            where data.scoutID == idNumber
                            select new { data.firstName, data.secondName, data.Address, data.dateOfBirth, data.healthInfo, data.parentEmail, data.parentEmergencyNumb, data.parentFirstName, data.parentSecondName };

                foreach (var result in query)
                {
                    Scout.scoutID             = idNumber;
                    Scout.firstName           = result.firstName;
                    Scout.secondName          = result.secondName;
                    Scout.Address             = result.Address;
                    Scout.dateOfBirth         = result.dateOfBirth;
                    Scout.healthInfo          = result.healthInfo;
                    Scout.parentEmail         = result.parentEmail;
                    Scout.parentEmergencyNumb = result.parentEmergencyNumb;
                    Scout.parentFirstName     = result.parentFirstName;
                    Scout.parentSecondName    = result.parentSecondName;
                }
            }

            return(Scout);
        }
        /// <summary>
        /// gets the personal details for the new scout that has been entered in the form and returns a scout object
        /// </summary>
        /// <param name="firstName">first name</param>
        /// <param name="secondName">surname</param>
        /// <param name="dateOfBirth">date of birth</param>
        /// <param name="Address">address</param>
        /// <param name="pEmail">parents email</param>
        /// <param name="pFName">parents first name</param>
        /// <param name="pSName">parent surname</param>
        /// <param name="pNumb">parent phone #</param>
        /// <param name="healthInfo">health information for scout</param>
        /// <returns></returns>
        public scout getPersonalDetails(string firstName, string secondName, string dateOfBirth, address Address, string pEmail, string pFName, string pSName, string pNumb, string healthInfo)
        {
            scout Scout = new scout();

            try
            {
                firstName   = firstNameTxtbx.Text;
                secondName  = secondNameTxtBx.Text;
                dateOfBirth = DOBPicker.Text;
                pEmail      = pEmailTxtBx.Text;
                pFName      = pFirstNameTxtBx.Text;
                pSName      = pSecondNameTxtBx.Text;
                healthInfo  = healthTxtBx.Text;
            }
            catch
            {
                MessageBox.Show("New scout could not be created. Please try again.");
            }

            bool phoneNumberCheck = checkPhoneNumber(pContactNumTxtBx.Text);

            if (phoneNumberCheck)
            {
                pNumb = pContactNumTxtBx.Text;

                Scout         = new scout(firstName, secondName, dateOfBirth, Address, pEmail, pFName, pSName, pNumb, healthInfo);
                Address       = getAddress();
                Scout.Address = Address;
            }
            if (!phoneNumberCheck)
            {
                Scout = new scout();
            }
            return(Scout);
        }
        private void addNewScoutBtn_Click(object sender, EventArgs e)
        {
            string  firstName   = "";
            string  secondName  = "";
            string  dateOfBirth = "";
            string  pEmail      = "";
            string  pFName      = "";
            string  pSName      = "";
            string  pNumb       = "";
            string  healthInfo  = "";
            address Address     = new address();
            string  groupName   = "";
            bool    groupChosen = false;
            bool    scoutAdded  = false;

            scout Scout = getPersonalDetails(firstName, secondName, dateOfBirth, Address, pEmail, pFName, pSName, pNumb, healthInfo);

            try
            {
                groupName   = getGroupName();
                groupChosen = true;
            }
            catch (Exception e2)
            {
                MessageBox.Show("New scout could not be created: Please select a group to add the scout to.");
                scoutAdded = false;
            }
            try
            {
                if (groupChosen)
                {
                    scout.addNewScout(Scout);
                    MessageBox.Show("New scout was created.");
                    scoutAdded = true;
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("New scout could not be created. Please try again.");
                scoutAdded = false;
            }
            try
            {
                int groupID = group.getGroupID(groupName);

                if (groupChosen && scoutAdded == true)
                {
                    group.addScoutToGroup(groupID, Scout.scoutID);
                    main_screen open_screen = new main_screen(currentUser);
                    open_screen.Show();
                    this.Close();
                }
            }
            catch (Exception e2)
            {
                MessageBox.Show("New scout created, but not added to group");
                scoutAdded = false;
            }
        }
示例#4
0
 private void displayScoutsDGV_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (displayScoutsDGV.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
     {
         scout     Scout       = scout.getScout(int.Parse(displayScoutsDGV.Rows[e.RowIndex].Cells[0].Value.ToString()));
         editScout open_screen = new editScout(Scout, selectedGroup, loggedInUser);
         this.Close();
         open_screen.Show();
     }
 }
示例#5
0
        public static bool RemoveScoutFromGroup(group group, scout scout)
        {
            bool userRemovedFromGroup = false;

            using (var ctx = new SALAHContext())
            {
                try
                {
                    var result = ctx.Groups.SingleOrDefault(g => g.group_name == group.group_name);
                    if (result != null)
                    {
                        group = result;
                    }

                    string[] oldGroupScouts = group.scoutID.Split(',');

                    for (int i = 0; i < oldGroupScouts.Length; i++)
                    {
                        if (oldGroupScouts[i] == scout.scoutID.ToString())
                        {
                            var result1 = ctx.Groups.SingleOrDefault(g => g.group_name == group.group_name);
                            if (result1 != null)
                            {
                                result1.scoutID = "";

                                for (int j = 0; j < oldGroupScouts.Length - 1; j++)
                                {
                                    if (i != j)
                                    {
                                        result1.scoutID += oldGroupScouts[j] + ",";
                                    }
                                }
                            }
                        }
                    }
                    userRemovedFromGroup = true;
                }
                catch
                {
                    userRemovedFromGroup = false;
                }
            }
            return(userRemovedFromGroup);
        }
示例#6
0
        public static bool addNewScout(scout scout)
        {
            bool scoutAdded = false;

            try
            {
                using (var ctx = new SALAHContext())
                {
                    ctx.Scouts.Add(scout);
                    ctx.SaveChanges();
                }
                scoutAdded = true;
                return(scoutAdded);
            }
            catch
            {
                scoutAdded = false;
                return(scoutAdded);
            }
        }
示例#7
0
        /// <summary>
        /// change which group the scout belongs to
        /// </summary>
        /// <param name="oldGroup">group the scout currently belongs to</param>
        /// <param name="newGroup">group the scout is going to belong to</param>
        /// <param name="scout">the scout to be moved</param>
        /// <param name="moveGroup">if the scout needs to be moved</param>
        public static void changeGroupScout(group oldGroup, group newGroup, scout scout, bool moveGroup)
        {
            if (moveGroup == true)
            {
                using (var ctx = new SALAHContext())
                {
                    var result = ctx.Groups.SingleOrDefault(g => g.groupID == newGroup.groupID);


                    if (result != null)
                    {
                        newGroup = result;
                    }

                    string[] oldGroupScouts = oldGroup.scoutID.Split(',');

                    for (int i = 0; i < oldGroupScouts.Length; i++)
                    {
                        if (oldGroupScouts[i] == scout.scoutID.ToString())
                        {
                            var result1 = ctx.Groups.SingleOrDefault(g => g.groupID == oldGroup.groupID);
                            if (result1 != null)
                            {
                                result1.scoutID = "";

                                for (int j = 0; j < oldGroupScouts.Length - 1; j++)
                                {
                                    if (i != j)
                                    {
                                        result1.scoutID += oldGroupScouts[j] + ",";
                                    }
                                }
                            }
                        }
                    }
                    group.addScoutToGroup(newGroup.groupID, scout.scoutID);
                    ctx.SaveChanges();
                    ctx.Dispose();
                }
            }
        }
示例#8
0
        public static bool deleteScout(int scoutID)
        {
            bool  scoutDeleted = false;
            scout scoutQuery   = new scout();

            using (var ctx = new SALAHContext())
            {
                try
                {
                    scoutQuery = ctx.Scouts.FirstOrDefault(m => m.scoutID == scoutID);
                    ctx.Scouts.Remove(scoutQuery);
                    ctx.SaveChanges();
                    ctx.Dispose();
                    //if (group.RemoveUserFromGroup())
                    scoutDeleted = true;
                }
                catch
                {
                    scoutDeleted = false;
                }
            }
            return(scoutDeleted);
        }