private void btnConfirm_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Style.BackColor == Color.Blue) { using (var context = new Session5Entities()) { var getSeat = int.Parse(dataGridView1[cell.Index, row.Index].Value.ToString().Split('\n')[0]); var getID = dataGridView1[cell.Index, row.Index].Value.ToString().Split('\n')[1]; var toAssign = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.competitorId == getID select x).FirstOrDefault(); toAssign.assignedSeat = getSeat; context.SaveChanges(); } } } } foreach (var item in lbUnassigned.Items) { using (var context = new Session5Entities()) { var toUnassign = (from x in context.Competitors where item.ToString().Contains(x.competitorName + ", " + x.competitorCountry) && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); toUnassign.assignedSeat = 0; context.SaveChanges(); } } MessageBox.Show("Assigned seats successfully!"); }
private void btnLogin_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Ensure no empty field(s)!"); } else { using (var context = new Session5Entities()) { var findUser = (from x in context.Users where x.userId == txtUserID.Text select x).FirstOrDefault(); if (findUser == null) { MessageBox.Show("User does not exist!"); } else if (findUser.passwd != txtPassword.Text) { MessageBox.Show("Password incorrect!"); } else { MessageBox.Show("Welcome!"); Hide(); (new AdminMain()).ShowDialog(); Close(); } } } }
private bool random() { var getUnassigned = new List <DataGridViewCell>(); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Style.BackColor != Color.Blue && dataGridView1[cell.Index, row.Index].Value.ToString() != "") { getUnassigned.Add(dataGridView1[cell.Index, row.Index]); } } } var random = new Random(); var toRemove = new List <string>(); foreach (var item in lbUnassigned.Items) { using (var context = new Session5Entities()) { var randInx = random.Next(0, getUnassigned.Count); var newSeat = getUnassigned[randInx]; var getToAssign = (from x in context.Competitors where item.ToString().Contains(x.competitorName + ", " + x.competitorCountry) && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var boolCheck = checkRules(newSeat, getToAssign); if (boolCheck) { dataGridView1[newSeat.ColumnIndex, newSeat.RowIndex].Value = $"{newSeat.Value.ToString().Split('\n')[0]}\n{getToAssign.competitorId}"; dataGridView1[newSeat.ColumnIndex, newSeat.RowIndex].Style.ForeColor = Color.White; dataGridView1[newSeat.ColumnIndex, newSeat.RowIndex].Style.BackColor = Color.Blue; lblAssigned.Text = $"{int.Parse(lblAssigned.Text) + 1}"; lblUnassigned.Text = $"{int.Parse(lblUnassigned.Text) - 1}"; getUnassigned.Remove(newSeat); toRemove.Add(item.ToString()); } else { continue; } } } foreach (var item in toRemove) { lbUnassigned.Items.Remove(item); } if (lbUnassigned.Items.Count == 0) { return(true); } else { return(false); } }
private void btnManualAssign_Click(object sender, EventArgs e) { if (lbUnassigned.SelectedItem == null || dataGridView1.SelectedCells.Count != 1) { MessageBox.Show("Please select only one competitor and one seat!"); } else { using (var context = new Session5Entities()) { if (dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex].Style.BackColor == Color.Blue) { var getAssignedID = dataGridView1.CurrentCell.Value.ToString().Split('\n')[1]; var seatNumber = dataGridView1.CurrentCell.Value.ToString().Split('\n')[0]; var getToAssign = (from x in context.Competitors where lbUnassigned.SelectedItem.ToString().Contains(x.competitorName + ", " + x.competitorCountry) && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var getToUnassign = (from x in context.Competitors where getAssignedID == x.competitorId && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var boolCheck = checkRules(dataGridView1.CurrentCell, getToAssign); if (boolCheck == false) { MessageBox.Show("Unable to assign as front or/and back has a competitor of the same country!"); } else { dataGridView1.CurrentCell.Value = $"{seatNumber}\n{getToAssign.competitorId}"; lbUnassigned.Items.Add($"{getToUnassign.competitorName}, {getToUnassign.competitorCountry}"); lbUnassigned.Items.Remove(lbUnassigned.SelectedItem); } } else { var seatNumber = dataGridView1.CurrentCell.Value.ToString().Split('\n')[0]; var getToAssign = (from x in context.Competitors where lbUnassigned.SelectedItem.ToString().Contains(x.competitorName + ", " + x.competitorCountry) && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var boolCheck = checkRules(dataGridView1.CurrentCell, getToAssign); if (boolCheck == false) { MessageBox.Show("Unable to assign as front or/and back has a competitor of the same country!"); } else { dataGridView1.CurrentCell.Value = $"{seatNumber}\n{getToAssign.competitorId}"; dataGridView1.CurrentCell.Style.BackColor = Color.Blue; dataGridView1.CurrentCell.Style.ForeColor = Color.White; lbUnassigned.Items.Remove(lbUnassigned.SelectedItem); lblAssigned.Text = $"{int.Parse(lblAssigned.Text) + 1}"; lblUnassigned.Text = $"{int.Parse(lblUnassigned.Text) - 1}"; } } } } }
private void LoadSkills() { cbSkill.Items.Clear(); using (var context = new Session5Entities()) { var getSkills = (from x in context.Skills select x.skillName).ToArray(); cbSkill.Items.AddRange(getSkills); } }
private void btnSwapSeat_Click(object sender, EventArgs e) { if (dataGridView1.SelectedCells.Count != 2) { MessageBox.Show("Please select 2 assigned seatings to swap!"); } else { var checkAssignmentBool = true; foreach (DataGridViewCell item in dataGridView1.SelectedCells) { if (item.Style.BackColor != Color.Blue) { checkAssignmentBool = false; } if (checkAssignmentBool == false) { break; } } if (checkAssignmentBool == false) { MessageBox.Show("Ensure that the seats are already assigned!"); } else { using (var context = new Session5Entities()) { var firstSeat = dataGridView1.SelectedCells[0].Value.ToString().Split('\n')[0]; var getAssigned1ID = dataGridView1.SelectedCells[0].Value.ToString().Split('\n')[1]; var secondSeat = dataGridView1.SelectedCells[1].Value.ToString().Split('\n')[0]; var getAssigned2ID = dataGridView1.SelectedCells[1].Value.ToString().Split('\n')[1]; var getAssigned1 = (from x in context.Competitors where x.competitorId == getAssigned1ID && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var getAssigned2 = (from x in context.Competitors where x.competitorId == getAssigned2ID && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var boolCheck1 = checkRules(dataGridView1.SelectedCells[1], getAssigned1); var boolCheck2 = checkRules(dataGridView1.SelectedCells[0], getAssigned2); if (boolCheck1 && boolCheck2) { dataGridView1.SelectedCells[0].Value = $"{firstSeat}\n{getAssigned2.competitorId}"; dataGridView1.SelectedCells[1].Value = $"{secondSeat}\n{getAssigned1.competitorId}"; } else { MessageBox.Show("Unable to assign as front or/and back has a competitor of the same country!"); } } } } }
private void cbSessionNo_SelectedIndexChanged(object sender, EventArgs e) { lblTotal.Text = 0.ToString(); dataGridView1.Rows.Clear(); cbCompetitorName.Items.Clear(); using (var context = new Session5Entities()) { var getCompetitors = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() select x.competitorName).ToArray(); cbCompetitorName.Items.AddRange(getCompetitors); } }
private void LoadSkills() { lblTotal.Text = 0.ToString(); dataGridView1.Rows.Clear(); cbSkill.Items.Clear(); cbCompetitorName.Items.Clear(); cbSessionNo.Items.Clear(); using (var context = new Session5Entities()) { var getSkills = (from x in context.Skills select x.skillName).ToArray(); cbSkill.Items.AddRange(getSkills); } }
private void cbCompetitorName_SelectedIndexChanged(object sender, EventArgs e) { lblTotal.Text = 0.ToString(); dataGridView1.Rows.Clear(); using (var context = new Session5Entities()) { var getCompetiton = (from x in context.Competitions where x.Skill.skillName == cbSkill.SelectedItem.ToString() where x.sessionNo.ToString() == cbSessionNo.SelectedItem.ToString() select x).FirstOrDefault(); if (getCompetiton.q1MaxMarks != 0) { var newRow = new List <string>() { "Question 1", getCompetiton.q1MaxMarks.ToString(), "", "0" }; dataGridView1.Rows.Add(newRow.ToArray()); } if (getCompetiton.q2MaxMarks != 0) { var newRow = new List <string>() { "Question 2", getCompetiton.q2MaxMarks.ToString(), "", "0" }; dataGridView1.Rows.Add(newRow.ToArray()); } if (getCompetiton.q3MaxMarks != 0) { var newRow = new List <string>() { "Question 3", getCompetiton.q3MaxMarks.ToString(), "", "0" }; dataGridView1.Rows.Add(newRow.ToArray()); } if (getCompetiton.q4MaxMarks != 0) { var newRow = new List <string>() { "Question 4", getCompetiton.q4MaxMarks.ToString(), "", "0" }; dataGridView1.Rows.Add(newRow.ToArray()); } } }
private void btnSubmit_Click(object sender, EventArgs e) { using (var context = new Session5Entities()) { var getCompetitor = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.competitorName == cbCompetitorName.SelectedItem.ToString() select x).FirstOrDefault(); var getCompetition = (from x in context.Competitions where x.sessionNo.ToString() == cbSessionNo.SelectedItem.ToString() && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); var newResult = new Result() { competitionIdFK = getCompetition.competitionId, recordsIdFK = getCompetitor.recordsId, totalMarks = double.Parse(lblTotal.Text) }; if (getCompetition.q1MaxMarks != 0) { foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1[0, item.Index].Value.ToString() == "Question 1") { newResult.q1Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } } } else { newResult.q1Marks = 0; } if (getCompetition.q2MaxMarks != 0) { foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1[0, item.Index].Value.ToString() == "Question 2") { newResult.q2Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } } } else { newResult.q2Marks = 0; } if (getCompetition.q3MaxMarks != 0) { foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1[0, item.Index].Value.ToString() == "Question 3") { newResult.q3Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } } } else { newResult.q3Marks = 0; } if (getCompetition.q4MaxMarks != 0) { foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1[0, item.Index].Value.ToString() == "Question 4") { newResult.q4Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } } } else { newResult.q4Marks = 0; } context.Results.Add(newResult); context.SaveChanges(); MessageBox.Show("Saved results!"); LoadSkills(); } }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { dataGridView1.Rows.Clear(); lbUnassigned.Items.Clear(); lblAssigned.Text = 0.ToString(); lblUnassigned.Text = 0.ToString(); using (var context = new Session5Entities()) { var getUnassigned = (from x in context.Competitors where x.assignedSeat == 0 && x.Skill.skillName == cbSkill.SelectedItem.ToString() select x); lblUnassigned.Text = getUnassigned.Count().ToString(); foreach (var item in getUnassigned) { lbUnassigned.Items.Add($"{item.competitorName}, {item.competitorCountry}"); } var getTotal = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.noOfCompetitors).FirstOrDefault(); if (getTotal % 2 == 0) { var c1 = 1; var c2 = 2; for (int i = 1; i <= getTotal / 2; i++) { var newRow = new List <string>() { c1.ToString(), c2.ToString() }; dataGridView1.Rows.Add(newRow.ToArray()); c1 += 2; c2 += 2; } } else { var c1 = 1; var c2 = 2; for (int i = 1; i <= (getTotal / 2) + 1; i++) { if (i != (getTotal / 2) + 1) { var newRow = new List <string>() { c1.ToString(), c2.ToString() }; dataGridView1.Rows.Add(newRow.ToArray()); c1 += 2; c2 += 2; } else { var newRow = new List <string>() { c1.ToString(), "" }; dataGridView1.Rows.Add(newRow.ToArray()); } } } var getAssigned = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.assignedSeat != 0 select x); lblAssigned.Text = getAssigned.Count().ToString(); foreach (var item in getAssigned) { var boolCheck = false; foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Value.ToString() == item.assignedSeat.ToString()) { dataGridView1[cell.Index, row.Index].Value = $"{item.assignedSeat}\n{item.competitorId}"; dataGridView1[cell.Index, row.Index].Style.ForeColor = Color.White; dataGridView1[cell.Index, row.Index].Style.BackColor = Color.Blue; boolCheck = true; } if (boolCheck) { break; } } if (boolCheck) { break; } } } } }
private bool checkRules(DataGridViewCell dataGridViewCell, Competitor toAssign) { using (var context = new Session5Entities()) { var rowIndex = dataGridViewCell.RowIndex; if (rowIndex == 0) { if (dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex + 1].Style.BackColor == Color.Blue) { var getBottom = dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex + 1].Value.ToString().Split('\n')[1]; var checkBottom = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.competitorId == getBottom select x.competitorCountry).FirstOrDefault(); if (checkBottom == toAssign.competitorCountry) { return(false); } else { return(true); } } else { return(true); } } else if (rowIndex == dataGridView1.Rows.Count - 1) { if (dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex - 1].Style.BackColor == Color.Blue) { var getAbove = dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex - 1].Value.ToString().Split('\n')[1]; var checkAbove = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.competitorId == getAbove select x.competitorCountry).FirstOrDefault(); if (checkAbove == toAssign.competitorCountry) { return(false); } else { return(true); } } else { return(true); } } else { var checkBottom = string.Empty; var checkAbove = string.Empty; if (dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex + 1].Style.BackColor == Color.Blue) { var getBottom = dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex + 1].Value.ToString().Split('\n')[1]; checkBottom = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.competitorId == getBottom select x.competitorCountry).FirstOrDefault(); } if (dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex - 1].Style.BackColor == Color.Blue) { var getAbove = dataGridView1[dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex - 1].Value.ToString().Split('\n')[1]; checkAbove = (from x in context.Competitors where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.competitorId == getAbove select x.competitorCountry).FirstOrDefault(); } if (checkAbove == toAssign.competitorCountry || checkBottom == toAssign.competitorCountry) { return(false); } else { return(true); } } } }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { dataGridView1.Rows.Clear(); lblCompleted.Text = 0.ToString(); lblTotal.Text = 0.ToString(); pbBronze1.Image = null; pbBronze2.Image = null; pbSilver1.Image = null; pbSilver2.Image = null; pbGold1.Image = null; pbGold2.Image = null; btnGold.Visible = false; btnSilver.Visible = false; btnBronze.Visible = false; using (var context = new Session5Entities()) { var getSessions = (from x in context.Competitions where x.Skill.skillName == cbSkill.SelectedItem.ToString() select x); var totalMarks = (double)getSessions.Sum(x => x.q1MaxMarks + x.q2MaxMarks + x.q3MaxMarks + x.q4MaxMarks); var getTotalCompetitors = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.noOfCompetitors).FirstOrDefault(); lblTotal.Text = getSessions.Count().ToString(); foreach (var item in getSessions) { var countResults = (from x in context.Results where x.competitionIdFK == item.competitionId select x).Count(); if (countResults == getTotalCompetitors) { lblTotal.Text = $"{int.Parse(lblTotal.Text) + 1}"; } } var getResults = (from x in context.Results where x.Competitor.Skill.skillName == cbSkill.SelectedItem.ToString() group new { x.totalMarks, x.Competitor.competitorCountry } by x.Competitor.competitorName into y select y); foreach (var item in getResults) { var newRow = new List <string>() { item.Key, item.Select(x => x.competitorCountry).FirstOrDefault(), item.Sum(x => x.totalMarks).ToString() }; dataGridView1.Rows.Add(newRow.ToArray()); } foreach (DataGridViewRow item in dataGridView1.Rows) { if (Convert.ToDouble(dataGridView1[2, item.Index].Value) > totalMarks * 0.8) { if (moreGold.Count == 0) { pbGold1.Image = getFlags(dataGridView1[1, item.Index].Value.ToString()); moreGold.Add(dataGridView1[1, item.Index].Value.ToString()); moreGoldMarks.Add(Convert.ToDouble(dataGridView1[2, item.Index].Value)); } else if (moreGold.Count == 1) { } else { } } } } }