Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

using System;

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

namespace PROYECTO
{
public partial class Form1 : Form
{
SqlConnection cn = new SqlConnection("data source=DESKTOP-0C9G0LI\\
SQLEXPRESS; initial catalog=biblioteca; integrated security=true");

public DataTable listados_autores()


{ SqlCommand cmd = new SqlCommand("listado_autor", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dat = new SqlDataAdapter(cmd);
DataTable tabla=new DataTable();
dat.Fill(tabla);
return tabla;
}
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
dataGridView1.DataSource = listados_autores();
}

private void button1_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("ingreso_autor", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@COD_AUTOR", SqlDbType.Char).Value = txt_ca.Text;
cmd.Parameters.Add("@AUTOR", SqlDbType.Char).Value = txt_autor.Text;
cn.Open();
cmd.ExecuteNonQuery();
dataGridView1.DataSource = listados_autores();
cn.Close();
}

private void txt_ca_Leave(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("busqueda_autor", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@COD_AUTOR", SqlDbType.Char).Value = txt_ca.Text;
SqlDataAdapter dat = new SqlDataAdapter(cmd);
DataTable tabla = new DataTable();
dat.Fill(tabla);
if (tabla.Rows.Count > 0)
{
MessageBox.Show("El codigo del autor ya existe", "aviso");
txt_ca.Clear();
txt_ca.Focus();
}
else { txt_autor.Focus(); }
}

private void button2_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("busqueda_autor", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@COD_AUTOR", SqlDbType.Char).Value = txt_b.Text;
SqlDataAdapter dat = new SqlDataAdapter(cmd);
DataTable tabla = new DataTable();
dat.Fill(tabla);
if (tabla.Rows.Count > 0)
{
DataRow fila = tabla.Rows[0];
txt_ca.Text = fila[0].ToString();
txt_autor.Text = fila[1].ToString();

}
else { MessageBox.Show("El codigo del autor no existe", "aviso"); }
}

private void button3_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("actualiza_autor", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@COD_AUTOR", SqlDbType.Char).Value = txt_ca.Text;
cmd.Parameters.Add("@AUTOR", SqlDbType.Char).Value = txt_autor.Text;
cn.Open();
cmd.ExecuteNonQuery();
dataGridView1.DataSource = listados_autores();
cn.Close();

private void groupBox1_Enter(object sender, EventArgs e)


{

}
}
}

You might also like