Exemplo n.º 1
0
        public static void AddDiveToDiver(DiveType d, int eventID, int diveNumber, int diveTypeID, int diverID, MySqlConnection conn = null)
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

            //MySqlConnection conn = Database.ConnectToDatabase();

            if(conn != null)
            {
                try
                {
                    MySqlCommand comm = conn.CreateCommand();
                    comm.CommandText = "INSERT INTO dive(diverId, difficulty, eventId, diveNumber, DiveTypeID) VALUES(@diverId, @difficulty, @eventId, @diveNumber, @DiveTypeID)";
                    comm.Parameters.AddWithValue("@diverId", diverID);
                    comm.Parameters.AddWithValue("@difficulty", d.Difficulty);
                    comm.Parameters.AddWithValue("@eventId", eventID);
                    comm.Parameters.AddWithValue("@diveNumber", diveNumber);
                    comm.Parameters.AddWithValue("@DiveTypeID", diveTypeID);
                    comm.ExecuteNonQuery();
                }
                catch(Exception ex)
                {
                    ExceptionHandler.Handle(ex);
                }

                //conn.Close();
            }
        }
Exemplo n.º 2
0
        public static int AddDiveTypeToDatabase(DiveType d, MySqlConnection conn = null)
        {
            //MySqlConnection conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                string id = "";
                //lägger till i databasen
                MySqlCommand comm = conn.CreateCommand();
                comm.CommandText = "INSERT INTO divetype(Type, Position, Height) VALUES(@type, @position, @height)";
                comm.Parameters.AddWithValue("@type", d._no);
                comm.Parameters.AddWithValue("@position", d.Position.ToString());
                comm.Parameters.AddWithValue("@height", d.GetHeight());
                comm.ExecuteNonQuery();

                MySqlCommand comm2 = conn.CreateCommand();
                comm2.CommandText = "SELECT LAST_INSERT_ID() AS id";
                var dr = comm2.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);
                DataRow row = dt.Rows[0];
                id = row["id"].ToString();

                //conn.Close();
                return(Int32.Parse(id));
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 3
0
        public static List <DiveType> GetDiversDiveTypeInContest(int diverId, int eventId)
        {
            List <DiveType> dives = new List <DiveType>();

            MySqlConnection conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                MySqlCommand comm = conn.CreateCommand();
                string       sql  = "SELECT * FROM divetype WHERE id IN(SELECT DiveTypeID FROM dive WHERE diverId=" + diverId + " AND eventId=" + eventId + ")";
                comm.CommandText = sql;
                var dr = comm.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);

                foreach (DataRow row in dt.Rows)
                {
                    DiveType d = new DiveType();
                    d.No = Int32.Parse(row["Type"].ToString());
                    d.SetPosition(row["Position"].ToString());
                    d.SetHeight(Double.Parse(row["Height"].ToString()));

                    dives.Add(d);
                }
                conn.Close();
            }
            return(dives);
        }
Exemplo n.º 4
0
        public static void AddDiveToDiver(DiveType d, int eventID, int diveNumber, int diveTypeID, int diverID, MySqlConnection conn = null)
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

            //MySqlConnection conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                try
                {
                    MySqlCommand comm = conn.CreateCommand();
                    comm.CommandText = "INSERT INTO dive(diverId, difficulty, eventId, diveNumber, DiveTypeID) VALUES(@diverId, @difficulty, @eventId, @diveNumber, @DiveTypeID)";
                    comm.Parameters.AddWithValue("@diverId", diverID);
                    comm.Parameters.AddWithValue("@difficulty", d.Difficulty);
                    comm.Parameters.AddWithValue("@eventId", eventID);
                    comm.Parameters.AddWithValue("@diveNumber", diveNumber);
                    comm.Parameters.AddWithValue("@DiveTypeID", diveTypeID);
                    comm.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Handle(ex);
                }


                //conn.Close();
            }
        }
