Menu

#3 Registro de Insumos

1.0
open
None
2013-10-26
2013-10-26
No

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Sistema_de_Almacen
{
public partial class FrmRegInsumo : Form
{
public FrmRegInsumo()
{
InitializeComponent();
}

    SqlConnection cn = new SqlConnection("DATA SOURCE=FAMILIA; Initial Catalog=BDSisAlmacen; Integrated Security=SSPI");

    private void FrmRegInsumo_Load(object sender, EventArgs e)
    {
        CargarDatos();
    }

    private void CargarDatos()
    {
        SqlDataAdapter da = new SqlDataAdapter("Select * from Insumos", cn);
        DataSet ds = new DataSet();

        da.Fill(ds, "Insumos");
        DataView dv = new DataView(ds.Tables["Insumos"]);
        dataGridView1.DataSource = dv;
    }

    private void BtnGrabar_Click(object sender, EventArgs e)
    {
        String nombre = txtNombre.Text;
        String cat = txtCant.Text;
        String marca = txtMarca.Text;
        int cant = Convert.ToInt16(txtCant.Text);
        String doc = txtDoc.Text;

        SqlCommand cmd = new SqlCommand("sp_Insertar_Insumos");
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = cn;

        SqlParameter prm1 = new SqlParameter();
        prm1.ParameterName = "@nombre";
        prm1.Value = nombre;
        cmd.Parameters.Add(prm1);

        SqlParameter prm2 = new SqlParameter();
        prm2.ParameterName = "@cat";
        prm2.Value = cat;
        cmd.Parameters.Add(prm2);

        SqlParameter prm3 = new SqlParameter();
        prm3.ParameterName = "@marca";
        prm3.Value = marca;
        cmd.Parameters.Add(prm3);

        SqlParameter prm4 = new SqlParameter();
        prm4.ParameterName = "@cant";
        prm4.Value = cant;
        cmd.Parameters.Add(prm4);

        SqlParameter prm5 = new SqlParameter();
        prm5.ParameterName = "@doc";
        prm5.Value = doc;
        cmd.Parameters.Add(prm5);

        try
        {
            cn.Open();
            cmd.ExecuteNonQuery();


            MessageBox.Show("Se registró Insumo correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

            Limpiar();
            CargarDatos();
        }
        catch (Exception err)
        {
            MessageBox.Show("Se ha producido un error al registrar Insumo " + err);
        }
        cn.Close();
    }

    private void Limpiar()
    {
        txtNombre.Text="";
        txtCat.Text="";
        txtMarca.Text="";
        txtCant.Value=0;
        txtDoc.Text= "";
        txtNombre.Focus();
    }

    private void BtnCancelar_Click(object sender, EventArgs e)
    {
        Limpiar();
    }


    private void BtnSalir_Click(object sender, EventArgs e)
    {
        this.Close();
    }
}

}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB