private void btn_guardar_Click(object sender, EventArgs e) { string identifica = ""; string nombre = ""; string apellido = ""; string id_product = ""; string nombre_producto = ""; string precio = ""; string cantidad = ""; double subtotal = 0.0; double iva = 0.0; double total = 0.0; string fecha = "GETDATE()"; int productosComprados = 0; string cedula = Interaction.InputBox("Ingrese Cedular del Cliente para Verificar si se encuentra en la Base de Datos", "Verificacion de Cliente", ""); daoUsuario usuario = new daoUsuario(); daoVenta venta = new daoVenta(); DataTable verificacion_usuario = new DataTable(); verificacion_usuario = usuario.ConsultaVerificacionUsuario(cedula); if (verificacion_usuario.Rows.Count > 0) { identifica = Convert.ToString((verificacion_usuario.Rows[0]["NUMERO_DOCUMENTO"].ToString())); nombre = Convert.ToString((verificacion_usuario.Rows[0]["NOMBRES"].ToString())); apellido = Convert.ToString((verificacion_usuario.Rows[0]["APELLIDOS"].ToString())); subtotal = Convert.ToDouble(txt_subtotal.Text); iva = Convert.ToDouble(txt_iva.Text); total = Convert.ToDouble(txt_total.Text); foreach (DataGridViewRow row in grid_productos.Rows) { id_product = Convert.ToString(row.Cells["CODIGO"].Value); nombre_producto = Convert.ToString(row.Cells["PROD"].Value); precio = Convert.ToString(row.Cells["PRECIO"].Value); cantidad = Convert.ToString(row.Cells["CO"].Value); double sumas_precio = Convert.ToDouble(precio); double sumas_cantidad = Convert.ToDouble(cantidad); double sumas_subtotal = sumas_precio * sumas_cantidad; double suma_iva = sumas_subtotal * 0.16; double suma_total = sumas_subtotal + suma_iva; productosComprados += venta.insertVenta(fecha, identifica, id_product, nombre_producto, precio, cantidad, sumas_subtotal, suma_iva, suma_total, consecutivo); } txt_cantidad.Text = ""; combo_categoria.SelectedIndex = -1; grid_productos.Rows.Clear(); grid_productos.Refresh(); txt_subtotal.Text = ""; txt_iva.Text = ""; txt_total.Text = ""; string mensaje = string.Format("MUCHAS GRACIAS POR SU COMPRA{0} Identificacion : {1}{0}Nombre : {2}{0}Apellido : {3}{0}Productos Comprados : {4} ", Environment.NewLine, identifica, nombre, apellido, productosComprados); MessageBox.Show(mensaje); codigo_venta = venta.ConsultaCodigoVenta(); this.Refresh(); if (codigo_venta.Rows.Count == 0) { txt_codigo_venta.Text = "1"; } else { int codigo_vent = Convert.ToInt32((codigo_venta.Rows[0]["CODIGO_MAYOR"].ToString())); int consecutivo = codigo_vent + 1; txt_codigo_venta.Text = Convert.ToString(consecutivo); } } else { MessageBox.Show("USUARIO NO REGISTRADO POR FAVOR PROCESA A INGRESARLO"); FormularioUsuarios user = new FormularioUsuarios(); user.Show(); } }
private void btn_cargar_Click(object sender, EventArgs e) { string identi = ""; identi = txt_identificacion.Text; daoUsuario usuario = new daoUsuario(); DataTable consultaUsuario = new DataTable(); consultaUsuario = usuario.ConsultaVerificacionUsuario(identi); if (!txt_identificacion.Text.Equals("") && !combo_roles.SelectedIndex.Equals(-1) && !txt_nombre.Text.Equals("") && !txt_apellidos.Text.Equals("")) { if (consultaUsuario.Rows.Count <= 0) { try { // Objetos de conexión y comando System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(@"Data Source=ASUS\ASUS;Initial Catalog=DBcafeteria;Integrated Security=SSPI"); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); // Estableciento propiedades cmd.Connection = conn; cmd.CommandText = "INSERT INTO [dbo].[INFO_USUARIOS] VALUES (@numero, @nombre, @apellido, @direccion,@telefono_ca,@telefono_pe,@rol,@email, @image)"; // Creando los parámetros necesarios cmd.Parameters.Add("@numero", System.Data.SqlDbType.Int); cmd.Parameters.Add("@nombre", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@apellido", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@direccion", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@telefono_ca", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@telefono_pe", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@rol", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@email", System.Data.SqlDbType.NVarChar); cmd.Parameters.Add("@image", System.Data.SqlDbType.Image); // Asignando los valores a los atributos cmd.Parameters["@numero"].Value = int.Parse(txt_identificacion.Text); cmd.Parameters["@nombre"].Value = txt_nombre.Text; cmd.Parameters["@apellido"].Value = txt_apellidos.Text; cmd.Parameters["@direccion"].Value = txt_direccion.Text; cmd.Parameters["@telefono_ca"].Value = txtx_casa.Text; cmd.Parameters["@telefono_pe"].Value = txt_personal.Text; cmd.Parameters["@rol"].Value = combo_roles.SelectedItem.ToString(); cmd.Parameters["@email"].Value = txt_email.Text; // Asignando el valor de la imagen // Stream usado como buffer System.IO.MemoryStream ms = new System.IO.MemoryStream(); // Se guarda la imagen en el buffer caja_imagen.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // Se extraen los bytes del buffer para asignarlos como valor para el // parámetro. cmd.Parameters["@image"].Value = ms.GetBuffer(); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); txt_identificacion.Text = ""; txt_nombre.Text = ""; txt_apellidos.Text = ""; txt_direccion.Text = ""; txtx_casa.Text = ""; txt_personal.Text = ""; combo_roles.SelectedIndex = -1; txt_email.Text = ""; caja_imagen.Image = null; MessageBox.Show("El Usuario Se ingreso Correctamente"); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Ya se encuentra en la base de datos"); } } else { MessageBox.Show("Ingrese los Datos correctamente con (*)"); } }