//Funcion para llenar todos los datagrids (Usuario,Alimento y Mesa) private void llenarGrids() { //Agregando toda la tabla de usuarios al datagridview conexion search = new conexion(); search.crearConexion(); string search3 = "SELECT *FROM usuario"; MySqlCommand buscarproductos = new MySqlCommand(search3, search.getConexion()); MySqlDataAdapter cmc = new MySqlDataAdapter(buscarproductos); DataSet tht = new DataSet(); cmc.Fill(tht, "usuario"); dataGridView1.DataSource = tht.Tables["usuario"].DefaultView; search.cerrarConexion(); //Agregando toda la tabla de alimentos al datagridview conexion search2 = new conexion(); search2.crearConexion(); string search4 = "SELECT *FROM alimento"; MySqlCommand buscaralimentos = new MySqlCommand(search4, search2.getConexion()); MySqlDataAdapter cmc2 = new MySqlDataAdapter(buscaralimentos); DataSet tht2 = new DataSet(); cmc2.Fill(tht2, "alimento"); dataGridView2.DataSource = tht2.Tables["alimento"].DefaultView; search2.cerrarConexion(); //Agregando toda la tabla de mesas al datagridview conexion search6 = new conexion(); search6.crearConexion(); string search5 = "SELECT *FROM mesa"; MySqlCommand buscarmesas = new MySqlCommand(search5, search6.getConexion()); MySqlDataAdapter cmc3 = new MySqlDataAdapter(buscarmesas); DataSet tht3 = new DataSet(); cmc3.Fill(tht3, "mesa"); dataGridView3.DataSource = tht3.Tables["mesa"].DefaultView; search6.cerrarConexion(); //Agregando toda la tabla de pedidos dependiendo de pedidos try { conexion search7 = new conexion(); search7.crearConexion(); string dia = String.Format("{0:00}", Convert.ToInt32(dateTimePicker1.Value.Day)); string mes = String.Format("{0:00}", Convert.ToInt32(dateTimePicker1.Value.Month)); string anio = String.Format("{0:0000}", Convert.ToInt32(dateTimePicker1.Value.Year)); string comando = "SELECT pedido.idorden, count(*), tablota.nombre, tablota.precio, count(*) * tablota.precio FROM pedido LEFT JOIN (SELECT *FROM alimento AS alimentodia WHERE idalimento IN (SELECT idalimento FROM pedido AS pedidos WHERE idorden IN (SELECT idorden FROM orden AS ordenes WHERE fecha LIKE '" + anio + "-" + mes + "-" + dia + "%'))) AS tablota USING(idalimento) GROUP BY nombre;"; MySqlCommand buscarpedidos = new MySqlCommand(comando, search7.getConexion()); MySqlDataAdapter cmc4 = new MySqlDataAdapter(buscarpedidos); DataSet tht4 = new DataSet(); cmc4.Fill(tht4, "orden"); int rowCount = dataGridView4.Rows.Count; int n; double Suma = 0; for (n = 0; n < rowCount; n++) { if (dataGridView4.Rows[0].IsNewRow == false) { dataGridView4.Rows.RemoveAt(0); } } if (tht4.Tables["orden"].Rows[1][3].ToString() != "") { dataGridView4.DataSource = tht4.Tables["orden"].DefaultView; dataGridView4.Rows.RemoveAt(0); dataGridView4.Columns[0].HeaderText = "Orden"; dataGridView4.Columns[0].Width = 100; dataGridView4.Columns[1].HeaderText = "Cantidad"; dataGridView4.Columns[1].Width = 100; dataGridView4.Columns[2].HeaderText = "Alimento"; dataGridView4.Columns[2].Width = 200; dataGridView4.Columns[3].HeaderText = "Precio"; dataGridView4.Columns[4].HeaderText = "Importe"; } search7.cerrarConexion(); rowCount = dataGridView4.Rows.Count; for (n = 0; n < rowCount; n++) { Suma += Convert.ToDouble(dataGridView4.Rows[n].Cells[4].Value); } textBox15.Enabled = false; textBox15.Text = Suma.ToString(); } catch (Exception) { int rowCount = dataGridView4.Rows.Count; for (int n = 0; n < rowCount; n++) { if (dataGridView4.Rows[0].IsNewRow == false) { dataGridView4.Rows.RemoveAt(0); } } textBox15.Text = "0"; } }