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 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"];
             }
         }
     }
 }