You are on page 1of 7

using System;

using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EC.Darwin.LogicaNegocios;
using nmExcel = Microsoft.Office.Interop.Excel;
namespace EC.Darwin.GUIAsistencia
{
public partial class FrmDatosPersona : Form
{
public FrmDatosPersona()
{
InitializeComponent();
}
private void FrmDatosCliente_Load(object sender, EventArgs e)
{
try
{
ConsultarEmpleados();
HabilitarCombo(false);
}
catch (Exception)
{
throw;
}
}
private void timer1_Tick_1(object sender, EventArgs e)
{
txtReloj.Text = DateTime.Now.ToLongTimeString();
}
private void dgvEmpleado_CellEnter(object sender, DataGridViewCellEventA
rgs e)
{
DataSet dsPropiedad = new DataSet();
dsPropiedad = new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().Con
sultarEmpleado();
txtCedula.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].Cell
s["PERSON_CEDULA"].Value.ToString();
txtNombre.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].Cell
s["PERSON_NOMBRE"].Value.ToString();
txtTelefono.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].Ce
lls["PERSON_TELEFONO"].Value.ToString();
txtDireccion.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].C
ells["PERSON_DIRECCION"].Value.ToString();
txtDireccion.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].C
ells["PERSON_DIRECCION"].Value.ToString();
txtCargo.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].Cells
["CARGO_NOMBRE"].Value.ToString();

