private void BusquedaLibros() { if (generoCbx.Text.Length > 0 || nombreTxt.Text.Length > 0) { MySqlDb mySqlDb = new MySqlDb { ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString }; mySqlDb.OpenConnection(); string query = ""; query = String.Format("select l.nombre, l.color, g.nombre from libros l join generos_libros gl on gl.id_libro = l.id_libro join generos g on g.id_genero = gl.id_genero join usuarios u on u.avatar = '{0}' where l.nombre like '%{1}%' and g.nombre like '%{2}%'", Singlenton.Instance.usuarioActual.NombreUsuario, nombreTxt.Text, generoCbx.Text); foreach (var libro in Singlenton.Instance.listfromDb.GetListFromDataTable(mySqlDb.QuerySQL(query))) { LibroControlForm libroControl = new LibroControlForm { Nombre = libro.Nombre, ColorLibro = libro.Color, }; string idLibros = string.Format("Select id_libro from libros where nombre='{0}'", libro.Nombre); string idGenero = string.Format("SELECT id_genero from generos_libros where id_libro='{0}'", mySqlDb.QuerySQL(idLibros).Rows[0][0].ToString()); DataTable data = mySqlDb.QuerySQL(idGenero); foreach (DataRow dataRow in data.Rows) { string nombreGeneros = String.Format("Select nombre from generos where id_genero='{0}'", Convert.ToInt16(dataRow["id_genero"].ToString())); libroControl.Genero = libroControl.Genero + "/" + mySqlDb.QuerySQL(nombreGeneros).Rows[0][0].ToString(); } busquedaPanel.Controls.Add(libroControl); } mySqlDb.CloseConnection(); } }
public void BusquedaInicialLibros() { if (generoCbx.Text.Length == 0 && nombreTxt.Text.Length == 0) { MySqlDb mySqlDb = new MySqlDb { ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString }; mySqlDb.OpenConnection(); string query = String.Format("Select nombre,color from libros where id_usuario=(Select id_usuario from usuarios where avatar='{0}')", Singlenton.Instance.usuarioActual.NombreUsuario); foreach (var libro in Singlenton.Instance.listfromDb.GetListFromDataTable(mySqlDb.QuerySQL(query))) { LibroControlForm libroControl = new LibroControlForm { Nombre = libro.Nombre, ColorLibro = libro.Color, }; string idLibro = string.Format("Select id_libro from libros where nombre='{0}'", libro.Nombre); string idGenero = string.Format("SELECT id_genero from generos_libros where id_libro='{0}'", mySqlDb.QuerySQL(idLibro).Rows[0][0].ToString()); DataTable data = mySqlDb.QuerySQL(idGenero); foreach (DataRow dataRow in data.Rows) { string nombreGeneros = String.Format("Select nombre from generos where id_genero='{0}'", Convert.ToInt16(dataRow["id_genero"].ToString())); libroControl.Genero = libroControl.Genero + "/" + mySqlDb.QuerySQL(nombreGeneros).Rows[0][0].ToString(); } busquedaPanel.Controls.Add(libroControl); } mySqlDb.CloseConnection(); } }
public void CrearLibroDB() { MySqlDb mySqlDb = new MySqlDb { ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString }; mySqlDb.OpenConnection(); bibliotecaTabControl.Controls.Clear(); TabPage biblioteca = new TabPage { Text = "Biblioteca" }; bibliotecaTabControl.Controls.Add(biblioteca); string query = String.Format("Select nombre,color from libros where id_usuario=(Select id_usuario from usuarios where avatar='{0}')", Singlenton.Instance.usuarioActual.NombreUsuario); // Singlenton.Instance.listfromDb.GetListFromDataTable(mySqlDb.QuerySQL(query)); String nombreUsuario = Singlenton.Instance.usuarioActual.NombreUsuario; FlowLayoutPanel contenedorLibros = new FlowLayoutPanel(); // foreach (var libro in Singlenton.Instance.LibrosList) foreach (var libro in Singlenton.Instance.listfromDb.GetListFromDataTable(mySqlDb.QuerySQL(query))) { LibroControlForm libroControl = new LibroControlForm { Nombre = libro.Nombre, ColorLibro = libro.Color, }; string idLibro = string.Format("Select id_libro from libros where nombre='{0}'", libro.Nombre); string idGenero = string.Format("SELECT id_genero from generos_libros where id_libro='{0}'", mySqlDb.QuerySQL(idLibro).Rows[0][0].ToString()); DataTable data = mySqlDb.QuerySQL(idGenero); foreach (DataRow dataRow in data.Rows) { string nombreGeneros = String.Format("Select nombre from generos where id_genero='{0}'", Convert.ToInt16(dataRow["id_genero"].ToString())); libroControl.Genero = libroControl.Genero + "/" + mySqlDb.QuerySQL(nombreGeneros).Rows[0][0].ToString(); } TabPage pestaña = new TabPage(); libroControl.MouseClick += (a, b) => { if (libro.Abrir == false) { libro.Abrir = true; libroControl.Abierto = true; pestaña.Text = libro.Nombre; pestaña.BackColor = Color.FromArgb(libro.Color); pestaña.Select(); pestaña.MouseClick += (s, e) => { int x = e.X; int y = e.Y; FormularioNotaForm formulario = new FormularioNotaForm(); formulario.SetXY(x, y); formulario.NombreLibro = libro.Nombre; formulario.ShowDialog(); string queryNot; queryNot = String.Format("Select privacidad,titulo,fecha_creacion,categoria,color_fondo,posicion_x,posicion_y,color_fuente,width,heigh from notas where(id_libro=(select id_libro from libros where nombre=('{0}')))", libroControl.Nombre); foreach (var nota in Singlenton.Instance.listNotafromDb.GetListFromDataTable(mySqlDb.QuerySQL(queryNot))) { // MessageBox.Show(nota.Titulo); if (nota.Privacidad == false) { NotaControlForm notaControl = CrearNotaControl(nota); pestaña.Controls.Add(notaControl); } else { NotaPrivadaControlForm notaPrivada = CrearNotaPrivada(nota); pestaña.Controls.Add(notaPrivada); } } }; if (libro.Abrir == true) { string queryN = String.Format("Select privacidad,titulo,categoria,fecha_creacion,color_fondo,posicion_x,posicion_y,color_fuente,width,heigh from notas where(id_libro=(select id_libro from libros where nombre=('{0}')))", libroControl.Nombre); foreach (var nota in Singlenton.Instance.listNotafromDb.GetListFromDataTable(mySqlDb.QuerySQL(queryN))) { if (nota.Privacidad == false) { NotaControlForm notaControl = CrearNotaControl(nota); pestaña.Controls.Add(notaControl); } else { NotaPrivadaControlForm notaPrivada = CrearNotaPrivada(nota); pestaña.Controls.Add(notaPrivada); } } } bibliotecaTabControl.Controls.Add(pestaña); bibliotecaTabControl.SelectedTab = pestaña; } }; if (libro.Abrir == true) { TabPage pestañaLibro = new TabPage { Text = libro.Nombre, BackColor = Color.FromArgb(libro.Color) }; pestañaLibro.Select(); pestañaLibro.MouseClick += (s, e) => { int x = e.X; int y = e.Y; FormularioNotaForm formulario = new FormularioNotaForm(); formulario.SetXY(x, y); formulario.NombreLibro = libro.Nombre; formulario.ShowDialog(); foreach (var nota in libro.Notas) { if (nota.Privacidad == false || nota.Usuario == nombreUsuario) { NotaControlForm notaControl = CrearNotaControl(nota); pestañaLibro.Controls.Add(notaControl); } else { NotaPrivadaControlForm notaPrivada = CrearNotaPrivada(nota); pestaña.Controls.Add(notaPrivada); } } }; foreach (var nota in libro.Notas) { if (nota.Privacidad == false || nota.Usuario == nombreUsuario) { NotaControlForm notaControl = CrearNotaControl(nota); pestañaLibro.Controls.Add(notaControl); } else { NotaPrivadaControlForm notaPrivada = CrearNotaPrivada(nota); pestañaLibro.Controls.Add(notaPrivada); } } bibliotecaTabControl.Controls.Add(pestañaLibro); bibliotecaTabControl.SelectedTab = pestañaLibro; } contenedorLibros.Size = new Size(bibliotecaTabControl.Size.Width, bibliotecaTabControl.Size.Height); contenedorLibros.Controls.Add(libroControl); contenedorLibros.AutoScroll = true; biblioteca.Controls.Add(contenedorLibros); } }