Sie sind auf Seite 1von 22

SISTEMA DE VENTA

“TRABAJO FINAL DE MATEMÁTICA APLICADA AL


USO DE TECNOLOGÍAS”
USER

Presentado por:

Rodríguez Cordero Giancarlo Felipe

Docente:

Nilton Vera Grande


INDICE
Estructura del Sistema de venta en SQL Server_________________________3
Procedimientos Almacenados de Ventas y Detalle Venta en SQL Server___4
a) FDetalleVenta_Actualizar_______________________________________________4
b) FDetalleVenta_Insertar_________________________________________________4
c) FDetalleVenta_Eliminar_________________________________________________4
d) FDetalleVenta_AumentarStock__________________________________________5
e) FDetalleVenta_DisminuirStock__________________________________________5
f) FDetalleVenta_GetAll___________________________________________________5
g) FEditarDetalleVenta_Set________________________________________________6
Reporte de Venta__________________________________________________________6
h) FVenta________________________________________________________________7
Programación Orientada a Objeto______________________________________8
1. Capa Datos____________________________________________________________8
1.1. FDetalleVenta____________________________________________________________8
1.2. FVenta__________________________________________________________________10

2. Capa Entidades_______________________________________________________11
2.1. Detalle Venta____________________________________________________________11
2.2. Venta___________________________________________________________________12

3. Capa Presentación____________________________________________________13
3.1. FrmDetalleVenta_________________________________________________________13
3.2. FrmVenta_______________________________________________________________17

GENERA EL REPORTE ASI COMO SE MUESTRA EN ESTA IMAGEN______22

1
Estructura del Sistema de venta en SQL Server

2
Procedimientos Almacenados de Ventas y Detalle
Venta en SQL Server

a) FDetalleVenta_Actualizar

CREATE PROCEDURE usp_Data_FDetalleVenta_Actualizar


@Id int,
@VentaId int,
@ProductoId int,
@Cantidad decimal (18,2),
@PrecioUnitario decimal(18,2)
AS
BEGIN
update tblDetalleVenta set
VentaId=@VentaId,ProductoId=@ProductoId,Cantidad=@Cantidad,@PrecioUnitario=@Preci
oUnitario where Id=@Id

select @@ROWCOUNT AS CantidadAfectada


END

b) FDetalleVenta_Insertar

CREATE PROCEDURE usp_Data_FDetalleVenta_Insertar


@VentaId int,
@ProductoId int,
@Cantidad decimal (18,2),
@PrecioUnitario decimal(18,2)
AS
BEGIN
insert into tblDetalleVenta
(VentaId,ProductoId,Cantidad,PrecioUnitario)
values
(@VentaId,@ProductoId,@Cantidad,@PrecioUnitario)

select @@IDENTITY as VentaDetalleId


END

c) FDetalleVenta_Eliminar

CREATE PROCEDURE usp_Data_FDetalleVenta_Eliminar


@Id int
AS
BEGIN
delete from tblDetalleVenta where Id=@Id
select @@ROWCOUNT as CantidadAfectada
END

3
d) FDetalleVenta_AumentarStock

CREATE PROCEDURE usp_Data_FDetalleVenta_AumentarStock


@ProductoId int,
@Cantidad decimal(18,2)
AS
BEGIN
update tblProducto set Stock=Stock+@Cantidad where Id=@ProductoId

select @@ROWCOUNT AS CantidadAfectada


END

e) FDetalleVenta_DisminuirStock

CREATE PROCEDURE usp_Data_FDetalleVenta_DisminuirStock


@ProductoId int,
@Cantidad decimal(18,2)
AS
BEGIN
update tblProducto set Stock=Stock-@Cantidad where Id=@ProductoId
select @@ROWCOUNT AS CantidadAfectada
END

f) FDetalleVenta_GetAll

CREATE PROCEDURE usp_Data_FDetalleVenta_GetAll


