/// <summary> /// Esta funcion nos permite introducir una puntuacion en la base de datos /// </summary> /// <param name="puntuacion">Es el tiempo y el nombre del usuario</param> /// <returns>El numero de filas que altera</returns> public int insertarPuntuacion(clsScore puntuacion) { int filasCambiadas = 0; SqlConnection connection; clsMyConnection myConnection; try { SqlCommand command = new SqlCommand(); myConnection = new clsMyConnection(); connection = new SqlConnection(); connection = myConnection.getConnection(); command.CommandText = "INSERT INTO dbo.Scores (nombre,tiempo) VALUES(@nombreJugador,@tiempo)"; command.Parameters.Add("@nombreJugador", System.Data.SqlDbType.VarChar).Value = (string)puntuacion.Nombre; command.Parameters.Add("@tiempo", System.Data.SqlDbType.VarChar).Value = (string)puntuacion.Tiempo; command.Connection = connection; filasCambiadas = command.ExecuteNonQuery(); myConnection.closeConnection(ref connection); } catch (SqlException) { throw; } return(filasCambiadas); }
private static void DumpScores(StreamWriter xsw, int showcount, clsKey mkey, clsMTime.clsBBT bbt, List <clsScore> ret, string inchordstr) { //int ShowCount = 9; if (showcount < 0) { showcount = int.MaxValue; } xsw.WriteLine(""); //delimit bbt entries if (bbt != null) { xsw.WriteLine("BBT: " + bbt.ToString()); } xsw.WriteLine("InChord: " + inchordstr); xsw.WriteLine("Key: " + mkey.KeyStrLong); xsw.WriteLine("MaxType: " + MaxType); xsw.WriteLine("MaxNotes: " + MaxNotes); //* print header xsw.WriteLine(Fmt, "Agg", "Scr", "RKD", "Typ", "Len", "Chr", "TI", "RT", "Name", "Notes"); if (indFlush) { xsw.Flush(); } for (int i = 0; i < showcount && i < ret.Count; i++) { clsScore sc = ret[i]; //foreach (clsScore sc in ret) { xsw.Write(Fmt, sc.Agg, sc.Score, sc.COFRootKeyDistance, //Templates[sc.TIndex].Rank, //Templates[sc.TIndex].Length, FileSeqToTemplate[sc.TIndex].Rank, FileSeqToTemplate[sc.TIndex].Length, sc.ChromaticNotes, sc.TIndex, GetNoteName(sc.Root, mkey), sc.Desc, ""); for (int n = 0; n < 12; n++) { //if (Templates[sc.TIndex].PC[n]) { if (FileSeqToTemplate[sc.TIndex].PC[n]) { xsw.Write(GetNoteName(n + sc.Root, mkey) + " "); } } //if (sc.Dup) xsw.Write("***"); xsw.WriteLine(""); } if (indFlush) { xsw.Flush(); } }
/// <summary> /// Esta funcion se conecta con la capa DAL y nos permite insertar una nueva puntuacion a la base de datos /// </summary> /// <param name="puntuacion">Es el tiempo y el nombre del usuario</param> /// <returns>El numero de columnas modificadas</returns> public int insertarPuntuacionBL(clsScore puntuacion) { int filas = 0; clsManejadoraScores manejadoraScores = new clsManejadoraScores(); filas = manejadoraScores.insertarPuntuacion(puntuacion); return(filas); }
/// <summary> /// Esta funcion obtiene el listado de puntuaciones de la base de datos ordenadas de mejor a peor /// </summary> /// <returns>Un listado con las puntuaciones de mejor a peor</returns> public List <clsScore> obtenerPuntuaciones() { List <clsScore> scores = new List <clsScore>(); SqlConnection connection; clsMyConnection myConnection; try { myConnection = new clsMyConnection(); connection = new SqlConnection(); SqlCommand command = new SqlCommand(); SqlDataReader reader; clsScore puntuacion; connection = myConnection.getConnection(); command.CommandText = "SELECT top 10 * FROM Scores order by tiempo "; command.Connection = connection; reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { puntuacion = new clsScore(); puntuacion.ID = (int)reader["id"]; if (!String.IsNullOrEmpty(reader["nombre"].ToString())) { puntuacion.Nombre = (String)reader["nombre"]; } if (!String.IsNullOrEmpty(reader["tiempo"].ToString())) { puntuacion.Tiempo = (string)reader["tiempo"]; } scores.Add(puntuacion); } } reader.Dispose(); myConnection.closeConnection(ref connection); } catch (SqlException) { throw; } return(scores); }
/// <summary> /// Este procedimiento se encargara de llamar al metodo de la BL para guardar /// el resultado de la partida en la base de datos /// </summary> public void guardarResultado() { clsScore score = new clsScore(_tiempo, _nombreJugador); clsManejadoraScoresBL scoresBL = new clsManejadoraScoresBL(); try { scoresBL.insertarPuntuacionBL(score); } catch (SqlException) { this.mensajeError(); } }
internal static List <clsScore> GetChordsSeg(int[] inpercent, int[] basspercent, clsKeyTicks mkey, clsMTime.clsSegment segment) { //* inpc = segment weights for each pitchclass (0 = not present, 100 = occupies whole segment //* calculate scores //* segment param only used by dumpscores List <clsScore> scores = new List <clsScore>(); bool[] prevpc = new bool[12]; int adder = (int)P.frmCfgChords.nudAdder.Value; //high value favours 3-note chords... int factor = (int)P.frmCfgChords.nudChordFactor.Value; //high value favours notes present for (int t = 0; t < USToTemplate.Count; t++) //each possible chord (template) { if (USToTemplate.Values[t].Rank > MaxType) { continue; } if (USToTemplate.Values[t].Length > MaxNotes) { continue; } if (USToTemplate.Values[t].PC.SequenceEqual(prevpc)) { continue; } for (int r = 0; r < 12; r++) //for each root { int score = 0; for (int p = 0; p < 12; p++) //each pitchclass { int pp = p - r; if (pp < 0) { pp += 12; } //* calc score for this t/r/p //* range: -50 to 50 //if (Templates[t].PC[pp]) score += factor * inpc[p] - adder; else score += adder - inpc[p]; if (USToTemplate.Values[t].PC[pp]) { score += (factor * inpercent[p]) / 10 - adder; } else { score += adder - inpercent[p]; } } //* calc template pc relative to current key bool[] temppc = new bool[12]; for (int i = 0; i < 12; i++) { if (USToTemplate.Values[t].PC[i]) { int tempi = (i + r - mkey.KeyNote).Mod12(); temppc[tempi] = true; } } clsScore newscore = new clsScore(score, t, r, mkey, temppc, basspercent); scores.Add(newscore); } prevpc = USToTemplate.Values[t].PC; } if (scores.Count == 0) { return(new List <clsScore>()); } scores.Sort(new SimpleScoreComparer()); //simple sort (score only) scores.Reverse(); //highest score first #if (DEBUG && DumpTopScores) clsMTime.clsBBT bbt = new clsMTime.clsBBT(segment.SegQILo * P.F.TicksPerQI); DumpScores(XSWDump, -1, mkey, bbt, scores, ""); #endif //* create list of top scores, sorted by other criteria List <clsScore> topscores = new List <clsScore>(9); topscores.Add(scores[0]); //top score for (int i = 1; i < scores.Count; i++) //start at second element { if (scores[i].Score <= scores[0].Score - (int)P.frmCfgChords.nudScoreRange.Value) { break; } topscores.Add(scores[i]); } //topscores.Sort(new SecondaryScoreComparer()); //secondary fields, then score topscores.Sort(new AggScoreComparer()); //aggregate score topscores.Reverse(); if (P.frmCfgChords.chkRemoveDups.Checked) { topscores = RemoveDups(topscores); } #if (DEBUG && DumpTopScores) DumpScores(XSWDumpTop, -1, mkey, bbt, topscores, ""); #endif return(topscores); }