//DEFINICIÓN DEL MÉTODO INSERTAR DETALLEFACT
        public int insertarDetalleFact(DetalleFact D)
        {
            try
            {
                SqlConnection cnx = cn.conectar();

                cm = new SqlCommand("DetalleFactura", cnx);
                cm.Parameters.AddWithValue("@b", 1);
                cm.Parameters.AddWithValue("@Descripcion", D.Descripcion);
                cm.Parameters.AddWithValue("@CantidadV", D.CantidadV);
                cm.Parameters.AddWithValue("@Precio", D.Precio);
                cm.Parameters.AddWithValue("@idFactura", D.idFactura);
                cm.Parameters.AddWithValue("@idProducto", D.idProducto);


                cm.CommandType = CommandType.StoredProcedure;
                cnx.Open();
                cm.ExecuteNonQuery();
                indicador = 1;
            }
            catch (Exception e)
            {
                e.Message.ToString();
                indicador = 0;
            }
            finally
            {
                cm.Connection.Close();
            }
            return(indicador);
        }
        //DEFINICIÓN DEL MÉTODO LISTAR DETALLEFACT
        public List <DetalleFact> listarDetalleFact()
        {
            try
            {
                SqlConnection cnx = cn.conectar();

                cm = new SqlCommand("DetalleFactura", cnx);
                cm.Parameters.AddWithValue("@b", 3);
                cm.Parameters.AddWithValue("@Descripcion", "");
                cm.Parameters.AddWithValue("@CantidadV", "");
                cm.Parameters.AddWithValue("@Precio", "");
                cm.Parameters.AddWithValue("@idFactura", "");
                cm.Parameters.AddWithValue("@idProducto", "");

                cm.CommandType = CommandType.StoredProcedure;
                cnx.Open();
                dr = cm.ExecuteReader();
                listaDetalleFact = new List <DetalleFact>();

                while (dr.Read())
                {
                    DetalleFact df = new DetalleFact();
                    df.Descripcion = dr["Descripcion"].ToString();
                    df.CantidadV   = dr["CantidadV"].ToString();
                    df.Precio      = dr["Precio"].ToString();
                    df.idFactura   = Convert.ToInt32(dr["idFactura"].ToString());
                    df.idProducto  = Convert.ToInt32(dr["idProducto"].ToString());
                    listaDetalleFact.Add(df);
                }
            }
            catch (Exception e)
            {
                e.Message.ToString();
                listaDetalleFact = null;
            }
            finally
            {
                cm.Connection.Close();
            }
            return(listaDetalleFact);
        }
        private void buttonGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (buttonGuardar.Text == "Guardar")
                {
                    DetalleFact objetoDetalleF = new DetalleFact();
                    //objetoRecurso.idrecursos = Convert.ToInt32(textBoxId.Text);
                    objetoDetalleF.Descripcion = textBoxDescripcion.Text;
                    objetoDetalleF.CantidadV   = textBoxCantidadV.Text;
                    objetoDetalleF.Precio      = textBoxPrecio.Text;
                    objetoDetalleF.idFactura   = Convert.ToInt32(textBoxIdFactura.Text);
                    objetoDetalleF.idProducto  = Convert.ToInt32(textBoxIdProducto.Text);

                    if (logicaNR.insertarDetalleFact(objetoDetalleF) > 0)
                    {
                        MessageBox.Show("Agregado con éxito");
                        dataGridViewDetalleFact.DataSource = logicaNR.listarDetalleFact();
                        //textBoxId.Text = "";
                        textBoxDescripcion.Text           = "";
                        textBoxCantidadV.Text             = "";
                        textBoxPrecio.Text                = "";
                        textBoxIdFactura.Text             = "";
                        textBoxIdProducto.Text            = "";
                        tabControlDetalleFact.SelectedTab = tabPage2;     //Consultar
                    }
                    else
                    {
                        MessageBox.Show("Error al agregar Clientes");
                    }
                }
                if (buttonGuardar.Text == "Actualizar")
                {
                    DetalleFact objetoDetalleFact = new DetalleFact();
                    //objetoRecurso.idrecursos = Convert.ToInt32(textBoxId.Text);
                    objetoDetalleFact.Descripcion = textBoxDescripcion.Text;
                    objetoDetalleFact.CantidadV   = textBoxCantidadV.Text;
                    objetoDetalleFact.Precio      = textBoxPrecio.Text;
                    objetoDetalleFact.idFactura   = Convert.ToInt32(textBoxIdFactura.Text);
                    objetoDetalleFact.idProducto  = Convert.ToInt32(textBoxIdProducto.Text);

                    if (logicaNR.editarDetalleFact(objetoDetalleFact) > 0)
                    {
                        MessageBox.Show("Agregado con éxito");
                        dataGridViewDetalleFact.DataSource = logicaNR.listarDetalleFact();
                        //textBoxId.Text = "";
                        textBoxDescripcion.Text           = "";
                        textBoxCantidadV.Text             = "";
                        textBoxPrecio.Text                = "";
                        textBoxIdFactura.Text             = "";
                        textBoxIdProducto.Text            = "";
                        tabControlDetalleFact.SelectedTab = tabPage2;
                    }
                    else
                    {
                        MessageBox.Show("Error al actualizar Detalle Factura");
                    }
                    buttonGuardar.Text = "Guardar";
                }
            }
            catch
            {
                MessageBox.Show("ERROR");
            }
        }
Example #4
0
 public int editarDetalleFact(DetalleFact D)
 {
     return(ad.editarDetalleFact(D));
 }
Example #5
0
 public int insertarDetalleFact(DetalleFact D)
 {
     return(ad.insertarDetalleFact(D));
 }