Exemplo n.º 1
0
        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();
        }
Exemplo 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.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();
            }
        }