Exemplo n.º 5
0
 public Dive()
 {
     this.Id = -1;
     this._diver = null;
     this.Difficulty = 0.0;
     this._contest = null;
     Scores = new List<Score>();
     _diveType = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 6
0
 public Dive(int ID, Diver person, double difficulty, Contest comp)
 {
     this.Id = ID;
     this._diver = person;
     this.Difficulty = difficulty;
     this._contest = comp;
     Scores = new List<Score>();
     _diveType = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 7
0
        public Dive(int ID, Diver person, Contest comp, DiveType diveType)
        {
            this.Id = ID;
            this._diver = person;
            this._contest = comp;
            _diveType = diveType;

            Scores = new List<Score>();
        }
Exemplo n.º 8
0
 public Dive()
 {
     this.Id         = -1;
     this._diver     = null;
     this.Difficulty = 0.0;
     this._contest   = null;
     Scores          = new List <Score>();
     _diveType       = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 9
0
 public Dive(int ID, Diver person, double difficulty, Contest comp)
 {
     this.Id         = ID;
     this._diver     = person;
     this.Difficulty = difficulty;
     this._contest   = comp;
     Scores          = new List <Score>();
     _diveType       = new DiveType(1, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
 }
Exemplo n.º 10
0
        public Dive(int ID, Diver person, Contest comp, DiveType diveType)
        {
            this.Id       = ID;
            this._diver   = person;
            this._contest = comp;
            _diveType     = diveType;

            Scores = new List <Score>();
        }
Exemplo n.º 11
0
 public static double Difficulty(DiveType diveType)
 {
     foreach (DiveType dt in _diveTypes)
     {
         if (dt.Height == diveType.Height &&
             dt.No == diveType.No &&
             dt.Position == diveType.Position)
         {
             return(dt.Difficulty);
         }
     }
     return(0);
 }
Exemplo n.º 12
0
 public static double Difficulty(DiveType diveType)
 {
     foreach (DiveType dt in _diveTypes)
     {
         if (dt.Height == diveType.Height &&
             dt.No == diveType.No &&
             dt.Position == diveType.Position)
     {
             return dt.Difficulty;
         }
     }
     return 0;
 }
Exemplo n.º 13
0
        public static void LoadDDTable()
        {
            if (_diveTypes != null)
            {
                return;
            }

            _diveTypes = new List <DiveType>();

            DataTable dt = Database.GetDDList();

            if (dt == null)
            {
                throw new Exception("Kunde ej ladda DD DataTable");
            }

            foreach (DataRow row in dt.Rows)
            {
                foreach (DiveType.DiveHeight diveHeight in Enum.GetValues(typeof(DiveType.DiveHeight)))
                {
                    foreach (DiveType.DivePosition divePosition in Enum.GetValues(typeof(DiveType.DivePosition)))
                    {
                        String colName = "A" + DiveType.GetDescription(diveHeight) + DiveType.GetDescription(divePosition);

                        double difficutly = Double.Parse(row[colName].ToString());

                        if (difficutly.Equals(0))
                        {
                            continue;
                        }

                        DiveType diveType = new DiveType(
                            Int32.Parse(row["DiveNo"].ToString()),
                            row["DiveName"].ToString(),
                            divePosition,
                            diveHeight,
                            difficutly
                            );
                        _diveTypes.Add(diveType);
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Sätter position till en DiveType
        /// </summary>
        /// <param name="d"></param>
        /// <param name="position"></param>
        private static void SetDiveTypePosition(DiveType d, string position)
        {
            if (position.CompareTo("A") == 0)
            {
                d.Position = DiveType.DivePosition.A;
            }

            else if (position.CompareTo("B") == 0)
            {
                d.Position = DiveType.DivePosition.B;
            }

            else if (position.CompareTo("C") == 0)
            {
                d.Position = DiveType.DivePosition.C;
            }

            else if (position.CompareTo("D") == 0)
            {
                d.Position = DiveType.DivePosition.D;
            }
        }
Exemplo n.º 15
0
        public static void LoadDDTable()
        {
            if (_diveTypes != null)
                return;

            _diveTypes = new List<DiveType>();

            DataTable dt = Database.GetDDList();

            if (dt == null)
            {
                throw new Exception("Kunde ej ladda DD DataTable");
            }

            foreach (DataRow row in dt.Rows)
            {
                foreach (DiveType.DiveHeight diveHeight in Enum.GetValues(typeof (DiveType.DiveHeight)))
                {
                    foreach (DiveType.DivePosition divePosition in Enum.GetValues(typeof (DiveType.DivePosition)))
                    {
                        String colName = "A" + DiveType.GetDescription(diveHeight) + DiveType.GetDescription(divePosition);

                        double difficutly = Double.Parse(row[colName].ToString());

                        if (difficutly.Equals(0))
                            continue;

                        DiveType diveType = new DiveType(
                                Int32.Parse(row["DiveNo"].ToString()),
                                row["DiveName"].ToString(),
                                divePosition,
                                diveHeight,
                                difficutly
                            );
                        _diveTypes.Add(diveType);
                    }
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Sätter höjd till en DiveType
 /// </summary>
 /// <param name="d"></param>
 /// <param name="radioButton1meter"></param>
 /// <param name="radioButton3meter"></param>
 /// <param name="radioButton5meter"></param>
 /// <param name="radioButton7meter"></param>
 /// <param name="radioButton10meter"></param>
 private static void SetDiveTypeHeight(DiveType d, RadioButton radioButton1meter, RadioButton radioButton3meter, RadioButton radioButton5meter, RadioButton radioButton7meter, RadioButton radioButton10meter)
 {
     if (radioButton1meter.Checked)
     {
         d.Height = DiveType.DiveHeight._1M;
     }
     if (radioButton3meter.Checked)
     {
         d.Height = DiveType.DiveHeight._3M;
     }
     if (radioButton5meter.Checked)
     {
         d.Height = DiveType.DiveHeight._5M;
     }
     if (radioButton7meter.Checked)
     {
         d.Height = DiveType.DiveHeight._7_5M;
     }
     if (radioButton10meter.Checked)
     {
         d.Height = DiveType.DiveHeight._10M;
     }
 }
Exemplo n.º 17
0
        public static void _AddDiveToDiver(DiveType d, int eventID, int diveNumber, int diveTypeID, int diverID, MySqlConnection conn = null)
        {
            Thread t = new Thread(() => AddDiveToDiver(d, eventID, diveNumber, diveTypeID, diverID, conn));

            t.Start();
        }
Exemplo n.º 18
0
        /// <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;
            }
        }
Exemplo n.º 19
0
 public void TestDD()
 {
     DiveType.LoadDDTable();
     DiveType diveType = new DiveType(103, DiveType.DivePosition.A, DiveType.DiveHeight._1M);
     Assert.AreEqual(diveType.Difficulty, 2.0);
     System.Diagnostics.Debug.WriteLine("Name: " + diveType.Name);
 }
Exemplo n.º 20
0
        /// <summary>
        /// När positionen har ändrats i hoppet laddas AutoComplete listan om
        /// </summary>
        /// <param name="_dataGridViewList"></param>
        /// <param name="tabControl1"></param>
        /// <param name="_diveNo"></param>
        /// <param name="_diveNoReadOnly"></param>
        /// <param name="_diveName"></param>
        /// <param name="_diveNameReadOnly"></param>
        /// <param name="groupBox"></param>
        public static void UpdateAutoCompleteList(DataGridView currentDataGridView, TabControl tabControl1, AutoCompleteStringCollection _diveNo, AutoCompleteStringCollection _diveNoReadOnly, AutoCompleteStringCollection _diveName, AutoCompleteStringCollection _diveNameReadOnly, GroupBox groupBox)
        {
            //int columnIndex = currentDataGridView.CurrentCell.ColumnIndex;
            //string headerText = currentDataGridView.Columns[columnIndex].HeaderText;
            int rad = currentDataGridView.CurrentCell.RowIndex;

            string position = currentDataGridView.Rows[rad].Cells[0].Value.ToString();
            string height = "";

            _diveName.Clear();
            _diveNo.Clear();

            DiveType.DiveHeight diveHeight = DiveType.DiveHeight._1M;

            //hämtar den valda höjden
            foreach (Control button in groupBox.Controls)
            {
                RadioButton b = button as RadioButton;
                if (b.Checked)
                    height = b.Text.ToString();
            }

            switch (height)
            {
                case "1 m":
                    diveHeight = DiveType.DiveHeight._1M;
                    break;
                case "3 m":
                    diveHeight = DiveType.DiveHeight._3M;
                    break;
                case "5 m":
                    diveHeight = DiveType.DiveHeight._5M;
                    break;
                case "7,5 m":
                    diveHeight = DiveType.DiveHeight._7_5M;
                    break;
                case "10 m":
                    diveHeight = DiveType.DiveHeight._10M;
                    break;
            }

            DiveType diveType = new DiveType();
            diveType.Height = diveHeight;
            SetDiveTypePosition(diveType, position);

            foreach (string s in _diveNoReadOnly)
            {
                diveType.No = Int32.Parse(s);
                if (diveType.Difficulty != 0)
                    _diveNo.Add(s);
            }

            //diveType = new DiveType();
            //diveType.Height = diveHeight;
            //SetDiveTypePosition(diveType, position);

            foreach (string s in _diveNameReadOnly)
            {
                diveType.Name = s;
                diveType.SetNo();
                if (diveType.Difficulty != 0)
                    _diveName.Add(s);
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Sätter höjd till en DiveType
 /// </summary>
 /// <param name="d"></param>
 /// <param name="radioButton1meter"></param>
 /// <param name="radioButton3meter"></param>
 /// <param name="radioButton5meter"></param>
 /// <param name="radioButton7meter"></param>
 /// <param name="radioButton10meter"></param>
 private static void SetDiveTypeHeight(DiveType d, RadioButton radioButton1meter, RadioButton radioButton3meter, RadioButton radioButton5meter, RadioButton radioButton7meter, RadioButton radioButton10meter)
 {
     if (radioButton1meter.Checked)
         d.Height = DiveType.DiveHeight._1M;
     if (radioButton3meter.Checked)
         d.Height = DiveType.DiveHeight._3M;
     if (radioButton5meter.Checked)
         d.Height = DiveType.DiveHeight._5M;
     if (radioButton7meter.Checked)
         d.Height = DiveType.DiveHeight._7_5M;
     if (radioButton10meter.Checked)
         d.Height = DiveType.DiveHeight._10M;
 }
Exemplo n.º 22
0
 public Dive(int diveNumber, DiveType.DiveHeight diveHeight, DiveType.DivePosition divePosition)
 {
     _diveType = new DiveType(diveNumber, divePosition, diveHeight);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Sätter position till en DiveType
        /// </summary>
        /// <param name="d"></param>
        /// <param name="position"></param>
        private static void SetDiveTypePosition(DiveType d, string position)
        {
            if (position.CompareTo("A") == 0)
                d.Position = DiveType.DivePosition.A;

            else if(position.CompareTo("B") == 0)
                d.Position = DiveType.DivePosition.B;

            else if (position.CompareTo("C") == 0)
                d.Position = DiveType.DivePosition.C;

            else if (position.CompareTo("D") == 0)
                d.Position = DiveType.DivePosition.D;
        }
Exemplo n.º 24
0
        public static List<DiveType> GetDiversDiveTypeInContest(int diverId, int eventId)
        {
            List<DiveType> dives = new List<DiveType>();

            MySqlConnection conn = Database.ConnectToDatabase();
            if(conn != null)
            {
                MySqlCommand comm = conn.CreateCommand();
                string sql = "SELECT * FROM divetype WHERE id IN(SELECT DiveTypeID FROM dive WHERE diverId=" + diverId + " AND eventId=" + eventId + ")";
                comm.CommandText = sql;
                var dr = comm.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);

                foreach (DataRow row in dt.Rows)
                {
                    DiveType d = new DiveType();
                    d.No = Int32.Parse(row["Type"].ToString());
                    d.SetPosition(row["Position"].ToString());
                    d.SetHeight(Double.Parse(row["Height"].ToString()));

                    dives.Add(d);
                }
                conn.Close();
            }
            return dives;
        }
Exemplo n.º 25
0
 public static void _AddDiveToDiver(DiveType d, int eventID, int diveNumber, int diveTypeID, int diverID, MySqlConnection conn = null)
 {
     Thread t = new Thread(() => AddDiveToDiver(d, eventID, diveNumber, diveTypeID, diverID, conn));
     t.Start();
 }
Exemplo n.º 26
0
        public static int AddDiveTypeToDatabase(DiveType d, MySqlConnection conn = null)
        {
            //MySqlConnection conn = Database.ConnectToDatabase();

            if (conn != null)
            {
                string id = "";
                //lägger till i databasen
                MySqlCommand comm = conn.CreateCommand();
                comm.CommandText = "INSERT INTO divetype(Type, Position, Height) VALUES(@type, @position, @height)";
                comm.Parameters.AddWithValue("@type", d._no);
                comm.Parameters.AddWithValue("@position", d.Position.ToString());
                comm.Parameters.AddWithValue("@height", d.GetHeight());
                comm.ExecuteNonQuery();

                MySqlCommand comm2 = conn.CreateCommand();
                comm2.CommandText = "SELECT LAST_INSERT_ID() AS id";
                var dr = comm2.ExecuteReader();
                var dt = new DataTable();
                dt.Load(dr);
                DataRow row = dt.Rows[0];
                id = row["id"].ToString();

                //conn.Close();
                return Int32.Parse(id);
            }
            else
                return -1;
        }
Exemplo n.º 27
0
        /// <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;
            }
        }
Exemplo n.º 28
0
 public Dive(int diveNumber, DiveType.DiveHeight diveHeight, DiveType.DivePosition divePosition)
 {
     _diveType = new DiveType(diveNumber, divePosition, diveHeight);
 }
Exemplo n.º 29
0
        /// <summary>
        /// När positionen har ändrats i hoppet laddas AutoComplete listan om
        /// </summary>
        /// <param name="_dataGridViewList"></param>
        /// <param name="tabControl1"></param>
        /// <param name="_diveNo"></param>
        /// <param name="_diveNoReadOnly"></param>
        /// <param name="_diveName"></param>
        /// <param name="_diveNameReadOnly"></param>
        /// <param name="groupBox"></param>

        public static void UpdateAutoCompleteList(DataGridView currentDataGridView, TabControl tabControl1, AutoCompleteStringCollection _diveNo, AutoCompleteStringCollection _diveNoReadOnly, AutoCompleteStringCollection _diveName, AutoCompleteStringCollection _diveNameReadOnly, GroupBox groupBox)
        {
            //int columnIndex = currentDataGridView.CurrentCell.ColumnIndex;
            //string headerText = currentDataGridView.Columns[columnIndex].HeaderText;
            int rad = currentDataGridView.CurrentCell.RowIndex;

            string position = currentDataGridView.Rows[rad].Cells[0].Value.ToString();
            string height   = "";

            _diveName.Clear();
            _diveNo.Clear();

            DiveType.DiveHeight diveHeight = DiveType.DiveHeight._1M;

            //hämtar den valda höjden
            foreach (Control button in groupBox.Controls)
            {
                RadioButton b = button as RadioButton;
                if (b.Checked)
                {
                    height = b.Text.ToString();
                }
            }

            switch (height)
            {
            case "1 m":
                diveHeight = DiveType.DiveHeight._1M;
                break;

            case "3 m":
                diveHeight = DiveType.DiveHeight._3M;
                break;

            case "5 m":
                diveHeight = DiveType.DiveHeight._5M;
                break;

            case "7,5 m":
                diveHeight = DiveType.DiveHeight._7_5M;
                break;

            case "10 m":
                diveHeight = DiveType.DiveHeight._10M;
                break;
            }

            DiveType diveType = new DiveType();

            diveType.Height = diveHeight;
            SetDiveTypePosition(diveType, position);

            foreach (string s in _diveNoReadOnly)
            {
                diveType.No = Int32.Parse(s);
                if (diveType.Difficulty != 0)
                {
                    _diveNo.Add(s);
                }
            }

            //diveType = new DiveType();
            //diveType.Height = diveHeight;
            //SetDiveTypePosition(diveType, position);

            foreach (string s in _diveNameReadOnly)
            {
                diveType.Name = s;
                diveType.SetNo();
                if (diveType.Difficulty != 0)
                {
                    _diveName.Add(s);
                }
            }
        }
Exemplo n.º 30
0
        //kollar så att ett giltigt värde finns i DataGridViewCellen
        private void DataGridViewDives_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView currentDataGridView = new DataGridView();

            foreach (DataGridView gridView in _dataGridViewList)
            {
                if (sender.Equals(gridView))
                {
                    currentDataGridView = gridView;
                }
            }

            switch (e.ColumnIndex)
            {
            case 1:
                if (_jumpBackToCell.X == e.RowIndex && _jumpBackToCell.Y == e.ColumnIndex)
                {
                    //om det angivna värdet inte finns med i AutoComplete listan
                    if (currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                    {
                        if (!_diveNo.Contains(currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) && currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Length > 0)
                        {
                            MessageBox.Show(currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() + ": är ej ett giltigt värde!");
                            DataGridViewCellIndex_Back = true;
                            _jumpBackToCell.X          = e.RowIndex;
                            _jumpBackToCell.Y          = e.ColumnIndex;
                        }
                        //om det var ett giltigt värde ska DiveName cellen autocompletas
                        else
                        {
                            if (currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Length > 0)
                            {
                                DiveType dType = new DiveType(Int32.Parse(currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()));
                                string   name  = dType.Name;
                                currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = name;
                                DataGridViewCellIndex_Back = false;
                                _jumpBackToCell.X          = -1;
                                _jumpBackToCell.Y          = -1;
                            }
                        }
                    }
                }
                break;

            case 2:
                if (_jumpBackToCell.X == e.RowIndex && _jumpBackToCell.Y == e.ColumnIndex)
                {
                    //om det angivna värdet inte finns med i AutoComplete listan
                    if (currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                    {
                        if (!_diveName.Contains(currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) && currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Length > 0)
                        {
                            MessageBox.Show(currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() + ": är ej ett giltigt värde!");
                            DataGridViewCellIndex_Back = true;
                            _jumpBackToCell.X          = e.RowIndex;
                            _jumpBackToCell.Y          = e.ColumnIndex;
                        }
                        else
                        {
                            if (currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Length > 0)
                            {
                                DiveType dType = new DiveType();
                                dType.Name = currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                                string diveId = dType.No.ToString();
                                currentDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value = diveId;
                                DataGridViewCellIndex_Back = false;
                                _jumpBackToCell.X          = -1;
                                _jumpBackToCell.Y          = -1;
                            }
                        }
                    }
                }
                break;
            }
        }