Ejemplo n.º 1
0
        private void UpdateResource_Load(object sender, EventArgs e)
        {
            using (var context = new Session1Entities())
            {
                clbAllocatedSkills.Items.Clear();

                var getSkills = (from x in context.Skills
                                 select x.skillName).Distinct().ToArray();
                clbAllocatedSkills.Items.AddRange(getSkills);

                var getResource = (from x in context.Resources
                                   where x.resId == _resourceID
                                   select x).FirstOrDefault();
                lblResourceName.Text       = getResource.resName;
                lblResourceType.Text       = getResource.Resource_Type.resTypeName;
                nudAvailableQuantity.Value = getResource.remainingQuantity;
                var allocation = (from x in context.Resource_Allocation
                                  where x.resIdFK == _resourceID
                                  select x);
                foreach (var skill in allocation)
                {
                    _list.Add(skill.Skill.skillName);
                }
                CheckItems();
            }
        }
Ejemplo n.º 2
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     using (var context = new Session1Entities())
     {
         var getUser = (from x in context.Users
                        where x.userId == txtUserID.Text
                        select x).FirstOrDefault();
         if (getUser == null)
         {
             MessageBox.Show("User does not exist!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else if (getUser.userPw != txtPassword.Text)
         {
             MessageBox.Show("Password is incorrect!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else
         {
             if (getUser.userTypeIdFK == 1)
             {
                 MessageBox.Show($"Welcome {getUser.userName}!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Hide();
                 (new ResourceManagement()).ShowDialog();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Sorry, your account is not permitted to use this application!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     using (var context = new Session1Entities())
     {
         var getAllocation = (from x in context.Resource_Allocation
                              where x.resIdFK == _resourceID
                              select x);
         foreach (var item in getAllocation)
         {
             context.Resource_Allocation.Remove(item);
         }
         context.SaveChanges();
         var getResource = (from x in context.Resources
                            where x.resId == _resourceID
                            select x).FirstOrDefault();
         getResource.remainingQuantity = Convert.ToInt32(nudAvailableQuantity.Value);
         context.SaveChanges();
         foreach (var item in _list)
         {
             var getSkillID = (from x in context.Skills
                               where x.skillName == item
                               select x.skillId).FirstOrDefault();
             context.Resource_Allocation.Add(new Resource_Allocation()
             {
                 resIdFK = _resourceID, skillIdFK = getSkillID
             });
         }
         context.SaveChanges();
         MessageBox.Show("Updated resource successfully!", "Update Resource", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Hide();
         (new ResourceManagement()).ShowDialog();
         this.Close();
     }
 }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                MessageBox.Show("Please select a resource to delete!", "Delete Resource", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var response = MessageBox.Show("Are you sure you want to delete this resource?", "Delete Resource", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (response == DialogResult.Yes)
                {
                    var resourceID = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
                    using (var context = new Session1Entities())
                    {
                        var allocation = (from x in context.Resource_Allocation
                                          where x.resIdFK == resourceID
                                          select x);
                        foreach (var item in allocation)
                        {
                            context.Resource_Allocation.Remove(item);
                        }
                        context.SaveChanges();

                        var resourceDelete = (from x in context.Resources
                                              where x.resId == resourceID
                                              select x).FirstOrDefault();
                        context.Resources.Remove(resourceDelete);
                        context.SaveChanges();
                    }
                    MessageBox.Show("Resource deleted successfully!", "Delete Resource", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
                }
            }
        }
 private void RMAccountCreation_Load(object sender, EventArgs e)
 {
     using (var context = new Session1Entities())
     {
         var getUserTypes = (from x in context.User_Type
                             select x.userTypeName).Distinct().ToArray();
         cbUserType.Items.AddRange(getUserTypes);
     }
 }
Ejemplo n.º 6
0
        private void AddNewResource_Load(object sender, EventArgs e)
        {
            using (var context = new Session1Entities())
            {
                cbResourceType.Items.Clear();
                clbAllocatedSkills.Items.Clear();
                var getResourceTypes = (from x in context.Resource_Type
                                        select x.resTypeName).Distinct().ToArray();
                cbResourceType.Items.AddRange(getResourceTypes);

                var getSkills = (from x in context.Skills
                                 select x.skillName).Distinct().ToArray();
                clbAllocatedSkills.Items.AddRange(getSkills);
            }
        }
Ejemplo n.º 7
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (var context = new Session1Entities())
     {
         var checkResource = (from x in context.Resources
                              where x.resName == txtResourceName.Text
                              select x).FirstOrDefault();
         if (checkResource != null)
         {
         }
         else if (cbResourceType.SelectedItem == null)
         {
         }
         else
         {
             var getResourceTypeID = (from x in context.Resource_Type
                                      where x.resTypeName == cbResourceType.SelectedItem.ToString()
                                      select x.resTypeId).FirstOrDefault();
             context.Resources.Add(new Resource()
             {
                 resName           = txtResourceName.Text,
                 remainingQuantity = Convert.ToInt32(nudAvailableQuantity.Value),
                 resTypeIdFK       = getResourceTypeID
             });
             context.SaveChanges();
             var getNewID = (from x in context.Resources
                             where x.resName == txtResourceName.Text
                             select x.resId).FirstOrDefault();
             foreach (var item in _list)
             {
                 var getSkillID = (from x in context.Skills
                                   where x.skillName == item
                                   select x.skillId).FirstOrDefault();
                 context.Resource_Allocation.Add(new Resource_Allocation()
                 {
                     resIdFK = getNewID, skillIdFK = getSkillID
                 });
             }
             context.SaveChanges();
             MessageBox.Show("Successfully added new resource!", "Add Resource", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txtResourceName.Text       = string.Empty;
             nudAvailableQuantity.Value = 0;
             AddNewResource_Load(null, null);
         }
     }
 }
        private void ResourceManagement_Load(object sender, EventArgs e)
        {
            cbSkill.Items.Clear();
            cbType.Items.Clear();
            cbSkill.Items.Add("All");
            cbType.Items.Add("All");
            using (var context = new Session1Entities())
            {
                var getTypes = (from x in context.Resource_Type
                                select x.resTypeName).Distinct().ToArray();
                cbType.Items.AddRange(getTypes);


                var getSkills = (from x in context.Skills
                                 select x.skillName).Distinct().ToArray();
                cbSkill.Items.AddRange(getSkills);
            }
            LoadDGV();
        }
 private void btnCreate_Click(object sender, EventArgs e)
 {
     using (var context = new Session1Entities())
     {
         var checkUserID = (from x in context.Users
                            where x.userId == txtUserID.Text
                            select x).FirstOrDefault();
         if (txtUserID.TextLength < 8)
         {
             MessageBox.Show("User ID must be 8 characters long or more!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (cbUserType.SelectedItem == null)
         {
             MessageBox.Show("Please select User Type!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (checkUserID != null)
         {
             MessageBox.Show("User ID has been taken!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (txtPassword.Text != txtReEnterPassword.Text)
         {
             MessageBox.Show("Passwords do not match! Please check your passwords again!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             var getUserTypeID = (from x in context.User_Type
                                  where x.userTypeName == cbUserType.SelectedItem.ToString()
                                  select x.userTypeId).FirstOrDefault();
             context.Users.Add(new User()
             {
                 userId       = txtUserID.Text,
                 userName     = txtUserName.Text,
                 userPw       = txtReEnterPassword.Text,
                 userTypeIdFK = getUserTypeID
             });
             context.SaveChanges();
             MessageBox.Show("Account created successfully!", "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
     }
 }
        private void LoadDGV()
        {
            dataGridView1.Rows.Clear();
            using (var context = new Session1Entities())
            {
                if ((cbSkill.SelectedItem == null || cbSkill.SelectedItem.ToString() == "All") && (cbType.SelectedItem == null || cbType.SelectedItem.ToString() == "All"))
                {
                    var getResources = (from x in context.Resources
                                        orderby x.remainingQuantity descending
                                        select x);
                    foreach (var Resources in getResources)
                    {
                        var newRow = new List <string>()
                        {
                            Resources.resId.ToString(), Resources.resName, Resources.Resource_Type.resTypeName,
                                 context.Resource_Allocation.Where(x => x.resIdFK == Resources.resId).Select(x => x).Count().ToString()
                        };
                        var getAllocation = (from x in context.Resource_Allocation
                                             where x.resIdFK == Resources.resId
                                             select x);
                        string allocationString = "Nil";
                        foreach (var skill in getAllocation)
                        {
                            if (allocationString == "Nil")
                            {
                                allocationString = skill.Skill.skillName;
                            }
                            else
                            {
                                allocationString += $", {skill.Skill.skillName}";
                            }
                        }
                        newRow.Add(allocationString);

                        if (Resources.remainingQuantity > 5)
                        {
                            newRow.Add("Sufficient");
                        }
                        else if (Resources.remainingQuantity <= 5 && Resources.remainingQuantity >= 1)
                        {
                            newRow.Add("Low Stock");
                        }
                        else
                        {
                            newRow.Add("Not Available");
                        }
                        dataGridView1.Rows.Add(newRow.ToArray());
                    }
                }
                else
                {
                    if ((cbType.SelectedItem == null || cbType.SelectedItem.ToString() == "All") && cbSkill.SelectedItem.ToString() != "All")
                    {
                        var getResources = (from x in context.Resources
                                            orderby x.remainingQuantity descending
                                            select x);
                        foreach (var Resources in getResources)
                        {
                            var getAllocationCheck = (from x in context.Resource_Allocation
                                                      where x.resIdFK == Resources.resId && x.Skill.skillName.Contains(cbSkill.SelectedItem.ToString())
                                                      select x).FirstOrDefault();
                            if (getAllocationCheck == null)
                            {
                                continue;
                            }
                            else
                            {
                                var newRow = new List <string>()
                                {
                                    Resources.resId.ToString(), Resources.resName, Resources.Resource_Type.resTypeName,
                                    context.Resource_Allocation.Where(x => x.resIdFK == Resources.resId).Select(x => x).Count().ToString()
                                };
                                var getAllocation = (from x in context.Resource_Allocation
                                                     where x.resIdFK == Resources.resId
                                                     select x);
                                string allocationString = "Nil";
                                foreach (var skill in getAllocation)
                                {
                                    if (allocationString == "Nil")
                                    {
                                        allocationString = skill.Skill.skillName;
                                    }
                                    else
                                    {
                                        allocationString += $", {skill.Skill.skillName}";
                                    }
                                }
                                newRow.Add(allocationString);

                                if (Resources.remainingQuantity > 5)
                                {
                                    newRow.Add("Sufficient");
                                }
                                else if (Resources.remainingQuantity <= 5 && Resources.remainingQuantity >= 1)
                                {
                                    newRow.Add("Low Stock");
                                }
                                else
                                {
                                    newRow.Add("Not Available");
                                }
                                dataGridView1.Rows.Add(newRow.ToArray());
                            }
                        }
                    }
                    else if ((cbSkill.SelectedItem == null || cbSkill.SelectedItem.ToString() == "All") && cbType.SelectedItem.ToString() != "All")
                    {
                        var getResources = (from x in context.Resources
                                            where x.Resource_Type.resTypeName == cbType.SelectedItem.ToString()
                                            orderby x.remainingQuantity descending
                                            select x);
                        foreach (var Resources in getResources)
                        {
                            var newRow = new List <string>()
                            {
                                Resources.resId.ToString(), Resources.resName, Resources.Resource_Type.resTypeName,
                                     context.Resource_Allocation.Where(x => x.resIdFK == Resources.resId).Select(x => x).Count().ToString()
                            };
                            var getAllocation = (from x in context.Resource_Allocation
                                                 where x.resIdFK == Resources.resId
                                                 select x);
                            string allocationString = "Nil";
                            foreach (var skill in getAllocation)
                            {
                                if (allocationString == "Nil")
                                {
                                    allocationString = skill.Skill.skillName;
                                }
                                else
                                {
                                    allocationString += $", {skill.Skill.skillName}";
                                }
                            }
                            newRow.Add(allocationString);

                            if (Resources.remainingQuantity > 5)
                            {
                                newRow.Add("Sufficient");
                            }
                            else if (Resources.remainingQuantity <= 5 && Resources.remainingQuantity >= 1)
                            {
                                newRow.Add("Low Stock");
                            }
                            else
                            {
                                newRow.Add("Not Available");
                            }
                            dataGridView1.Rows.Add(newRow.ToArray());
                        }
                    }
                    else if (cbSkill.SelectedItem.ToString() != "All" && cbType.SelectedItem.ToString() != "All")
                    {
                        var getResources = (from x in context.Resources
                                            where x.Resource_Type.resTypeName == cbType.SelectedItem.ToString()
                                            orderby x.remainingQuantity descending
                                            select x);
                        foreach (var Resources in getResources)
                        {
                            var getAllocationCheck = (from x in context.Resource_Allocation
                                                      where x.resIdFK == Resources.resId && x.Skill.skillName.Contains(cbSkill.SelectedItem.ToString())
                                                      select x).FirstOrDefault();
                            if (getAllocationCheck == null)
                            {
                                continue;
                            }
                            else
                            {
                                var newRow = new List <string>()
                                {
                                    Resources.resId.ToString(), Resources.resName, Resources.Resource_Type.resTypeName,
                                    context.Resource_Allocation.Where(x => x.resIdFK == Resources.resId).Select(x => x).Count().ToString()
                                };
                                var getAllocation = (from x in context.Resource_Allocation
                                                     where x.resIdFK == Resources.resId
                                                     select x);
                                string allocationString = "Nil";
                                foreach (var skill in getAllocation)
                                {
                                    if (allocationString == "Nil")
                                    {
                                        allocationString = skill.Skill.skillName;
                                    }
                                    else
                                    {
                                        allocationString += $", {skill.Skill.skillName}";
                                    }
                                }
                                newRow.Add(allocationString);

                                if (Resources.remainingQuantity > 5)
                                {
                                    newRow.Add("Sufficient");
                                }
                                else if (Resources.remainingQuantity <= 5 && Resources.remainingQuantity >= 1)
                                {
                                    newRow.Add("Low Stock");
                                }
                                else
                                {
                                    newRow.Add("Not Available");
                                }
                                dataGridView1.Rows.Add(newRow.ToArray());
                            }
                        }
                    }
                }
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (dataGridView1.Rows[row.Index].Cells[5].Value.ToString() == "Not Available")
                    {
                        dataGridView1.Rows[row.Index].DefaultCellStyle.BackColor = Color.Red;
                    }
                }
            }
        }