@VentaId int
AS
BEGIN
SELECT dbo.tblDetalleVenta.Id, dbo.tblDetalleVenta.VentaId,
dbo.tblDetalleVenta.ProductoId,
dbo.tblProducto.Nombre,dbo.tblDetalleVenta.Cantidad,
dbo.tblProducto.PrecioVenta,dbo.tblDetalleVenta.PrecioUnitario
FROM dbo.tblDetalleVenta INNER JOIN
dbo.tblProducto ON dbo.tblDetalleVenta.ProductoId =
dbo.tblProducto.Id

where tblDetalleVenta.VentaId=@VentaId
END

4
g) FEditarDetalleVenta_Set

CREATE PROCEDURE usp_Data_FEditarDetalleVenta_Set


-- Add the parameters for the stored procedure here

@DetalledVentaId int,
@PrecioUnitario decimal(18,4)
as
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here


update [dbo].[tblDetalleVenta] set PrecioUnitario = @PrecioUnitario where Id
= @DetalledVentaId

select @@ROWCOUNT
END

Reporte de Venta

CREATE PROCEDURE usp_Reporte_GenerarReporteVenta


@VentaId int
AS
BEGIN
SELECT dbo.tblDetalleVenta.VentaId, dbo.tblDetalleVenta.Cantidad,
dbo.tblDetalleVenta.PrecioUnitario, dbo.tblVenta.FechaVenta,
dbo.tblVenta.NumeroDocumento, dbo.tblVenta.TipoDocumento, dbo.tblCliente.Nombre,
dbo.tblCliente.Apellido, dbo.tblCliente.Dni,
dbo.tblProducto.Nombre AS ProductoDescripcion,
(dbo.tblDetalleVenta.Cantidad *
dbo.tblDetalleVenta.PrecioUnitario)as TotalParcial
FROM dbo.tblVenta INNER JOIN
dbo.tblDetalleVenta ON dbo.tblVenta.Id =
dbo.tblDetalleVenta.VentaId INNER JOIN
dbo.tblCliente ON dbo.tblVenta.ClienteId =
dbo.tblCliente.Id INNER JOIN
dbo.tblProducto ON dbo.tblDetalleVenta.ProductoId =
dbo.tblProducto.Id
where tblVenta.Id=@VentaId
END

5
h) FVenta
CREATE PROCEDURE usp_Data_FVenta_Actualizar
@Id int,
@ClienteId int,
@FechaVenta DateTime,
@NumeroDocumento varchar(50),
@TipoDocumento varchar(100)
AS
BEGIN
Update tblVenta set
ClienteId=@ClienteId,FechaVenta=@FechaVenta,NumeroDocumento=@NumeroDocumento,Tipo
Documento=@TipoDocumento where Id=@Id

select @@ROWCOUNT as CantidadAfectada


END
------------------------------------------------

CREATE PROCEDURE usp_Data_FVenta_Eliminar


@Id int
AS
BEGIN
Delete from tblVenta where Id=@Id
END

------------------------------------------------

CREATE PROCEDURE usp_Data_FVenta_GetAll

AS
BEGIN
SELECT dbo.tblVenta.Id, dbo.tblVenta.ClienteId,
dbo.tblVenta.FechaVenta, dbo.tblVenta.NumeroDocumento,
dbo.tblVenta.TipoDocumento, dbo.tblCliente.Nombre, dbo.tblCliente.Apellido
FROM dbo.tblVenta INNER JOIN
dbo.tblCliente ON dbo.tblVenta.ClienteId =
dbo.tblCliente.Id
END

------------------------------------------------

CREATE PROCEDURE usp_Data_FVenta_Insertar


@ClienteId int,
@FechaVenta DateTime,
@NumeroDocumento varchar(50),
@TipoDocumento varchar(100)
AS
BEGIN
insert into tblVenta (ClienteId,FechaVenta,NumeroDocumento,TipoDocumento)
values (@ClienteId,@FechaVenta,@NumeroDocumento,@TipoDocumento)

