private void btnConfirm_Click(object sender, EventArgs e) { using (var context = new Session5Entities()) { var getSkill = (from x in context.Skills where x.skillName == cbSkill.SelectedItem.ToString() select x).FirstOrDefault(); foreach (DataGridViewRow row in dataGridView1.Rows) { foreach (DataGridViewColumn cell in dataGridView1.Columns) { if (dataGridView1[cell.Index, row.Index].Style.BackColor == Color.Blue) { var seat = int.Parse(dataGridView1[cell.Index, row.Index].Value.ToString().Split('\n')[0]); var competitorID = dataGridView1[cell.Index, row.Index].Value.ToString().Split('\n')[1]; var getCompetitor = (from x in context.Competitors where x.skillIdFK == getSkill.skillId && x.competitorId == competitorID select x).FirstOrDefault(); getCompetitor.assignedSeat = seat; } } } foreach (var item in lbUnassigned.Items) { var getCompetitor = (from x in context.Competitors where x.skillIdFK == getSkill.skillId && item.ToString().Contains(x.competitorName + ", " + x.competitorCountry) select x).FirstOrDefault(); getCompetitor.assignedSeat = 0; } context.SaveChanges(); MessageBox.Show("Completed seat assignment!"); } }
private void btnSubmit_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(); var getSession = (from x in context.Competitions where x.sessionNo.ToString() == cbSession.SelectedItem.ToString() && x.skillIdFK == getSkillID select x).FirstOrDefault(); var getCompetitor = (from x in context.Competitors where x.competitorName == cbCompetitors.SelectedItem.ToString() && x.skillIdFK == getSkillID select x.recordsId).FirstOrDefault(); var findResults = (from x in context.Results where x.recordsIdFK == getCompetitor && x.competitionIdFK == getSession.competitionId select x).FirstOrDefault(); if (findResults != null) { foreach (DataGridViewRow item in dataGridView1.Rows) { if (dataGridView1[0, item.Index].Value.ToString() == "Question 1") { findResults.q1Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } else if (dataGridView1[0, item.Index].Value.ToString() == "Question 2") { findResults.q2Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } else if (dataGridView1[0, item.Index].Value.ToString() == "Question 3") { findResults.q3Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } else { findResults.q4Marks = Convert.ToDouble(dataGridView1[3, item.Index].Value); } findResults.totalMarks = double.Parse(lblTotalMarks.Text); } } else { var newResults = new Result(); newResults.competitionIdFK = getSession.competitionId; newResults.recordsIdFK = getCompetitor; newResults.totalMarks = double.Parse(lblTotalMarks.Text); if (getSession.q2MaxMarks == 0) { newResults.q1Marks = Convert.ToDouble(dataGridView1[3, 0].Value); newResults.q2Marks = 0; newResults.q3Marks = 0; newResults.q4Marks = 0; } else if (getSession.q3MaxMarks == 0) { newResults.q1Marks = Convert.ToDouble(dataGridView1[3, 0].Value); newResults.q2Marks = Convert.ToDouble(dataGridView1[3, 1].Value); newResults.q3Marks = 0; newResults.q4Marks = 0; } else if (getSession.q4MaxMarks == 0) { newResults.q1Marks = Convert.ToDouble(dataGridView1[3, 0].Value); newResults.q2Marks = Convert.ToDouble(dataGridView1[3, 1].Value); newResults.q3Marks = Convert.ToDouble(dataGridView1[3, 2].Value); newResults.q4Marks = 0; } else { newResults.q1Marks = Convert.ToDouble(dataGridView1[3, 0].Value); newResults.q2Marks = Convert.ToDouble(dataGridView1[3, 1].Value); newResults.q3Marks = Convert.ToDouble(dataGridView1[3, 2].Value); newResults.q4Marks = Convert.ToDouble(dataGridView1[3, 3].Value); } context.Results.Add(newResults); } context.SaveChanges(); MessageBox.Show("Results saved!"); btnClear_Click(null, null); } }