Menu

#4 Registro de Materia Prima

1.0
open
None
2015-02-07
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 frmRegMatPrima : Form
{
public frmRegMatPrima()
{
InitializeComponent();
}

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

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

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

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

    private void BtnGrabar_Click(object sender, EventArgs e)
    {
        String nombre = txtNombre.Text;
        int cant = Convert.ToInt16(txtCant.Text);
        String calidad = txtCalidad.Text;
        String tipo = txtTipo.Text;

        SqlCommand cmd = new SqlCommand("sp_Insertar_MateriaPrima");
        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 = "@cant";
        prm2.Value = cant;
        cmd.Parameters.Add(prm2);

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

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

        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 = "";
        txtCant.Value=0;
        txtCalidad.Text = "";
        txtTipo.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