select @@IDENTITY as VentaId


END

6
Programación Orientada a Objeto
1. Capa Datos
1.1.FDetalleVenta
namespace SistemaVenta_TECnite.Datos
{
public static class FDetalleVenta
{
public static DataSet GetAll(int ventaId)
{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@VentaId", SqlDbType.Int,0,ventaId),
};
return FDBHelper.ExecuteDataSet("usp_Data_FDetalleVenta_GetAll",
dbParams);

}
public static int Insertar(DetalleVenta detalleventa)
{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@VentaId",
SqlDbType.Int,0,detalleventa.Venta.Id),
FDBHelper.MakeParam("@ProductoId",
SqlDbType.Int,0,detalleventa.Producto.Id),
FDBHelper.MakeParam("@Cantidad",
SqlDbType.Decimal,0,detalleventa.Cantidad),
FDBHelper.MakeParam("@PrecioUnitario",
SqlDbType.Decimal,0,detalleventa.PrecioUnitario)
};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FDetalleVenta_Insertar",
dbParams));

//public static int Actualizar(DetalleVenta detalleventa)


//{
// SqlParameter[] dbParams = new SqlParameter[]
// {
// FDBHelper.MakeParam("@Id",
SqlDbType.Int,0,detalleventa.Id),
// FDBHelper.MakeParam("@VentaId",
SqlDbType.Int,0,detalleventa.Venta.Id),
// FDBHelper.MakeParam("@ProductoId",
SqlDbType.Date,0,detalleventa.Producto.Id),
// FDBHelper.MakeParam("@Cantidad",
SqlDbType.VarChar,0,detalleventa.Cantidad),
// FDBHelper.MakeParam("@PrecioUnitario",
SqlDbType.VarChar,0,detalleventa.PrecioUnitario)
// };
// return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FDetalleVenta_Actualizar",
dbParams));

//}
public static int Eliminarr(DetalleVenta detalleventa)

7
{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@Id", SqlDbType.Int,0,detalleventa.Id),

};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FDetalleVenta_Eliminar",
dbParams));

internal static int DisminuirStock(DetalleVenta detVenta)


{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@ProductoId",
SqlDbType.Int,0,detVenta.Producto.Id),
FDBHelper.MakeParam("@Cantidad",
SqlDbType.Decimal,0,detVenta.Cantidad),

};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FDetalleVenta_DisminuirStock",
dbParams));

}
internal static int AumentarStock(DetalleVenta detVenta)
{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@ProductoId",
SqlDbType.Int,0,detVenta.Producto.Id),
FDBHelper.MakeParam("@Cantidad",
SqlDbType.Decimal,0,detVenta.Cantidad),

};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FDetalleVenta_AumentarStock",
dbParams));

}
}
}

8
1.2. FVenta
namespace SistemaVenta_TECnite.Datos
{
public static class FVenta
{
public static DataSet GetAll()
{
SqlParameter[] dbParams = new SqlParameter[]
{

};
return FDBHelper.ExecuteDataSet("usp_Data_FVenta_GetAll", dbParams);

}
public static int Insertar(Venta venta)
{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@ClienteId",
SqlDbType.Int,0,venta.Cliente.Id),
FDBHelper.MakeParam("@FechaVenta",
SqlDbType.Date,0,venta.FechaVenta),
FDBHelper.MakeParam("@NumeroDocumento",
SqlDbType.VarChar,0,venta.NumeroDocumento),
FDBHelper.MakeParam("@TipoDocumento",
SqlDbType.VarChar,0,venta.TipoDocumento)
};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FVenta_Insertar", dbParams));

public static int Actualizar(Venta venta)


{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@Id", SqlDbType.Int,0,venta.Id),
FDBHelper.MakeParam("@ClienteId",
SqlDbType.Int,0,venta.Cliente.Id),
FDBHelper.MakeParam("@FechaVenta",
SqlDbType.Date,0,venta.FechaVenta),
FDBHelper.MakeParam("@NumeroDocumento",
SqlDbType.VarChar,0,venta.NumeroDocumento),
FDBHelper.MakeParam("@TipoDocumento",
SqlDbType.VarChar,0,venta.TipoDocumento)
};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FVenta_Actualizar", dbParams));

}
public static int Eliminarr(Venta venta)
{
SqlParameter[] dbParams = new SqlParameter[]
{
FDBHelper.MakeParam("@Id", SqlDbType.Int,0,venta.Id),

};
return
Convert.ToInt32(FDBHelper.ExecuteScalar("usp_Data_FVenta_Eliminar", dbParams));

9
}
}
}

