public void CrearBotones() { consultaSQL = " SELECT count(ID_MENU) FROM MENU "; datos = con.EjecutarNSQL(consultaSQL); for (int i = 1; i <= datos; i++) { consultaSQL = null; consultaSQL = " Select ID_MENU from MENU where ID_MENU= " + i; idmenuBase[i] = con.EjecutarNSQL(consultaSQL); } int x = 5, y = 5; for (int i = 1; i <= datos; i++) { Button btn = new Button(); btn.Height = 200; btn.Width = 200; btn.Location = new Point(x, y); //Posicion y = y + 150; //Acomodado de botones if (y > 700) //Si hay 3 botones en la misma linea aumentamos la posicion X para crear otra linea al lado y no salirnos de la pantalla { y = 10; x = x + 150; } btn.Name = "c" + i.ToString(); btn.Text = idmenuBase[i].ToString(); SqlCommand consultaSQL = new SqlCommand("SELECT FOTO FROM MENU WHERE ID_MENU = " + i + ";", con.conexion()); SqlDataAdapter dp = new SqlDataAdapter(consultaSQL); DataSet ds = new DataSet("foto"); byte[] bytes = new byte[0]; dp.Fill(ds, "foto"); DataRow myRiw = ds.Tables["foto"].Rows[0]; bytes = (byte[])myRiw["foto"]; MemoryStream ms = new MemoryStream(bytes); //Para hacer stretch la imagen del boton btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackgroundImage = Image.FromStream(ms); //btn.Image = Image.FromStream(ms); btn.Click += new EventHandler(button_Click); flowLayoutPanel1.Controls.Add(btn); } }
private void btnPedido_Click(object sender, EventArgs e) { consultaSQLL = null; consultaSQLL = "SELECT count(ID_PEDIDO)+1 FROM PEDIDO"; ClaseCompartida.numeroDePedidos = con.EjecutarNSQL(consultaSQLL); // MessageBox.Show(" N se " + ClaseCompartida.numeroDePedidos + " ddd "+ClaseCompartida.idMenu, "Validacion " + ClaseCompartida.clienteid, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); consultaSQLL = null; //consultaSQLL = "INSERT INTO PEDIDO(ID_PEDIDO, DESPACHADO, ID_MENU, ID_CLIENTE) VALUES ("+(ClaseCompartida.numeroDePedidos+1)+ ", 0, "+(ClaseCompartida.numeroDePedidos+1)+", "+ClaseCompartida.clienteid+");"; consultaSQLL += "INSERT INTO PEDIDO(ID_PEDIDO, DESPACHADO, ID_MENU, ID_CLIENTE) VALUES ('"; consultaSQLL += (ClaseCompartida.numeroDePedidos + 1) + "','0"; consultaSQLL += "','"; consultaSQLL += (ClaseCompartida.idMenu) + "','"; consultaSQLL += ClaseCompartida.clienteid + "')"; con.EjecutarSQL(consultaSQLL); if (MessageBox.Show("Se ha añadido el pedido! , Desea seguir comprando?", "Validacion ", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { ClaseCompartida.bandera = true; this.Close(); } else { MessageBox.Show("GRACIAS POR SU COMPRA", "DESPEDIDA", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ClaseCompartida.bandera = false; this.Close(); } }
private void btnGuardar_Click(object sender, EventArgs e) { string mensaje = null; if (ValidarFormulario()) { consultaSQL = "SELECT COUNT(ID_MENU) FROM MENU;"; datos = con.EjecutarNSQL(consultaSQL); if (Agregando) { //Preparar consulta INSERT consultaSQL = null; consultaSQL = "INSERT INTO MENU (ID_MENU, NOM_MENU, DESC_MENU, URL, PRECIO, FOTO) SELECT " + (datos += 1) + ",'" + txtNomMenu.Text + "', '" + txtDescMenu.Text + "', '" + destino + "', " + txtPrecio.Text + ", " + " BulkColumn FROM Openrowset(Bulk '" + destino + "', Single_Blob) as Imagen;"; mensaje = "Registro almacenado conrrectamente"; } else { if (abierto == false) { destino = dgvMenu.Rows[dgvMenu.CurrentRow.Index].Cells["URL"].Value.ToString(); } consultaSQL = null; consultaSQL = "UPDATE MENU SET ID_MENU = " + txtIdMenu.Text + ", NOM_MENU = '" + txtNomMenu.Text + "', DESC_MENU = '" + txtDescMenu.Text + "', URL ='" + destino + "', " + "PRECIO=" + txtPrecio.Text + " , FOTO = BulkColumn FROM Openrowset(Bulk '" + destino + "', Single_Blob) as Imagen WHERE ID_MENU = " + dgvMenu.Rows[dgvMenu.CurrentRow.Index].Cells["ID_MENU"].Value + ";"; mensaje = "Registro actualizado correctamente"; } //Ejecutar consulta resultante if (con.EjecutarSQL(consultaSQL) > 0) { MessageBox.Show(mensaje, "Validacion de formulario", MessageBoxButtons.OK, MessageBoxIcon.Information); } LimpiarObjetos(); mostrarMenu(); HabilitarObjetos(false); Agregando = false; Editando = false; ControlBarra(); HabilitarObjetosMenu(false); } }