Exemple #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                if (Properties.Settings.Default.CompetitionID < 0)
                {
                    CompetitionSelectForm csForm = new CompetitionSelectForm();
                    csForm.ShowDialog();
                }

                MatchListForm frm = new MatchListForm();
                Application.Run(frm);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Could not create form due to database issues");
                Console.Out.WriteLine(e.StackTrace);
            }
        }
Exemple #2
0
        private void SaveData(bool exit)
        {
            MySqlConnection connection = new MySqlConnection(Utils.getConnectionString());
            MySqlCommand    cmd;
            bool            saved = true, validated = true;

            long[]   teamIDs           = new long[] { -1, -1, -1, -1, -1, -1 };
            string[] alliancePositions = new string[] { "Blue1", "Blue2", "Blue3", "Red1", "Red2", "Red3" };

            connection.Open();

            try
            {
                teamIDs[0] = Utils.getLongIDFromComboSelectedValue(cmbBlue1, lblStatus);
                teamIDs[1] = Utils.getLongIDFromComboSelectedValue(cmbBlue2, lblStatus);
                teamIDs[2] = Utils.getLongIDFromComboSelectedValue(cmbBlue3, lblStatus);
                teamIDs[3] = Utils.getLongIDFromComboSelectedValue(cmbRed1, lblStatus);
                teamIDs[4] = Utils.getLongIDFromComboSelectedValue(cmbRed2, lblStatus);
                teamIDs[5] = Utils.getLongIDFromComboSelectedValue(cmbRed3, lblStatus);
            }
            catch (Exception e)
            {
                validated = false;
                Console.Out.WriteLine(e.Message);
            }

            if (validated)
            {
                try
                {
                    cmd             = connection.CreateCommand();
                    cmd.CommandText = MatchTable.getInsertRecordString();

                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_EVENT_ID, this.compID);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_MATCH_COMP_LEVEL, txtMatchType.Text);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_MATCH_NUMBER, int.Parse(txtMatchNumber.Text));
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_MATCH_STATUS, "");

                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_1, teamIDs[3]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_2, teamIDs[4]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_3, teamIDs[5]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_AUTO_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_TELEOP_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_TOTAL_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_QP, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_FOUL_POINTS, 0);

                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_1, teamIDs[0]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_2, teamIDs[1]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_3, teamIDs[2]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_AUTO_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_TELEOP_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_TOTAL_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_QP, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_FOUL_POINTS, 0);

                    cmd.Parameters.AddWithValue("@" + MatchTable.COLUMN_NAME_MATCH_WINNER, "");
                    cmd.Parameters.AddWithValue("@" + MatchTable.COLUMN_NAME_DRIVE_TEAM_COMMENTS, "");

                    cmd.ExecuteNonQuery();
                    long match_id = cmd.LastInsertedId;
                    //long tablet_id = 0;
                    cmd.Parameters.Clear();

                    cmd.CommandText = TeamMatchTable.INSERT_RECORD;

                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_TEAM_ID, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_MATCH_ID, 0);
                    //cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_EVENT_ID, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_POSITION, "");
                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_ALLIANCE, "");

                    for (int tm = 0; tm < teamIDs.Length; tm++)
                    {
                        cmd.Parameters["@" + TeamMatchTable.COL_TEAM_ID].Value  = teamIDs[tm];
                        cmd.Parameters["@" + TeamMatchTable.COL_MATCH_ID].Value = match_id;
                        //cmd.Parameters["@" + TeamMatchTable.COL_EVENT_ID].Value = this.compID;
                        cmd.Parameters["@" + TeamMatchTable.COL_POSITION].Value = (tm % 3) + 1;
                        cmd.Parameters["@" + TeamMatchTable.COL_ALLIANCE].Value = (tm < 3) ? "Blue" : "Red";

                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception)
                {
                    saved          = false;
                    lblStatus.Text = "Failed to save data, check that database is active, and verify data is entered correctly";
                    //throw;
                }
                finally
                {
                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }

            if (saved)
            {
                if (exit)
                {
                    MatchListForm formObj = (MatchListForm)Application.OpenForms["MatchListForm"];
                    formObj.LoadMatchData();
                    this.Close();
                }
                else
                {
                    txtMatchNumber.Text   = "";
                    txtMatchTime.Text     = "";
                    txtMatchType.Text     = "Qualification";
                    txtMatchLocation.Text = "";
                    cmbBlue1.Text         = "";
                    cmbBlue2.Text         = "";
                    cmbBlue3.Text         = "";
                    cmbRed1.Text          = "";
                    cmbRed2.Text          = "";
                    cmbRed3.Text          = "";
                }
            }
        }
