/// <summary> /// Insertar tiempo jugado a un juego! /// </summary> /// <param name="juego"></param> /// <returns></returns> public Boolean mysqlJuego(tiempoJugado juego) { try { conectar.Open(); MySqlCommand comandom = new MySqlCommand("INSERT INTO tiempoJugado (idUsuario , idJuego , tiempoJugado , fecha ) VALUES (" + '"' + juego.NombreUsuario + '"' + ", " + '"' + juego.NombreJuego + '"' + ", " + '"' + juego.Tiempo + '"' + "," + '"' + juego.Fecha + '"' + ")", conectar); int comando = comandom.ExecuteNonQuery(); if (comando != 0) { //Si s'inserta correctament conectar.Close(); //tanquem conexio a la bbdd return(true); } else { //Si no s'inserta correctament. conectar.Close(); //tanquem conexio a la bbdd return(false); } } catch { conectar.Close(); logs.Save("Error al insertar tiempoJugado!!", 70); return(false); } }
public void CalcularTiempo2() { var instancia = new tiempoJugado(); var segundos = instancia.calcularTiempo2("0", "0", "20"); Assert.AreEqual(segundos, "20"); var segundos2 = instancia.calcularTiempo2("0", "2", "20"); Assert.AreEqual(segundos2, "140"); }
public void CalcularTiempo() { var instancia = new tiempoJugado(); var segundos = instancia.CalcularTiempo(20); Assert.AreEqual(segundos, "0:0:20"); var segundos2 = instancia.CalcularTiempo(140); Assert.AreEqual(segundos2, "0:2:20"); }
// Consultar a la BBDD registres d'hores Jugades. /// <summary> /// Consultar timepoJugado! /// </summary> /// <param name="juego"></param> /// <returns></returns> public int tiempoJugado(tiempoJugado juego) { int temps = 0; try { String[] tot; conectar.Open(); MySqlCommand comandom = new MySqlCommand("Select tiempoJugado from tiempoJugado where idUsuario=" + '"' + juego.NombreUsuario + '"' + " and idJuego = " + '"' + juego.NombreJuego + '"', conectar); MySqlDataReader read = comandom.ExecuteReader(); string h = "", m = "", s = ""; while (read.Read()) { String total = (String.Format("{0}", read[0])); int i = 0; tot = total.Split(':'); foreach (String tota in tot) { Console.WriteLine("{0}:{1}", i, tota); switch (i) { case 0: h = tota; break; case 1: m = tota; break; case 2: s = tota; break; default: Console.WriteLine("Error"); break; } i++; } temps += Int32.Parse(tiempoJugados.calcularTiempo2(h, m, s)); } conectar.Close(); return(temps); } catch { conectar.Close(); logs.Save("Error al consultar tiempoJugado!", 80); return(temps); } }
// Accions al buscar Joc /// <summary> /// Acciones al pulsar el boton de buscar. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { try { buscadortabla.Rows.Clear(); foreach (juego juegos in con.guardarEnTablaBuscar(buscadortxt.Text)) { tiempoJugado tempsJugat = new tiempoJugado(juegos.NombreJuego, usuario.Text); buscadortabla.Rows.Add(new object[] { juegos.NombreJuego, tempsJugat.CalcularTiempo(con.tiempoJugado(tempsJugat)) }); } } catch { logs.Save("Error al cargar datos a dataGridView!", 160); } }
////////////////////////////////////////// /// Carregar Dades ////////////////////////////////////////// //Carregar les hores jugades de cada joc!!! /// <summary> /// Cargar datos a la pantalla. /// </summary> private void labelhoras() { //carregar taula buscadorjoc!!! try { buscadortabla.Rows.Clear(); foreach (juego juegos in con.guardarEnTabla("juegos")) { tiempoJugado tempsJugat = new tiempoJugado(juegos.NombreJuego, usuario.Text); buscadortabla.Rows.Add(new object[] { juegos.NombreJuego, tempsJugat.CalcularTiempo(con.tiempoJugado(tempsJugat)) }); } tiempoJugado JuegoBeta = new tiempoJugado("JuegoBeta", usuario.Text); tiempoJugado jocPDE = new tiempoJugado("joc_pde", usuario.Text); tiempoJugado arquer = new tiempoJugado("arquer", usuario.Text); tiempoJugado wegi = new tiempoJugado("wegi", usuario.Text); int tiempoWegi = con.tiempoJugado(wegi); int tiempoJuegoBeta = con.tiempoJugado(JuegoBeta); int tiempoJuegoPDE = con.tiempoJugado(jocPDE); int tiempoArquer = con.tiempoJugado(arquer); tiempoJugadoJuegoBeta.Text = "Tiempo Jugado: " + tJugat.CalcularTiempo(tiempoJuegoBeta); tiempoJugadoJocPDE.Text = "Tiempo Jugado: " + tJugat.CalcularTiempo(tiempoJuegoPDE); tiempoJugadoArquer.Text = "Tiempo Jugado: " + tJugat.CalcularTiempo(tiempoArquer); tiempoJugadoWegi.Text = "Tiempo Jugado: " + tJugat.CalcularTiempo(tiempoWegi); lblTotalJugado.Text = tJugat.CalcularTiempo(con.tiempoJugadototal(usuario.Text)); lblUser.Text = usuario.Text; txtEmail.Text = con.mysqlEmail(usuario.Text); sexe.Text = con.mysqlSexe(usuario.Text); dateNeixament.Text = con.mysqlFechaNacimiento(usuario.Text); } catch { logs.Save("Error en cargar labels!!", 130); } }
//clase jugar /// <summary> /// Metodo para iniciar juegos i contar el tiempo jugado. /// </summary> /// <param name="game"></param> public void jugar(string game) { try { //Creem un string on indiqui el directori actual on esta colocat el executable.. string path = Directory.GetCurrentDirectory(); int idproc = 0; // Creem el process per iniciar el joc. Process p = new Process(); // Creem la informacio per iniciar el process. ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo(); //Declarem el executable que volem que s'executi. PSI.FileName = game + ".exe"; //Declarem el Directori on es troba el executable. PSI.WorkingDirectory = path + "\\" + game + "\\"; //Amaguem el launcher. this.WindowState = FormWindowState.Minimized; //Declarem al proces que la informacio que te que tractar es la declarada anteriorment. p.StartInfo = PSI; //executem el process. p.Start(); this.Hide(); //Esperem 2 segons per poder donar temps a que el joc s'inici. System.Threading.Thread.Sleep(2000); //Creem un array amb tots el processos que hi hagi actius en aquell moment. Process[] procesos; procesos = Process.GetProcesses(); //Fem recorrem l'array y quant trobem el process que en interesa guardem el seu pid. foreach (Process pro in procesos) { //Console.WriteLine(pro.ProcessName); if (pro.ProcessName == "javaw") { Console.WriteLine(pro.ProcessName + " id :" + pro.Id); //Process p2 = Process.GetProcessById(pro.Id); idproc = pro.Id; } } //Declarem un altre process on li diem que el seu pid es el que anteriorment hem guardat. Process p2 = new Process(); p2 = Process.GetProcessById(idproc); DateTime inici = DateTime.Now; //Creem un while que no surti fins que el joc es tanqui. while (p2.HasExited == false) { //Console.WriteLine(p2.HasExited); } // Agafem la diferencia entre quant s'ha creat el process fins que el joc s'ha tancat amb un timespan. //Pasem el timespan a segons i ho pasem a int per poder pasar-ho a calcularTiempo(). TimeSpan ts = inici - DateTime.Now; tiempoJugado tempsJugat = new tiempoJugado(game, usuario.Text, tJugat.CalcularTiempo((int)ts.TotalSeconds), DateTime.Now); conexion con = new conexion(); // Enviem el objecte tempsJugat per a que s'insereixi a la BBDD con.mysqlJuego(tempsJugat); FormPrincipal form = new FormPrincipal(usuario.Text); form.Show(); } catch { logs.Save("Error en la clase jugar!", 150); } }