Sei sulla pagina 1di 8

EN SQL SERVER

create database PEDIDOS;

use PEDIDOS;

create table articulos(


num_art varchar(5) primary key not null,
nom_art varchar(35),
precio float,
stock int);

create table clientes(


id_cliente varchar(5) primary key not null,
nom_cliente varchar(35));

create table ordenes(


id_orden int primary key not null,
fecha date,
id_cliente varchar(5),
foreign key (id_cliente) references Clientes (id_cliente));

create table detalleOrdenes(


id_orden int,
num_art varchar(5),
cant int,
precio float
foreign key (id_orden) references ordenes (id_orden),
foreign key (num_art) references articulos (num_art));
insert into articulos values(3786,'Red',35,3500),
(4011,'Raqueta',65,6500),
(9132,'Paq-3',4.75,475),
(5794,'Paq-6',5,500),
(3141,'Funda',10,1000);

insert into clientes values(101,'Martin'),


(107,'Hernan'),
(110,'Pedro');

select*from articulos;
select*from clientes;
select*from ordenes;
select*from detalleOrdenes;

EN VISUAL STUDIO C#

private void Btnventas_Click(object sender, EventArgs e)


{
FormOrdenes abrir = new FormOrdenes();
abrir.Show();
this.Hide();
}
private void Btnsalir_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void Btncancelar_Click(object sender, EventArgs e)


{
FormMenu abrir = new FormMenu();
abrir.Show();
this.Hide();
}

EN VISUAL STUDIO C# CLASE CONEXION


