private void button1_Click(object sender, EventArgs e) { using (var db = new Session1Entities()) { var checkUser = from x in db.Users where x.userId == tbUser.Text && x.userPw == tbPW.Text select x; if (checkUser.Count() != 1) { MessageBox.Show("Invalid Username or Password!"); } else if (checkUser.First().userTypeIdFK != 1) { MessageBox.Show("This tool is only for resource managers."); } else { //login success MessageBox.Show($"Welcome, {checkUser.First().userName}"); var nform = new formResourceManagement(); nform.Show(); this.Close(); } } }
private void formAccCreation_Load(object sender, EventArgs e) { using (var db = new Session1Entities()) { var userTypeList = (from x in db.User_Type select x.userTypeName).ToList(); cbUserType.DataSource = userTypeList; } }
private void button1_Click(object sender, EventArgs e) { //add resource data checks using (var db = new Session1Entities()) { var itemlist = from x in db.Resources select x.resName; if (itemlist.Contains(tbResname.Text)) { MessageBox.Show("Resource already exist"); } else { var qcheck = int.TryParse(textBox1.Text, out int quantity); if (!qcheck || quantity < 0) { MessageBox.Show("Invalid input for quantity"); } else { if (quantity == 0 && checkedListBox1.CheckedItems.Count > 0) { MessageBox.Show("You cannot assign items without any quantity to skills"); } else { var res = new Resource(); res.resName = tbResname.Text; res.resTypeIdFK = comboBox1.SelectedIndex + 1; res.remainingQuantity = quantity; db.Resources.Add(res); db.SaveChanges(); foreach (string skill in checkedListBox1.CheckedItems) { var skillid = (from x in db.Skills where x.skillName == skill select x.skillId).First(); var alloc = new Resource_Allocation(); alloc.resIdFK = res.resId; alloc.skillIdFK = skillid; db.Resource_Allocation.Add(alloc); } db.SaveChanges(); MessageBox.Show("add success"); var nform = new formResourceManagement(); nform.Show(); this.Close(); } } } } }
private void button1_Click(object sender, EventArgs e) { using (var db = new Session1Entities()) { var qcheck = int.TryParse(tbQty.Text, out int quantity); if (!qcheck || quantity < 0) { MessageBox.Show("Invalid input for quantity"); } else { if (quantity == 0 && checkedListBox1.CheckedItems.Count > 0) { MessageBox.Show("You cannot assign items without any quantity to skills"); } else { var res = (from x in db.Resources where x.resId == resid select x).First(); res.remainingQuantity = quantity; var allocO = from x in db.Resource_Allocation where x.resIdFK == resid select x; foreach (var a in allocO) { db.Resource_Allocation.Remove(a); } db.SaveChanges(); foreach (string skill in checkedListBox1.CheckedItems) { var skillid = (from x in db.Skills where x.skillName == skill select x.skillId).First(); var alloc = new Resource_Allocation(); alloc.resIdFK = res.resId; alloc.skillIdFK = skillid; db.Resource_Allocation.Add(alloc); } db.SaveChanges(); MessageBox.Show("update success"); var nform = new formResourceManagement(); nform.Show(); this.Close(); } } } }
private void formAddNewResource_Load(object sender, EventArgs e) { using (var db = new Session1Entities()) { var skillList = (from x in db.Skills select x.skillName).ToList(); foreach (var item in skillList) { checkedListBox1.Items.Add(item); } var typelist = (from x in db.Resource_Type select x.resTypeName).ToList(); comboBox1.DataSource = typelist; } }
private void formResourceManagement_Load(object sender, EventArgs e) { using (var db = new Session1Entities()) { var typeList = (from x in db.Resource_Type select x.resTypeName).ToList(); var skillList = (from x in db.Skills select x.skillName).ToList(); cbType.DataSource = typeList; cbSkill.DataSource = skillList; } fillDGV(-1, -1); starting = false; }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { if (!starting) { using (var db = new Session1Entities()) { var skillid = (from x in db.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).FirstOrDefault(); var typeid = (from x in db.Resource_Type where x.resTypeName == cbSkill.SelectedItem.ToString() select x.resTypeId).FirstOrDefault(); fillDGV(skillid, typeid); } } }
private void btnCreateAcc_Click(object sender, EventArgs e) { //data entry check var error = true; if (tbUserID.TextLength < 8) { MessageBox.Show("User ID must be at least 8 characters."); error = false; } if (tbPW.Text != tbRPW.Text) { MessageBox.Show("Passwords do not match."); error = false; } //make the acc if no error using (var db = new Session1Entities()) { var userList = (from x in db.Users select x.userId).ToList(); if (userList.Contains(tbUserID.Text)) { MessageBox.Show("User ID is already in use."); } else { var newUser = new User(); newUser.userName = tbUserName.Text; newUser.userId = tbUserID.Text; newUser.userPw = tbPW.Text; newUser.userTypeIdFK = cbUserType.SelectedIndex + 1; db.Users.Add(newUser); db.SaveChanges(); var nform = new formMain(); nform.Show(); this.Close(); } } }
private void button3_Click(object sender, EventArgs e) { //delete if (dataGridView1.SelectedRows.Count != 0) { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { var resid = int.Parse(row.Cells[0].Value.ToString()); using (var db = new Session1Entities()) { var restodel = (from x in db.Resources where x.resId == resid select x).First(); db.Resources.Remove(restodel); db.SaveChanges(); fillDGV(-1, -1); } } } }
private void formUpdateResource_Load(object sender, EventArgs e) { using (var db = new Session1Entities()) { var res = (from x in db.Resources where x.resId == resid select x).First(); label7.Text = res.resName; label8.Text = res.Resource_Type.resTypeName; tbQty.Text = res.remainingQuantity.ToString(); var skillList = (from x in db.Skills select x.skillName).ToList(); foreach (var item in skillList) { checkedListBox1.Items.Add(item); } } }
private void fillDGV(int skillID, int typeID) { dataGridView1.Rows.Clear(); var resList = new List <int>(); using (var db = new Session1Entities()) { if (skillID == -1) { resList = (from x in db.Resources orderby x.remainingQuantity descending select x.resId).ToList(); } else { resList = (from x in db.Resource_Allocation where x.skillIdFK == skillID && x.Resource.resTypeIdFK == typeID orderby x.Resource.remainingQuantity descending select x.resIdFK).ToList(); } foreach (var resid in resList) { var skills = from x in db.Resource_Allocation where x.resIdFK == resid select x; var res = (from x in db.Resources where x.resId == resid select x).FirstOrDefault(); //making skill names var skillname = ""; if (skills.Count() != 0) { foreach (var q in skills) { skillname = $"{skillname}, {q.Skill.skillName}"; } } else { skillname = "Nil"; } //filtering into avail qty if (res.remainingQuantity > 5) { dataGridView1.Rows.Add(res.resId, res.resName, res.Resource_Type.resTypeName, skills.Count(), skillname, "Sufficient"); } else if (res.remainingQuantity > 0) { dataGridView1.Rows.Add(res.resId, res.resName, res.Resource_Type.resTypeName, skills.Count(), skillname, "Low Stock"); } else { var row = dataGridView1.Rows.Add(res.resId, res.resName, res.Resource_Type.resTypeName, skills.Count(), skillname, "Not Available"); dataGridView1.Rows[row].DefaultCellStyle.BackColor = Color.Red; } } } }