public static Contest GetContest(int contestId) { Contest c = new Contest(); MySqlConnection conn = Database.ConnectToDatabase(); if (conn != null) { MySqlCommand comm = conn.CreateCommand(); string sql = "SELECT * FROM event WHERE id=" + contestId; comm.CommandText = sql; var dr = comm.ExecuteReader(); var dt = new DataTable(); dt.Load(dr); //skapar en Contest foreach (DataRow row in dt.Rows) { c = new Contest(Int32.Parse(row["id"].ToString()), row["name"].ToString(), row["date"].ToString(), row["location"].ToString(), Int32.Parse(row["discipline"].ToString()), Int32.Parse(row["sync"].ToString()), Int32.Parse(row["diveCount"].ToString()), Int32.Parse(row["sex"].ToString()), Int32.Parse(row["started"].ToString())); } //hämtar alla dommare och hoppare som är med i contesten c.AddDivers(Database.GetDiversInEvent(contestId)); c.AddJudges(Database.GetJudgesInEvent(contestId)); //lägger till hopp till alla hoppare foreach (Diver d in c.Divers) { List <DiveType> dType = new List <DiveType>(); List <Dive> dives = new List <Dive>(); List <Dive> divesId = new List <Dive>(); divesId = Database.GetDiversDiveInContest(d.Id, contestId); dType = Database.GetDiversDiveTypeInContest(d.Id, contestId); int count = 0; foreach (DiveType type in dType) { Dive dDive = new Dive(); dDive._diveType = type; dDive._diver = d; dDive.Id = divesId[count].Id; count++; dives.Add(dDive); } d.Dives = dives; } conn.Close(); } return(c); }
public void SetUp() { _judges = new List<Judge>(); _divers = new List<Diver>(); _contest = new Contest(0, "Nunit Test Contest", "2015-02-02", "Badhuset", 1, 1, 1, 5); _judges.Add(new Judge(0, "Mr. Test")); _judges.Add(new Judge(1, "Mrs. Fest")); _judges.Add(new Judge(2, "Konstapel Kuk")); _judges.Add(new Judge(3, "Domherre")); _judges.Add(new Judge(4, "McFlash")); _divers.Add(new Diver(0, "Kalle")); _divers.Add(new Diver(1, "Greger")); _divers.Add(new Diver(2, "Skitunge")); _contest.AddDivers(_divers); _contest.AddJudges(_judges); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { Dive dive = new Dive(0, null, j + 1, _contest); _contest.Divers[i].AddDive(dive); for (int k = 0; k < 5; k++) { Score s = new Score(0, null, _judges[k], (k + j)%11); dive.AddScore(s); } } } }
/// <summary> /// Skapar en Contest med hoppare, hopp och domare /// </summary> /// <param name="textBox1"></param> /// <param name="textBox2"></param> /// <param name="dateTimePicker1"></param> /// <param name="numericUpDown1"></param> /// <param name="radioButton1meter"></param> /// <param name="radioButton3meter"></param> /// <param name="radioButton5meter"></param> /// <param name="radioButton7meter"></param> /// <param name="radioButton10meter"></param> /// <param name="radioButtonSingle"></param> /// <param name="radioButtonSync"></param> /// <param name="radioButtonMale"></param> /// <param name="radioButtonFemale"></param> /// <param name="listViewDivers"></param> /// <param name="listViewJudge"></param> /// <param name="successfully"></param> /// <param name="errorlabel"></param> /// <param name="dataGridViewList"></param> public static void AddNewEventToDatabase(TextBox textBox1, TextBox textBox2, DateTimePicker dateTimePicker1, NumericUpDown numericUpDown1, RadioButton radioButton1meter, RadioButton radioButton3meter, RadioButton radioButton5meter, RadioButton radioButton7meter, RadioButton radioButton10meter, RadioButton radioButtonSingle, RadioButton radioButtonSync, RadioButton radioButtonMale, RadioButton radioButtonFemale, ListView listViewDivers, ListView listViewJudge, Label successfully, Label errorlabel, List <DataGridView> dataGridViewList) { string eventName; string location; string date; int diveCount; int discipline = -1; int sync = -1; int sex = -1; eventName = textBox1.Text; location = textBox2.Text; date = dateTimePicker1.Value.ToString("yyyy-MM-dd"); diveCount = (int)numericUpDown1.Value; //discipline if (radioButton1meter.Checked) { discipline = 0; } else if (radioButton3meter.Checked) { discipline = 1; } else if (radioButton5meter.Checked) { discipline = 2; } else if (radioButton7meter.Checked) { discipline = 3; } else if (radioButton10meter.Checked) { discipline = 4; } //sync: single = 0, sync = 1 if (radioButtonSingle.Checked) { sync = 0; } else if (radioButtonSync.Checked) { sync = 1; } //sex: male = 0, female = 1 if (radioButtonMale.Checked) { sex = 0; } else if (radioButtonFemale.Checked) { sex = 1; } //lägger till eventet i databasen Contest ev = new Contest(eventName, date, location, discipline, sync, diveCount, sex); //hämtar dommare och hoppare från tabellerna List <Judge> addJudgesToEvent = new List <Judge>(); List <Diver> addDiversToEvent = new List <Diver>(); Diver d; Judge j; string gender; int g; foreach (ListViewItem item in listViewDivers.CheckedItems) { gender = item.SubItems[3].Text; if (gender.CompareTo("M") == 0) { g = 0; } else { g = 1; } d = new Diver(Int32.Parse(item.SubItems[4].Text), item.SubItems[0].Text, Int32.Parse(item.SubItems[2].Text), g, item.SubItems[1].Text); addDiversToEvent.Add(d); } ev.AddDivers(addDiversToEvent); foreach (ListViewItem item in listViewJudge.CheckedItems) { j = new Judge(Int32.Parse(item.SubItems[0].Text), item.SubItems[1].Text); addJudgesToEvent.Add(j); } ev.AddJudges(addJudgesToEvent); int code = Database.AddEventToDatabase(ev); //om inmatningen lyckades if (code == 1) { int eventID = Database.GetLatestAddedEventID(); DiveType dType = new DiveType(); int diverID = -1, dNumber, diveTypeID; string dPosition; MySqlConnection conn; using (conn = Database.ConnectToDatabase()) { for (int i = 0; i < dataGridViewList.Count; i++) { //antal rader i en DataGridView for (int rad = 0; rad < dataGridViewList[i].RowCount; rad++) { //diver ID diverID = Int32.Parse(dataGridViewList[i].Tag.ToString()); //DiveNo dNumber = Int32.Parse(dataGridViewList[i].Rows[rad].Cells[1].Value.ToString()); dPosition = dataGridViewList[i].Rows[rad].Cells[0].Value.ToString(); dType.No = dNumber; SetDiveTypeHeight(dType, radioButton1meter, radioButton3meter, radioButton5meter, radioButton7meter, radioButton10meter); SetDiveTypePosition(dType, dPosition); diveTypeID = Database.AddDiveTypeToDatabase(dType, conn); Database.AddDiveToDiver(dType, eventID, rad + 1, diveTypeID, diverID, conn); } } } successfully.Visible = true; } else if (code == -1) { successfully.Visible = false; errorlabel.Text = "Identical event already exist"; errorlabel.Visible = true;; } else { successfully.Visible = false; errorlabel.Text = "An error occoured, try again"; errorlabel.Visible = true; } }
public static Contest GetContest(int contestId) { Contest c = new Contest(); MySqlConnection conn = Database.ConnectToDatabase(); if(conn != null) { MySqlCommand comm = conn.CreateCommand(); string sql = "SELECT * FROM event WHERE id=" + contestId; comm.CommandText = sql; var dr = comm.ExecuteReader(); var dt = new DataTable(); dt.Load(dr); //skapar en Contest foreach (DataRow row in dt.Rows) { c = new Contest(Int32.Parse(row["id"].ToString()), row["name"].ToString(), row["date"].ToString(), row["location"].ToString(), Int32.Parse(row["discipline"].ToString()), Int32.Parse(row["sync"].ToString()), Int32.Parse(row["diveCount"].ToString()), Int32.Parse(row["sex"].ToString()), Int32.Parse(row["started"].ToString())); } //hämtar alla dommare och hoppare som är med i contesten c.AddDivers(Database.GetDiversInEvent(contestId)); c.AddJudges(Database.GetJudgesInEvent(contestId)); //lägger till hopp till alla hoppare foreach(Diver d in c.Divers) { List<DiveType> dType = new List<DiveType>(); List<Dive> dives = new List<Dive>(); List<Dive> divesId = new List<Dive>(); divesId = Database.GetDiversDiveInContest(d.Id, contestId); dType = Database.GetDiversDiveTypeInContest(d.Id, contestId); int count = 0; foreach(DiveType type in dType) { Dive dDive = new Dive(); dDive._diveType = type; dDive._diver = d; dDive.Id = divesId[count].Id; count++; dives.Add(dDive); } d.Dives = dives; } conn.Close(); } return c; }
/// <summary> /// Skapar en Contest med hoppare, hopp och domare /// </summary> /// <param name="textBox1"></param> /// <param name="textBox2"></param> /// <param name="dateTimePicker1"></param> /// <param name="numericUpDown1"></param> /// <param name="radioButton1meter"></param> /// <param name="radioButton3meter"></param> /// <param name="radioButton5meter"></param> /// <param name="radioButton7meter"></param> /// <param name="radioButton10meter"></param> /// <param name="radioButtonSingle"></param> /// <param name="radioButtonSync"></param> /// <param name="radioButtonMale"></param> /// <param name="radioButtonFemale"></param> /// <param name="listViewDivers"></param> /// <param name="listViewJudge"></param> /// <param name="successfully"></param> /// <param name="errorlabel"></param> /// <param name="dataGridViewList"></param> public static void AddNewEventToDatabase(TextBox textBox1, TextBox textBox2, DateTimePicker dateTimePicker1, NumericUpDown numericUpDown1, RadioButton radioButton1meter, RadioButton radioButton3meter, RadioButton radioButton5meter, RadioButton radioButton7meter, RadioButton radioButton10meter, RadioButton radioButtonSingle, RadioButton radioButtonSync, RadioButton radioButtonMale, RadioButton radioButtonFemale, ListView listViewDivers, ListView listViewJudge, Label successfully, Label errorlabel, List<DataGridView> dataGridViewList) { string eventName; string location; string date; int diveCount; int discipline = -1; int sync = -1; int sex = -1; eventName = textBox1.Text; location = textBox2.Text; date = dateTimePicker1.Value.ToString("yyyy-MM-dd"); diveCount = (int)numericUpDown1.Value; //discipline if (radioButton1meter.Checked) discipline = 0; else if (radioButton3meter.Checked) discipline = 1; else if (radioButton5meter.Checked) discipline = 2; else if (radioButton7meter.Checked) discipline = 3; else if (radioButton10meter.Checked) discipline = 4; //sync: single = 0, sync = 1 if (radioButtonSingle.Checked) sync = 0; else if (radioButtonSync.Checked) sync = 1; //sex: male = 0, female = 1 if (radioButtonMale.Checked) sex = 0; else if (radioButtonFemale.Checked) sex = 1; //lägger till eventet i databasen Contest ev = new Contest(eventName, date, location, discipline, sync, diveCount, sex); //hämtar dommare och hoppare från tabellerna List<Judge> addJudgesToEvent = new List<Judge>(); List<Diver> addDiversToEvent = new List<Diver>(); Diver d; Judge j; string gender; int g; foreach (ListViewItem item in listViewDivers.CheckedItems) { gender = item.SubItems[3].Text; if (gender.CompareTo("M") == 0) g = 0; else g = 1; d = new Diver(Int32.Parse(item.SubItems[4].Text), item.SubItems[0].Text, Int32.Parse(item.SubItems[2].Text), g, item.SubItems[1].Text); addDiversToEvent.Add(d); } ev.AddDivers(addDiversToEvent); foreach (ListViewItem item in listViewJudge.CheckedItems) { j = new Judge(Int32.Parse(item.SubItems[0].Text), item.SubItems[1].Text); addJudgesToEvent.Add(j); } ev.AddJudges(addJudgesToEvent); int code = Database.AddEventToDatabase(ev); //om inmatningen lyckades if (code == 1) { int eventID = Database.GetLatestAddedEventID(); DiveType dType = new DiveType(); int diverID = -1, dNumber, diveTypeID; string dPosition; MySqlConnection conn; using (conn = Database.ConnectToDatabase()) { for (int i = 0; i < dataGridViewList.Count; i++) { //antal rader i en DataGridView for (int rad = 0; rad < dataGridViewList[i].RowCount; rad++) { //diver ID diverID = Int32.Parse(dataGridViewList[i].Tag.ToString()); //DiveNo dNumber = Int32.Parse(dataGridViewList[i].Rows[rad].Cells[1].Value.ToString()); dPosition = dataGridViewList[i].Rows[rad].Cells[0].Value.ToString(); dType.No = dNumber; SetDiveTypeHeight(dType, radioButton1meter, radioButton3meter, radioButton5meter, radioButton7meter, radioButton10meter); SetDiveTypePosition(dType, dPosition); diveTypeID = Database.AddDiveTypeToDatabase(dType, conn); Database.AddDiveToDiver(dType, eventID, rad + 1, diveTypeID, diverID, conn); } } } successfully.Visible = true; } else if (code == -1) { successfully.Visible = false; errorlabel.Text = "Identical event already exist"; errorlabel.Visible = true; ; } else { successfully.Visible = false; errorlabel.Text = "An error occoured, try again"; errorlabel.Visible = true; } }