Вы находитесь на странице: 1из 29

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapaDatos
{
class Conexion
{
//La base de datos e sql server se llama dbventas
//La ubicacin de la base de datos es local y la instancia que se
llama MSSQLSERVER
//Se conecta a la base de datos utilizando seguridad integrada
public static string Cn = "Data Source=JCARLOSAD7;Initial
Catalog=sisventas;Integrated Security=True";
}
}

--Procedimiento Mostrar
create proc spmostrar_categoria
as
select * from categoria
order by idcategoria desc
go
-- Procedimiento Buscar Categora Nombre
create proc spbuscar_categoria_nombre
@textobuscar varchar(50)
as
select * from categoria
where nombre like @textobuscar + '%'
go
-- Procedimiento Insertar Categora
create proc spinsertar_categoria
@idcategoria int output,
@nombre varchar(50),
@descripcion varchar(256)
as
insert into categoria (nombre,descripcion)
values (@nombre,@descripcion)
go
-- Procedimiento Editar Categora

create proc speditar_categoria


@idcategoria int output,
@nombre varchar(50),
@descripcion varchar(256)
as
update categoria set nombre=@nombre,
descripcion=@descripcion
where idcategoria=@idcategoria
go
-- Procedimiento Eliminar Categora
create proc speliminar_categoria
@idcategoria int
as
delete from categoria
where idcategoria=@idcategoria
go

Capa Datos
Clase Conexin
Clase DCategora

Capa Negocio
Capa Presentacin

Cdigo clase DCategoria


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Importaciones necesarias
using System.Data;
using System.Data.SqlClient;
namespace CapaDatos
{
public class dCategoria
{
private int VarIdcategoria;
private string VarNombre;
private string VarDescripcion;
public string TextoBuscar;
//Constructor vaco
public dCategoria()
{
}
//Constructor con parmetros
public dCategoria(int Idcategoria,string Nombre,string Descripcion)
{
this.VarIdcategoria = Idcategoria;
this.VarNombre = Nombre;
this.VarDescripcion = Descripcion;
}
//Mtodos setter and Getter

#region Metodos Get y Set


public int Idcategoria
{
get { return VarIdcategoria; }
set { VarIdcategoria = value; }
}
public string Nombre
{
get { return VarNombre; }
set { VarNombre = value; }
}
public string Descripcion
{
get { return VarDescripcion; }
set { VarDescripcion = value; }
}
#endregion
//Mtodo utilizado para insertar una Categora
public string Insertar(dCategoria Categoria)
{
string Rpta = "";
SqlConnection SqlCon = new SqlConnection();
try
{
//1. Establecer la cadena de conexin
SqlCon.ConnectionString = Conexion.Cn;
//2. Abrir la conexin de la BD
SqlCon.Open();
//3. Establecer el comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spinsertar_categoria";
SqlCmd.CommandType = CommandType.StoredProcedure;
//4. Agregar los parmetros al comando
//Establecemos los valores para el parmetro
//@idcategoria del Procedimiento Almacenado
SqlParameter ParIdcategoria = new SqlParameter();
ParIdcategoria.ParameterName = "@idcategoria";
ParIdcategoria.SqlDbType = SqlDbType.Int;
//Le declaramos que el parmetro es de salida,
//porque obtendremos el cdigo generado por la base de datos
ParIdcategoria.Direction = ParameterDirection.Output;
SqlCmd.Parameters.Add(ParIdcategoria);
//Agregamos el parmetro al comando
//Establecemos los valores para el parmetro
//@nombre del Procedimiento Almacenado
SqlParameter ParNombre = new SqlParameter();
ParNombre.ParameterName = "@nombre";
ParNombre.SqlDbType = SqlDbType.VarChar;
ParNombre.Size = 100;
ParNombre.Value = Categoria.Nombre;
SqlCmd.Parameters.Add(ParNombre);
//Agregamos el parmetro al comando
//Establecemos los valores para el parmetro
//@descripcin del Procedimiento Almacenado
SqlParameter ParDescripcion = new SqlParameter();
ParDescripcion.ParameterName = "@descripcion";

ParDescripcion.SqlDbType = SqlDbType.VarChar;
ParDescripcion.Size = 256;
ParDescripcion.Value = Categoria.Descripcion;
SqlCmd.Parameters.Add(ParDescripcion);
//Agregamos el parmetro al comando
//5. Ejecutamos el commando
Rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se ingreso el registro de
forma correcta";
}
catch (Exception ex)
{
Rpta = ex.Message;
}
finally
{
//6. Cerramos la conexion con la BD
if (SqlCon.State == ConnectionState.Open) SqlCon.Close();
}
return Rpta;
}
//Mtodo utilizado para actualizar un Producto
public string Editar(dCategoria Categoria)
{
string Rpta = "";
SqlConnection SqlCon = new SqlConnection();
try
{
//1. Establecer la cadena de conexin
SqlCon.ConnectionString = Conexion.Cn;
//2. Abrir la conexin de la BD
SqlCon.Open();
//3. Establecer el comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spEditar_Categoria";
SqlCmd.CommandType = CommandType.StoredProcedure;
//4. Agregar los parmetros al comando
//Establecemos los valores para el parmetro
//@idcategoria del Procedimiento Almacenado
SqlParameter ParIdcategoria = new SqlParameter();
ParIdcategoria.ParameterName = "@idcategoria";
ParIdcategoria.SqlDbType = SqlDbType.Int;
ParIdcategoria.Value = Categoria.Idcategoria;
SqlCmd.Parameters.Add(ParIdcategoria);
//Agregamos el parmetro al comando
//Establecemos los valores para el parmetro
//@nombre del Procedimiento Almacenado
SqlParameter ParNombre = new SqlParameter();
ParNombre.ParameterName = "@nombre";
ParNombre.SqlDbType = SqlDbType.VarChar;
ParNombre.Size = 100;
ParNombre.Value = Categoria.Nombre;
SqlCmd.Parameters.Add(ParNombre);
//Agregamos el parmetro al comando
//Establecemos los valores para el parmetro

//@descripcion del Procedimiento Almacenado


SqlParameter ParDescripcion = new SqlParameter();
ParDescripcion.ParameterName = "@descripcion";
ParDescripcion.SqlDbType = SqlDbType.VarChar;
ParDescripcion.Size = 256;
ParDescripcion.Value = Categoria.Descripcion;
SqlCmd.Parameters.Add(ParDescripcion);
//Agregamos el parmetro al comando
//5. Ejecutamos el commando
Rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se actualizo el registro de
forma correcta";
}
catch (Exception ex)
{
Rpta = ex.Message;
}
finally
{
//6. Cerramos la conexin con la BD
if (SqlCon.State == ConnectionState.Open) SqlCon.Close();
}
return Rpta;
}
//Mtodo utilizado para eliminar un Producto
public string Eliminar(dCategoria Categoria)
{
string Rpta = "";
SqlConnection SqlCon = new SqlConnection();
try
{
//1. Establecer la cadena de conexin
SqlCon.ConnectionString = Conexion.Cn;
//2. Abrir la conexin de la BD
SqlCon.Open();
//3. Establecer el comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "speliminar_categoria";
SqlCmd.CommandType = CommandType.StoredProcedure;
//4. Agregar los parmetros al comando
//Establecemos los valores para el parmetro
//@idcategoria del Procedimiento Almacenado
SqlParameter ParIdcategoria = new SqlParameter();
ParIdcategoria.ParameterName = "@idcategoria";
ParIdcategoria.SqlDbType = SqlDbType.Int;
ParIdcategoria.Value = Categoria.Idcategoria;
SqlCmd.Parameters.Add(ParIdcategoria);
//Agregamos el parmetro al comando
//5. Ejecutamos el commando
Rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se pudo eliminar el
registro";
}
catch (Exception ex)
{
Rpta = ex.Message;
}
finally
{

//6. Cerramos la conexin con la BD


if (SqlCon.State == ConnectionState.Open) SqlCon.Close();
}
return Rpta;
}

//Mtodo utilizado para obtener todas las categoras de la base de datos


public DataTable Mostrar()
{
DataTable DtResultado = new DataTable("categoria");
SqlConnection SqlCon = new SqlConnection();
try
{
//1. Establecer la cadena de conexion
SqlCon.ConnectionString = Conexion.Cn;
//2. Establecer el comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;//La conexin que va a usar el comando
SqlCmd.CommandText = "spmostrar_categoria";//El comando a ejecutar
SqlCmd.CommandType = CommandType.StoredProcedure;
//Decirle al comando que va a ejecutar una sentencia SQL
//3. No hay parmetros
//4. El DataAdapter que va a ejecutar el comando y
//es el encargado de llena el DataTable
SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
SqlDat.Fill(DtResultado);//Llenamos el DataTable

}
catch (Exception ex)
{
DtResultado = null;
}
return DtResultado;
}

public DataTable BuscarNombre(dCategoria Categoria)


{
DataTable DtResultado = new DataTable("categoria");
SqlConnection SqlCon = new SqlConnection();
try
{
//1. Establecer la cadena de conexion
SqlCon.ConnectionString = Conexion.Cn;
//2. Establecer el comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;//La conexin que va a usar el comando
SqlCmd.CommandText = "spBuscar_Categoria_Nombre";//El comando
ejecutar
SqlCmd.CommandType = CommandType.StoredProcedure;
//Decirle al comando que va a ejecutar una sentencia SQL
//3.Enviamos wl parmetro de Bsqueda
SqlParameter ParTextoBuscar = new SqlParameter();
ParTextoBuscar.ParameterName = "@textobuscar";
ParTextoBuscar.SqlDbType = SqlDbType.VarChar;
ParTextoBuscar.Size = 50;

ParTextoBuscar.Value = Categoria.TextoBuscar;
SqlCmd.Parameters.Add(ParTextoBuscar);
//4. El DataAdapter que va a ejecutar el comando y
//es el encargado de llena el DataTable
SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
SqlDat.Fill(DtResultado);//Llenamos el DataTable
}
catch (Exception ex)
{
DtResultado = null;
}
return DtResultado;
}
}
}

