private void POnedatos()
        {
            Blanquear();
            if ((dgRubroGastos.CurrentRow != null))
            {
                txtCodigo.Text = dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["CODIGO"].Value.ToString();
                txtNombre.Text = dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["DESCRIPCION"].Value.ToString();
                ckInactivo.Checked = Convert.ToInt32(dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["inactivo"].Value) == 1;
                txtHoraInicio.Text = dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["Hora_inicial"].Value.ToString().Trim();
                txtHoraFin.Text = dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["Hora_final"].Value.ToString().Trim();
                txtTotalHoras.Text = dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["Total_horas"].Value.ToString();
                txtTotalMinutos.Text = dgRubroGastos.Rows[dgRubroGastos.CurrentRow.Index].Cells["Total_minutos"].Value.ToString();

                var BL = new tb_plla_turnoscabBL();
                var BE = new tb_plla_turnoscab();
                BE.cdiario = txtCodigo.Text.Trim();
                _Detalletabla = BL.GetAll_GetAllCONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
                _Detalletabla.Columns["des_evento"].ReadOnly = false;
                dgIngresos.AutoGenerateColumns = false;
                dgIngresos.DataSource = _Detalletabla;
            }
        }
        private void btNuevo_Click(object sender, EventArgs e)
        {
            _Detalletabla = (DataTable)dgIngresos.DataSource;
            if (_Detalletabla == null)
            {
                var BL = new tb_plla_turnoscabBL();
                var BE = new tb_plla_turnoscab();
                BE.cdiario = txtCodigo.Text.Trim();
                _Detalletabla = BL.GetAll_GetAllCONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
                _Detalletabla.Columns["des_evento"].ReadOnly = false;
            }
            var fila = _Detalletabla.NewRow();
            var item = 0;
            var desde = string.Empty;
            var hasta = string.Empty;
            desde = Convert.ToString("00:00");
            hasta = Convert.ToString("00:00");

            item = MaximoItem();
            fila[0] = txtCodigo.Text.Trim();
            fila[1] = VariablesPublicas.FormateaNumeroaCadena2(Convert.ToString(item), 2, '0', true);
            fila[2] = string.Empty;
            fila[3] = string.Empty;
            fila[4] = desde;
            fila[5] = hasta;
            fila[6] = string.Empty;
            fila[7] = 0;

            _Detalletabla.Rows.Add(fila);
            _Detalletabla.AcceptChanges();

            dgIngresos.AutoGenerateColumns = false;

            _Detalletabla.Columns[0].AllowDBNull = true;
            _Detalletabla.Columns[1].AllowDBNull = true;
            _Detalletabla.Columns[2].AllowDBNull = true;
            _Detalletabla.Columns[3].AllowDBNull = true;
            _Detalletabla.Columns[4].AllowDBNull = true;
            _Detalletabla.Columns[5].AllowDBNull = true;
            _Detalletabla.Columns[6].AllowDBNull = true;
            _Detalletabla.Columns[7].AllowDBNull = true;
            _Detalletabla.Columns["des_evento"].ReadOnly = false;
            _Detalletabla.AcceptChanges();
            dgIngresos.DataSource = _Detalletabla;
            var l_ubica = 0;
            for (l_ubica = 0; l_ubica <= dgIngresos.Rows.Count - 1; l_ubica++)
            {
                if (Convert.ToInt32(item) == Convert.ToInt32(dgIngresos.Rows[l_ubica].Cells[0].Value))
                {
                    dgIngresos.CurrentCell = dgIngresos.Rows[l_ubica].Cells[1];
                    dgIngresos.BeginEdit(true);
                    break;
                }
            }
        }