/// <summary> /// Método llamado desde el onclick con el cuál se crea el empleado /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void CrearEmpleado(object sender, EventArgs e) { try { EmpleadosLN empleado = new EmpleadosLN(); var archivo = new ArchivoLN(); var data = ObtenerDatos(); if (data.url_Imagen != string.Empty) { var resultado = archivo.NuevoArchivo(new Archivo { url = data.url_Imagen }); data.id_archivo = resultado.id_archivo; } DataTable dt = empleado.NuevoEmpleado(data); if (dt.HasErrors) { Page_Load(sender, e); } else { Response.Redirect("ListadoEmpleados.aspx"); } } catch (Exception ex) { l_error.Visible = true; l_error.InnerText = "Error: " + ex.Message; } }
/// <summary> /// Método con el cuál se obtienen todos los empleados o un empleado en especifico, según la busqueda ingresada /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void GetEmpleados(object sender, EventArgs e) { int codigo = String.IsNullOrEmpty(tb_codigo.Text) ? -1 : Convert.ToInt32(tb_codigo.Text); string primer_nombre = String.IsNullOrEmpty(tb_primer_nombre.Text) ? "" : tb_primer_nombre.Text.ToUpper(); string segundo_nombre = String.IsNullOrEmpty(tb_segundo_nombre.Text) ? "" : tb_segundo_nombre.Text.ToUpper(); string primer_apellido = String.IsNullOrEmpty(tb_primer_apellido.Text) ? "" : tb_primer_apellido.Text.ToUpper(); string segundo_apellido = String.IsNullOrEmpty(tb_segundo_apellido.Text) ? "" : tb_segundo_apellido.Text.ToUpper(); string cui = String.IsNullOrEmpty(tb_cui.Text) ? "" : tb_cui.Text.ToUpper(); EmpleadosLN empleadoLN = new EmpleadosLN(); DataTable empleados = empleadoLN.Search(codigo, cui, primer_nombre, segundo_nombre, primer_apellido, segundo_apellido); for (int i = 0; i < empleados.Rows.Count; i++) { int fil = i + 1; int id = Convert.ToInt32(empleados.Rows[i]["id_empleado"]); tabla_empleados.Rows.Add(NewRow()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells.Add(NewCell()); tabla_empleados.Rows[fil].Cells[0].Text = empleados.Rows[i]["codigo"].ToString(); tabla_empleados.Rows[fil].Cells[1].Text = empleados.Rows[i]["primer_nombre"].ToString(); tabla_empleados.Rows[fil].Cells[2].Text = empleados.Rows[i]["segundo_nombre"].ToString(); tabla_empleados.Rows[fil].Cells[3].Text = empleados.Rows[i]["primer_apellido"].ToString(); tabla_empleados.Rows[fil].Cells[4].Text = empleados.Rows[i]["segundo_apellido"].ToString(); tabla_empleados.Rows[fil].Cells[5].Text = empleados.Rows[i]["cui"].ToString(); tabla_empleados.Rows[fil].Cells[6].Controls.Add(BotonEditar(id)); } }
protected void btnEliminar_Click(object sender, EventArgs e) { try { limpiarControlesError(); int idEmpleado = 0; int.TryParse(txtNoEmpleado.Text, out idEmpleado); if (idEmpleado == 0) { throw new Exception("No existe Empleado para eliminar"); } eEmpleadosLN = new EmpleadosLN(); DataSet dsResultado = eEmpleadosLN.EliminarEmpleado(idEmpleado); if (bool.Parse(dsResultado.Tables["RESULTADO"].Rows[0]["ERRORES"].ToString())) { throw new Exception(dsResultado.Tables["RESULTADO"].Rows[0]["MSG_ERROR"].ToString()); } NuevoIngresoEmpleado(); lblSuccess.Text = "Empleado eliminado correctamente!"; } catch (Exception ex) { lblError.Text = "btnEliminar(). " + ex.Message; } }
public void NuevoIngresoEmpleado() { try { validarEstadoEmpleado(0); txtNoEmpleado.Text = "0"; txtNombres.Text = txtApellidos.Text = txtDireccion.Text = string.Empty; rblGenero.SelectedValue = "1"; txtFechaNacimiento.Text = string.Empty; txtCui.Text = txtNit.Text = txtTel.Text = txtEmail.Text = string.Empty; ddlUnidades.SelectedIndex = 0; ddlPuestos.SelectedIndex = 0; ddlRenglones.SelectedIndex = 0; ddlEstado.SelectedIndex = 0; ddlEstado.Enabled = false; eEmpleadosLN = new EmpleadosLN(); eEmpleadosLN.DdlUnidades(ddlUnidades); eEmpleadosLN.DdlPuestos(ddlPuestos); } catch (Exception ex) { throw new Exception("NuevoPedidoEnc(). " + ex.Message); } }
protected void btnGuardar_Click(object sender, EventArgs e) { try { if (validarControlesABC()) { int idEmpleado = 0; int.TryParse(txtNoEmpleado.Text, out idEmpleado); eEmpleadosEN = new EmpleadosEN(); eEmpleadosEN.ID_EMPLEADO = idEmpleado; eEmpleadosEN.NOMBRES = txtNombres.Text; eEmpleadosEN.APELLIDOS = txtApellidos.Text; eEmpleadosEN.DIRECCION = txtDireccion.Text; eEmpleadosEN.TELEFONO = txtTel.Text; eEmpleadosEN.EMAIL = txtEmail.Text; eEmpleadosEN.ID_GENERO = int.Parse(rblGenero.SelectedValue); eEmpleadosEN.NIT = txtNit.Text; eEmpleadosEN.CUI = txtCui.Text; eEmpleadosEN.FECHA_NACIMINETO = txtFechaNacimiento.Text; eEmpleadosEN.ID_PUESTO = int.Parse(ddlPuestos.SelectedValue); eEmpleadosEN.RENGLON = ddlRenglones.SelectedValue; eEmpleadosEN.ID_UNIDAD = int.Parse(ddlUnidades.SelectedValue); eEmpleadosEN.ID_ESTADO = int.Parse(ddlEstado.SelectedValue); eEmpleadosEN.SUELDO_NOMINAL = decimal.Parse(txtSueldo.Text); eEmpleadosEN.USUARIO = Session["USUARIO"].ToString(); eEmpleadosEN.Motivo_Baja = txtmBaja.Text; if (validarEstadoEmpleado(idEmpleado)) { eEmpleadosLN = new EmpleadosLN(); DataSet dsResultado = eEmpleadosLN.AlmacenarEmpleado(eEmpleadosEN); if (bool.Parse(dsResultado.Tables[0].Rows[0]["ERRORES"].ToString())) { throw new Exception("No se INSERTÓ/ACTUALIZÓ el pedido: " + dsResultado.Tables[0].Rows[0]["MSG_ERROR"].ToString()); } int.TryParse(dsResultado.Tables[0].Rows[0]["VALOR"].ToString(), out idEmpleado); txtNoEmpleado.Text = idEmpleado.ToString(); validarEstadoEmpleado(idEmpleado); btnNuevo_Click(sender, e); lblSuccess.Text = "Empleado ALMACENADO exitosamente: "; } } } catch (Exception ex) { lblError.Text = "btnGuardar(). " + ex.Message; } }
protected void filtrarGrid() { try { gridEmpleados.DataSource = null; gridEmpleados.DataBind(); gridEmpleados.SelectedIndex = -1; eEmpleadosLN = new EmpleadosLN(); DataSet dsResultado = eEmpleadosLN.InformacionEmpleado(0, 5); if (bool.Parse(dsResultado.Tables["RESULTADO"].Rows[0]["ERRORES"].ToString())) { throw new Exception(dsResultado.Tables["RESULTADO"].Rows[0]["MSG_ERROR"].ToString()); } if (dsResultado.Tables["BUSQUEDA"].Rows.Count > 0 && dsResultado.Tables["BUSQUEDA"].Rows[0]["ID"].ToString() != "") { gridEmpleados.DataSource = dsResultado.Tables["BUSQUEDA"]; gridEmpleados.DataBind(); string filtro = string.Empty; object obj = gridEmpleados.DataSource; System.Data.DataTable tbl = gridEmpleados.DataSource as System.Data.DataTable; System.Data.DataView dv = tbl.DefaultView; filtro = "0 = 0"; if (!txtBValor.Text.Equals(string.Empty)) { filtro += " AND " + rblCriterio.SelectedValue + " LIKE '%" + txtBValor.Text + "%'"; } dv.RowFilter = filtro; gridEmpleados.DataSource = dv; gridEmpleados.DataBind(); } else { gridEmpleados.DataSource = null; gridEmpleados.DataBind(); } } catch (Exception ex) { throw new Exception("filtrarGridDetalles(). " + ex.Message); } }
/// <summary> /// Asigna las descripciones de alergias y enfermedades que tiene el empleado a las listas /// </summary> private void DarValoresAlergiasEnfermedades() { EmpleadosLN empleado = new EmpleadosLN(); List <bool> StateAlergias = empleado.AlergiasSelected(Convert.ToInt32(Request["id"]), d_alergias.Items.Cast <ListItem>().ToList()); List <bool> StateEnfermedades = empleado.EnfermedadesSelected(Convert.ToInt32(Request["id"]), d_enfermedades.Items.Cast <ListItem>().ToList()); for (int i = 0; i < d_alergias.Items.Count; i++) { d_alergias.Items.Cast <ListItem>().ElementAt(i).Selected = StateAlergias[i]; } for (int i = 0; i < d_enfermedades.Items.Count; i++) { d_enfermedades.Items.Cast <ListItem>().ElementAt(i).Selected = StateEnfermedades[i]; } }
/// <summary> /// Método con el cuál se obtienen los datos generales del empleado y se editan /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void EditarEmpleado(object sender, EventArgs e) { try { EmpleadosLN empleado = new EmpleadosLN(); var data = ObtenerDatos(); var archivo = new ArchivoLN(); if (banderaCambioImagen.Value == "1" && data.id_archivo.ToString() != "0" && data.url_Imagen != string.Empty) { var resultado = archivo.ModificarArchivo(new Archivo { url = data.url_Imagen , id_archivo = data.id_archivo ?? 0 }); data.id_archivo = resultado.id_archivo; } else if (data.url_Imagen != string.Empty) { var resultado = archivo.NuevoArchivo(new Archivo { url = data.url_Imagen }); data.id_archivo = resultado.id_archivo; } DataTable dt = empleado.EditarEmpleado(data); if (!dt.HasErrors) { ScriptManager.RegisterClientScriptBlock(this, typeof(string), "Mensaje", "alert('Datos guardados éxitosamente');", true); Response.Redirect("Editar.aspx?id=" + Request["id"]); } else { l_error.Visible = true; l_error.InnerText = "Error inesperado"; } } catch (Exception ex) { l_error.Visible = true; l_error.InnerText = "Error: " + ex.Message; } }
protected void generateExcelSheet_click(object sender, EventArgs e) { try { DataTable dt = new DataTable(); GridView gv = new GridView(); EmpleadosLN empleadoLN = new EmpleadosLN(); gv.DataSource = empleadoLN.ReporteEmpleados(); gv.DataBind(); Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=ListaEmpleados.xls"); Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); gv.RenderControl(hw); Response.Output.Write(sw.ToString()); Response.End(); } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, typeof(string), "Error", "alert('Ocurrio un error innesperado en la descarga del archivo');", true); } }
/// <summary> /// Método con el que se obtienen los datos de la condición médica y se editan /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void EditarCondicionMedica(object sender, EventArgs e) { try { EmpleadosLN empleado = new EmpleadosLN(); DataTable dt = empleado.EditarAlergiaEnfermedad(ObtenerData()); if (!dt.HasErrors) { ScriptManager.RegisterClientScriptBlock(this, typeof(string), "Mensaje", "alert('Datos guardados éxitosamente');", true); Response.Redirect("Editar.aspx?id=" + Request["id"] + "#tab_condicion_medica"); } else { l_error.Visible = true; l_error.InnerText = "Error inesperado"; } } catch (Exception ex) { l_error.Visible = true; l_error.InnerText = "Error: " + ex.Message; } }
protected bool validarEstadoEmpleado(int idEmpleado) { bool pedidoValido = false; try { if (idEmpleado == 0) { btnEliminar.Visible = btnGuardar.Visible = btnLimpiarC.Visible = true; lblErrorPoa.Text = lblError.Text = ""; pedidoValido = true; } else { btnEliminar.Visible = btnGuardar.Visible = btnLimpiarC.Visible = false; eEmpleadosLN = new EmpleadosLN(); DataSet dsResultado = eEmpleadosLN.InformacionEmpleado(idEmpleado, 6); if (bool.Parse(dsResultado.Tables["RESULTADO"].Rows[0]["ERRORES"].ToString())) { throw new Exception(dsResultado.Tables["RESULTADO"].Rows[0]["MSG_ERROR"].ToString()); } if (dsResultado.Tables.Count == 0) { throw new Exception("Error al consultar el estado del empleado."); } if (dsResultado.Tables[0].Rows.Count == 0) { throw new Exception("No existe estado asignado al empleado"); } int idEstadoEmpleado = 1; if (dsResultado.Tables["BUSQUEDA"].Rows.Count > 0) { int.TryParse(dsResultado.Tables["BUSQUEDA"].Rows[0]["ESTADO"].ToString(), out idEstadoEmpleado); } //EL EMPLEADO ESTÁ DE ALTA if (idEstadoEmpleado == 1) { btnEliminar.Visible = btnGuardar.Visible = btnLimpiarC.Visible = true; lblErrorPoa.Text = lblError.Text = ""; pedidoValido = true; }//EL EMPLEADO ESTÁ DE BAJA else if (idEstadoEmpleado == 2) { //btnEliminar.Visible = btnGuardar.Visible = btnLimpiarC.Visible = false; btnEliminar.Visible = btnGuardar.Visible = btnLimpiarC.Visible = true; //lblErrorPoa.Text = lblError.Text = "El PEDIDO seleccionado se encuenta en estado: " + lblEstadoPedido.Text + ", por: " + dsResultado.Tables["BUSQUEDA"].Rows[0]["OBSERVACIONES"].ToString(); lblErrorPoa.Text = lblError.Text = ""; pedidoValido = true; } } } catch (Exception ex) { lblErrorPoa.Text = lblError.Text = "Error: " + ex.Message; } return(pedidoValido); }
protected void Page_LoadComplete(object sender, EventArgs e) { if (IsPostBack == false) { try { btnNuevo_Click(sender, e); string s = Convert.ToString(Request.QueryString["No"]); if (s != null) { int idEmpleado = 0; int.TryParse(s, out idEmpleado); txtNoEmpleado.Text = idEmpleado.ToString(); eEmpleadosLN = new EmpleadosLN(); DataSet dsResultado = eEmpleadosLN.InformacionEmpleado(idEmpleado, 6); if (bool.Parse(dsResultado.Tables["RESULTADO"].Rows[0]["ERRORES"].ToString())) { throw new Exception(dsResultado.Tables["RESULTADO"].Rows[0]["MSG_ERROR"].ToString()); } if (dsResultado.Tables.Count == 0) { throw new Exception("Error al consultar la información del empleado."); } if (dsResultado.Tables[0].Rows.Count == 0) { throw new Exception("No existe información del empleado"); } txtNombres.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["NOMBRES"].ToString(); txtApellidos.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["APELLIDOS"].ToString(); txtDireccion.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["DIRECCION"].ToString(); txtFechaNacimiento.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["FECHA_NACIMIENTO"].ToString(); txtCui.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["CUI"].ToString(); txtNit.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["NIT"].ToString(); txtTel.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["TELEFONO"].ToString(); txtEmail.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["EMAIL"].ToString(); txtSueldo.Text = dsResultado.Tables["BUSQUEDA"].Rows[0]["SUELDO_BASE"].ToString(); int idGenero, idUnidad, idPuesto, idEstado; string renglon; int.TryParse(dsResultado.Tables["BUSQUEDA"].Rows[0]["ID_GENERO"].ToString(), out idGenero); int.TryParse(dsResultado.Tables["BUSQUEDA"].Rows[0]["ID_UNIDAD"].ToString(), out idUnidad); int.TryParse(dsResultado.Tables["BUSQUEDA"].Rows[0]["ID_PUESTO"].ToString(), out idPuesto); int.TryParse(dsResultado.Tables["BUSQUEDA"].Rows[0]["ESTADO"].ToString(), out idEstado); renglon = dsResultado.Tables["BUSQUEDA"].Rows[0]["RENGLON"].ToString(); ListItem item = rblGenero.Items.FindByValue(idGenero.ToString()); if (item != null) { rblGenero.SelectedValue = idGenero.ToString(); } item = ddlUnidades.Items.FindByValue(idUnidad.ToString()); if (item != null) { ddlUnidades.SelectedValue = idUnidad.ToString(); } item = ddlPuestos.Items.FindByValue(idPuesto.ToString()); if (item != null) { ddlPuestos.SelectedValue = idPuesto.ToString(); } item = ddlRenglones.Items.FindByValue(renglon); if (item != null) { ddlRenglones.SelectedValue = renglon.ToString(); } item = ddlEstado.Items.FindByValue(idEstado.ToString()); if (item != null) { ddlEstado.SelectedValue = idEstado.ToString(); } ddlEstado.Enabled = true; validarEstadoEmpleado(idEmpleado); } } catch (Exception ex) { lblError.Text = "Page_LoadComplete(). " + ex.Message; } } }
/// <summary> /// Carga todos los datos que se tienen actualmente del empleado que se va a editar /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { String usuario = this.Session["usuario"].ToString(); UsuarioAD Datos = new UsuarioAD(); DataTable Usuario = Datos.usuarioRRHH(usuario); if (Usuario.Rows.Count == 0) { RRHH.Value = "0"; } else { RRHH.Value = "1"; } int idConstancia = 0; EmpleadosLN empleadoLN = new EmpleadosLN(); Session["id"] = Request["id"]; id = Convert.ToInt32(Request["id"]); DataTable result = empleadoLN.GetEmpleado(id); if (Page.IsPostBack && Request["delC"] != null && int.TryParse(Request["delC"].ToString(), out idConstancia)) { ConstanciaEducativaLN ln = new ConstanciaEducativaLN(); ln.EliminarConstancia(new ConstanciaEducativa { id_constancia = idConstancia }); } string eventTarget = Request.Params.Get("__EVENTTARGET"); if (Page.IsPostBack && Request["loadC"] != null && int.TryParse(Request["loadC"].ToString(), out idConstancia) && (eventTarget != string.Empty) ) { if (eventTarget != "ctl00$ContentPlaceHolder3$btnAgregarConstanciaEdu") { ConstanciaEducativaLN ln = new ConstanciaEducativaLN(); var dt = ln.ConsultarConstancia(idConstancia); CargarConstanciaEdicion(dt); } } if (!Page.IsPostBack) { LlenarDropDowns(); if (!result.HasErrors) { l_empleado.Text = result.Rows[0]["codigo"].ToString() + " - " + result.Rows[0]["primer_nombre"].ToString() + " " + result.Rows[0]["primer_apellido"].ToString(); codigo.Value = result.Rows[0]["codigo"].ToString(); primer_nombre.Value = result.Rows[0]["primer_nombre"].ToString(); primer_apellido.Value = result.Rows[0]["primer_apellido"].ToString(); segundo_nombre.Value = result.Rows[0]["segundo_nombre"].ToString(); segundo_apellido.Value = result.Rows[0]["segundo_apellido"].ToString(); apellido_casada.Value = result.Rows[0]["apellido_casada"].ToString(); cui.Value = result.Rows[0]["cui"].ToString(); fecha_nacimiento.Value = Convert.ToDateTime(result.Rows[0]["fecha_nacimiento"].ToString()).ToString("yyyy-MM-dd"); lugar_nacimiento.Value = result.Rows[0]["lugar_nacimiento"].ToString(); d_genero.Value = result.Rows[0]["id_genero"].ToString(); d_profesion.Value = result.Rows[0]["id_profesion"].ToString(); d_estado_civil.Value = result.Rows[0]["id_estado_civil"].ToString(); casa_propia.Checked = result.Rows[0]["tipo_vivienda"].ToString() == "1" ? true : false; alquiler.Checked = result.Rows[0]["tipo_vivienda"].ToString() == "1" ? false : true; direccion_residencial.Value = result.Rows[0]["direccion_residencial"].ToString(); correo.Value = result.Rows[0]["correo"].ToString(); telefono_movil.Value = result.Rows[0]["telefono_movil"].ToString(); telefono_residencial.Value = result.Rows[0]["telefono_residencial"].ToString(); igss.Value = result.Rows[0]["afiliacion_igss"].ToString(); nit.Value = result.Rows[0]["nit"].ToString(); d_tipo_licencia.Value = result.Rows[0]["id_tipo_licencia"].ToString(); numero_licencia.Value = result.Rows[0]["licencia_conducir"].ToString(); imagenEmpleado.ImageUrl = result.Rows[0]["ruta"]?.ToString().Trim() == string.Empty ? "~/Content/Imagenes/empleado_default.png" : result.Rows[0]["ruta"]?.ToString().Trim(); banderaCambioImagen.Value = "0"; id_archivo.Value = result.Rows[0]["id_fotografia"]?.ToString().Trim() ?? ""; d_tipo_sangre.Value = result.Rows[0]["id_tipo_sangre"].ToString(); //Carga Tabs ListadoFamiliares(); CargarConstancias(); DarValoresAlergiasEnfermedades(); LlenarContrato(id); d_municipio_cui.Value = result.Rows[0]["id_municipio_cui"].ToString(); d_municipio_residencia.Value = result.Rows[0]["id_municipio_residencial"].ToString(); } } }