public static SqlConnection ObtenerConexion()
{
SqlConnection con = new SqlConnection("Data Source=(local);Initial
Catalog=PEDIDOS;Integrated Security=True");
con.Open();
return con;
}

EN SQL SERVER
USE PEDIDOS;
CREATE PROCEDURE CANTIDAD_ORDENES
@NRO INT OUTPUT
AS
SELECT @NRO=COUNT(ID_ORDEN)
FROM ORDENES
GO

DECLARE @N INT
EXEC CANTIDAD_ORDENES
@NRO=@N OUTPUT
PRINT 'CANTIDAD DE ORDENES:'+STR(@N)
GO

EN VISUAL STUDIO C# CLASE ORDENES


public static int NroOrden()
{
using (SqlConnection con = conexion.ObtenerConexion())
{
SqlCommand command = new SqlCommand("CANTIDAD_ORDENES", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@NRO", SqlDbType.Int);
command.Parameters["@NRO"].Direction = ParameterDirection.Output;
command.ExecuteNonQuery();
int NRO = Convert.ToInt32(command.Parameters["@NRO"].Value) + 2031;
con.Close();
return NRO;
}
}

EN SQL SERVER
USE PEDIDOS;
CREATE PROCEDURE NOMBRES_ARTICULOS
AS
SELECT NOM_ART
FROM ARTICULOS
GO

EXEC NOMBRES_ARTICULOS
GO

EN VISUAL STUDIO C# CLASE ARTICULOS


public static void NombresArticulos(System.Windows.Forms.ComboBox combito)
{
using (SqlConnection con = conexion.ObtenerConexion())
{
SqlCommand command = new SqlCommand("NOMBRES_ARTICULOS", con);
command.CommandType = CommandType.StoredProcedure;
DataSet datos = new DataSet();
SqlDataAdapter adaptador = new SqlDataAdapter();
adaptador.SelectCommand = command;
adaptador.Fill(datos, "ARTICULOS");
con.Close();
DataTable tabla = datos.Tables["ARTICULOS"];
combito.ValueMember = "nom_art";
combito.DataSource = tabla;
}
}
EN VISUAL STUDIO C# FORMORDENES
private void limpiarArticulo()
{
comboArticulos.Text = "";
txtcantex.Clear();
txtprecio.Clear();
txtcantped.Clear();
}

private void FormOrdenes_Load(object sender, EventArgs e)


{
txtnro.Text = ordenes.NroOrden().ToString();
articulos.NombresArticulos(comboArticulos);
limpiarArticulo();
}

EN SQL SERVER
USE PEDIDOS;
CREATE PROCEDURE NOMBRE_CLIENTE
@ID VARCHAR(5),
@NOM VARCHAR(35) OUTPUT
AS
SELECT @NOM=NOM_CLIENTE
FROM CLIENTES
WHERE ID_CLIENTE=@ID
IF @NOM IS NULL
BEGIN
SET @NOM=''
END
GO

DECLARE @NOMBRE VARCHAR(35)


EXEC NOMBRE_CLIENTE @ID='1100',
@NOM=@NOMBRE OUTPUT
PRINT 'NOMBRE CLIENTE:'+ @NOMBRE
GO

EN VISUAL STUDIO C# CLASE CLIENTES


public static string BuscarNombre(string id)
{
using (SqlConnection con = conexion.ObtenerConexion())
{
SqlCommand command = new SqlCommand("NOMBRE_CLIENTE", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@ID", SqlDbType.VarChar, 5);
command.Parameters["@ID"].Value = id;
command.Parameters.Add("@NOM", SqlDbType.VarChar, 35);
command.Parameters["@NOM"].Direction =ParameterDirection.Output;
command.ExecuteNonQuery();
string nom = Convert.ToString(command.Parameters["@NOM"].Value);
con.Close();
return nom;
}
}

EN VISUAL STUDIO C# FORMORDENES


Boolean clienteNuevo;
public FormOrdenes()
{
……………………………………………….
}

private void FormOrdenes_Load(object sender, EventArgs e)


{
………………………………………….
}

private void txtnit_Leave(object sender, EventArgs e)


{
txtcliente.Text = clientes.BuscarNombre(txtnit.Text);
if (txtcliente.Text == "")
{
txtcliente.ReadOnly = false;
clienteNuevo = true;
}
else
{
txtcliente.ReadOnly = true;
clienteNuevo = false;
}
}

EN SQL SERVER
USE PEDIDOS;
CREATE PROCEDURE BUSCAR_ARTICULO
@NOM VARCHAR(35),
@ID VARCHAR(5) OUTPUT,
@PREC FLOAT OUTPUT,
@STOC INT OUTPUT
AS
SELECT @ID=NUM_ART,@PREC=PRECIO,@STOC=STOCK
FROM ARTICULOS
WHERE NOM_ART=@NOM
GO

DECLARE @NUM VARCHAR(5)


DECLARE @PRECIO FLOAT
DECLARE @STOCK INT
EXEC BUSCAR_ARTICULO @NOM='Red',
@ID=@NUM OUTPUT,
@PREC=@PRECIO OUTPUT,
@STOC=@STOCK OUTPUT
PRINT 'ID ARTICULO:'+ @NUM
PRINT 'PRECIO ARTICULO:'+ STR(@PRECIO)
PRINT 'STOCK ARTICULO:'+ STR(@STOCK)
GO

EN VISUAL STUDIO C# EN CLASE ARTICULOS


public string id_art { get; set; }
public string nom_art { get; set; }
public double precio { get; set; }
public int stock { get; set; }

public static void NombresArticulos(System.Windows.Forms.ComboBox combito)


{
…….............................
}
public static articulos BuscarArticulo(string nom)
{
using (SqlConnection con = conexion.ObtenerConexion())
{
articulos art = new articulos();
SqlCommand command = new SqlCommand("BUSCAR_ARTICULO", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@NOM", SqlDbType.VarChar, 35);
command.Parameters["@NOM"].Value = nom;
command.Parameters.Add("@ID", SqlDbType.VarChar, 5);
command.Parameters["@ID"].Direction = ParameterDirection.Output;
command.Parameters.Add("@PREC", SqlDbType.Float);
command.Parameters["@PREC"].Direction = ParameterDirection.Output;
command.Parameters.Add("@STOC", SqlDbType.Int);
command.Parameters["@STOC"].Direction = ParameterDirection.Output;
command.ExecuteNonQuery();
art.id_art= Convert.ToString(command.Parameters["@ID"].Value);
art.precio= Convert.ToDouble(command.Parameters["@PREC"].Value);
art.stock= Convert.ToInt32(command.Parameters["@STOC"].Value);
con.Close();
return art;
}
}

EN VISUAL STUDIO C# FORMORDENES


string NUM_ART;

public FormOrdenes()
{
……………………………………………….
}

private void FormOrdenes_Load(object sender, EventArgs e)


{
………………………………………….
}

private void txtnit_Leave(object sender, EventArgs e)


{
………………………………………….
}

private void ComboArticulos_SelectedIndexChanged(object sender, EventArgs e)


{
articulos art = new articulos();
art=articulos.BuscarArticulo(comboArticulos.Text);
txtcantex.Text = art.stock.ToString();
txtprecio.Text = art.precio.ToString();
NUM_ART = art.id_art;
}

EN VISUAL STUDIO C# FORMORDENES


private void txtcantped_Leave(object sender, EventArgs e)
{
if (Convert.ToInt32(txtcantped.Text) >
Convert.ToInt32(txtcantex.Text))
{
MessageBox.Show("No hay suficientes Articulos");
}
}

EN VISUAL STUDIO C# FORMORDENES


private void calcularTotal()
{
int suma = 0;
foreach (DataGridViewRow columna in DGVarticulos.Rows)
{
suma = suma + Convert.ToInt32(columna.Cells[4].Value);
}
txttotal.Text = suma.ToString();
}

private void Btnagregar_Click(object sender, EventArgs e)


{
int total = Convert.ToInt32(txtprecio.Text) *
Convert.ToInt32(txtcantped.Text);
DGVarticulos.Rows.Add();
int fila = DGVarticulos.Rows.Count - 1;
DGVarticulos.Rows[fila].Cells[0].Value = NUM_ART;
DGVarticulos.Rows[fila].Cells[1].Value = comboArticulos.Text;
DGVarticulos.Rows[fila].Cells[2].Value = txtcantped.Text;
DGVarticulos.Rows[fila].Cells[3].Value = txtprecio.Text;
DGVarticulos.Rows[fila].Cells[4].Value = total;
calcularTotal();
limpiarArticulo();
}

EN VISUAL STUDIO C# FORMORDENES


private void Btneliminar_Click(object sender, EventArgs e)
{
if (DGVarticulos.Rows.Count > 0)
{
int fila = DGVarticulos.CurrentRow.Index;
DGVarticulos.Rows.RemoveAt(fila);
calcularTotal();
}
else
{
MessageBox.Show("No hay articulos pedidos que eliminar!!!!!!!");
}
}

Potrebbero piacerti anche