private bool loadScouter(MySqlConnection connection) { MySqlCommand cmd = connection.CreateCommand(); DataSet ds = new DataSet(); cmd.CommandText = TeamMatchTable.getScouterNameQuery(this.teamMatchID); MySqlDataAdapter adap = new MySqlDataAdapter(cmd); adap.Fill(ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { txtScouter.Text = ds.Tables[0].Rows[0].Field <String>(TeamMatchTable.COL_SCOUT_NAME); return(true); } return(false); }
private bool loadAllianceColorForMatch(MySqlConnection connection) { MySqlCommand cmd = connection.CreateCommand(); DataSet ds = new DataSet(); cmd.CommandText = TeamMatchTable.getRecordQuery(this.teamMatchID); MySqlDataAdapter adap = new MySqlDataAdapter(cmd); adap.Fill(ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { String color = ds.Tables[0].Rows[0].Field <String>(TeamMatchTable.COL_ALLIANCE); int index = this.cmbAllianceColor.FindString(color); if (index >= 0) { this.cmbAllianceColor.SelectedIndex = index; return(true); } } return(false); }
private bool loadTeamMatchID(MySqlConnection connection) { MySqlCommand cmd = connection.CreateCommand(); DataSet ds = new DataSet(); cmd.CommandText = TeamMatchTable.getIdQuery(teamID, matchID); MySqlDataAdapter adap = new MySqlDataAdapter(cmd); adap.Fill(ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { this.teamMatchID = ds.Tables[0].Rows[0].Field <Int32>(TeamMatchTable.COL_ID); return(true); } else { statusMessage = "There is no TeamMatchID"; toolStripStatusLabel1.Text = statusMessage; } return(false); }
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."); } } }