2. Capa Entidades
2.1. Detalle Venta
public class DetalleVenta
{
private int _id;
private Venta _venta;
private Producto _producto;
private double _cantidad;
private double _precioUnitario;

public int Id
{
get { return _id; }
set { _id = value; }
}
public Venta Venta
{
get { return _venta; }
set { _venta = value; }
}
public Producto Producto
{
get { return _producto; }
set { _producto = value; }
}
public double Cantidad
{
get { return _cantidad; }
set { _cantidad = value; }
}
public double PrecioUnitario
{
get { return _precioUnitario; }
set { _precioUnitario = value; }
}

public DetalleVenta()
{
_producto = new Producto();
_venta = new Venta();
}

10
2.2. Venta
public class Venta
{
private int _id;
private Cliente _cliente;
private DateTime _fechaVenta;
private string _numeroDocumento;
private string _tipoDocumento;

public int Id
{
get { return _id; }
set { _id = value; }
}
public Cliente Cliente
{
get { return _cliente; }
set { _cliente = value; }
}
public DateTime FechaVenta
{
get { return _fechaVenta; }
set { _fechaVenta = value; }
}
public string NumeroDocumento
{
get { return _numeroDocumento; }
set { _numeroDocumento = value; }
}
public string TipoDocumento
{
get { return _tipoDocumento; }
set { _tipoDocumento = value; }
}

public Venta()
{
_cliente = new Cliente();
}
}

11
3. Capa Presentación
3.1. FrmDetalleVenta
namespace SistemaVenta_TECnite.Presentacion
{
public partial class FrmDetalleVenta : Form
{
private static DataTable dt = new DataTable();
private static FrmDetalleVenta _instancia=null;
public FrmDetalleVenta()
{
InitializeComponent();
}

public static FrmDetalleVenta GetInstance()


{
if (_instancia ==null)

_instancia = new FrmDetalleVenta();

return _instancia;

private void btnBuscarProducto_Click(object sender, EventArgs e)


{
FrmProducto frmProd = FrmProducto.GetInscance();
frmProd.SetFlag("1");
frmProd.ShowDialog();
}

private void FrmDetalleVenta_Load(object sender, EventArgs e)


{
try
{
DataSet ds =
FDetalleVenta.GetAll(Convert.ToInt32(txtVentaId.Text));
dt = ds.Tables[0];
dgvVenta.DataSource = dt;
dgvVenta.Columns["VentaId"].Visible = false;
dgvVenta.Columns["Id"].Visible = false;
dgvVenta.Columns["ProductoId"].Visible = false;
dgvVenta.Columns["PrecioVenta"].Visible = false;

if (dt.Rows.Count > 0)
{
lblDatosNoEncontrados.Visible = false;
//dgv_CellClick(null, null);
}
else
{
lblDatosNoEncontrados.Visible = true;
}
//MostrarGuardarCancelar(false);
}
catch (Exception ex)
{

MessageBox.Show(ex.Message + ex.StackTrace);
}

12
}

internal void SetProducto(Producto producto)


{
txtProductoId.Text = producto.Id.ToString();
txtProductoDescripcion.Text = producto.Nombre;
txtStock.Text = producto.Stock.ToString();
txtPrecioUnitario.Text = producto.PrecioVenta.ToString();
}

internal void SetVenta(Venta venta)


{
txtVentaId.Text = venta.Id.ToString();
txtClienteId.Text = venta.Cliente.Id.ToString();
txtClienteNombre.Text = venta.Cliente.Nombre;
txtFecha.Text = venta.FechaVenta.ToShortDateString();
cmbTipoDoc.Text = venta.TipoDocumento;
txtNumeroDocumento.Text = venta.NumeroDocumento;
}

private void btnGuardar_Click(object sender, EventArgs e)


{
try
{
string sResultado = ValidarDatos();

if (sResultado == "")
{

DetalleVenta detVenta = new DetalleVenta();


detVenta.Venta.Id = Convert.ToInt32(txtVentaId.Text);
detVenta.Producto.Id = Convert.ToInt32(txtProductoId.Text);
detVenta.Cantidad = Convert.ToDouble(txtCantidad.Text);
detVenta.PrecioUnitario =
Convert.ToDouble(txtPrecioUnitario.Text);

int iDetVentaId = FDetalleVenta.Insertar(detVenta);

if (iDetVentaId > 0)
{
FrmDetalleVenta_Load(null,null);
FDetalleVenta.DisminuirStock(detVenta);
MessageBox.Show("El producto se agrego correctamente");
Limpiar();
}
else
{
MessageBox.Show("El producto no se pudo agregar intente
nuevamente");
}

}
else
{

13
MessageBox.Show(sResultado,"Error",MessageBoxButtons.OK,MessageBoxIcon.Informatio
n);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}

private void Limpiar()


{
txtProductoId.Text = "";
txtProductoDescripcion.Text = "";
txtCantidad.Text = "1";
txtStock.Text = "0";
txtPrecioUnitario.Text = "";

private string ValidarDatos()


{
string Resultado = "";
if (txtProductoId.Text == "")
{
Resultado = Resultado + "Debe seleccionar un producto \n";
}
if (Convert.ToInt32(txtCantidad.Text)>
Convert.ToInt32(txtStock.Text))
{
Resultado = Resultado + "la cantidad que intenta vender supera el
Stock \n";
}

return Resultado;
}

private void dgvVenta_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dgvVenta.Columns["Eliminar"].Index)
{
DataGridViewCheckBoxCell chkEliminar =

(DataGridViewCheckBoxCell)dgvVenta.Rows[e.RowIndex].Cells["Eliminar"];
chkEliminar.Value = !Convert.ToBoolean(chkEliminar.Value);
}
}

private void btnQuitar_Click(object sender, EventArgs e)


{
try
{
if (MessageBox.Show("¿Realmente desea quitar los productos
seleccionados?", "Eliminacion de Producto", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
{

foreach (DataGridViewRow row in dgvVenta.Rows)


{
if (Convert.ToBoolean(row.Cells["Eliminar"].Value))

14
{
DetalleVenta detVenta = new DetalleVenta();
detVenta.Producto.Id =
Convert.ToInt32(row.Cells["ProductoId"].Value);
detVenta.Cantidad =
Convert.ToInt32(row.Cells["Cantidad"].Value);
detVenta.Id = Convert.ToInt32(row.Cells["Id"].Value);
if (FDetalleVenta.Eliminarr(detVenta) > 0)
{
if (FDetalleVenta.AumentarStock(detVenta) != 1)
{
MessageBox.Show("No se pudo actualizar el
stock", "Eliminacion de Producto", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("El Producto no pudo ser
quitado de la venta", "Eliminacion de Producto", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
}
FrmDetalleVenta_Load(null, null);

}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}

private void btnImprimir_Click(object sender, EventArgs e)


{
FrmReporteVenta frmRepVenta = new FrmReporteVenta();
frmRepVenta.SetVentaId(Convert.ToInt32(txtVentaId.Text));
frmRepVenta.ShowDialog();
}
}
}

15
3.2. FrmVenta
namespace SistemaVenta_TECnite.Presentacion
{
public partial class FrmVenta : Form
{
private static DataTable dt = new DataTable();
private static FrmVenta _instancia = null;
public FrmVenta()
{
InitializeComponent();
}
public static FrmVenta GetInscance()
{
if (_instancia == null)
_instancia = new FrmVenta();
return _instancia;

private void FrmVenta_Load(object sender, EventArgs e)


{
try
{
DataSet ds = FVenta.GetAll();
dt = ds.Tables[0];
dgvVenta.DataSource = dt;

if (dt.Rows.Count > 0)
{
lblDatosNoEncontrados.Visible = false;
dgvVenta_CellClick(null, null);
}
else
{
lblDatosNoEncontrados.Visible = true;
}
MostrarGuardarCancelar(false);

}
catch (Exception ex)
{

MessageBox.Show(ex.Message + ex.StackTrace);
}
}
public void MostrarGuardarCancelar(bool b)
{
btnGuardar.Visible = b;
btnCancelar.Visible = b;
btnbuscarcliente.Visible = b;
btnNuevo.Visible = !b;
btnEditar.Visible = !b;

dgvVenta.Enabled = !b;
txtFecha.Enabled = b;
cmbTipoDoc.Enabled = b;
txtNumeroDocumento.Enabled = b;

16
}
private void btnCancelar_Click(object sender, EventArgs e)
{
MostrarGuardarCancelar(false);
dgvVenta_CellClick(null, null);
}

private void cmbBuscar_SelectedIndexChanged(object sender, EventArgs e)


{

}
public string ValidarDatos()
{
string Resultado = "";
if (txtClienteId.Text == "")
{
Resultado = Resultado + "Cliente \n";
}
if (txtNumeroDocumento.Text == "")
{
Resultado = Resultado + "Numero de Documento \n";
}

return Resultado;
}

private void btnGuardar_Click(object sender, EventArgs e)


{
try
{
string sResultado = ValidarDatos();

if (sResultado == "")
{

if (txtId.Text == "")
{

Venta venta = new Venta();


venta.Cliente.Id = Convert.ToInt32(txtClienteId.Text);
venta.FechaVenta = txtFecha.Value;
venta.TipoDocumento = cmbTipoDoc.Text;
venta.NumeroDocumento = txtNumeroDocumento.Text;

venta.Cliente.Nombre = txtClienteNombre.Text;

int iventaId = FVenta.Insertar(venta);


if (iventaId > 0)
{
FrmVenta_Load(null, null);
venta.Id = iventaId;
CargarDetalle(venta);
}

}
else
{
Venta venta = new Venta();
venta.Id = Convert.ToInt32(txtId.Text);

17
venta.Cliente.Id = Convert.ToInt32(txtClienteId.Text);
venta.FechaVenta = txtFecha.Value;
venta.TipoDocumento = cmbTipoDoc.Text;
venta.NumeroDocumento = txtNumeroDocumento.Text;

if (FVenta.Actualizar(venta) == 1)
{
MessageBox.Show("Datos Modificados correctamente");
FrmVenta_Load(null, null);
}
}
}
else
{
MessageBox.Show("Faltan cargar Datos: \n" + sResultado);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}

private void CargarDetalle(Venta venta)


{
FrmDetalleVenta fDetVenta= FrmDetalleVenta.GetInstance();
fDetVenta.SetVenta(venta);
fDetVenta.ShowDialog();
}

private void btnNuevo_Click(object sender, EventArgs e)


{
MostrarGuardarCancelar(true);
txtId.Text = "";
txtClienteId.Text = "";
txtClienteNombre.Text = "";
txtNumeroDocumento.Text = "";
}

private void btnEditar_Click(object sender, EventArgs e)


{
MostrarGuardarCancelar(true);
}

private void txtBuscar_TextChanged(object sender, EventArgs e)


{
try
{
DataView dv = new DataView(dt.Copy());
if (cmbBuscar.Text == "Dni")
dv.RowFilter = "Convert(Dni, 'System.String') LIKE '" +
txtBuscar.Text + "%'";
else
dv.RowFilter = cmbBuscar.Text + " Like '" + txtBuscar.Text +
"%'";

dgvVenta.DataSource = dv;

if (dv.Count == 0)
{
lblDatosNoEncontrados.Visible = true;
}

18
else
{
lblDatosNoEncontrados.Visible = false;
}

}
catch (Exception ex)
{

MessageBox.Show(ex.Message + ex.StackTrace);
}
}

private void label6_Click(object sender, EventArgs e)


{

private void dgvVenta_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
//if (e.ColumnIndex == dgvVenta.Columns["Eliminar"].Index)
//{
// DataGridViewCheckBoxCell chkEliminar =
//
(DataGridViewCheckBoxCell)dgvVenta.Rows[e.RowIndex].Cells["Eliminar"];
// chkEliminar.Value = !Convert.ToBoolean(chkEliminar.Value);
//}
}

private void dgvVenta_CellClick(object sender, DataGridViewCellEventArgs


e)
{
if (dgvVenta.CurrentRow != null)
{
txtId.Text = dgvVenta.CurrentRow.Cells["Id"].Value.ToString();
txtClienteId.Text =
dgvVenta.CurrentRow.Cells["ClienteId"].Value.ToString();
txtClienteNombre.Text =
dgvVenta.CurrentRow.Cells["Nombre"].Value.ToString() + " " +
dgvVenta.CurrentRow.Cells["Apellido"].Value.ToString();
txtFecha.Text =
dgvVenta.CurrentRow.Cells["FechaVenta"].Value.ToString();
cmbTipoDoc.Text =
dgvVenta.CurrentRow.Cells["TipoDocumento"].Value.ToString();
txtNumeroDocumento.Text =
dgvVenta.CurrentRow.Cells["NumeroDocumento"].Value.ToString();
}
}

private void btnbuscarcliente_Click(object sender, EventArgs e)


{
FrmCliente frmccli = new FrmCliente();
frmccli.SetFlag("1");
frmccli.ShowDialog();
}

internal void SetCliente(string sIdCliente, string sNombreCliente)


{
txtClienteId.Text = sIdCliente;
txtClienteNombre.Text = sNombreCliente;

19
}

private void dgvVenta_CellDoubleClick(object sender,


DataGridViewCellEventArgs e)
{
if (dgvVenta.CurrentRow != null)
{
Venta venta = new Venta();

venta.Id =
Convert.ToInt32(dgvVenta.CurrentRow.Cells["Id"].Value.ToString());
venta.Cliente.Id =
Convert.ToInt32(dgvVenta.CurrentRow.Cells["ClienteId"].Value.ToString());
venta.Cliente.Nombre =
dgvVenta.CurrentRow.Cells["Nombre"].Value.ToString() + " " +
dgvVenta.CurrentRow.Cells["Apellido"].Value.ToString();
venta.FechaVenta =
Convert.ToDateTime(dgvVenta.CurrentRow.Cells["FechaVenta"].Value.ToString());
venta.TipoDocumento =
dgvVenta.CurrentRow.Cells["TipoDocumento"].Value.ToString();
venta.NumeroDocumento =
dgvVenta.CurrentRow.Cells["NumeroDocumento"].Value.ToString();

CargarDetalle(venta);
}
}

private void FrmVenta_FormClosing(object sender, FormClosingEventArgs e)


{
this.Hide();
this.Parent = null;
e.Cancel = true;
}
}
}

20
GENERA EL REPORTE ASI COMO SE MUESTRA
EN ESTA IMAGEN

21

Das könnte Ihnen auch gefallen