Ejemplo n.º 1
0
        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!");
        }
Ejemplo n.º 2
0
 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();
     }
 }