Ejemplo n.º 1
0
        private void btnComprar_Click(object sender, EventArgs e)
        {
            int cant_compra=0;
            //Valido los campos numericos
            try
            {
                cant_compra = int.Parse(this.txtCant.Text);
            }
            catch
            {
                MessageBox.Show("Debe ingresar una cantidad a comprar numerica");
                return;
            }

            if (cant_compra > int.Parse(this.lblStock.Text))
            {
                MessageBox.Show("Debe ingresar una cantidad menor o igual al stock disponible");
                return;
            }

            // Creo la venta

            //Abro la conexion
            AccesoDatos.getInstancia().abrirConexion();

            System.Data.SqlClient.SqlCommand comVenta = new System.Data.SqlClient.SqlCommand("LOS_GESTORES.sp_app_creaVenta");

            System.Data.SqlClient.SqlParameter p1V = new System.Data.SqlClient.SqlParameter("@id_publ", this.id_pub);
            comVenta.Parameters.Add(p1V);

            System.Data.SqlClient.SqlParameter p2V = new System.Data.SqlClient.SqlParameter("@id_comprador", this.id_comprador);
            comVenta.Parameters.Add(p2V);

            System.Data.SqlClient.SqlParameter p3V = new System.Data.SqlClient.SqlParameter("@fecha", this.fecha_hoy);
            comVenta.Parameters.Add(p3V);

            System.Data.SqlClient.SqlParameter p4V = new System.Data.SqlClient.SqlParameter("@cant", cant_compra);
            comVenta.Parameters.Add(p4V);

            System.Data.SqlClient.SqlDataReader rolReader = AccesoDatos.getInstancia().ejecutaSP(comVenta);

            //Cierro la conexion
            AccesoDatos.getInstancia().cerrarConexion();

            Comprar_Ofertar.VisVendedor fVend = new VisVendedor();
            fVend.idVendedor = this.id_vendedor;
            fVend.ShowDialog();
            this.Close();
        }