public bool Delete(string empresaid, tb_pt_entalle BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPtEntalle_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@entalleid", SqlDbType.Char, 4).Value = BE.entalleid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll_paginacion(string empresaid, tb_pt_entalle BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPtEntalle_SEARCH_paginacion", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@entalleid", SqlDbType.Char, 2).Value = BE.entalleid;
                 cmd.Parameters.Add("@posicion", SqlDbType.Char, 10).Value = BE.posicion;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 void CargarCmbEntalle()
 {
     tb_pt_entalleBL BL = new tb_pt_entalleBL();
     tb_pt_entalle BE = new tb_pt_entalle();
     DataTable dt = new DataTable();
     dt = BL.GetAll(EmpresaID, BE).Tables[0];
     if (dt.Rows.Count > 0)
     {
         cmb_entalleid.DataSource = dt;
         cmb_entalleid.ValueMember = "entalleid";
         cmb_entalleid.DisplayMember = "entallename";
     }
 }
 private void cmb_entalleid_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ssModo == "EDIT" || ssModo == "NEW")
     {
         if (cmb_entalleid.SelectedIndex >= 0)
         {
             var BE = new tb_pt_entalle();
             var BL = new tb_pt_entalleBL();
             var dt = new DataTable();
             BE.entalleid = cmb_entalleid.SelectedValue.ToString();
             dt = BL.GetAll(EmpresaID, BE).Tables[0];
             foreach (DataRow fila in dt.Rows)
             {
                 _xentalledescort = fila["entalledescort"].ToString().Trim();
                 _GenerarNombre();
             }
         }
     }
 }
        private void Update()
        {
            try
            {
                if (entalleid.Text.Trim().Length != 2)
                {
                    MessageBox.Show("Falta Codigo Entalle !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (entallename.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese Nombre de entalle", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        var BL = new tb_pt_entalleBL();
                        var BE = new tb_pt_entalle();

                        BE.entalleid = entalleid.Text.Trim().PadLeft(2, '0');
                        BE.entallename = entallename.Text.ToUpper();
                        BE.entalledescort = entalledescort.Text.ToUpper();
                        BE.usuar = VariablesPublicas.Usuar.Trim();

                        if (BL.Update(EmpresaID, BE))
                        {
                            SEGURIDAD_LOG("M");
                            MessageBox.Show("Datos Modificado Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            procesado = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Insert()
        {
            try
            {
                if (entallename.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Ingrese nombre de entalle", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_pt_entalleBL();
                    var BE = new tb_pt_entalle();

                    BE.entalleid = entalleid.Text.Trim().PadLeft(2, '0');
                    BE.entallename = entallename.Text.ToUpper().ToUpper();
                    BE.entalledescort = entalledescort.Text.ToUpper();
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (BL.Insert(EmpresaID, BE))
                    {
                        MessageBox.Show("Datos Grabados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        procesado = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void form_cargar_datos(String posicion)
        {
            try
            {
                var BL = new tb_pt_entalleBL();
                var BE = new tb_pt_entalle();
                var dt = new DataTable();
                if (entalleid.Text.Trim().Length > 0)
                {
                    BE.entalleid = entalleid.Text.Trim().PadLeft(2, '0');
                }
                BE.posicion = posicion.Trim();

                dt = BL.GetAll_paginacion(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    limpiar_documento();
                    ssModo = "EDIT";

                    entalleid.Text = dt.Rows[0]["entalleid"].ToString().Trim();
                    entallename.Text = dt.Rows[0]["entallename"].ToString().Trim();
                    entalledescort.Text = dt.Rows[0]["entalledescort"].ToString().Trim();

                    btn_editar.Enabled = true;
                    btn_eliminar.Enabled = true;
                    btn_imprimir.Enabled = true;

                    btn_primero.Enabled = true;
                    btn_anterior.Enabled = true;
                    btn_siguiente.Enabled = true;
                    btn_ultimo.Enabled = true;

                    btn_log.Enabled = true;
                    btn_salir.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Delete()
        {
            try
            {
                if (entalleid.Text.Trim().Length != 2)
                {
                    MessageBox.Show("Falta Codigo entalle !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_pt_entalleBL();
                    var BE = new tb_pt_entalle();
                    BE.entalleid = entalleid.Text.Trim().PadLeft(2, '0');

                    if (BL.Delete(EmpresaID, BE))
                    {
                        SEGURIDAD_LOG("E");
                        MessageBox.Show("Datos Eliminados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        form_bloqueado(false);
                        data_Tablaentalle();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tablaentalle()
        {
            try
            {
                if (Tablaentalle.Rows.Count > 0)
                {
                    Tablaentalle.Rows.Clear();
                }
                var BL = new tb_pt_entalleBL();
                var BE = new tb_pt_entalle();

                BE.entallename = txt_criterio.Text.Trim().ToUpper();

                Tablaentalle = BL.GetAll(EmpresaID, BE).Tables[0];
                if (Tablaentalle.Rows.Count > 0)
                {
                    btn_imprimir.Enabled = true;
                    gridentalle.DataSource = Tablaentalle;
                    gridentalle.Rows[0].Selected = false;
                    gridentalle.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool Insert(string empresaid, tb_pt_entalle BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPtEntalle_INSERT", cnx))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@entalleid", SqlDbType.Char, 4).Value = BE.entalleid;
                    cmd.Parameters.Add("@entallename", SqlDbType.VarChar, 30).Value = BE.entallename;
                    cmd.Parameters.Add("@entalledescort", SqlDbType.Char, 10).Value = BE.entalledescort;
                    cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = BE.usuar;

                    try
                    {
                        cnx.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
 public bool Update(string empresaid, tb_pt_entalle BE)
 {
     return tablaDA.Update(empresaid, BE);
 }
 public bool Insert(string empresaid, tb_pt_entalle BE)
 {
     return tablaDA.Insert(empresaid, BE);
 }
 public DataSet GetAll_paginacion(string empresaid, tb_pt_entalle BE)
 {
     return tablaDA.GetAll_paginacion(empresaid, BE);
 }
 public bool Delete(string empresaid, tb_pt_entalle BE)
 {
     return tablaDA.Delete(empresaid, BE);
 }