private void btnLogin_Click(object sender, EventArgs e) { using (var context = new Session5Entities()) { if (string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Please check your fields!", "Empty Field(s)", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var findUser = (from x in context.Users where x.userId == txtUserID.Text select x).FirstOrDefault(); if (findUser == null) { MessageBox.Show("No such user exist!", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (findUser.passwd != txtPassword.Text) { MessageBox.Show("User ID or Password do not match our DB!", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Hide(); (new AdminMain()).ShowDialog(); Close(); } } } }
private void btnConfirm_Click(object sender, EventArgs e) { using (var context = new Session5Entities()) { var getSkillID = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).FirstOrDefault(); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Style.BackColor != Color.Blue) { continue; } else { 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 getCompetitor = (from x in context.Competitors where x.competitorId == getID && x.skillIdFK == getSkillID select x).FirstOrDefault(); getCompetitor.assignedSeat = getSeat; } } } context.SaveChanges(); } MessageBox.Show("Assign seats successful!", "Assign seat", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); (new AdminMain()).ShowDialog(); Close(); }
private void LoadSeats() { dataGridView1.Rows.Clear(); dataGridView1.ColumnHeadersVisible = false; using (var context = new Session5Entities()) { var getNumberOfCompetitors = (from x in context.Skills where x.skillId == getSkillID select x.noOfCompetitors).FirstOrDefault(); var numberRows = 0; if (getNumberOfCompetitors % 2 == 0) { numberRows = getNumberOfCompetitors / 2; } else { numberRows = (getNumberOfCompetitors / 2) + 1; } var seatC1 = 1; var seatC2 = 2; for (int i = 1; i <= numberRows; i++) { var newRow = new List <string>() { seatC1.ToString(), seatC2.ToString() }; dataGridView1.Rows.Add(newRow.ToArray()); seatC1 += 2; seatC2 += 2; } } }
private void EnterMarks_Load(object sender, EventArgs e) { using (var context = new Session5Entities()) { var getSkills = (from x in context.Skills select x.skillName).Distinct().ToArray(); cbSkill.Items.AddRange(getSkills); } }
private void LoadDGV() { dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); dataGridView1.ColumnCount = 1; dataGridView1.Columns[0].Name = "Question"; DataGridViewComboBoxColumn c = new DataGridViewComboBoxColumn(); c.Name = "Grade"; c.Items.Add("Gd"); c.Items.Add("Avr"); c.Items.Add("Pr"); dataGridView1.Columns.Add(c); var list = new List <string>() { "TMarks", "Marks" }; foreach (var item in list) { dataGridView1.Columns.Add(item, item); } dataGridView1.Columns[2].Visible = false; dataGridView1.Columns[0].ReadOnly = true; dataGridView1.Columns[2].ReadOnly = true; dataGridView1.Columns[3].ReadOnly = true; using (var context = new Session5Entities()) { var sessionNo = Convert.ToInt32(cbSession.SelectedItem); var getQuestions = (from x in context.Competitions where x.Skill.skillName == cbSkill.SelectedItem.ToString() && x.sessionNo == sessionNo select x).First(); var dict = new Dictionary <string, int>(); dict.Add("Question 1", getQuestions.q1MaxMarks); dict.Add("Question 2", getQuestions.q2MaxMarks); dict.Add("Question 3", getQuestions.q3MaxMarks); dict.Add("Question 4", getQuestions.q4MaxMarks); foreach (var item in dict) { if (item.Value == 0) { continue; } else { List <string> rows = new List <string>() { item.Key, "", item.Value.ToString(), "" }; dataGridView1.Rows.Add(rows.ToArray()); } } } }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { using (var context = new Session5Entities()) { getSkillID = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).FirstOrDefault(); } LoadSeats(); LoadCompetitors(); }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { cbCompetitor.Items.Clear(); using (var context = new Session5Entities()) { skillID = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).FirstOrDefault(); var competitors = (from x in context.Competitors where x.skillIdFK == skillID select x.competitorName).ToArray(); cbCompetitor.Items.AddRange(competitors); } }
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { using (var context = new Session5Entities()) { var value = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString(); var getNameAndCountry = (from x in context.Competitors where value.Contains(x.competitorId) && x.Skill.skillName == cbSkill.SelectedItem.ToString() select new { Name = x.competitorName, Country = x.competitorCountry }).FirstOrDefault(); if (getNameAndCountry != null) { dataGridView1[e.ColumnIndex, e.RowIndex].ToolTipText = $"{getNameAndCountry.Name}, {getNameAndCountry.Country}"; } } }
private void LoadCompetitors() { lbCompetitors.Items.Clear(); using (var context = new Session5Entities()) { var getUCompetitors = (from x in context.Competitors where x.skillIdFK == getSkillID && x.assignedSeat == 0 select x); lblUnassigned.Text = getUCompetitors.Count().ToString(); foreach (var item in getUCompetitors) { lbCompetitors.Items.Add($"{item.competitorName}, {item.competitorCountry}"); } var getACompetitors = (from x in context.Competitors where x.skillIdFK == getSkillID && x.assignedSeat != 0 select x); lblAssigned.Text = getACompetitors.Count().ToString(); foreach (var item in getACompetitors) { 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 = $"{dataGridView1[cell.Index, row.Index].Value}\n{item.competitorId}"; dataGridView1[cell.Index, row.Index].Style.BackColor = Color.Blue; dataGridView1[cell.Index, row.Index].Style.ForeColor = Color.White; boolCheck = true; } if (boolCheck == true) { break; } } if (boolCheck == true) { break; } } if (boolCheck == true) { continue; } } } }
private void btnSubmit_Click(object sender, EventArgs e) { using (var context = new Session5Entities()) { var getCompetitor = (from x in context.Competitors where x.competitorName == cbCompetitor.SelectedItem.ToString() select x.recordsId).FirstOrDefault(); var getSkillID = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).First(); var sessionNo = Convert.ToInt32(cbSession.SelectedItem); var getCompetitionID = (from x in context.Competitions where x.skillIdFK == getSkillID && x.sessionNo == sessionNo select x.competitionId).First(); var checkIfResults = (from x in context.Results where x.recordsIdFK == getCompetitor && x.competitionIdFK == getCompetitionID select x).FirstOrDefault(); var marks = new List <decimal>(); foreach (DataGridViewRow item in dataGridView1.Rows) { marks.Add(Math.Round(Convert.ToDecimal(item.Cells[3].Value), 1)); } var total = marks.Sum(); if (checkIfResults != null) { if (marks.Count() == 4) { checkIfResults.competitionIdFK = getCompetitionID; checkIfResults.recordsIdFK = getCompetitor; checkIfResults.q1Marks = Convert.ToDouble(marks[0]); checkIfResults.q2Marks = Convert.ToDouble(marks[1]); checkIfResults.q3Marks = Convert.ToDouble(marks[2]); checkIfResults.q4Marks = Convert.ToDouble(marks[3]); checkIfResults.totalMarks = Convert.ToDouble(total); } else if (marks.Count() == 3) { checkIfResults.competitionIdFK = getCompetitionID; checkIfResults.recordsIdFK = getCompetitor; checkIfResults.q1Marks = Convert.ToDouble(marks[0]); checkIfResults.q2Marks = Convert.ToDouble(marks[1]); checkIfResults.q3Marks = Convert.ToDouble(marks[2]); checkIfResults.q4Marks = 0; checkIfResults.totalMarks = Convert.ToDouble(total); } else { checkIfResults.competitionIdFK = getCompetitionID; checkIfResults.recordsIdFK = getCompetitor; checkIfResults.q1Marks = Convert.ToDouble(marks[0]); checkIfResults.q2Marks = Convert.ToDouble(marks[1]); checkIfResults.q3Marks = 0; checkIfResults.q4Marks = 0; checkIfResults.totalMarks = Convert.ToDouble(total); } } //If not, then add to DB else { if (marks.Count() == 4) { context.Results.Add(new Result() { competitionIdFK = getCompetitionID, recordsIdFK = getCompetitor, q1Marks = Convert.ToDouble(marks[0]), q2Marks = Convert.ToDouble(marks[1]), q3Marks = Convert.ToDouble(marks[2]), q4Marks = Convert.ToDouble(marks[3]), totalMarks = Convert.ToDouble(total) }); } else if (marks.Count() == 3) { context.Results.Add(new Result() { competitionIdFK = getCompetitionID, recordsIdFK = getCompetitor, q1Marks = Convert.ToDouble(marks[0]), q2Marks = Convert.ToDouble(marks[1]), q3Marks = Convert.ToDouble(marks[2]), q4Marks = 0, totalMarks = Convert.ToDouble(total) }); } else { context.Results.Add(new Result() { competitionIdFK = getCompetitionID, recordsIdFK = getCompetitor, q1Marks = Convert.ToDouble(marks[0]), q2Marks = Convert.ToDouble(marks[1]), q3Marks = 0, q4Marks = 0, totalMarks = Convert.ToDouble(total) }); } } context.SaveChanges(); MessageBox.Show("Entered marks successfully!", "Enter Marks", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); (new AdminMain()).ShowDialog(); this.Close(); } }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { moreGold.Clear(); moreSilver.Clear(); moreBronze.Clear(); dataGridView1.Rows.Clear(); pbGold1.Image = null; pbGold2.Image = null; pbSilver1.Image = null; pbSilver2.Image = null; pbBronze1.Image = null; pbBronze2.Image = null; btnGold.Visible = false; btnSilver.Visible = false; btnBronze.Visible = false; lblSessions.Text = 0.ToString(); lblCompleted.Text = 0.ToString(); using (var context = new Session5Entities()) { var getSkillID = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).FirstOrDefault(); var getResults = (from x in context.Results where x.Competition.skillIdFK == getSkillID group x by x.Competitor.competitorName into y orderby y.Sum(z => z.totalMarks) descending select y); var getTotalSessions = (from x in context.Competitions where x.skillIdFK == getSkillID select x); var getNumberOfCompetitors = (from x in context.Competitors where x.skillIdFK == getSkillID select x).Count(); lblSessions.Text = getTotalSessions.Count().ToString(); var totalCompleted = 0; foreach (var item in getTotalSessions) { var getTotalResults = (from x in context.Results where x.competitionIdFK == item.competitionId select x).Count(); if (getTotalResults == getNumberOfCompetitors) { totalCompleted += 1; } } lblCompleted.Text = totalCompleted.ToString(); foreach (var item in getResults) { var newRow = new List <string>() { item.Key, item.Where(x => x.Competitor.competitorName == item.Key).Select(x => x.Competitor.competitorCountry).FirstOrDefault(), item.Where(x => x.Competitor.competitorName == item.Key).Sum(x => x.totalMarks).ToString() }; dataGridView1.Rows.Add(newRow.ToArray()); } var getSessionTotal = Convert.ToDouble((from x in context.Competitions where x.skillIdFK == getSkillID select x).Sum(x => x.q1MaxMarks + x.q2MaxMarks + x.q3MaxMarks + x.q4MaxMarks)); foreach (DataGridViewRow row in dataGridView1.Rows) { var getTotalMarks = Convert.ToDouble(dataGridView1[2, row.Index].Value); if (getTotalMarks >= getSessionTotal * 0.80) { if (moreGold.Count == 0) { pbGold1.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreGold.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); } else if (moreGold.Count == 1 && moreGold.ElementAt(0).Value - getTotalMarks <= 2 * moreGold.Count) { pbGold2.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreGold.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); } else if (moreGold.Count == 2 && moreGold.ElementAt(0).Value - getTotalMarks <= 2 * moreGold.Count) { moreGold.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); btnGold.Visible = true; } else { if (getTotalMarks >= getSessionTotal * 0.75) { if (moreSilver.Count == 0) { pbSilver1.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreSilver.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); } else if (moreSilver.Count == 1 && moreSilver.ElementAt(0).Value - getTotalMarks <= 2 * moreSilver.Count) { pbSilver2.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreSilver.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); } else if (moreSilver.Count == 2 && moreSilver.ElementAt(0).Value - getTotalMarks <= 2 * moreSilver.Count) { moreSilver.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); btnSilver.Visible = true; } else { if (getTotalMarks >= getSessionTotal * 0.71) { if (moreBronze.Count == 0) { pbBronze1.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); } else if (moreBronze.Count == 1 && moreBronze.ElementAt(0).Value - getTotalMarks <= 2 * moreBronze.Count) { pbBronze2.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); } else if (moreBronze.Count == 2 && moreBronze.ElementAt(0).Value - getTotalMarks <= 2 * moreBronze.Count) { moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), getTotalMarks); btnBronze.Visible = true; } } } } } } else if (getTotalMarks >= getSessionTotal * 0.75) { if (moreSilver.Count == 0) { pbSilver1.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreSilver.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); } else if (moreSilver.Count == 1 && moreSilver.ElementAt(0).Value - getSessionTotal <= 2 * moreSilver.Count) { pbSilver2.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreSilver.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); } else if (moreSilver.Count == 2 && moreSilver.ElementAt(0).Value - getSessionTotal <= 2 * moreSilver.Count) { moreSilver.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); btnSilver.Visible = true; } else { if (getTotalMarks >= getSessionTotal * 0.71) { if (moreBronze.Count == 0) { pbBronze1.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); } else if (moreBronze.Count == 1 && moreBronze.ElementAt(0).Value - getSessionTotal <= 2 * moreBronze.Count) { pbBronze2.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); } else if (moreBronze.Count == 2 && moreBronze.ElementAt(0).Value - getSessionTotal <= 2 * moreBronze.Count) { moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); btnBronze.Visible = true; } } } } else if (getTotalMarks >= getSessionTotal * 0.71) { if (moreBronze.Count == 0) { pbBronze1.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); } else if (moreBronze.Count == 1 && moreBronze.ElementAt(0).Value - getSessionTotal <= 2 * moreBronze.Count) { pbBronze2.Image = ReturnFlag(dataGridView1[1, row.Index].Value.ToString()); moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); } else if (moreBronze.Count == 2 && moreBronze.ElementAt(0).Value - getSessionTotal <= 2 * moreBronze.Count) { moreBronze.Add(dataGridView1[1, row.Index].Value.ToString(), Convert.ToInt32(dataGridView1[2, row.Index].Value)); btnBronze.Visible = true; } } } } }
private void LoadData() { using (var context = new Session5Entities()) { var getResults = (from x in context.Results where x.Competitor.competitorName == cbCompetitor.SelectedItem.ToString() && x.Competitor.skillIdFK == skillID orderby x.Competition.sessionNo select x); var bonus = 0.0; var totalAmountEarned = 0.0; foreach (var item in getResults) { double totalMark = item.Competition.q1MaxMarks + item.Competition.q2MaxMarks + item.Competition.q3MaxMarks + item.Competition.q4MaxMarks; double q1Worth = item.Competition.q1MaxMarks / totalMark * 100; double q2Worth = item.Competition.q2MaxMarks / totalMark * 100; double q3Worth = item.Competition.q3MaxMarks / totalMark * 100; double q4Worth = item.Competition.q4MaxMarks / totalMark * 100; if (item.Competition.q3MaxMarks == 0) { var q1Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 1", item.q1Marks.ToString(), item.Competition.q1MaxMarks.ToString(), Math.Round(item.q1Marks / item.Competition.q1MaxMarks * q1Worth, 2).ToString() }; var q2Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 2", item.q2Marks.ToString(), item.Competition.q2MaxMarks.ToString(), Math.Round(item.q2Marks / item.Competition.q2MaxMarks * q2Worth, 2).ToString() }; dataGridView1.Rows.Add(q1Row.ToArray()); dataGridView1.Rows.Add(q2Row.ToArray()); } else if (item.Competition.q4MaxMarks == 0) { var q1Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 1", item.q1Marks.ToString(), item.Competition.q1MaxMarks.ToString(), Math.Round(item.q1Marks / item.Competition.q1MaxMarks * q1Worth, 2).ToString() }; var q2Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 2", item.q2Marks.ToString(), item.Competition.q2MaxMarks.ToString(), Math.Round(item.q2Marks / item.Competition.q2MaxMarks * q2Worth, 2).ToString() }; var q3Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 3", item.q3Marks.ToString(), item.Competition.q3MaxMarks.ToString(), Math.Round(item.q3Marks / item.Competition.q3MaxMarks * q3Worth, 2).ToString() }; dataGridView1.Rows.Add(q1Row.ToArray()); dataGridView1.Rows.Add(q2Row.ToArray()); dataGridView1.Rows.Add(q3Row.ToArray()); } else { var q1Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 1", item.q1Marks.ToString(), item.Competition.q1MaxMarks.ToString(), Math.Round(item.q1Marks / item.Competition.q1MaxMarks * q1Worth, 2).ToString() }; var q2Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 2", item.q2Marks.ToString(), item.Competition.q2MaxMarks.ToString(), Math.Round(item.q2Marks / item.Competition.q2MaxMarks * q2Worth, 2).ToString() }; var q3Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 3", item.q3Marks.ToString(), item.Competition.q3MaxMarks.ToString(), Math.Round(item.q3Marks / item.Competition.q3MaxMarks * q3Worth, 2).ToString() }; var q4Row = new List <string>() { item.Competition.sessionNo.ToString(), "Question 4", item.q4Marks.ToString(), item.Competition.q4MaxMarks.ToString(), Math.Round(item.q4Marks / item.Competition.q4MaxMarks * q4Worth, 2).ToString() }; dataGridView1.Rows.Add(q1Row.ToArray()); dataGridView1.Rows.Add(q2Row.ToArray()); dataGridView1.Rows.Add(q3Row.ToArray()); dataGridView1.Rows.Add(q4Row.ToArray()); } var totalMarksForSession = item.totalMarks; if (totalMarksForSession > totalMark * 0.75) { bonus += 5; } } var totalMarksOverall = 0.0; foreach (DataGridViewRow item in dataGridView1.Rows) { totalAmountEarned += Convert.ToDouble(dataGridView1[4, item.Index].Value); totalMarksOverall += Convert.ToDouble(dataGridView1[2, item.Index].Value); } if (totalMarksOverall > context.Competitions.Where(x => x.skillIdFK == skillID).Select(x => x).Count()) { bonus += 10; } totalAmountEarned += bonus; lblAmount.Text = totalAmountEarned.ToString(); lblTotalBonus.Text = bonus.ToString(); } }
private bool random() { Random random = new Random(); var unAssignedList = new List <int>(); var listToRemove = new List <string>(); using (var context = new Session5Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Style.BackColor != Color.Blue) { unAssignedList.Add(Convert.ToInt32(dataGridView1[cell.Index, row.Index].Value)); } } } foreach (var item in lbCompetitors.Items) { var getID = (from x in context.Competitors where item.ToString().Contains(x.competitorName + ", " + x.competitorCountry) select x.competitorId).FirstOrDefault(); var getCurrentCountry = (from x in context.Competitors where x.competitorId == getID select x.competitorCountry).FirstOrDefault(); var randomIndex = random.Next(unAssignedList.Count - 1); var randomSeat = unAssignedList[randomIndex].ToString(); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Value.ToString() == randomSeat) { var getRowIndex = row.Index; if (getRowIndex == 0) { var getBelowCountry = dataGridView1[cell.Index, row.Index + 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBelowCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry != checkBottom) { dataGridView1[cell.Index, row.Index].Value = $"{randomSeat}\n{getID}"; listToRemove.Add(item.ToString()); dataGridView1[cell.Index, row.Index].Style.BackColor = Color.Blue; dataGridView1[cell.Index, row.Index].Style.ForeColor = Color.White; lblAssigned.Text = (int.Parse(lblAssigned.Text) + 1).ToString(); lblUnassigned.Text = (int.Parse(lblUnassigned.Text) - 1).ToString(); } } else if (getRowIndex == dataGridView1.RowCount - 1) { var getAboveCountry = dataGridView1[cell.Index, row.Index - 1].Value.ToString(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry != checkAbove) { dataGridView1[cell.Index, row.Index].Value = $"{randomSeat}\n{getID}"; listToRemove.Add(item.ToString()); dataGridView1[cell.Index, row.Index].Style.BackColor = Color.Blue; dataGridView1[cell.Index, row.Index].Style.ForeColor = Color.White; lblAssigned.Text = (int.Parse(lblAssigned.Text) + 1).ToString(); lblUnassigned.Text = (int.Parse(lblUnassigned.Text) - 1).ToString(); } } else { var getAboveCountry = dataGridView1[cell.Index, row.Index - 1].Value.ToString(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); var getBelowCountry = dataGridView1[cell.Index, row.Index + 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBelowCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry != checkAbove && getCurrentCountry != checkBottom) { dataGridView1[cell.Index, row.Index].Value = $"{randomSeat}\n{getID}"; listToRemove.Add(item.ToString()); dataGridView1[cell.Index, row.Index].Style.BackColor = Color.Blue; dataGridView1[cell.Index, row.Index].Style.ForeColor = Color.White; lblAssigned.Text = (int.Parse(lblAssigned.Text) + 1).ToString(); lblUnassigned.Text = (int.Parse(lblUnassigned.Text) - 1).ToString(); } } } } } } foreach (var item in listToRemove) { lbCompetitors.Items.Remove(item); } } if (lbCompetitors.Items.Count != 0) { return(false); } else { return(true); } }
private void btnManual_Click(object sender, EventArgs e) { if (dataGridView1.CurrentCell == null || lbCompetitors.SelectedItem == null) { MessageBox.Show("Please ensure that a seat and a competitor have been selected!", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var getCurrentRowIndex = dataGridView1.CurrentCell.RowIndex; using (var context = new Session5Entities()) { var getSeatNumber = dataGridView1.CurrentCell.Value.ToString(); var getSelectedCountry = (from x in context.Competitors where lbCompetitors.SelectedItem.ToString().Contains(x.competitorName + ", " + x.competitorCountry) select x.competitorCountry).FirstOrDefault(); var getSelectedID = (from x in context.Competitors where lbCompetitors.SelectedItem.ToString().Contains(x.competitorName + ", " + x.competitorCountry) select x.competitorId).FirstOrDefault(); if (getCurrentRowIndex == dataGridView1.RowCount - 1) { var getAboveCountry = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, getCurrentRowIndex - 1].Value.ToString(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getSelectedCountry == checkAbove) { MessageBox.Show("Competitors of same country cannot be in front or behind each other!", "Invalid seating assignment", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (dataGridView1.CurrentCell.Style.BackColor == Color.Blue) { var getSeatNumber1 = dataGridView1.CurrentCell.Value.ToString().Split('\n')[0]; var getCurrentAssignedID = dataGridView1.CurrentCell.Value.ToString().Split('\n')[1]; var getCompetitor = (from x in context.Competitors where x.competitorId == getCurrentAssignedID select x).FirstOrDefault(); lbCompetitors.Items.Add($"{getCompetitor.competitorName}, {getCompetitor.competitorCountry}"); dataGridView1.CurrentCell.Value = $"{getSeatNumber1}\n{getSelectedID}"; lbCompetitors.Items.Remove(lbCompetitors.SelectedItem.ToString()); } else { dataGridView1.CurrentCell.Value = $"{getSeatNumber}\n{getSelectedID}"; lbCompetitors.Items.Remove(lbCompetitors.SelectedItem.ToString()); dataGridView1.CurrentCell.Style.BackColor = Color.Blue; dataGridView1.CurrentCell.Style.ForeColor = Color.White; lblAssigned.Text = (int.Parse(lblAssigned.Text) + 1).ToString(); lblUnassigned.Text = (int.Parse(lblUnassigned.Text) - 1).ToString(); } } else if (getCurrentRowIndex == 0) { var getBottomCountry = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, getCurrentRowIndex + 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBottomCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getSelectedCountry == checkBottom) { MessageBox.Show("Competitors of same country cannot be in front or behind each other!", "Invalid seating assignment", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (dataGridView1.CurrentCell.Style.BackColor == Color.Blue) { var getSeatNumber1 = dataGridView1.CurrentCell.Value.ToString().Split('\n')[0]; var getCurrentAssignedID = dataGridView1.CurrentCell.Value.ToString().Split('\n')[1]; var getCompetitor = (from x in context.Competitors where x.competitorId == getCurrentAssignedID select x).FirstOrDefault(); lbCompetitors.Items.Add($"{getCompetitor.competitorName}, {getCompetitor.competitorCountry}"); dataGridView1.CurrentCell.Value = $"{getSeatNumber1}\n{getSelectedID}"; lbCompetitors.Items.Remove(lbCompetitors.SelectedItem.ToString()); } else { dataGridView1.CurrentCell.Value = $"{getSeatNumber}\n{getSelectedID}"; lbCompetitors.Items.Remove(lbCompetitors.SelectedItem.ToString()); dataGridView1.CurrentCell.Style.BackColor = Color.Blue; dataGridView1.CurrentCell.Style.ForeColor = Color.White; lblAssigned.Text = (int.Parse(lblAssigned.Text) + 1).ToString(); lblUnassigned.Text = (int.Parse(lblUnassigned.Text) - 1).ToString(); } } else { var getBottomCountry = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, getCurrentRowIndex + 1].Value.ToString(); var getAboveCountry = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, getCurrentRowIndex - 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBottomCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getSelectedCountry == checkBottom || getSelectedCountry == checkAbove) { MessageBox.Show("Competitors of same country cannot be in front or behind each other!", "Invalid seating assignment", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (dataGridView1.CurrentCell.Style.BackColor == Color.Blue) { var getSeatNumber1 = dataGridView1.CurrentCell.Value.ToString().Split('\n')[0]; var getCurrentAssignedID = dataGridView1.CurrentCell.Value.ToString().Split('\n')[1]; var getCompetitor = (from x in context.Competitors where x.competitorId == getCurrentAssignedID select x).FirstOrDefault(); lbCompetitors.Items.Add($"{getCompetitor.competitorName}, {getCompetitor.competitorCountry}"); dataGridView1.CurrentCell.Value = $"{getSeatNumber1}\n{getSelectedID}"; lbCompetitors.Items.Remove(lbCompetitors.SelectedItem.ToString()); } else { dataGridView1.CurrentCell.Value = $"{getSeatNumber}\n{getSelectedID}"; lbCompetitors.Items.Remove(lbCompetitors.SelectedItem.ToString()); dataGridView1.CurrentCell.Style.BackColor = Color.Blue; dataGridView1.CurrentCell.Style.ForeColor = Color.White; lblAssigned.Text = (int.Parse(lblAssigned.Text) + 1).ToString(); lblUnassigned.Text = (int.Parse(lblUnassigned.Text) - 1).ToString(); } } } } }
private void btnSwap_Click(object sender, EventArgs e) { if (dataGridView1.SelectedCells.Count != 2 && (dataGridView1.SelectedCells[0].Style.BackColor != Color.Blue || dataGridView1.SelectedCells[1].Style.BackColor != Color.Blue)) { MessageBox.Show("Please ensure there are two competitors' seats selected!", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var list = new List <DataGridViewCell>(); var valueList = new List <string>(); foreach (DataGridViewCell item in dataGridView1.SelectedCells) { list.Add(item); valueList.Add(item.Value.ToString().Split('\n')[1]); } var boolCheck = true; var seat1 = 0; var seat2 = 0; for (int i = 0; i < list.Count; i++) { if (i == 0) { var checkNewPos = list[i + 1]; var currentPos = list[i]; var getRowIndex = checkNewPos.RowIndex; var getCurrentAssignedID = currentPos.Value.ToString().Split('\n')[1]; using (var context = new Session5Entities()) { seat1 = int.Parse(checkNewPos.Value.ToString().Split('\n')[0]); var getCurrentCountry = (from x in context.Competitors where x.competitorId == getCurrentAssignedID select x.competitorCountry).FirstOrDefault(); if (getRowIndex == dataGridView1.RowCount - 1) { var getAboveCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex - 1].Value.ToString(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry == checkAbove) { boolCheck = false; break; } else { continue; } } else if (getRowIndex == 0) { var getBottomCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex + 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBottomCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry == checkBottom) { boolCheck = false; break; } else { continue; } } else { var getBottomCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex + 1].Value.ToString(); var getAboveCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex - 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBottomCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry == checkBottom || getCurrentCountry == checkAbove) { boolCheck = false; break; } else { continue; } } } } else { var checkNewPos = list[i - 1]; var currentPos = list[i]; var getRowIndex = checkNewPos.RowIndex; var getCurrentAssignedID = currentPos.Value.ToString().Split('\n')[1]; using (var context = new Session5Entities()) { seat2 = int.Parse(checkNewPos.Value.ToString().Split('\n')[0]); var getCurrentCountry = (from x in context.Competitors where x.competitorId == getCurrentAssignedID select x.competitorCountry).FirstOrDefault(); if (getRowIndex == dataGridView1.RowCount - 1) { var getAboveCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex - 1].Value.ToString(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry == checkAbove) { boolCheck = false; break; } else { continue; } } else if (getRowIndex == 0) { var getBottomCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex + 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBottomCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry == checkBottom) { boolCheck = false; break; } else { continue; } } else { var getBottomCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex + 1].Value.ToString(); var getAboveCountry = dataGridView1[checkNewPos.ColumnIndex, getRowIndex - 1].Value.ToString(); var checkBottom = (from x in context.Competitors where getBottomCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); var checkAbove = (from x in context.Competitors where getAboveCountry.Contains(x.competitorId) select x.competitorCountry).FirstOrDefault(); if (getCurrentCountry == checkBottom || getCurrentCountry == checkAbove) { boolCheck = false; break; } else { continue; } } } } } if (boolCheck == false) { MessageBox.Show("Unable to swap seats as Competitors of same country cannot be in front or behind each other!", "Invalid seating assignment", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { for (int i = 0; i < list.Count; i++) { if (i == 0) { var newPos = list[i + 1]; var curretID = valueList[i]; dataGridView1[newPos.ColumnIndex, newPos.RowIndex].Value = $"{seat1}\n{curretID}"; } else { var newPos = list[i - 1]; var curretID = valueList[i]; dataGridView1[newPos.ColumnIndex, newPos.RowIndex].Value = $"{seat2}\n{curretID}"; } } } } }
private void cbSkill_SelectedIndexChanged(object sender, EventArgs e) { bestCountry.Clear(); lblBestCountry.Text = "Best Country"; lblEasiest.Text = "Session No (Mark Range)"; lblToughest.Text = "Session No (Mark Range)"; lblMedian.Text = 0.ToString(); pbGreenUp.Visible = true; pbRedDown.Visible = true; pbCountry.Image = null; chart1.Series.Clear(); using (var context = new Session5Entities()) { var getSkillID = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.skillId).FirstOrDefault(); var getResults = (from x in context.Results where x.Competition.skillIdFK == getSkillID group x by x.Competitor.competitorCountry into y select y); foreach (var item in getResults) { var listAverage = new List <double>(); var getCompetitors = (from x in context.Competitors where x.competitorCountry == item.Key select x); foreach (var competitor in getCompetitors) { listAverage.Add(competitor.Results.Where(x => x.recordsIdFK == competitor.recordsId).Sum(x => x.totalMarks)); } bestCountry.Add(item.Key, listAverage.Average()); } if (bestCountry.Count != 0) { var bestPerformingCountry = bestCountry.OrderByDescending(x => x.Value).ElementAt(0).Key; pbCountry.Image = ReturnFlag(bestPerformingCountry); lblBestCountry.Text = $"{bestPerformingCountry} ({bestCountry.OrderByDescending(x => x.Value).ElementAt(0).Value})"; var getBestSession = (from x in context.Results where x.Competition.skillIdFK == getSkillID group x.totalMarks by x.Competition.sessionNo into y select new { minVale = y.Min(), maxValue = y.Max(), SessionNo = y.Key }); var sessionDictMin = new Dictionary <int, double>(); var sessionDictMax = new Dictionary <int, double>(); foreach (var item in getBestSession) { sessionDictMin.Add(item.SessionNo, item.minVale); sessionDictMax.Add(item.SessionNo, item.maxValue); } var getEasiestSession = sessionDictMax.Where(x => x.Key == sessionDictMin.Where(y => y.Value == sessionDictMin.Values.Max()).Select(y => y.Key).FirstOrDefault()).Select(x => x.Key).FirstOrDefault();; var getThoughestSession = sessionDictMin.Where(x => x.Key == sessionDictMax.Where(y => y.Value == sessionDictMax.Values.Min()).Select(y => y.Key).FirstOrDefault()).Select(x => x.Key).FirstOrDefault(); lblEasiest.Text = $"Session {getEasiestSession} ({sessionDictMin.Where(x => x.Key == getEasiestSession).Select(x => x.Value).FirstOrDefault()}-{sessionDictMax.Where(x => x.Key == getEasiestSession).Select(x => x.Value).FirstOrDefault()})"; lblToughest.Text = $"Session {getThoughestSession} ({sessionDictMin.Where(x => x.Key == getThoughestSession).Select(x => x.Value).FirstOrDefault()}-{sessionDictMax.Where(x => x.Key == getThoughestSession).Select(x => x.Value).FirstOrDefault()})"; var getResultsTotal = (from x in context.Results where x.Competitor.Skill.skillName == cbSkill.SelectedItem.ToString() orderby x.totalMarks select x.totalMarks).Count(); var median = (from x in context.Results where x.Competitor.Skill.skillName == cbSkill.SelectedItem.ToString() orderby x.totalMarks select x.totalMarks).ToList(); double getMedian = 0; if (getResultsTotal % 2 != 0) { var midpoint = (getResultsTotal / 2); getMedian = median[midpoint]; } else { var midpoint1 = (getResultsTotal / 2) - 1; var midpoint2 = (getResultsTotal / 2); var medianResult = (median[midpoint1] + median[midpoint2]) / 2; getMedian = Math.Round(medianResult, 1); } lblMedian.Text = $"{getMedian}"; var getSkillMedian = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x.expectedMedianMark).FirstOrDefault(); if (getMedian > getSkillMedian) { pbRedDown.Visible = false; } else { pbGreenUp.Visible = false; } var getCompetitors = (from x in context.Competitors where x.skillIdFK == getSkillID select x); foreach (var item in getCompetitors) { chart1.Series.Add(item.competitorName); chart1.Series[item.competitorName].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; chart1.Series[item.competitorName].BorderWidth = 3; var getSessions = (from x in context.Competitions where x.skillIdFK == getSkillID orderby x.sessionNo select x.sessionNo); foreach (var session in getSessions) { var getMarks = (from x in context.Results where x.Competition.sessionNo == session && x.recordsIdFK == item.recordsId && x.Competition.skillIdFK == getSkillID select x).FirstOrDefault(); if (getMarks != null) { chart1.Series[item.competitorName].Points.AddXY($"Session {session}", getMarks.totalMarks); } else { chart1.Series[item.competitorName].Points.AddXY($"Session {session}", 0); } } } } } }