public void RecibetrabajadorIni(string codigo, bool zselect)
 {
     if (zselect)
     {
         var BL = new tb_plla_fichatrabajadoresBL();
         var BE = new tb_plla_fichatrabajadores();
         BE.Fichaid = codigo;
         BE.Norden = 2;
         BE.Estado_trabaj = 0;
         tmpcursor = BL.GetAll_Consulta(VariablesPublicas.EmpresaID, BE).Tables[0];
         if (BL.Sql_Error.Length == 0)
         {
             if (tmpcursor.Rows.Count > 0)
             {
                 Tabla.Rows.Add(VariablesPublicas.INSERTINTOTABLE(Tabla));
                 Tabla.Rows[Tabla.Rows.Count - 1]["fichaid"] = tmpcursor.Rows[0]["fichaid"];
                 Tabla.Rows[Tabla.Rows.Count - 1]["nombrelargo"] = tmpcursor.Rows[0]["nombrelargo"].ToString().Trim();
                 Tabla.AcceptChanges();
                 U_RefrescaControles();
                 Examinar.Focus();
                 for (lc_cont = 0; lc_cont <= Examinar.Rows.Count - 1; lc_cont++)
                 {
                     if (Examinar.Rows[lc_cont].Cells["fichaid"].Value.ToString() == tmpcursor.Rows[0]["fichaid"].ToString())
                     {
                         Examinar.CurrentCell = Examinar.Rows[lc_cont].Cells["nombrelargo"];
                         Examinar.BeginEdit(true);
                         Examinar.CurrentCell = Examinar.Rows[lc_cont].Cells["salxretener"];
                         break;
                     }
                 }
             }
         }
     }
 }
 private void btnAccion_Click(object sender, EventArgs e)
 {
     string ficha = null;
     string nombre = null;
     string empresa = null;
     if ((dgTrabProceso.CurrentRow != null))
     {
         ficha = dgTrabProceso["ficha", dgTrabProceso.CurrentRow.Index].Value.ToString();
         empresa = dgTrabProceso["empresa", dgTrabProceso.CurrentRow.Index].Value.ToString();
         nombre = dgTrabProceso["dficha", dgTrabProceso.CurrentRow.Index].Value.ToString().Trim();
         if (_varProcesoCesar == 1)
         {
             Panel.Visible = true;
             validacion_panel(false);
         }
         if (_varProcesoCesar == 2)
         {
             if (MessageBox.Show("Desea Desactivar al trabajador (" + ficha + ") " + nombre, string.Empty, MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 var retorno = false;
                 var BL = new tb_plla_fichatrabajadoresBL();
                 var BE = new tb_plla_fichatrabajadores();
                 BE.Fichaid = ficha.Trim();
                 BE.Empresaid = empresa.Trim();
                 retorno = BL.DesactivarTrabajadorUpdate(VariablesPublicas.EmpresaID, BE);
                 if (retorno)
                 {
                     MessageBox.Show("Desactivado Correctamente !!", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     if (swB == 2)
                     {
                         DesEnlazaControles();
                     }
                     if (swB == 1)
                     {
                         EnlazarControles();
                     }
                 }
                 else
                 {
                     MessageBox.Show("Hubo problemas al momento de Desactivar, cierra la ventana e intente de nuevo", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
         }
     }
 }
        public bool U_Validacion()
        {
            var xmsg = string.Empty;
            var objeto = new object();
            DataTable tmptabla = null;

            if (txtnombres.Text.Trim().Length == 0)
            {
                xmsg = "Ingrese Apellidos y Nombres del Trabajador";
                objeto = txtNombrelargo;
            }
            else
            {
                if (txtDni.Text.Length > 0)
                {
                    if (u_n_opsel == 1 | (!(j_Ruc == txtDni.Text)))
                    {
                        var BL = new tb_plla_fichatrabajadoresBL();
                        var BE = new tb_plla_fichatrabajadores();
                        BE.Tipdocid = cboTipdoc.SelectedValue.ToString();
                        BE.Nrodni = txtDni.Text.Trim();
                        tmptabla = BL.GetAll(VariablesPublicas.EmpresaID, BE).Tables[0];
                        if (tmptabla.Rows.Count > 0)
                        {
                            xmsg = "DNI ya registrado";
                            objeto = txtDni;
                        }
                    }
                }
                if (u_n_opsel == 1)
                {
                    if (txtcodigo.Text.Trim().Length == 0)
                    {
                        xmsg = "Ingrese Código";
                        objeto = txtcodigo;
                    }
                    else
                    {
                        var BL = new tb_plla_fichatrabajadoresBL();
                        var BE = new tb_plla_fichatrabajadores();
                        BE.Fichaid = txtcodigo.Text.Trim();
                        BE.Empresaid = cbo_empresaid.SelectedValue.ToString();
                        tmptabla = BL.GetAll(VariablesPublicas.EmpresaID, BE).Tables[0];
                        if (tmptabla.Rows.Count > 0)
                        {
                            xmsg = "Código ya registrado";
                            objeto = txtcodigo;
                        }
                    }
                }
            }
            if (fIngreso.Checked == false)
            {
                xmsg = xmsg + "\r" + "Ingrese fecha de ingreso";
                objeto = fIngreso;
            }
            if (xmsg.Trim().Length == 0)
            {
                if (!(VM_AntiguoValorImagen == VM_mimagen_3))
                {
                    if (!VariablesPublicas.CopiarArchivo(VM_mimagen_3))
                    {
                        xmsg = xmsg + "\r" + "Error al Subir Archivo";
                    }
                    else
                    {
                        VM_mimagen_3 = VariablesPublicas.NombreArchivoSubido;
                    }
                }
            }
            if (u_n_opsel == 1 | !(vm_Nombretrabajador == txtapepat.Text.Trim() + " " + txtapemat.Text.Trim() + " " + txtnombres.Text.Trim()))
            {
                string tmpstring = null;
                tmpstring = txtapepat.Text.Trim() + " " + txtapemat.Text.Trim() + " " + txtnombres.Text.Trim();
                var BL = new tb_plla_fichatrabajadoresBL();
                var BE = new tb_plla_fichatrabajadores();
                BE.Nombrelargo = VariablesPublicas.Palabras(tmpstring, 1);
                BE.Nombrelargo = VariablesPublicas.Palabras(tmpstring, 2);
                BE.Nombrelargo = VariablesPublicas.Palabras(tmpstring, 3);
                BE.Nrodni = txtDni.Text.Trim();
                tmpcursor = BL.GetAll(VariablesPublicas.EmpresaID, BE).Tables[0];
                if (BL.Sql_Error.Length > 0)
                {
                    Frm_Class.ShowError(BL.Sql_Error + "\r" + "Error al validar duplicidad de nombres", this);
                    return false;
                }
                if (tmpcursor.Rows.Count > 0)
                {
                    if (u_n_opsel == 1)
                    {
                        xmsg = xmsg + "\r" + "Trabajador ya se encuentra registrado con código " + tmpcursor.Rows[0]["fichaid"] + "-" + tmpcursor.Rows[0]["nombrelargo"];
                        objeto = txtapemat;
                    }
                    else
                    {
                        for (lc_cont = 0; lc_cont <= tmpcursor.Rows.Count - 1; lc_cont++)
                        {
                            if (!(tmpcursor.Rows[lc_cont]["fichaid"].ToString() == txtcodigo.Text))
                            {
                                xmsg = xmsg + "\r" + "Trabajador ya se encuentra registrado con código " + tmpcursor.Rows[lc_cont]["fichaid"] + "-" + tmpcursor.Rows[lc_cont]["nombrelargo"];
                                objeto = txtapemat;
                                break;
                            }
                        }
                    }
                }
            }
            if (xmsg.Trim().Length > 0)
            {
                MessageBox.Show(xmsg.Trim(), "Error en Ingreso de Datos");
                if ((objeto != null))
                {
                    objeto = Focus();
                }
            }
            return xmsg.Trim().Length == 0;
        }
        private void Llenar_cboEstadTrabjFil()
        {
            cmbfiltroestado.ValueMember = "cele";
            cmbfiltroestado.DisplayMember = "descripcion";

            var BL = new tb_plla_fichatrabajadoresBL();
            var BE = new tb_plla_fichatrabajadores();

            cmbfiltroestado.DataSource = BL.GetAll_EstadoTrabj(VariablesPublicas.EmpresaID, BE).Tables[0];
        }
        private void cbo_empresaid_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbo_empresaid.SelectedIndex != -1)
            {
                var BL = new tb_plla_fichatrabajadoresBL();

                var Codigo = cbo_empresaid.SelectedValue.ToString();

                txtcodigo.Text = BL.GetAll_ConsultaMaxCod(VariablesPublicas.EmpresaID.ToString(), Codigo).Tables[0].Rows[0]["maximo_codigo"].ToString();
                u_CargaAnexos();
                cboTipdoc.SelectedValue = "01";
                cmbestadotrab.SelectedValue = "01";
                cmbtipolocal.SelectedValue = "0000";
                cboDepar.SelectedValue = "15";
                cboDeparN.SelectedValue = "15";
                txtpaisid.Text = "9589";
                ValidaPais();

                cmbtipo.SelectedValue = S_TipoDeta;
                rbnatural.Checked = true;
                txtcodigo.Focus();

                cmbestadocivil.SelectedValue = "S";
                cmbafp.SelectedValue = "02";
                cboNiveleducativo.SelectedValue = "13";
                cmbcategoria.SelectedValue = "3";
                cmbmodalidad.SelectedValue = "02";
                cboTipoplanilla.SelectedValue = "B";
                cmbestado.SelectedValue = "01";

                rbmasculino.Checked = true;
                rbnodiscapacitado.Checked = true;

                cboEps.SelectedValue = string.Empty;
                cboSitutrab.SelectedValue = string.Empty;
                cboEps_SelectedIndexChanged(sender, e);
                cboTpago.SelectedValue = string.Empty;
                cboCtributario.SelectedValue = "0";
                rbnoConvenio.Checked = true;

                if (fIngreso.Checked)
                {
                    fIngreso.Value = DateTime.Now;
                }
                j_Ruc = txtDni.Text;

                cbo_empresaid.Enabled = false;
                txtcodigo.Enabled = false;
            }
        }
        private void CargaDatos()
        {
            var xtipoplanilla = string.Empty;
            var xestadotrab = string.Empty;
            var xtipolocal = string.Empty;
            if (cmbfiltroestado.Enabled)
            {
                if (cmbfiltroestado.SelectedValue != null)
                {
                    xestadotrab = cmbfiltroestado.SelectedValue.ToString();
                }
            }
            if (cmbfiltrotipolocal.Enabled)
            {
                if (cmbfiltrotipolocal.SelectedValue != null)
                {
                    xtipolocal = cmbfiltrotipolocal.SelectedValue.ToString();
                }
            }

            if (cmbfiltrotipoplanilla.Enabled)
            {
                if (cmbfiltrotipoplanilla.SelectedValue != null)
                {
                    xtipoplanilla = cmbfiltrotipoplanilla.SelectedValue.ToString();
                }
            }

            var xxxswload = Sw_LOad;
            Sw_LOad = true;
            var BLES = new tb_plla_establecimientosBL();
            var BEES = new tb_plla_establecimientos();
            BEES.empresaid = VariablesPublicas.EmpresaID;
            BEES.norden = 1;
            BEES.ver_blanco = 0;

            cmbfiltrotipolocal.DisplayMember = "estabname";
            cmbfiltrotipolocal.ValueMember = "estabid";
            cmbfiltrotipolocal.DataSource = BLES.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BEES).Tables[0];

            cmbtipolocal.DisplayMember = "estabname";
            cmbtipolocal.ValueMember = "estabid";
            cmbtipolocal.DataSource = BLES.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BEES).Tables[0];

            Sw_LOad = xxxswload;

            var nposcolumnasortear = 0;
            var PrvSotOrder = default(SortOrder);
            var xnumdoclike = txtfiltronumdoc.Text;
            var xcodlike = txtfiltrocodigo.Text;
            var zordenado = false;
            var xcodcliente = "..";
            var xpalabra1 = string.Empty;
            var xpalabra2 = string.Empty;
            var xpalabra3 = string.Empty;
            if (txtfiltronombre.Text.Trim().Length > 0)
            {
                xpalabra1 = VariablesPublicas.Palabras(txtfiltronombre.Text, 1);
                xpalabra2 = VariablesPublicas.Palabras(txtfiltronombre.Text, 2);
                xpalabra3 = VariablesPublicas.Palabras(txtfiltronombre.Text, 3);
            }
            if (Examinar.CurrentRow != null)
            {
                xcodcliente = Examinar.Rows[Examinar.CurrentRow.Index].Cells["fichaid"].Value.ToString();
            }
            if (Examinar.SortedColumn != null)
            {
                nposcolumnasortear = Examinar.SortedColumn.Index;
                PrvSotOrder = Examinar.SortOrder;
                zordenado = true;
            }
            var nestadotrab = 1;
            if (txtfiltronumdoc.Enabled)
            {
                xnumdoclike = txtfiltronumdoc.Text;
            }
            if (chkvercesados.Checked)
            {
                nestadotrab = 0;
            }
            if (txtfiltrocodigo.Enabled)
            {
                xcodlike = txtfiltrocodigo.Text;
            }
            var BL = new tb_plla_fichatrabajadoresBL();
            var BE = new tb_plla_fichatrabajadores();
            BE.Fichaid = xcodlike;
            BE.Nrodni = xnumdoclike;
            BE.Norden = 1;
            BE.Nomlike1 = xpalabra1;
            BE.Nomlike2 = xpalabra2;
            BE.Nomlike3 = xpalabra3;
            BE.Estado_trabaj = nestadotrab;
            BE.Tipoplla = xtipoplanilla;
            BE.Situtrabid = xestadotrab;
            BE.Establec = xtipolocal;

            tablaclientes = BL.GetAll_Consulta(VariablesPublicas.EmpresaID, BE).Tables[0];
            lbltotaltrab.Text = string.Empty;
            if (BL.Sql_Error.Length == 0)
            {
                lbltotaltrab.Text = "Total Trabajadores " + tablaclientes.Rows.Count.ToString();
            }
            Examinar.AutoGenerateColumns = false;
            Examinar.DataSource = tablaclientes;

            VariablesPublicas.PintaEncabezados(Examinar);

            if (zordenado)
            {
                if (PrvSotOrder == SortOrder.Ascending)
                {
                    Examinar.Sort(Examinar.Columns[nposcolumnasortear], ListSortDirection.Ascending);
                }
                else
                {
                    Examinar.Sort(Examinar.Columns[nposcolumnasortear], ListSortDirection.Descending);
                }
            }
            else
            {
                Examinar.Sort(Examinar.Columns["nombrelargo"], ListSortDirection.Ascending);
            }
            if (Examinar.CurrentRow == null)
            {
                if (Examinar.RowCount > 0)
                {
                    Examinar.CurrentCell = Examinar.Rows[0].Cells["fichaid"];
                }
            }
            for (lc_cont = 0; lc_cont <= Examinar.Rows.Count - 1; lc_cont++)
            {
                if (Examinar.Rows[lc_cont].Cells["fichaid"].Value.ToString() == xcodcliente)
                {
                    Examinar.CurrentCell = Examinar.Rows[lc_cont].Cells["fichaid"];
                    break;
                }
            }
        }
        private void btngrabar_Click(object sender, EventArgs e)
        {
            if (U_Validacion())
            {
                var tmpcursor = new DataTable();

                if (u_n_opsel == 1)
                {
                    var BL = new tb_plla_fichatrabajadoresBL();
                    var BE = new tb_plla_fichatrabajadores();
                    BE.Fichaid = txtcodigo.Text.Trim();
                    BE.Empresaid = cbo_empresaid.SelectedValue.ToString();
                    BE.Norden = 1;
                    BE.Estado_trabaj = 0;

                    tmpcursor = BL.GetAll_Consulta(VariablesPublicas.EmpresaID, BE).Tables[0];
                    if (tmpcursor.Rows.Count > 0)
                    {
                        var BLMX = new tb_plla_fichatrabajadoresBL();
                        var Codigo = cbo_empresaid.SelectedValue.ToString();
                        txtcodigo.Text = BLMX.GetAll_ConsultaMaxCod(VariablesPublicas.EmpresaID.ToString(), Codigo).Tables[0].Rows[0]["maximo_codigo"].ToString();
                    }
                    tmpcursor.Rows.Add(VariablesPublicas.InsertIntoTable(tmpcursor));
                    var BLMX1 = new tb_plla_fichatrabajadoresBL();
                    var Codigo1 = cbo_empresaid.SelectedValue.ToString();

                    tmpcursor.Rows[0]["fichaid"] = BLMX1.GetAll_ConsultaMaxCod(VariablesPublicas.EmpresaID.ToString(), Codigo1).Tables[0].Rows[0]["maximo_codigo"].ToString();
                    tmpcursor.Rows[0]["activo"] = "1";
                    tmpcursor.Rows[0]["status"] = "0";
                    tmpcursor.Rows[0]["motivocese"] = string.Empty;
                    tmpcursor.Rows[0]["fechcese"] = DBNull.Value;
                    tmpcursor.Rows[0]["tipsuspenid"] = string.Empty;
                }
                else
                {
                    var BL = new tb_plla_fichatrabajadoresBL();
                    var BE = new tb_plla_fichatrabajadores();
                    BE.Fichaid = txtcodigo.Text.Trim();
                    BE.Empresaid = cbo_empresaid.SelectedValue.ToString();
                    BE.Norden = 1;
                    BE.Estado_trabaj = 0;
                    tmpcursor = BL.GetAll_Consulta(VariablesPublicas.EmpresaID, BE).Tables[0];
                }

                tmpcursor.Rows[0]["empresaid"] = cbo_empresaid.SelectedValue;

                tmpcursor.Rows[0]["fichaid"] = txtcodigo.Text.Trim();
                tmpcursor.Rows[0]["apepat"] = txtapepat.Text.Trim();
                tmpcursor.Rows[0]["apemat"] = txtapemat.Text.Trim();
                tmpcursor.Rows[0]["nombres"] = txtnombres.Text.Trim();
                tmpcursor.Rows[0]["nombrelargo"] = txtNombrelargo.Text.Trim();
                if ((cboTipdoc.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["tipdocid"] = cboTipdoc.SelectedValue;
                }
                tmpcursor.Rows[0]["nrodni"] = txtDni.Text.Trim();
                tmpcursor.Rows[0]["nmruc"] = txtDni.Text.Trim();
                tmpcursor.Rows[0]["ctactename"] = txtNombrelargo.Text.Trim();
                tmpcursor.Rows[0]["direcc"] = txtdireccion.Text.Trim();
                if ((cboDistr.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["ubiged"] = cboDistr.SelectedValue;
                }
                if ((cboDistrN.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["ubigen"] = cboDistrN.SelectedValue;
                }
                if ((cmbestadocivil.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["estadocivil"] = cmbestadocivil.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["estadocivil"] = string.Empty;
                }
                if (rbmasculino.Checked)
                {
                    tmpcursor.Rows[0]["sexo"] = "M";
                }
                else
                {
                    tmpcursor.Rows[0]["sexo"] = "F";
                }
                tmpcursor.Rows[0]["telef1"] = txttelefono.Text.Trim();
                tmpcursor.Rows[0]["telef2"] = txtfax.Text.Trim();
                tmpcursor.Rows[0]["carnetsegsoc"] = txtcarnetseguro.Text.Trim();
                tmpcursor.Rows[0]["fechnacimiento"] = fnacimiento.Value;
                if (fIngreso.Checked)
                {
                    tmpcursor.Rows[0]["fechingreso"] = fIngreso.Value;
                }
                else
                {
                    tmpcursor.Rows[0]["fechingreso"] = DBNull.Value;
                }
                if ((cmbestadotrab.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["situtrabid"] = cmbestadotrab.SelectedValue;
                }
                tmpcursor.Rows[0]["sctr"] = chksctr.Checked;
                tmpcursor.Rows[0]["remintegral"] = chkremintegral.Checked;
                tmpcursor.Rows[0]["autocontrol"] = chkautocontrol.Checked;
                tmpcursor.Rows[0]["chkdephab"] = chkdephaberes.Checked;
                if ((cmbdephaberes.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["bancoidhab"] = cmbdephaberes.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["bancoidhab"] = string.Empty;
                }
                tmpcursor.Rows[0]["ctahaberes"] = txtctahaberes.Text.Trim();
                tmpcursor.Rows[0]["chkdepcts"] = chkdepcts.Checked;
                if ((cmbdepcts.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["bancoidcts"] = cmbdepcts.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["bancoidcts"] = string.Empty;
                }
                tmpcursor.Rows[0]["ctacts"] = txtctacts.Text.Trim();
                if ((cmbtipo.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["tipodeta"] = cmbtipo.SelectedValue;
                }
                tmpcursor.Rows[0]["cencosid"] = txtccosto.Text.Trim();
                tmpcursor.Rows[0]["cargoid"] = txtccargo.Text.Trim();
                tmpcursor.Rows[0]["detallecontable"] = txtdetallecontable.Text.Trim();
                if ((cmbafp.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["regipenid"] = cmbafp.SelectedValue;
                }
                if (Equivalencias.Left(cmbafp.SelectedValue.ToString(), 1) == "2")
                {
                    tmpcursor.Rows[0]["cuspp"] = txtctaafp.Text.Trim();
                    if (fafiliacion.Checked)
                    {
                        tmpcursor.Rows[0]["fechafiliacion"] = fafiliacion.Value;
                    }
                    if ((cboTComision.SelectedValue != null))
                    {
                        tmpcursor.Rows[0]["tipcomisionafp"] = cboTComision.SelectedValue;
                    }
                }
                else
                {
                    tmpcursor.Rows[0]["cuspp"] = string.Empty;
                    tmpcursor.Rows[0]["fechafiliacion"] = DBNull.Value;
                    tmpcursor.Rows[0]["tipcomisionafp"] = string.Empty;
                }
                tmpcursor.Rows[0]["essaludvida"] = chkesalud.Checked;
                tmpcursor.Rows[0]["email"] = txtemail.Text.Trim();
                if ((cboNiveleducativo.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["niveleduid"] = cboNiveleducativo.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["niveleduid"] = string.Empty;
                }
                if (rbsidiscapacitado.Checked)
                {
                    tmpcursor.Rows[0]["discapacitado"] = rbsidiscapacitado.Checked;
                }
                if (rbnodiscapacitado.Checked)
                {
                    tmpcursor.Rows[0]["discapacitado"] = false;
                }
                tmpcursor.Rows[0]["tipestabid"] = string.Empty;
                if ((cmbtipolocal.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["establec"] = cmbtipolocal.SelectedValue;
                }
                if ((cmbcategoria.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["cateocupid"] = cmbcategoria.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["cateocupid"] = string.Empty;
                }
                tmpcursor.Rows[0]["fotografia"] = VM_mimagen_3;
                tmpcursor.Rows[0]["observacion"] = txtobservaciones.Text.Trim();
                if (u_n_opsel == 1 | object.ReferenceEquals(tmpcursor.Rows[0]["fechregistro"], DBNull.Value))
                {
                    tmpcursor.Rows[0]["fechregistro"] = DateTime.Now;
                }
                if ((TablaContratos != null))
                {
                    if (TablaContratos.Rows.Count > 0)
                    {
                        if ((!object.ReferenceEquals(TablaContratos.Rows[TablaContratos.Rows.Count - 1]["tipoplla"], DBNull.Value)))
                        {
                            tmpcursor.Rows[0]["tipoplla"] = TablaContratos.Rows[TablaContratos.Rows.Count - 1]["tipoplla"];
                        }
                    }
                }
                if ((cboVia.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["viaid"] = cboVia.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["viaid"] = string.Empty;
                }
                if ((cboZona.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["zonaid"] = cboZona.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["zonaid"] = string.Empty;
                }
                if ((cboEps.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["epsid"] = cboEps.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["epsid"] = string.Empty;
                }
                if ((cboSitutrab.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["situtrab"] = cboSitutrab.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["situtrab"] = string.Empty;
                }
                if ((cboTpago.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["tippagoid"] = cboTpago.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["tippagoid"] = string.Empty;
                }
                if (rbsiConvenio.Checked)
                {
                    tmpcursor.Rows[0]["chkconvenio"] = rbsiConvenio.Checked;
                }
                if (rbnoConvenio.Checked)
                {
                    tmpcursor.Rows[0]["chkconvenio"] = false;
                }
                if ((cboCtributario.SelectedValue != null))
                {
                    tmpcursor.Rows[0]["convendobletribid"] = cboCtributario.SelectedValue;
                }
                else
                {
                    tmpcursor.Rows[0]["convendobletribid"] = string.Empty;
                }
                tmpcursor.Rows[0]["paisid"] = txtpaisid.Text.Trim();
                tmpcursor.Rows[0]["status"] = (rbactivo.Checked ? "0" : "9");
                tmpcursor.Rows[0]["usuar"] = VariablesPublicas.Usuar.Trim();

                for (lc_cont = 0; lc_cont <= TablaContratos.Rows.Count - 1; lc_cont++)
                {
                    TablaContratos.Rows[lc_cont]["fichaid"] = txtcodigo.Text.Trim();
                    TablaContratos.Rows[lc_cont]["empresaid"] = cbo_empresaid.SelectedValue;
                }
                for (lc_cont = 0; lc_cont <= TablaRubrosContrato.Rows.Count - 1; lc_cont++)
                {
                    TablaRubrosContrato.Rows[lc_cont]["fichaid"] = txtcodigo.Text.Trim();
                    TablaRubrosContrato.Rows[lc_cont]["empresaid"] = cbo_empresaid.SelectedValue;
                }

                var BLIN = new tb_plla_fichatrabajadoresBL();

                if (BLIN.Insert_Update(VariablesPublicas.EmpresaID, tmpcursor, TablaContratos, TablaRubrosContrato))
                {
                    seguridadlog();
                    U_CancelarEdicion(0);
                }
                else
                {
                    Frm_Class.ShowError(BLIN.Sql_Error, this);
                }
            }
        }
        private void btneliminar_Click(object sender, EventArgs e)
        {
            if ((Examinar.CurrentRow != null))
            {
                var xnomcampo = string.Empty;
                if (xnomcampo.Length == 0)
                {
                    var BL = new tb_plla_fichatrabajadoresBL();
                    var BE = new tb_plla_fichatrabajadores();
                    BE.Fichaid = Examinar.Rows[Examinar.CurrentRow.Index].Cells["fichaid"].Value.ToString();
                    BE.Empresaid = Examinar.Rows[Examinar.CurrentRow.Index].Cells["empresaid"].Value.ToString();
                    BE.Norden = 1;
                    BE.Estado_trabaj = 0;
                    tmptabla = BL.GetAll_Consulta(VariablesPublicas.EmpresaID, BE).Tables[0];
                    if (BL.Sql_Error.Length == 0)
                    {
                        var message = "Desea eliminar datos de Trabajador " + tmptabla.Rows[0]["fichaid"].ToString().Trim() + " - " + tmptabla.Rows[0]["nombrelargo"].ToString().Trim() + " ...?";
                        var caption = "Mensaje del Sistema";
                        var buttons = MessageBoxButtons.YesNo;
                        DialogResult result;
                        result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                        if (result == DialogResult.Yes)
                        {
                            var BL1 = new tb_plla_fichatrabajadoresBL();
                            if (BL1.Eliminar(VariablesPublicas.EmpresaID, tmptabla))
                            {
                                var BLS = new tb_co_seguridadlogBL();
                                var BES = new tb_co_seguridadlog();

                                BES.moduloid = Name;
                                BES.clave = VariablesPublicas.EmpresaID + Examinar.Rows[Examinar.CurrentRow.Index].Cells["fichaid"].Value.ToString();
                                BES.cuser = VariablesPublicas.Usuar;
                                BES.fecha = DateTime.Now;
                                BES.pc = VariablesPublicas.userip;
                                BES.accion = "B";
                                BES.detalle = "Trabajador:" + txtNombrelargo.Text.Trim();

                                BLS.Insert(VariablesPublicas.EmpresaID.ToString(), BES);
                                Examinar.Rows.Remove(Examinar.CurrentRow);
                                Examinar.Refresh();
                            }
                        }
                    }
                    else
                    {
                        Frm_Class.ShowError(BL.Sql_Error, this);
                    }
                }
                else
                {
                    MessageBox.Show(xnomcampo, "IMPOSIBLE ELIMINAR REGISTRO");
                }
            }
            U_RefrescaControles();
        }
 public void SeleccionarDegrilla(int opcion)
 {
     var n = 0;
     var i = 0;
     var retorno = false;
     if (chkInactivos.Checked)
     {
         i = 1;
     }
     else
     {
         i = 0;
     }
     if (DataGridView1.Rows.Count > 0)
     {
         for (n = 0; n <= DataGridView1.Rows.Count - 1; n++)
         {
             if (Convert.ToInt32(DataGridView1.Rows[n].Cells[0].Value) == 1)
             {
                 var BL = new tb_plla_fichatrabajadoresBL();
                 var BE = new tb_plla_fichatrabajadores();
                 BE.Fichaid = DataGridView1.Rows[n].Cells[1].Value.ToString().Trim();
                 BE.Ntipo = opcion;
                 retorno = BL.ReactivarTrabajadorUpdate(VariablesPublicas.EmpresaID, BE);
             }
         }
         if (retorno)
         {
             MessageBox.Show("Accion realizada con exito !!!");
             U_LoadPlanillas(0);
         }
         else
         {
             MessageBox.Show("Error al Grabar !!!!");
         }
     }
 }
        private void U_LoadPlanillas(Int16 nInit)
        {
            DataGridView1.AutoGenerateColumns = false;
            DataGridView1.Columns[0].DataPropertyName = "nselect";
            DataGridView1.Columns[1].DataPropertyName = "ficha";
            DataGridView1.Columns[2].DataPropertyName = "dficha";
            DataGridView1.Columns[3].DataPropertyName = "f_ingreso";
            DataGridView1.Columns[4].DataPropertyName = "f_cese";
            DataGridView1.Columns[5].DataPropertyName = "planilla";
            DataGridView1.Columns[6].DataPropertyName = "estado";

            var BL = new tb_plla_fichatrabajadoresBL();
            var BE = new tb_plla_fichatrabajadores();
            BE.Ver_inactivos = nInit;
            DataGridView1.DataSource = BL.GetAllTrabajadoresReactivar(VariablesPublicas.EmpresaID, BE).Tables[0];
        }
 private void Frm_PllaAyudaRta5ta_Load(object sender, EventArgs e)
 {
     MaximizeBox = false;
     MinimizeBox = false;
     tb_plla_fichatrabajadoresBL BL = new tb_plla_fichatrabajadoresBL();
     tb_plla_fichatrabajadores BE = new tb_plla_fichatrabajadores();
     BE.Tipoplla = TipoPlanilla;
     dw = new DataView(BL.GetAll_TrabajadorRetenciones(VariablesPublicas.EmpresaID, BE).Tables[0]);
     dgAyuda.AutoGenerateColumns = false;
     dgAyuda.DataSource = dw;
     dgAyuda.Columns[0].DataPropertyName = "fichaid";
     dgAyuda.Columns[1].DataPropertyName = "nombrelargo";
     dgAyuda.Columns[2].DataPropertyName = "nrodni";
     dgAyuda.Columns[3].DataPropertyName = "estado";
     checks();
 }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            string ficha = null;
            string nombre = null;
            string empresa = null;
            if ((dgTrabProceso.CurrentRow != null))
            {
                if (string.IsNullOrEmpty(txtjefe.Text.Trim()))
                {
                    MessageBox.Show("Ingrese a un Jefe para Poder Cesar", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                ficha = dgTrabProceso["ficha", dgTrabProceso.CurrentRow.Index].Value.ToString();
                empresa = dgTrabProceso["empresa", dgTrabProceso.CurrentRow.Index].Value.ToString();
                nombre = dgTrabProceso["dficha", dgTrabProceso.CurrentRow.Index].Value.ToString().Trim();
                if (MessageBox.Show("Desea Cesar al trabajador (" + ficha + ") " + nombre, string.Empty, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    var retorno = false;
                    var BL = new tb_plla_fichatrabajadoresBL();
                    var BE = new tb_plla_fichatrabajadores();

                    BE.Empresaid = empresa.Trim();
                    BE.Fichaid = ficha.Trim();
                    BE.Jefe = txtjefe.Text.Trim().ToString();
                    BE.Fechcese = dtpFechaCese.Value;
                    BE.Motivocese = cbMotivoCese.SelectedValue.ToString();
                    BE.Observacion = txtObs.Text.Trim();
                    retorno = BL.CesarTrabajadorUpdate(VariablesPublicas.EmpresaID, BE);
                    if (retorno)
                    {
                        MessageBox.Show("Cesado Correctamente !!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        validacion_panel(true);
                        Panel.Visible = false;
                        if (swB == 2)
                        {
                            DesEnlazaControles();
                        }
                        if (swB == 1)
                        {
                            EnlazarControles();
                        }
                        limpiar();
                    }
                    else
                    {
                        MessageBox.Show("Hubo problemas al momento de Cesar, cierra la ventana e intente de nuevo", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
 private void txtjefe_LostFocus(object sender, System.EventArgs e)
 {
     if (txtjefe.Text.Trim().Length > 0)
     {
         txtjefe.Text = VariablesPublicas.PADL(txtjefe.Text.Trim(), 7, "0");
     }
     if (!(j_Valor == txtjefe.Text))
     {
         var odata = new DataTable();
         var BL = new tb_plla_fichatrabajadoresBL();
         var BE = new tb_plla_fichatrabajadores();
         BE.Fichaid = txtjefe.Text.Trim();
         BE.Norden = 1;
         odata = BL.GetAll_GETTRABAJADORES(VariablesPublicas.EmpresaID, BE).Tables[0];
         if (odata.Rows.Count > 0)
         {
             txtDjefe.Text = odata.Rows[0]["nombrelargo"].ToString();
             txtjefe.Text = odata.Rows[0]["fichaid"].ToString();
         }
         else
         {
             txtDjefe.Text = string.Empty;
             txtjefe.Text = string.Empty;
         }
     }
 }
        private void EnlazarControles()
        {
            swB = 2;
            var BindingTable = new DataTable();
            var BL = new tb_plla_fichatrabajadoresBL();
            var BE = new tb_plla_fichatrabajadores();
            BE.Ntipo = _varProcesoCesar;
            BindingTable = BL.GetAll_ActivosCesados(VariablesPublicas.EmpresaID, BE).Tables[0];
            vistaDatos = new DataView(BindingTable);
            dgTrabProceso.AutoGenerateColumns = false;
            dgTrabProceso.DataSource = vistaDatos;

            Llenar_cboEstadoContrato();
        }
        private void btncontrato_Click(object sender, EventArgs e)
        {
            DataTable tmpdata = null;
            var xcodestado = string.Empty;
            var xcodficha = "...";
            if ((Examinar.CurrentRow != null))
            {
                xcodficha = Examinar.Rows[Examinar.CurrentRow.Index].Cells["fichaid"].Value.ToString();
            }

            var BL = new tb_plla_fichatrabajadoresBL();
            var BE = new tb_plla_fichatrabajadores();
            BE.Empresaid = Examinar.Rows[Examinar.CurrentRow.Index].Cells["empresaid"].Value.ToString();
            ;
            BE.FichaidIni = xcodficha;
            BE.FichaidFin = xcodficha;
            BE.Situtrabid = xcodestado;
            tmpdata = BL.GetAll_GeneraDatosFormatoContrato(VariablesPublicas.EmpresaID, BE).Tables[0];
            if (BL.Sql_Error.Length > 0)
            {
                Frm_Class.ShowError(BL.Sql_Error, this);
                return;
            }
            var BLPC = new tb_plla_plantilla_contratosBL();
            var BEPC = new tb_plla_plantilla_contratos();
            BEPC.norden = 1;
            BEPC.ver_blanco = 0;
            BEPC.vista = 1;
            tmpcursor = BLPC.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BEPC).Tables[0];
            if (BLPC.Sql_Error.Length > 0)
            {
                Frm_Class.ShowError(BLPC.Sql_Error, this);
                return;
            }
            if (tmpcursor.Rows.Count == 0)
            {
                MessageBox.Show("No hay formatos creados !!!", "Mensaje del Sistema");
                return;
            }
            if (tmpdata.Rows.Count == 0)
            {
                MessageBox.Show("No hay información seleccionada !!!", "Mensaje del Sistema");
                return;
            }
            var xmsgerror = string.Empty;
            if (tmpdata.Rows[0]["VM_SUELDOTRABAJADOR"].ToString().Trim().Length == 0)
            {
                xmsgerror = xmsgerror + "\r" + "Trabajador no tiene remuneración definida !!!";
            }
            else
            {
                if (tmpdata.Rows[0]["msgvalidafecha"].ToString().Trim().Length > 0)
                {
                    xmsgerror = xmsgerror + "\r" + tmpdata.Rows[0]["msgvalidafecha"];
                }
                else
                {
                    if (tmpdata.Rows[0]["VM_NROMESESYDIAS"].ToString().Trim().Length == 0)
                    {
                        xmsgerror = xmsgerror + "\r" + "Trabajador no tiene fechas definidas en el contrato !!!";
                    }
                    else
                    {
                        if (tmpdata.Rows[0]["VM_CENTROCOSTOTRABAJADOR"].ToString().Trim().Length == 0)
                        {
                            xmsgerror = xmsgerror + "\r" + "Trabajador no tiene definido centro de costo !!!";
                        }
                        else
                        {
                            if (tmpdata.Rows[0]["VM_CARGOTRABAJADOR"].ToString().Trim().Length == 0)
                            {
                                xmsgerror = xmsgerror + "\r" + "Trabajador no tiene definido cargo !!!";
                            }
                            else
                            {
                            }
                        }
                    }
                }
            }
            if (xmsgerror.Trim().Length == 0)
            {
                VariablesPublicas.u_GeneraFormatoContrato(tmpdata, tmpcursor);
            }
            else
            {
                MessageBox.Show(xmsgerror, "Mensaje del Sistema");
            }
        }
 public void U_CargaDatos(bool nofocusgrid)
 {
     lbltotalregistros.Text = string.Empty;
     var nestado = 0;
     var xtipoplanilla = string.Empty;
     if (cmbtipoplanilla.Enabled)
     {
         if ((cmbtipoplanilla.SelectedValue != null))
         {
             xtipoplanilla = cmbtipoplanilla.SelectedValue.ToString();
         }
     }
     if (rbtodos1.Checked)
     {
         nestado = 0;
     }
     if (rbtodos2.Checked)
     {
         nestado = 1;
     }
     if (rbtodos3.Checked)
     {
         nestado = 2;
     }
     var xpalabra1 = string.Empty;
     var xpalabra2 = string.Empty;
     var xpalabra3 = string.Empty;
     if (txtnombre.Enabled)
     {
         xpalabra1 = VariablesPublicas.Palabras(txtnombre.Text.Trim(), 1);
         xpalabra2 = VariablesPublicas.Palabras(txtnombre.Text.Trim(), 2);
         xpalabra3 = VariablesPublicas.Palabras(txtnombre.Text.Trim(), 3);
     }
     var BL = new tb_plla_fichatrabajadoresBL();
     var BE = new tb_plla_fichatrabajadores();
     BE.Norden = 1;
     BE.Nomlike1 = xpalabra1;
     BE.Nomlike2 = xpalabra2;
     BE.Nomlike3 = xpalabra3;
     BE.Estado_trabaj = nestado;
     BE.Tipoplla = xtipoplanilla;
     tabla = BL.GetAll_Consulta(VariablesPublicas.EmpresaID, BE).Tables[0];
     if (BL.Sql_Error.Length > 0)
     {
         sw_Load = false;
         Frm_Class.ShowError(BL.Sql_Error, this);
     }
     else
     {
         lbltotalregistros.Text = (tabla.Rows.Count).ToString() + " Registro(s)";
         var sorted = default(SortOrder);
         var xnomcolumna = string.Empty;
         if ((dgProveedor.SortedColumn != null))
         {
             xnomcolumna = dgProveedor.Columns[dgProveedor.SortedColumn.Index].Name;
             sorted = dgProveedor.SortOrder;
         }
         dgProveedor.AutoGenerateColumns = false;
         dgProveedor.DataSource = tabla;
         dgProveedor.AllowUserToResizeRows = false;
         if (xnomcolumna.Trim().Length > 0)
         {
             if (sorted == SortOrder.Ascending)
             {
                 dgProveedor.Sort(dgProveedor.Columns[xnomcolumna], System.ComponentModel.ListSortDirection.Ascending);
             }
             else
             {
                 dgProveedor.Sort(dgProveedor.Columns[xnomcolumna], System.ComponentModel.ListSortDirection.Descending);
             }
         }
         else
         {
             dgProveedor.Sort(dgProveedor.Columns["nombrelargo"], System.ComponentModel.ListSortDirection.Ascending);
         }
         if (dgProveedor.Rows.Count > 0)
         {
             if (nofocusgrid)
             {
             }
             else
             {
                 dgProveedor.CurrentCell = dgProveedor.Rows[0].Cells["fichaid"];
                 dgProveedor.Focus();
                 dgProveedor.BeginEdit(true);
             }
         }
         pintar();
     }
 }
        private void btnficha_Click(object sender, EventArgs e)
        {
            if (u_n_opsel == 0 & (Examinar.CurrentRow != null))
            {
                var xficha = Examinar.Rows[Examinar.CurrentRow.Index].Cells["fichaid"].Value.ToString();
                var xempresa = Examinar.Rows[Examinar.CurrentRow.Index].Cells["empresaid"].Value.ToString();
                var xfichero = string.Empty;
                DataTable dt = null;
                var ncont = 0;
                var zprocesafoto = false;

                var BL = new tb_plla_fichatrabajadoresBL();
                var BE = new tb_plla_fichatrabajadores();
                BE.FichaidIni = xficha;
                BE.FichaidFin = xficha;
                BE.Empresaid = xempresa;
                BE.Norden = 2;
                dt = BL.GetAll_FichaDatos(VariablesPublicas.EmpresaID, BE).Tables[0];
                VariablesPublicas.CrearXml(dt, "fichadatos");
                if (BL.Sql_Error.Trim().Length == 0)
                {
                    if (dt.Rows.Count > 0)
                    {
                        for (ncont = 0; ncont <= dt.Rows.Count - 1; ncont++)
                        {
                            xfichero = string.Empty;
                            zprocesafoto = false;
                            if (dt.Rows[ncont]["fotografia"].ToString().Trim().Length > 0)
                            {
                                xfichero = GlobalVars.GetInstance().RutaFotoPersonal + dt.Rows[ncont]["fotografia"].ToString().Trim();
                                if (System.IO.File.Exists(xfichero))
                                {
                                    try
                                    {
                                        dt.Rows[ncont]["gfoto"] = VariablesPublicas.ImageToByte(System.Drawing.Image.FromFile(GlobalVars.GetInstance().RutaFotoPersonal + dt.Rows[ncont]["fotografia"].ToString().Trim()), true);
                                        zprocesafoto = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        dt.Rows[ncont]["fotografia"] = string.Empty;
                                    }
                                }
                            }
                            else
                            {
                                zprocesafoto = true;
                            }
                            if (!zprocesafoto)
                            {
                                dt.Rows[ncont]["gfoto"] = VariablesPublicas.ImageToByte(BapFormulariosNet.Properties.Resources.error, false);
                                dt.Rows[ncont]["fotografia"] = "ERROR";
                            }
                        }

                        var frmreporte = new Frm_Reportes();
                        frmreporte.Table = dt;
                        frmreporte.Reporte = new Crpt_FichaTrabajador();
                        frmreporte.Show();
                    }
                    else
                    {
                        MessageBox.Show("No existe Información a Procesar", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
 private void btnAutocontrol_Click(object sender, EventArgs e)
 {
     if ((Examinar.CurrentRow != null))
     {
         tmpcursor = null;
         var nindice = 0;
         for (nindice = 0; nindice <= tablaclientes.Rows.Count - 1; nindice++)
         {
             if (tablaclientes.Rows[nindice]["fichaid"] == Examinar.Rows[Examinar.CurrentRow.Index].Cells["fichaid"].Value)
             {
                 tablaclientes.Rows[nindice]["autocontrol"] = !Convert.ToBoolean(tablaclientes.Rows[nindice]["autocontrol"]);
                 tmpcursor = tablaclientes.Clone();
                 tmpcursor.ImportRow(tablaclientes.Rows[nindice]);
                 tmpcursor.AcceptChanges();
                 break;
             }
         }
         if (!VariablesPublicas.EofTable(tmpcursor))
         {
             var BL = new tb_plla_fichatrabajadoresBL();
             if (BL.Insert_Update(VariablesPublicas.EmpresaID, tmpcursor, null, null))
             {
                 Examinar.Rows[Examinar.CurrentRow.Index].Cells["autocontrol"].Value = tmpcursor.Rows[0]["autocontrol"];
             }
         }
     }
 }