Clase NCategora

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Para que se comunique con la Capa de Datos
using CapaDatos;
using System.Data;

namespace CapaNegocio
{
public class nCategoria
{
//Mtodo que llama al mtodo Insertar de la Capa de Datos
//de la clase dCategoria
public static string Insertar(string Nombre, string Descripcion)
{
dCategoria Cat = new dCategoria();
Cat.Nombre = Nombre;
Cat.Descripcion = Descripcion;
return Cat.Insertar(Cat);
}

//Mtodo que llama al mtodo Actualizar de la Capa de Datos


//de la clase dCategoia
public static string Editar(int Idcategoria, string Nombre, string Descrip
cion)
{
dCategoria Cat = new dCategoria();
Cat.Idcategoria = Idcategoria;
Cat.Nombre = Nombre;
Cat.Descripcion = Descripcion;
return Cat.Editar(Cat);
}
//Mtodo que se encarga de llamar al mtodo Eliminar
//de la clase dCategoria
public static string Eliminar(int Idcategoria)
{
dCategoria Cat = new dCategoria();
Cat.Idcategoria = Idcategoria;
return Cat.Eliminar(Cat);
}
//Mtodo que se encarga de llamar al mtodo ObtenerProducto
//de la clase Producto
public static DataTable Mostrar()
{
return new dCategoria().Mostrar();
}
public static DataTable BuscarNombre(string TextoBuscar)
{
dCategoria Cat = new dCategoria();
Cat.TextoBuscar = TextoBuscar;
return Cat.BuscarNombre(Cat);
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//Comunicarse con la Capa de Negocios
using CapaNegocio;
namespace CapaPresentacion
{
public partial class frmCategoria : Form
{
//Variable que nos indica si vamos a insertar un nuevo producto
private bool IsNuevo = false;
//Variable que nos indica si vamos a modificar un producto
private bool IsModificar = false;
//Constructor del formulario
public frmCategoria()
{
InitializeComponent();
this.ttMensaje.SetToolTip(this.txtNombre, "Ingrese el Nombre de la
categora");
}

//Para mostrar mensaje de confirmacin


private void MensajeOK(string Mensaje)
{
MessageBox.Show(Mensaje, "Sistema
Ventas", MessageBoxButtons.OK,MessageBoxIcon.Information);

}
//Para mostrar mensaje de error
private void MensajeError(string Mensaje)
{
MessageBox.Show(Mensaje, "Sistema
Ventas", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
//Limpia los controles del formulario
private void Limpiar()
{
this.txtNombre.Text = string.Empty;
this.txtDescripcion.Text=string.Empty;
this.txtIdcategoria.Text = string.Empty;
}
//Habilita los controles de los formularios
private void Habilitar(bool Valor)
{
this.txtNombre.ReadOnly = !Valor;
this.txtDescripcion.ReadOnly = !Valor;
this.txtIdcategoria.ReadOnly = !Valor;
}
//Habilita los botones
private void Botones()
{
if (this.IsNuevo || this.IsModificar)
{
this.Habilitar(true);
this.btnNuevo.Enabled = false;
this.btnGuardar.Enabled = true;
this.btnModificar.Enabled = false;
this.btnCancelar.Enabled = true;
}
else
{
this.Habilitar(false);
this.btnNuevo.Enabled = true;

this.btnGuardar.Enabled = false;
this.btnModificar.Enabled = true;
this.btnCancelar.Enabled = false;
}
}
private void OcultarColumnas()
{
this.datalistado.Columns[0].Visible = false;
this.datalistado.Columns[1].Visible = false;
}
//Mtodo Mostrar()
private void Mostrar()
{
this.datalistado.DataSource = nCategoria.Mostrar();
this.OcultarColumnas();
LblTotal.Text

="Total

Registros:

" +Convert.ToString(datalistado.Rows.Count);
}
//Mtodo BuscarNombre
private void BuscarNombre()
{
this.datalistado.DataSource
= nCategoria.BuscarNombre(this.txtBuscar.Text);
this.OcultarColumnas();
LblTotal.Text

="Total

" + Convert.ToString(datalistado.Rows.Count);
}

//Mtodo Constructor
private void frmCategoria_Load(object sender, EventArgs e)

Registros:

{
//Para ubicar al formulario en la parte superior del contenedor
this.Top = 0;
this.Left = 0;
//Le decimos al DataGridView que no auto genere las columnas
//Llenamos el DataGridView con la informacin
//de todos nuestras categoras
this.Mostrar();
//Deshabilita los controles
this.Habilitar(false);
//Establece los botones
this.Botones();
}
//Llamamos al Mtodo Buscar
private void btnbuscar_Click(object sender, EventArgs e)
{
this.BuscarNombre();
}
private void txtBuscar_TextChanged(object sender, EventArgs e)
{
this.BuscarNombre();
}
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.

//Cdigo del Botn nuevo


private void btnNuevo_Click(object sender, EventArgs e)
{
this.IsNuevo = true;
this.IsModificar = false;
this.Botones();
this.Limpiar();
this.txtIdcategoria.Text = string.Empty;
this.txtNombre.Focus();
}
//Cdigo del Botn Editar
private void btnEditar_Click(object sender, EventArgs e)
{
//Si no ha seleccionado un producto no puede modificar
if (!this.txtIdcategoria.Text.Equals(""))
{

18.
19.
20.
21.
22.
23.
24.
25.

this.IsModificar = true;
this.Botones();
}
else
{
this.MensajeError("Debe de buscar un registro para Modificar");
}
}
26. //Cdigo del Botn Guardar
27.
private void btnGuardar_Click(object sender, EventArgs e)
28.
{
29.
try
30.
{
31.
32.
//La variable que almacena si se inserto
33.
//o se modifico la tabla
34.
string Rpta = "";
35.
if (this.txtNombre.Text == string.Empty)
36.
{
37.
38.
MensajeError("Falta Ingresar algunos valores sern remarcados");
39.
erroricono.SetError(txtNombre, "Ingrese Nombre");
40.
}
41.
else
42.
{
43.
if (this.IsNuevo)
44.
{
45.
//Vamos a insertar un producto
46.
Rpta = nCategoria.Insertar(this.txtNombre.Text.Trim().ToUpper(),
47.
this.txtDescripcion.Text.Trim());
48.
49.
}
50.
else
51.
{
52.
//Vamos a modificar un producto
53.
Rpta = nCategoria.Editar(Convert.ToInt32(this.txtIdcategoria.Text),
54.
this.txtNombre.Text.Trim().ToUpper(),
55.
this.txtDescripcion.Text.Trim());
56.
}
57.
//Si la respuesta fue OK, fue porque se modifico
58.
//o inserto el Producto
59.
//de forma correcta
60.
if (Rpta.Equals("OK"))
61.
{
62.
if (this.IsNuevo)
63.
{
64.
this.MensajeOK("Se insert de forma correcta el registro");
65.
}
66.
else
67.
{
68.
this.MensajeOK("Se actualiz de forma correcta el registro");
69.
}
70.
71.
}
72.
else
73.
{
74.
//Mostramos el mensaje de error
75.
this.MensajeError(Rpta);
76.
}
77.
this.IsNuevo = false;
78.
this.IsModificar = false;
79.
this.Botones();
80.
this.Limpiar();
81.
this.Mostrar();
82.
this.txtIdcategoria.Text = "";
83.
84.
}
85.
}
86.
87.
catch (Exception ex)

88.
{
89.
MessageBox.Show(ex.Message + ex.StackTrace);
90.
}
91.
92.
}
93.
94.
//Cdigo del Botn Cancelar
95.
private void btnCancelar_Click(object sender, EventArgs e)
96.
{
97.
this.IsNuevo = false;
98.
this.IsModificar = false;
99.
this.Botones();
100.
this.Limpiar();
101.
this.txtIdcategoria.Text = string.Empty;
102.
}
103.
104.
//Evento DoubleClick del datagridview
105.
private void Datalistado_DoubleClick(object sender, EventArgs e)
106.
{
107.
this.txtIdcategoria.Text = Convert.ToString(this.datalistado.CurrentRow.C
ells["idcategoria"].Value);
108.
this.txtNombre.Text = Convert.ToString(this.datalistado.CurrentRow.Cells
["nombre"].Value);
109.
this.txtDescripcion.Text = Convert.ToString(this.datalistado.CurrentRow.C
ells["descripcion"].Value);
110.
this.tabControl1.SelectedIndex = 1;
111.
}
112.
113.
//Cdigo del Evento CellContentClick del Datagridview
114.
private void Datalistado_CellContentClick(object sender, DataGridViewCellEven
tArgs e)
115.
{
116.
if(e.ColumnIndex==datalistado.Columns["Eliminar"].Index)
117.
{
118.
DataGridViewCheckBoxCell ChkEliminar =
119.
(DataGridViewCheckBoxCell)datalistado.Rows[e.RowIndex].Cells["Eli
minar"];
120.
ChkEliminar.Value = !Convert.ToBoolean(ChkEliminar.Value);
121.
}
122.
123.
}
124.
125.
//Cdigo del Evento CheckedChanged del CheckBox
126.
private void chkEliminar_CheckedChanged(object sender, EventArgs e)
127.
{
128.
if(chkEliminar.Checked)
129.
{
130.
this.datalistado.Columns[0].Visible = true;
131.
}
132.
else
133.
{
134.
this.datalistado.Columns[0].Visible = false;
135.
}
136.
}
137.
138.
//Cdigo del Botn Eliminar
139.
private void btneliminar_Click(object sender, EventArgs e)
140.
{
141.
try
142.
{
143.
DialogResult Opcion;
144.
Opcion = MessageBox.Show("Realmente desea eliminar los registros?",
"Sistema Ventas", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
145.
146.
if (Opcion == DialogResult.OK)
147.
{
148.
string Codigo;
149.
string Rpta = "";
150.
151.
foreach (DataGridViewRow row in datalistado.Rows)

152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.

{
if (Convert.ToBoolean(row.Cells[0].Value))
{
Codigo = Convert.ToString(row.Cells[1].Value);
Rpta = nCategoria.Eliminar(Convert.ToInt32(Codigo));
if (Rpta.Equals("OK"))
{
this.MensajeOK("Se elimin de forma correcta el registro");
}
else
{
//Mostramos el mensaje de error
this.MensajeError(Rpta);
}
}
}
this.Mostrar();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}

Programs.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
//Comunicarse con la capa presentacin
using CapaPresentacion;
namespace SistVentasPrueba
{
static class Program
{
/// <summary>
/// Punto de entrada principal para la aplicacin.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmCategoria());
}
}
}

--Procedimiento Mostrar
crear proc spmostrar_presentacion
como
seleccionar * de presentacion
orden por idpresentacion desc
ir
- Procedimiento Buscar Presentacin Nombre
crear proc spbuscar_presentacion_nombre

textobuscar varchar (50)


como
seleccionar * de presentacion
donde nombre comotextobuscar + '%'
ir
- Procedimiento Insertar Presentacin
crear proc spinsertar_presentacion
idpresentacion int salida,
nombre varchar (50),
descripcion varchar (256)
como
inserte en presentacion (nombre, descripcion)
valores (nombre,descripcion)
ir
- Procedimiento Editar Presentacin
crear proc speditar_presentacion
idpresentacion int,
nombre varchar (50),
descripcion varchar (256)
como
actualizacin presentacion set nombre =nombre,
descripcion =descripcion
donde idpresentacion =idpresentacion
ir
- Procedimiento ELIMINAR Presentacin
crear proc speliminar_presentacion
idpresentacion int
como
Eliminar de presentacion
donde idpresentacion =idpresentacion
ir
Capa Datos - Clase DPresentacin
la vista de impresin?

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.

utilizando
utilizando
utilizando
utilizando
utilizando

Sistema;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

utilizando System.Data;
utilizando System.Data.SqlClient;
namespace CapaDatos
{
pblica clase DPresentacion
{
privada int _Idpresentacion;
privado cadena _Nombre;
privado cadena _Descripcion;
privado cadena _TextoBuscar;
// Mtodos Setter una Propiedades Getter
pblica int Idpresentacion
{
conseguir {volver _Idpresentacion; }
conjunto {_Idpresentacion = valor; }

24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.

}
pblica string Nombre
{
conseguir {volver _Nombre; }
conjunto {_Nombre = valor; }
}
pblica cadena Descripcion
{
conseguir {volver _Descripcion; }
conjunto {_Descripcion = valor; }
}
pblica cadena TextoBuscar
{
conseguir {volver _TextoBuscar; }
conjunto {_TextoBuscar = valor; }
}
// Constructores
pblica DPresentacion ()
{
}
pblica DPresentacion (int idpresentacion, string nombre, string descripcion)
{
este .Idpresentacion = idpresentacion;
este .Nombre = nombre;
este .Descripcion = descripcion;
}
// Mtodo Insertar
pblica cadena Insertar (DPresentacion Presentacion)
{
cadena RPTA = "";
SqlConnection SqlCon = nuevo SqlConnection ();
probar
{
// Cdigo
SqlCon.ConnectionString = Conexion.Cn;
SqlCon.Open ();
// Establecer el Comando
SqlCommand SQLCMD = nuevo SqlCommand ();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spinsertar_presentacion";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter ParIdpresentacion = nueva SqlParameter ();
ParIdpresentacion.ParameterName = "idpresentacion";
ParIdpresentacion.SqlDbType = SqlDbType.Int;
ParIdpresentacion.Direction = ParameterDirection.Output;
SqlCmd.Parameters.Add (ParIdpresentacion);
SqlParameter ParNombre = nueva SqlParameter ();
ParNombre.ParameterName = "nombre";
ParNombre.SqlDbType = SqlDbType.VarChar;
ParNombre.Size = 50;
ParNombre.Value = Presentacion.Nombre;
SqlCmd.Parameters.Add (ParNombre);
SqlParameter ParDescripcion = nueva SqlParameter ();
ParDescripcion.ParameterName = "descripcion";
ParDescripcion.SqlDbType = SqlDbType.VarChar;
ParDescripcion.Size = 256;
ParDescripcion.Value = Presentacion.Descripcion;
SqlCmd.Parameters.Add (ParDescripcion);
// Ejecutamos nuestro de comando

93.
el Registro";
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
el Registro";
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.

RPTA = SqlCmd.ExecuteNonQuery () == 1? "OK": "NO SE Ingreso

}
capturas (Exception ex)
{
RPTA = ex.Message;
}
finalmente
{
si (SqlCon.State == ConnectionState.Open) SqlCon.Close ();
}
volver RPTA;
}
// Mtodo Editar
pblica cadena Editar (DPresentacion Presentacion)
{
cadena RPTA = "";
SqlConnection SqlCon = nuevo SqlConnection ();
probar
{
// Cdigo
SqlCon.ConnectionString = Conexion.Cn;
SqlCon.Open ();
// Establecer el Comando
SqlCommand SQLCMD = nuevo SqlCommand ();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "speditar_presentacion";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter ParIdpresentacion = nueva SqlParameter ();
ParIdpresentacion.ParameterName = "idpresentacion";
ParIdpresentacion.SqlDbType = SqlDbType.Int;
ParIdpresentacion.Value = Presentacion.Idpresentacion;
SqlCmd.Parameters.Add (ParIdpresentacion);
SqlParameter ParNombre = nueva SqlParameter ();
ParNombre.ParameterName = "nombre";
ParNombre.SqlDbType = SqlDbType.VarChar;
ParNombre.Size = 50;
ParNombre.Value = Presentacion.Nombre;
SqlCmd.Parameters.Add (ParNombre);
SqlParameter ParDescripcion = nueva SqlParameter ();
ParDescripcion.ParameterName = "descripcion";
ParDescripcion.SqlDbType = SqlDbType.VarChar;
ParDescripcion.Size = 256;
ParDescripcion.Value = Presentacion.Descripcion;
SqlCmd.Parameters.Add (ParDescripcion);
// Ejecutamos nuestro de comando
RPTA = SqlCmd.ExecuteNonQuery () == 1? "OK": "NO SE Actualizo

}
capturas (Exception ex)
{
RPTA = ex.Message;
}
finalmente
{
si (SqlCon.State == ConnectionState.Open) SqlCon.Close ();
}
volver RPTA;
}

161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
el Registro";
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.

// Mtodo ELIMINAR
pblica cadena ELIMINAR (DPresentacion Presentacion)
{
cadena RPTA = "";
SqlConnection SqlCon = nuevo SqlConnection ();
probar
{
// Cdigo
SqlCon.ConnectionString = Conexion.Cn;
SqlCon.Open ();
// Establecer el Comando
SqlCommand SQLCMD = nuevo SqlCommand ();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "speliminar_presentacion";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter ParIdpresentacion = nueva SqlParameter ();
ParIdpresentacion.ParameterName = "idpresentacion";
ParIdpresentacion.SqlDbType = SqlDbType.Int;
ParIdpresentacion.Value = Presentacion.Idpresentacion;
SqlCmd.Parameters.Add (ParIdpresentacion);
// Ejecutamos nuestro de comando
RPTA = SqlCmd.ExecuteNonQuery () == 1? "OK": "no se elimino

}
capturas (Exception ex)
{
RPTA = ex.Message;
}
finalmente
{
si (SqlCon.State == ConnectionState.Open) SqlCon.Close ();
}
volver RPTA;
}
// Mtodo Mostrar
pblica DataTable Mostrar ()
{
DataTable DtResultado = nueva DataTable ("presentacion");
SqlConnection SqlCon = nuevo SqlConnection ();
probar
{
SqlCon.ConnectionString = Conexion.Cn;
SqlCommand SQLCMD = nuevo SqlCommand ();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spmostrar_presentacion";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter SqlDat = nuevo SqlDataAdapter (sqlcmd);
SqlDat.Fill (DtResultado);
}
capturas (Exception ex)
{
DtResultado = nula;
}
volver DtResultado;
}
// Mtodo BuscarNombre
pblica DataTable BuscarNombre (DPresentacion Presentacion)

230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.

{
DataTable DtResultado = nueva DataTable ("presentacion");
SqlConnection SqlCon = nuevo SqlConnection ();
probar
{
SqlCon.ConnectionString = Conexion.Cn;
SqlCommand SQLCMD = nuevo SqlCommand ();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spbuscar_presentacion_nombre";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter ParTextoBuscar = nueva SqlParameter ();
ParTextoBuscar.ParameterName = "textobuscar";
ParTextoBuscar.SqlDbType = SqlDbType.VarChar;
ParTextoBuscar.Size = 50;
ParTextoBuscar.Value = Presentacion.TextoBuscar;
SqlCmd.Parameters.Add (ParTextoBuscar);
SqlDataAdapter SqlDat = nuevo SqlDataAdapter (sqlcmd);
SqlDat.Fill (DtResultado);
}
capturas (Exception ex)
{
DtResultado = nula;
}
volver DtResultado;
}
}
}

Capa Negocio - Clase NPresentacin


la vista de impresin?

1.
utilizando Sistema;
2.
utilizando System.Collections.Generic;
3.
utilizando System.Linq;
4.
utilizando System.Text;
5.
utilizando System.Threading.Tasks;
6.
7.
utilizando CapaDatos;
8.
utilizando System.Data;
9.
10.
11.
espacio de nombres CapaNegocio
12.
{
13.
pblica clase Npresentacion
14.
{
15.
// Mtodo Insertar Que llama al Mtodo Insertar de la clase DPresentacin de la
CapaDatos
16.
pblica esttica cadena Insertar (string nombre, string descripcion)
17.
{
18.
DPresentacion Obj = nueva DPresentacion ();
19.
Obj.Nombre = nombre;
20.
Obj.Descripcion = descripcion;
21.
volver Obj.Insertar (obj);
22.
}
23.
24.
// Mtodo Editar Que llama al Mtodo Editar de la clase DPresentacin De La
CapaDatos
25.
pblica esttica cadena Editar (int idpresentacion, string nombre, string d
escripcion)
26.
{
27.
DPresentacion Obj = nueva DPresentacion ();
28.
Obj.Idpresentacion = idpresentacion;
29.
Obj.Nombre = nombre;
30.
Obj.Descripcion = descripcion;
31.
volver Obj.Editar (obj);
32.
}
33.

34.
CapaDatos
35.
36.
37.
38.
39.
40.
41.
42.
CapaDatos
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
}
59.
}

// Mtodo ELIMINAR Que llama al Mtodo ELIMINAR de la clase DPresentacin de la


pblica esttica cadena ELIMINAR (int idpresentacion)
{
DPresentacion Obj = nueva DPresentacion ();
Obj.Idpresentacion = idpresentacion;
volver Obj.Eliminar (obj);
}
// Mtodo Mostrar Que llama al Mtodo Mostrar de la clase DPresentacin de la
pblica esttica DataTable Mostrar ()
{
volver nueva DPresentacion () Mostrar ().;
}
// Mtodo BuscarNombre Que llama al Mtodo BuscarNombre
// de la clase DPresentacin de la CapaDatos
pblica esttica DataTable BuscarNombre (cadena textobuscar)
{
DPresentacion Obj = nueva DPresentacion ();
Obj.TextoBuscar = textobuscar;
volver Obj.BuscarNombre (obj);
}

1.
utilizando Sistema;
2.
utilizando System.Collections.Generic;
3.
utilizando System.ComponentModel;
4.
utilizando System.Data;
5.
utilizando System.Drawing;
6.
utilizando System.Linq;
7.
utilizando System.Text;
8.
utilizando System.Threading.Tasks;
9.
utilizando System.Windows.Forms;
10.
11.
utilizando CapaNegocio;
12.
13.
14.
espacio de nombres CapaPresentacion
15.
{
16.
pblica parcial clase frmPresentacion: Formulario
17.
{
18.
privada bool IsNuevo = false;
19.
20.
privada bool IsEditar = false;
21.
22.
pblica frmPresentacion ()
23.
{
24.
InitializeComponent ();
25.
este .ttMensaje.SetToolTip (este .txtNombre, "Ingrese el Nombre de
la Presentacin");
26.
27.
}
28.
29.
30.
// Mostrar Mensaje de confirmacion
31.
privada vaco MensajeOk (cadena de Mensaje)
32.
{
33.
MessageBox.Show (Mensaje, "Sistema de Ventas", MessageBoxButtons.OK,
MessageBoxIcon.Information);
34.
35.
}
36.
37.

38.
// Mostrar Mensaje de error
39.
privada vaco MensajeError (cadena de Mensaje)
40.
{
41.
MessageBox.Show (Mensaje, "Sistema de Ventas", MessageBoxButtons.OK,
MessageBoxIcon.Error);
42.
}
43.
44.
// Limpiar TODOS LOS Controles del Formulario
45.
privada sin efecto Limpiar ()
46.
{
47.
este .txtNombre.Text = cadena .Empty;
48.
este .txtDescripcion.Text = cadena .Empty;
49.
este .txtIdpresentacion.Text = cadena .Empty;
50.
}
51.
52.
// Habilitar los Controles del Formulario
53.
privada vaco Habilitar (bool valor)
54.
{
55.
esta! .txtNombre.ReadOnly = valor;
56.
esta! .txtDescripcion.ReadOnly = valor;
57.
esta! .txtIdpresentacion.ReadOnly = valor;
58.
}
59.
60.
// Habilitar los Botones
61.
privados vacos Botones ()
62.
{
63.
si (esta .IsNuevo || esta .IsEditar) // Alt + 124
64.
{
65.
este .Habilitar (verdadero);
66.
este .btnNuevo.Enabled = false;
67.
este .btnGuardar.Enabled = verdadero;
68.
este .btnModificar.Enabled = false;
69.
este .btnCancelar.Enabled = verdadero;
70.
}
71.
otro
72.
{
73.
este .Habilitar (false);
74.
este .btnNuevo.Enabled = verdadero;
75.
este .btnGuardar.Enabled = false;
76.
este .btnModificar.Enabled = verdadero;
77.
este .btnCancelar.Enabled = false;
78.
}
79.
80.
}
81.
82.
// Mtodo para Ocultar Columnas
83.
privados vacos OcultarColumnas ()
84.
{
85.
esta .dataListado.Columns [0] .Visible = false;
86.
esta .dataListado.Columns [1] .Visible = false;
87.
}
88.
89.
// Mtodo Mostrar
90.
privada void Mostrar ()
91.
{
92.
este .dataListado.DataSource Npresentacion.Mostrar = ();
93.
este .OcultarColumnas ();
94.
lblTotal.Text = "Total de Registros:" + Convert.ToString
(dataListado.Rows.Count);
95.
}
96.
97.
// Mtodo BuscarNombre
98.
privada vaco BuscarNombre ()
99.
{
100.
este .dataListado.DataSource =
Npresentacion.BuscarNombre (este .txtBuscar.Text);
101.
este .OcultarColumnas ();
102.
lblTotal.Text = "Total de Registros:" + Convert.ToString
(dataListado.Rows.Count);
103.
}

104.
105.
privada vaco frmPresentacion_Load (objeto emisor, EventArgs e)
106.
{
107.
// Para ubicar al Formulario en la parte superior, del contenedor
108.
este .Top = 0;
109.
este .Left = 0;
110.
// Le DECIMOS al DataGridView Que no genere automtica las Columnas
111.
//this.datalistado.AutoGenerateColumns = false;
112.
// Llenamos el DataGridView con LA INFORMACIN
113.
// de Todos Nuestras Presentaciones
114.
este .Mostrar ();
115.
// Deshabilita los Controles
116.
este .Habilitar (false);
117.
// Establece los Botones
118.
esta .Botones ();
119.
}
120.
121.
privada vaco btnBuscar_Click (objeto emisor, EventArgs e)
122.
{
123.
este .BuscarNombre ();
124.
}
125.
126.
privada vaco txtBuscar_TextChanged (objeto emisor, EventArgs e)
127.
{
128.
este .BuscarNombre ();
129.
}
130.
131.
privada vaco btnNuevo_Click (objeto emisor, EventArgs e)
132.
{
133.
este .IsNuevo = verdadero;
134.
este .IsEditar = false;
135.
esta .Botones ();
136.
este .Limpiar ();
137.
este .Habilitar (verdadero);
138.
este .txtNombre.Focus ();
139.
}
140.
141.
privada vaco btnGuardar_Click (objeto emisor, EventArgs e)
142.
{
143.
probar
144.
{
145.
cadena RPTA = "";
146.
si (esta .txtNombre.Text == cadena .Empty)
147.
{
148.
MensajeError ("Falta ingresar ALGUNOS Datos, remarcados Seran");
149.
errorIcono2.SetError (txtNombre, "Ingrese ONU Nombre");
150.
}
151.
otro
152.
{
153.
si (esta .IsNuevo)
154.
{
155.
RPTA = Npresentacion.Insertar (este .txtNombre.Text.Trim (). ToUpper (),
156.
este .txtDescripcion.Text.Trim ());
157.
158.
}
159.
otro
160.
{
161.
RPTA = Npresentacion.Editar
(Convert.ToInt32 (este .txtIdpresentacion.Text),
162.
este .txtNombre.Text.Trim (). ToUpper (),
163.
este .txtDescripcion.Text.Trim ());
164.
}
165.
166.
si (rpta.Equals ("OK"))
167.
{
168.
si (esta .IsNuevo)
169.
{
170.
este .MensajeOk ("Se Inserto de forma correcta del el registro");
171.
}
172.
otro

173.
{
174.
este .MensajeOk ("Se Actualiz de forma correcta del el registro");
175.
}
176.
}
177.
otro
178.
{
179.
este .MensajeError (RPTA);
180.
}
181.
182.
este .IsNuevo = false;
183.
este .IsEditar = false;
184.
esta .Botones ();
185.
este .Limpiar ();
186.
este .Mostrar ();
187.
188.
189.
}
190.
}
191.
capturas (Exception ex)
192.
{
193.
MessageBox.Show (ex.Message + ex.StackTrace);
194.
}
195.
}
196.
197.
privada vaco dataListado_DoubleClick (objeto emisor, EventArgs e)
198.
{
199.
este .txtIdpresentacion.Text =
Convert.ToString (este .dataListado.CurrentRow.Cells["idpresentacion"] .Value);
200.
este .txtNombre.Text =
Convert.ToString (esta .dataListado.CurrentRow.Cells ["nombre"].Value);
201.
este .txtDescripcion.Text =
Convert.ToString (este .dataListado.CurrentRow.Cells["descripcion"] .Value);
202.
203.
este .tabControl1.SelectedIndex = 1;
204.
}
205.
206.
privada vaco btnModificar_Click (objeto emisor, EventArgs e)
207.
{
208.
si (! esta .txtIdpresentacion.Text.Equals (""))
209.
{
210.
este .IsEditar = verdadero;
211.
esta .Botones ();
212.
este .Habilitar (verdadero);
213.
}
214.
otro
215.
{
216.
este .MensajeError ("debe de select Primero el Registro una Modificar");
217.
}
218.
}
219.
220.
privada vaco btnCancelar_Click (objeto emisor, EventArgs e)
221.
{
222.
este .IsNuevo = false;
223.
este .IsEditar = false;
224.
esta .Botones ();
225.
este .Limpiar ();
226.
este .Habilitar (false);
227.
}
228.
229.
privada vaco chkEliminar_CheckedChanged (objeto emisor, EventArgs e)
230.
{
231.
si (chkEliminar.Checked)
232.
{
233.
esta .dataListado.Columns [0] .Visible = verdadero;
234.
}
235.
otro
236.
{
237.
esta .dataListado.Columns [0] .Visible = false;
238.
}
239.
}

240.
241.
privada vaco dataListado_CellContentClick (objeto emisor,
DataGridViewCellEventArgs e)
242.
{
243.
si (e.ColumnIndex == dataListado.Columns ["ELIMINAR"] .index)
244.
{
245.
DataGridViewCheckBoxCell ChkEliminar = (DataGridViewCheckBoxCell)
dataListado.Rows [e.RowIndex] .Cells ["ELIMINAR"];
246.
ChkEliminar.Value = Convert.ToBoolean (ChkEliminar.Value!);
247.
}
248.
}
249.
250.
privada vaco btnEliminar_Click (objeto emisor, EventArgs e)
251.
{
252.
probar
253.
{
254.
DialogResult Opcion;
255.
Opcion = MessageBox.Show ("Realmente DESEA ELIMINAR
los Registros", "Sistema deVentas", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
256.
257.
si (Opcion == DialogResult.OK)
258.
{
259.
cadena Codigo;
260.
cadena Rpta = "";
261.
262.
foreach (fila DataGridViewRow en dataListado.Rows)
263.
{
264.
si (Convert.ToBoolean (row.Cells [0] .Value))
265.
{
266.
Codigo = Convert.ToString (row.Cells [1] .Value);
267.
Rpta = Npresentacion.Eliminar (Convert.ToInt32 (Codigo));
268.
269.
si (Rpta.Equals ("OK"))
270.
{
271.
este .MensajeOk ("Se elimino Correctamente el registro");
272.
}
273.
otro
274.
{
275.
este .MensajeError (Rpta);
276.
}
277.
278.
}
279.
}
280.
este .Mostrar ();
281.
}
282.
}
283.
capturas (Exception ex)
284.
{
285.
MessageBox.Show (ex.Message + ex.StackTrace);
286.
}
287.
}
288.
289.
290.
291.
292.
}
293.
}

Procedimiento Almacenado Login

create proc splogin


@usuario varchar(20),
@password varchar(20)
as
select idtrabajador,apellidos,nombre,acceso from trabajador
where usuario=@usuario and
password=(select password from trabajador where usuario=@usuario)
go
Cdigo fuente Mtodo Login - Clase DTrabajador
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.

public DataTable Login(DTrabajador Trabajador)


{
DataTable DtResultado = new DataTable("trabajador");
SqlConnection SqlCon = new SqlConnection();
try
{
SqlCon.ConnectionString = Conexion.Cn;
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "splogin";
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter ParUsuario = new SqlParameter();
ParUsuario.ParameterName = "@usuario";
ParUsuario.SqlDbType = SqlDbType.VarChar;
ParUsuario.Size = 20;
ParUsuario.Value = Trabajador.Usuario;
SqlCmd.Parameters.Add(ParUsuario);
SqlParameter ParPassword = new SqlParameter();
ParPassword.ParameterName = "@password";
ParPassword.SqlDbType = SqlDbType.VarChar;
ParPassword.Size = 50;
ParPassword.Value = Trabajador.Password;
SqlCmd.Parameters.Add(ParPassword);
SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
SqlDat.Fill(DtResultado);
}
catch (Exception ex)
{
DtResultado = null;
}
return DtResultado;
}

Cdigo fuente Mtodo Login - Clase NTrabajador


1.
2.
3.

public static DataTable Login(string usuario,string password)


{
DTrabajador Obj = new DTrabajador();

4.
5.
6.
7.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.

Obj.Usuario = usuario;
Obj.Password = password;
return Obj.Login(Obj);
}
using
using
using
using
using
using
using
using
using

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

using CapaNegocio;
namespace CapaPresentacion
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
LblHora.Text = DateTime.Now.ToString();
}
private void BtnSalir_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void TmHora_Tick(object sender, EventArgs e)
{
LblHora.Text = DateTime.Now.ToString();
}
private void BtnIngresar_Click(object sender, EventArgs e)
{
DataTable Datos= NTrabajador.Login(this.TxtUsuario.Text, this.TxtPassword.Text);

37.
//Evaluamos si no existen los Datos
38.
if (Datos.Rows.Count==0)
39.
{
40.
MessageBox.Show("No Tiene Acceso al Sistema", "Sistema Ventas", MessageBo
xButtons.OK, MessageBoxIcon.Error);
41.
}
42.
else
43.
{
44.
FrmPrincipal frm = new FrmPrincipal();
45.
frm.Idtrabajador = Datos.Rows[0][0].ToString();
46.
frm.Apellidos = Datos.Rows[0][1].ToString();
47.
frm.Nombre = Datos.Rows[0][2].ToString();
48.
frm.Acceso = Datos.Rows[0][3].ToString();
49.
50.
frm.Show();
51.
this.Hide();
52.
53.
}
54.
55.
}
56.
}
57.
}

Cdigo Fuente del FrmPrincipal para gestionar los accesos a los mdulos

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.

public string Idtrabajador="";


public string Apellidos = "";
public string Nombre = "";
public string Acceso = "";
private void FrmPrincipal_Load(object sender, EventArgs e)
{
GestionUsuarios();
}
private void GestionUsuarios()
{
//Controlamos los accesos Administrador, Vendedor, Almacenero
if (Acceso == "Administrador")
{
this.MnuAlmacen.Enabled = true;
this.MnuCompras.Enabled = true;
this.MnuVentas.Enabled = true;
this.MnuMantenimiento.Enabled = true;
this.MnuConsultas.Enabled = true;
this.MnuHerramientas.Enabled = true;
this.TsCompras.Enabled = true;
this.TsVentas.Enabled = true;
}
else if (Acceso == "Vendedor")
{
this.MnuAlmacen.Enabled = false;
this.MnuCompras.Enabled = false;
this.MnuVentas.Enabled = true;
this.MnuMantenimiento.Enabled = false;
this.MnuConsultas.Enabled = true;
this.MnuHerramientas.Enabled = true;
this.TsCompras.Enabled = false;
this.TsVentas.Enabled = true;
}
else if (Acceso == "Almacenero")
{
this.MnuAlmacen.Enabled = true;
this.MnuCompras.Enabled = true;
this.MnuVentas.Enabled = false;
this.MnuMantenimiento.Enabled = false;
this.MnuConsultas.Enabled =true;
this.MnuHerramientas.Enabled = true;
this.TsCompras.Enabled = true;
this.TsVentas.Enabled = true;
}
else
{
this.MnuAlmacen.Enabled = false;
this.MnuCompras.Enabled = false;
this.MnuVentas.Enabled = false;
this.MnuMantenimiento.Enabled = false;
this.MnuConsultas.Enabled = false;
this.MnuHerramientas.Enabled = false;
this.TsCompras.Enabled = false;
this.TsVentas.Enabled = false;
}
}

Вам также может понравиться