txtHorario.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].Cel
ls["HORARIO_NOMBRE"].Value.ToString();
txtFoto.Text = dgvEmpleado.Rows[dgvEmpleado.CurrentRow.Index].Cells[
"PERSON_FOTO"].Value.ToString();
HabilitarCombo(false);
}
public void Foto(string strPath) {
try
{
timer1.Start();
pbFoto.Image = Image.FromFile(@""+strPath);
}
catch (Exception)
{
// pbFoto.Image =Image.FromFile( @"D:\REGISTRO ASISTENCIA\ICONOS\
interrogacion.jpg");
}
}
private void txtFoto_TextChanged(object sender, EventArgs e)
{
Foto(txtFoto.Text);
}
public string ObtenerPath() {
try
{
string FileName = string.Empty;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Envi
ronment.SpecialFolder.Personal);
openFileDialog.Filter = "Text Files (*.jpg)|*.jpg|All Files (*.*
)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
FileName = openFileDialog.FileName;
}
return FileName;
}
catch (Exception)
{
throw;
}
}
private void btnPath_Click(object sender, EventArgs e)
{
txtFoto.Text = ObtenerPath();

}
public static void Limpiar(Form ofrm)
{
// Checar todos los textbox del formulario
foreach (Control c in ofrm.Controls)
{
if (c is GroupBox)
{
foreach (Control txt in c.Controls)
{
if (txt is TextBox)
{
txt.Text = String.Empty; // Eliminar el texto de
l TextBox
}
}
}
}
}
private void btnNuevo_Click(object sender, EventArgs e)
{
Limpiar(this);
HabilitarCombo(true);
LlenarComboCargo();
LlenarComboHorario();
}
private void btnActualizar_Click(object sender, EventArgs e)
{
try
{
DataSet ds = new DataSet();
DataTable dtInfo = new DataTable();
dtInfo.Columns.Add("PERSON_CEDULA", typeof(string));
dtInfo.Columns.Add("PERSON_NOMBRE", typeof(string));
dtInfo.Columns.Add("PERSON_TELEFONO", typeof(string));
dtInfo.Columns.Add("PERSON_DIRECCION", typeof(string));
dtInfo.Columns.Add("PERSON_FOTO", typeof(string));
dtInfo.Rows.Add(txtCedula.Text,txtNombre.Text,txtTelefono.Text,t
xtDireccion.Text,txtFoto.Text);
ds.Tables.Add(dtInfo);
new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().ActualizarEmp
leado(ds);
ConsultarEmpleados();
}
catch (Exception)
{
throw;
}

}
private void ConsultarEmpleados() {
try
{
dgvEmpleado.DataSource = new EC.Darwin.LogicaNegocios.ClsAccesoA
sistencia().ConsultarEmpleado().Tables[0];
dgvEmpleado.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Al
lCells;
}
catch (Exception)
{
throw;
}
}
private void LlenarComboCargo() {
try
{
DataSet ds =
new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().Consultar
Cargo();
cmbCargo.DataSource = ds.Tables[0].DefaultView;
cmbCargo.DisplayMember = "CARGO_NOMBRE";
cmbIdCargo.DataSource = ds.Tables[0].DefaultView;
cmbIdCargo.DisplayMember = "ID_CARGO";
}
catch (Exception)
{
throw;
}
}
private void LlenarComboHorario()
{
try
{
DataSet ds =
new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().Consultar
Horario();
cmbHorario.DataSource = ds.Tables[0].DefaultView;
cmbHorario.DisplayMember = "HORARIO_NOMBRE";
cmbIdHorario.DataSource = ds.Tables[0].DefaultView;
cmbIdHorario.DisplayMember = "ID_HORARIO";
}
catch (Exception)
{
throw;

}
}
public void HabilitarCombo( bool bol)
{
lstCargo.Visible=bol;
lstHorario.Visible=bol;
cmbCargo.Visible=bol;
cmbIdCargo.Visible=false;
cmbHorario.Visible=bol;
cmbIdHorario.Visible=false;
txtCargo.Enabled = false;
txtHorario.Enabled = false;
txtCodigo.Visible = bol;
lstCodigo.Visible = bol;
btnAgregar.Visible = bol;
btnAgregar.Enabled = bol;

}
private void InsertarEmpleado() {
try
{
string strIdEmpleado = string.Empty;
DataSet ds = new DataSet();
DataTable dtInfo = new DataTable();
dtInfo.Columns.Add("ID_CARGO", typeof(string));
dtInfo.Columns.Add("ID_HORARIO", typeof(string));
dtInfo.Columns.Add("PERSON_CEDULA", typeof(string));
dtInfo.Columns.Add("PERSON_NOMBRE", typeof(string));
dtInfo.Columns.Add("PERSON_CLAVE", typeof(string));
dtInfo.Columns.Add("PERSON_TELEFONO", typeof(string));
dtInfo.Columns.Add("PERSON_DIRECCION", typeof(string));
dtInfo.Columns.Add("PERSON_FOTO", typeof(string));
dtInfo.Rows.Add(cmbIdCargo.Text,cmbIdHorario.Text,txtCedula.Text
, txtNombre.Text,txtCodigo.Text,txtTelefono.Text, txtDireccion.Text, txtFoto.Tex
t);
ds.Tables.Add(dtInfo);
new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().InsertarEmple
ado(ds);
ConsultarEmpleados();
string inicial = "0:00:00";
DataSet dsInfo = new DataSet();
dsInfo = new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().Cons
ultarEmpleado(txtCodigo.Text);
strIdEmpleado = dsInfo.Tables[0].Rows[0]["ID_PERSONA"].ToString(
);
new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().InsertarDetal
lePrimera(strIdEmpleado);
}
catch (Exception)
{

throw;
}
}
private void btnAgregar_Click(object sender, EventArgs e)
{
try
{
InsertarEmpleado();
}
catch (Exception)
{
throw;
}
}
private void btnEliminar_Click(object sender, EventArgs e)
{
try
{
int valor =Convert.ToInt32( MessageBox.Show("Desea eliminar el r
egistro","Pregunta",MessageBoxButtons.YesNo,MessageBoxIcon.Question));
string a = "";
if (valor==6)
{
new EC.Darwin.LogicaNegocios.ClsAccesoAsistencia().EliminarE
mpleado(txtCedula.Text);
}
ConsultarEmpleados();
}
catch (Exception)
{
throw;
}
}
private void btnExportar_Click(object sender, EventArgs e)
{
}
private void exportar() {
nmExcel.ApplicationClass ExcelApp = new nmExcel.ApplicationClass();
ExcelApp.Application.Workbooks.Add(Type.Missing);
ExcelApp.Columns.ColumnWidth = 12;
int fila = 1;
int columna = 1;
for (int i = 0; i < dgvEmpleado.Rows.Count; i++)
{
fila++;
DataGridViewRow Fila = dgvEmpleado.Rows[i];
columna = 0;
for (int j = 0; j < Fila.Cells.Count; j++)
{

columna++;
ExcelApp.Cells[fila + 1, columna + 1] = Fila.Cells[j].Value;
}
}
// ---------- cuadro de dialogo para Guardar
SaveFileDialog CuadroDialogo = new SaveFileDialog();
CuadroDialogo.DefaultExt = "xlsx";
CuadroDialogo.Filter = "xlsx file(*.xlsx)|*.xlsx";
CuadroDialogo.AddExtension = true;
CuadroDialogo.RestoreDirectory = true;
CuadroDialogo.Title = "Guardar";
CuadroDialogo.InitialDirectory = @"c:\";
if (CuadroDialogo.ShowDialog() == DialogResult.OK)
{
ExcelApp.ActiveWorkbook.SaveCopyAs(CuadroDialogo.FileName);
ExcelApp.ActiveWorkbook.Saved = true;
CuadroDialogo.Dispose();
CuadroDialogo = null;
ExcelApp.Quit();
}
else
{
MessageBox.Show("No se pudo guardar Datos .. ");
}
}
private void btnExportar_Click_1(object sender, EventArgs e)
{
exportar();
}
private void txtReloj_TextChanged(object sender, EventArgs e)
{
}
}
}

You might also like