public bool Delete(string empresaid, tb_plla_geneventospermiso BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@eventoperid", SqlDbType.Char, 3).Value = BE.eventoperid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll(string empresaid, tb_plla_geneventospermiso BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_SEARCH", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@eventoperid", SqlDbType.Char, 3).Value = BE.eventoperid;
                 cmd.Parameters.Add("@eventopername", SqlDbType.VarChar, 50).Value = BE.eventopername;
                 //cmd.Parameters.Add("@planilla", SqlDbType.Int).Value = BE.planilla;
                 //cmd.Parameters.Add("@status", SqlDbType.Int).Value = BE.status;
                 cmd.Parameters.Add("@tipoevento", SqlDbType.Char, 1).Value = BE.tipoevento;
                 cmd.Parameters.Add("@rtpssunat", SqlDbType.Char, 2).Value = BE.rtpssunat; ;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Update(string empresaid, tb_plla_geneventospermiso BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_UPDATE", cnx))
         {
             {
                 cmd.CommandTimeout = 0;
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@eventoperid", SqlDbType.Char, 3).Value = BE.eventoperid;
                 cmd.Parameters.Add("@eventopername", SqlDbType.VarChar, 50).Value = BE.eventopername;
                 cmd.Parameters.Add("@planilla", SqlDbType.Int).Value = BE.planilla;
                 cmd.Parameters.Add("@status", SqlDbType.Int).Value = BE.status;
                 cmd.Parameters.Add("@tipoevento", SqlDbType.Char, 1).Value = BE.tipoevento;
                 cmd.Parameters.Add("@rtpssunat", SqlDbType.Char, 2).Value = BE.rtpssunat;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Insert_Update(string empresaid, tb_plla_geneventospermiso BE, DataTable Detalle)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         bool xreturn = true;
         int lcont = 0;
         for (lcont = 0; lcont <= Detalle.Rows.Count - 1; lcont++)
         {
             using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_INSERT", cnx))
             {
                 cmd.CommandTimeout = 0;
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@eventoperid", SqlDbType.Char, 3).Value = Detalle.Rows[lcont]["eventoperid"];
                 cmd.Parameters.Add("@eventopername", SqlDbType.VarChar, 50).Value = Detalle.Rows[lcont]["eventopername"];
                 cmd.Parameters.Add("@planilla", SqlDbType.Int).Value = Detalle.Rows[lcont]["planilla"];
                 cmd.Parameters.Add("@status", SqlDbType.Int).Value = Detalle.Rows[lcont]["status"];
                 cmd.Parameters.Add("@tipoevento", SqlDbType.Char, 2).Value = Detalle.Rows[lcont]["tipoevento"];
                 cmd.Parameters.Add("@rtpssunat", SqlDbType.Char, 2).Value = Detalle.Rows[lcont]["rtpssunat"];
                 try
                 {
                     cnx.Open();
                     if (cmd.ExecuteNonQuery() > 0)
                     {
                         xreturn = true;
                     }
                     else
                     {
                         xreturn = false;
                     }
                     cnx.Close();
                 }
                 catch (Exception ex)
                 {
                     Sql_Error = ex.Message;
                     //throw new Exception(ex.Message);
                     xreturn = false;
                     cnx.Close();
                 }
             }
         }
         return xreturn;
     }
 }
        public DataSet GetOne(string empresaid, tb_plla_geneventospermiso BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_SELECT", cnx))
                {
                    DataSet ds = new DataSet();
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@eventoperid", SqlDbType.Char, 3).Value = BE.eventoperid;
                    }

                    try
                    {
                        cnx.Open();
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            da.Fill(ds);
                        }
                        return ds;
                    }
                    catch (Exception ex)
                    {
                        Sql_Error = ex.Message;
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
 //public DataSet GetAll_CONSULTACCOSTO(string empresaid, tb_plla_plantilla_contratos BE)
 //{
 //    using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
 //    {
 //        using (SqlCommand cmd = new SqlCommand("gspTbPllaCcostogen_CONSULTASelectAll", cnx))
 //        {
 //            DataSet ds = new DataSet();
 //            {
 //                cmd.CommandType = CommandType.StoredProcedure;
 //                cmd.Parameters.AddWithValue("@empresaid", string.IsNullOrEmpty(BE.empresaid) ? (object)DBNull.Value : BE.empresaid);
 //                cmd.Parameters.AddWithValue("@nomlike1", string.IsNullOrEmpty(BE.nomlike1) ? (object)DBNull.Value : BE.nomlike1);
 //                cmd.Parameters.AddWithValue("@nomlike2", string.IsNullOrEmpty(BE.nomlike2) ? (object)DBNull.Value : BE.nomlike2);
 //                cmd.Parameters.AddWithValue("@nomlike3", string.IsNullOrEmpty(BE.nomlike3) ? (object)DBNull.Value : BE.nomlike3);
 //                cmd.Parameters.AddWithValue("@ccostodescartar", string.IsNullOrEmpty(BE.ccostodescartar) ? (object)DBNull.Value : BE.ccostodescartar);
 //            }
 //            try
 //            {
 //                cnx.Open();
 //                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
 //                {
 //                    da.Fill(ds);
 //                }
 //                return ds;
 //            }
 //            catch (Exception ex)
 //            {
 //                Sql_Error = ex.Message;
 //                throw new Exception(ex.Message);
 //            }
 //        }
 //    }
 //}
 public DataSet GetAll_MaxCodigo(string empresaid, tb_plla_geneventospermiso BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_MaxCodEventoPermiso", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 private void Frm_Planilla_GenEventosPermiso_Activated(object sender, EventArgs e)
 {
     if (Sw_LOad)
     {
         //cmbtipo.ValueMember = "cele";
         //cmbtipo.DisplayMember = "dele";
         //cmbtipo.DataSource = ocapa.CaeSoft_GetAllTipoEventoPermiso;
         tb_plla_geneventospermisoBL BL = new tb_plla_geneventospermisoBL();
         tb_plla_geneventospermiso BE = new tb_plla_geneventospermiso();
         cmbtipo.ValueMember = "cele";
         cmbtipo.DisplayMember = "descripcion";
         cmbtipo.DataSource = BL.GetAllTipoEvento(VariablesPublicas.EmpresaID, BE).Tables[0];
         U_RefrescaControles();
         CargaDatos();
         U_RefrescaControles();
         Sw_LOad = false;
     }
 }
 public DataSet GetAll_CONSULTAIR(string empresaid, tb_plla_geneventospermiso BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPllageneventospermiso_IR", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.AddWithValue("@eventoperid", string.IsNullOrEmpty(BE.eventoperid) ? (object)DBNull.Value : BE.eventoperid);
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        private void CargaDatos()
        {
            int nposcolumnasortear = 0;
            SortOrder PrvSotOrder = default(SortOrder);
            bool zordenado = false;
            string xcodcliente = "..";
            string xpalabra1 = "";
            string xpalabra2 = "";
            string xpalabra3 = "";
            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["eventoperid"].Value.ToString();
            }
            if ((Examinar.SortedColumn != null))
            {
                nposcolumnasortear = Examinar.SortedColumn.Index;
                PrvSotOrder = Examinar.SortOrder;
                zordenado = true;
            }
            tb_plla_geneventospermisoBL BL = new tb_plla_geneventospermisoBL();
            tb_plla_geneventospermiso BE = new tb_plla_geneventospermiso();
            BE.norden = 1;
            BE.nomlike1 = xpalabra1;
            BE.nomlike2 = xpalabra2;
            BE.nomlike3 = xpalabra3;
            tablaclientes = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
            if (BL.Sql_Error.Length > 0)
            {
                Frm_Class.ShowError(BL.Sql_Error, this);
                return;
            }
            Examinar.AutoGenerateColumns = false;
            Examinar.DataSource = tablaclientes;

            //if (!(txtdescripcion.MaxLength == tablaclientes.Columns["eventopername"].MaxLength))
            //{
            //    txtdescripcion.MaxLength = tablaclientes.Columns["eventopername"].MaxLength;
            //}

            VariablesPublicas.PintaEncabezados(Examinar);

            if (zordenado)
            {
                if (PrvSotOrder == SortOrder.Ascending)
                {
                    Examinar.Sort(Examinar.Columns[nposcolumnasortear], System.ComponentModel.ListSortDirection.Ascending);
                }
                else
                {
                    Examinar.Sort(Examinar.Columns[nposcolumnasortear], System.ComponentModel.ListSortDirection.Descending);
                }
            }
            else
            {
                Examinar.Sort(Examinar.Columns["eventoperid"], System.ComponentModel.ListSortDirection.Ascending);
            }
            if (Examinar.CurrentRow == null)
            {
                if (Examinar.RowCount > 0)
                {
                    Examinar.CurrentCell = Examinar.Rows[0].Cells["eventoperid"];
                }
            }
            for (lc_cont = 0; lc_cont <= Examinar.Rows.Count - 1; lc_cont++)
            {
                if (Examinar.Rows[lc_cont].Cells["eventoperid"].Value.ToString() == xcodcliente)
                {
                    Examinar.CurrentCell = Examinar.Rows[lc_cont].Cells["eventoperid"];
                    break;
                }
            }
        }
 private void btnnuevo_Click(object sender, EventArgs e)
 {
     if (!(TabControl1.SelectedIndex == 0))
     {
         TabControl1.SelectedIndex = 0;
     }
     u_n_opsel = 1;
     Blanquear();
     U_RefrescaControles();
     TabControl1.SelectedIndex = 0;
     TabControl1.SelectedIndex = 1;
     tb_plla_geneventospermisoBL BL = new tb_plla_geneventospermisoBL();
     tb_plla_geneventospermiso BE = new tb_plla_geneventospermiso();
     txtcodigo.Text = BL.GetAll_MaxCodigo(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0].Rows[0]["maximo_codigo"].ToString();
     chkactivo.Checked = true;
     cmbtipo.SelectedValue = "N";
     txtdescripcion.Focus();
 }
 private void btngrabar_Click(object sender, EventArgs e)
 {
     if (U_Validacion())
     {
         tb_plla_geneventospermisoBL BL = new tb_plla_geneventospermisoBL();
         tb_plla_geneventospermiso BE = new tb_plla_geneventospermiso();
         BE.eventoperid = txtcodigo.Text.Trim();
         BE.norden = 1;
         tmpcursor = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
         if (u_n_opsel == 1)
         {
             while (1 == 1)
             {
                 tmpcursor = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
                 if (BL.Sql_Error.Length > 0)
                 {
                     Frm_Class.ShowError(BL.Sql_Error + "\r" + "Error al buscar código", this);
                     return;
                 }
                 if (tmpcursor.Rows.Count > 0)
                 {
                     tb_plla_geneventospermisoBL BLMX = new tb_plla_geneventospermisoBL();
                     tb_plla_geneventospermiso BEMX = new tb_plla_geneventospermiso();
                     txtcodigo.Text = BLMX.GetAll_MaxCodigo(VariablesPublicas.EmpresaID.ToString(), BEMX).Tables[0].Rows[0]["maximo_codigo"].ToString();
                 }
                 else
                 {
                     break;
                 }
             }
             tmpcursor = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
             tmpcursor.Rows.Add(VariablesPublicas.InsertIntoTable(tmpcursor));
             tmpcursor.Rows[0]["eventoperid"] = txtcodigo.Text.Trim();
         }
         tmpcursor.Rows[0]["eventopername"] = txtdescripcion.Text.Trim();
         tmpcursor.Rows[0]["planilla"] = 1;
         tmpcursor.Rows[0]["status"] = (chkactivo.Checked ? 1 : 0);
         tmpcursor.Rows[0]["rtpssunat"] = cmbcodsunat.SelectedValue;
         if (cmbtipo.SelectedValue != null)
         {
             tmpcursor.Rows[0]["tipoevento"] = cmbtipo.SelectedValue;
         }
         tmpcursor.AcceptChanges();
         if (BL.Insert_Update(VariablesPublicas.EmpresaID, BE, tmpcursor))
         {
             seguridadlog();
             U_CancelarEdicion(0);
         }
         else
         {
             Frm_Class.ShowError(BL.Sql_Error, this);
         }
     }
 }
        private void btneliminar_Click(object sender, EventArgs e)
        {
            if ((Examinar.CurrentRow != null))
            {
                xnomcampo = "";
                tb_plla_geneventospermisoBL BLEP = new tb_plla_geneventospermisoBL();
                tb_plla_geneventospermiso BEEP = new tb_plla_geneventospermiso();
                BEEP.eventoperid = Examinar.Rows[Examinar.CurrentRow.Index].Cells["eventoperid"].Value.ToString();
                //tmpcursor = BLEP.GetAll_CONSULTAIR(VariablesPublicas.EmpresaID, BEEP).Tables[0];
                //tmpcursor = ocapa.IR_EVENTOSPERMISO(GlobalVars.GetInstance.Company, Examinar.Rows(Examinar.CurrentRow.Index).Cells("eventoperid").Value);
                if (BLEP.Sql_Error.Length > 0)
                {
                    xnomcampo = BLEP.Sql_Error;
                    Frm_Class.ShowError(BLEP.Sql_Error, this);
                }
                else
                {
                    //if (tmpcursor.Rows.Count == 0)
                    //{
                    //}
                    //else
                    //{
                    //    for (lc_cont = 0; lc_cont <= tmpcursor.Rows.Count - 1; lc_cont++)
                    //    {
                    //        xnomcampo = xnomcampo + tmpcursor.Rows[lc_cont]["relacion"] + "\r";
                    //        if (lc_cont + 1 == 10)
                    //        {
                    //            break;
                    //        }
                    //    }
                    //}
                }
                if (xnomcampo.Length == 0)
                {
                    tb_plla_geneventospermisoBL BL = new tb_plla_geneventospermisoBL();
                    tb_plla_geneventospermiso BE = new tb_plla_geneventospermiso();
                    BE.eventoperid = Examinar.Rows[Examinar.CurrentRow.Index].Cells["eventoperid"].Value.ToString().Trim();
                    BE.norden = 1;
                    tmptabla = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
                    if (BL.Sql_Error.Length == 0)
                    {
                        string message = "Desea eliminar datos  " + tmptabla.Rows[0]["eventoperid"].ToString().Trim() + "-" + tmptabla.Rows[0]["eventopername"].ToString().Trim() + " ...?";
                        string caption = "Mensaje del Sistema";
                        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                        DialogResult result;
                        // Muestra el cuadro de mensaje.
                        result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                        if (result == DialogResult.Yes)
                        {
                            BL.Eliminar(VariablesPublicas.EmpresaID, tmptabla);
                            if (BL.Sql_Error.Length == 0)
                            {
                                tb_co_seguridadlogBL BLL = new tb_co_seguridadlogBL();
                                tb_co_seguridadlog BEL = new tb_co_seguridadlog();

                                BEL.moduloid = Name;
                                BEL.clave = VariablesPublicas.EmpresaID + Examinar.Rows[Examinar.CurrentRow.Index].Cells["eventoperid"].Value.ToString();
                                BEL.cuser = VariablesPublicas.Usuar;
                                BEL.fecha = DateTime.Now;
                                BEL.pc = VariablesPublicas.userip;
                                BEL.accion = "B";
                                BEL.detalle = "Descripción: " + txtdescripcion.Text.Trim();
                                BLL.Insert(VariablesPublicas.EmpresaID.ToString(), BEL);
                                Examinar.Rows.Remove(Examinar.CurrentRow);
                                Examinar.Refresh();
                                u_PintaDatos();
                            }
                            else
                            {
                                Frm_Class.ShowError(BL.Sql_Error, this);
                            }
                        }
                    }
                    else
                    {
                        Frm_Class.ShowError(BL.Sql_Error, this);
                    }
                }
                else
                {
                    MessageBox.Show(xnomcampo, "IMPOSIBLE ELIMINAR REGISTRO");
                }
            }
            U_RefrescaControles();
        }
 private bool ValidaEventos(int fila, bool b)
 {
     var prove = string.Empty;
     var trab = new DataTable();
     if ((!object.ReferenceEquals(dgIngresos.Rows[fila].Cells[3].Value, DBNull.Value)))
     {
         if (dgIngresos.Rows[fila].Cells[3].Value.ToString() != string.Empty)
         {
             var BL = new tb_plla_geneventospermisoBL();
             var BE = new tb_plla_geneventospermiso();
             prove = VariablesPublicas.FormateaNumeroaCadena2(dgIngresos.Rows[fila].Cells[3].Value.ToString().Trim(), 3, '0', true);
             dgIngresos.Rows[fila].Cells[3].Value = prove;
             BE.eventoperid = prove;
             trab = BL.GetAll_CONSULTA(VariablesPublicas.EmpresaID, BE).Tables[0];
         }
     }
     if (trab.Rows.Count > 0)
     {
         dgIngresos.Rows[dgIngresos.CurrentRow.Index].Cells[4].Value = trab.Rows[0]["eventopername"].ToString().Trim();
         return true;
     }
     else
     {
         if (b)
         {
             MessageBox.Show("Codigo no existe !!!");
         }
         return false;
     }
 }