Exemple #3
0
        private void SaveData(bool exit)
        {
            MySqlConnection connection = new MySqlConnection(Utils.getConnectionString());
            MySqlCommand    cmd;
            bool            saved = true, validated = true;
            String          scoutName = "";

            Dictionary <int, Int32> dictIdToCount = new Dictionary <int, Int32>();

            connection.Open();

            if (this.teamMatchID <= 0)
            {
                toolStripStatusLabel1.Text      = "There is no TeamMatchID";
                toolStripStatusLabel1.ForeColor = System.Drawing.Color.Red;
                return;
            }
            else
            {
                toolStripStatusLabel1.Text      = statusMessage;
                toolStripStatusLabel1.ForeColor = System.Drawing.Color.Black;
            }

            try
            {
                foreach (Control k in dictActionTypeControls.Keys)
                {
                    String name;
                    int    id;
                    dictActionTypeControls.TryGetValue(k, out name);
                    dictActionTypes.TryGetValue(name, out id);
                    bool hasData = false;
                    dictUpdatedFieldIDs.TryGetValue(id, out hasData);
                    if (!String.IsNullOrEmpty(k.Text) && !hasData)
                    {
                        dictIdToCount.Add(id, Int32.Parse(k.Text));
                    }
                }

                scoutName = txtScouter.Text;
            }
            catch (Exception e)
            {
                validated = false;
                Console.Out.WriteLine(e.Message);
            }

            if (validated)
            {
                try
                {
                    cmd = connection.CreateCommand();

                    cmd.CommandText = TeamMatchActionTable.getInsertRecordQuery();

                    cmd.Parameters.AddWithValue("@" + TeamMatchActionTable.COL_TEAM_MATCH_ID, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchActionTable.COL_ACTION_TYPE_ID, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchActionTable.COL_QUANTITY, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchActionTable.COL_START_TIME, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchActionTable.COL_END_TIME, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchActionTable.COL_OBJECT_COUNT, 0);

                    foreach (Int32 id in dictIdToCount.Keys)
                    {
                        int count = 0;
                        dictIdToCount.TryGetValue(id, out count);
                        cmd.Parameters["@" + TeamMatchActionTable.COL_TEAM_MATCH_ID].Value  = this.teamMatchID;
                        cmd.Parameters["@" + TeamMatchActionTable.COL_ACTION_TYPE_ID].Value = id;
                        cmd.Parameters["@" + TeamMatchActionTable.COL_QUANTITY].Value       = count;
                        cmd.Parameters["@" + TeamMatchActionTable.COL_START_TIME].Value     = 0;
                        cmd.Parameters["@" + TeamMatchActionTable.COL_END_TIME].Value       = 0;
                        cmd.Parameters["@" + TeamMatchActionTable.COL_OBJECT_COUNT].Value   = 0;

                        cmd.ExecuteNonQuery();
                    }

                    if (!scouterDataFound)
                    {
                        cmd.CommandText = TeamMatchTable.getUpdateScouterQuery(this.teamMatchID, scoutName);
                        int numRowsUpdated = cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception)
                {
                    saved = false;
                }
                finally
                {
                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }

            if (saved)
            {
                if (exit)
                {
                    MatchListForm formObj = (MatchListForm)Application.OpenForms["MatchListForm"];
                    formObj.LoadMatchData();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Save failed, please try again.");
                }
            }
        }