public DataSet GetAll_paginacion(string empresaid, tb_pt_parte BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPtParte_SEARCH_paginacion", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@parteid", SqlDbType.Char, 2).Value = BE.parteid;
                 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);
             }
         }
     }
 }
 public bool Delete(string empresaid, tb_pt_parte BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPtparte_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@parteid", SqlDbType.Char, 2).Value = BE.parteid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        public bool Insert(string empresaid, tb_pt_parte BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPtparte_INSERT", cnx))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@parteid", SqlDbType.Char, 1).Value = BE.parteid;
                    cmd.Parameters.Add("@partename", SqlDbType.VarChar, 30).Value = BE.partename;
                    cmd.Parameters.Add("@partedescort", SqlDbType.Char, 10).Value = BE.partedescort;
                    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);
                    }
                }
            }
        }
        private void Update()
        {
            try
            {
                if (parteid.Text.Trim().Length != 1)
                {
                    MessageBox.Show("Falta Codigo parte !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (partename.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese Nombre de parte", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        var BL = new tb_pt_parteBL();
                        var BE = new tb_pt_parte();

                        BE.parteid = parteid.Text.Trim().PadLeft(1, '0');
                        BE.partename = partename.Text.ToUpper();
                        BE.partedescort = partedescort.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 form_cargar_datos(String posicion)
        {
            try
            {
                var BL = new tb_pt_parteBL();
                var BE = new tb_pt_parte();
                var dt = new DataTable();
                if (parteid.Text.Trim().Length > 0)
                {
                    BE.parteid = parteid.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";

                    parteid.Text = dt.Rows[0]["parteid"].ToString().Trim();
                    partename.Text = dt.Rows[0]["partename"].ToString().Trim();
                    partedescort.Text = dt.Rows[0]["partedescort"].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 (parteid.Text.Trim().Length != 1)
                {
                    MessageBox.Show("Falta Codigo parte !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_pt_parteBL();
                    var BE = new tb_pt_parte();
                    BE.parteid = parteid.Text.Trim().PadLeft(1, '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_Tablaparte();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tablaparte()
        {
            try
            {
                if (Tablaparte.Rows.Count > 0)
                {
                    Tablaparte.Rows.Clear();
                }
                var BL = new tb_pt_parteBL();
                var BE = new tb_pt_parte();

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

                Tablaparte = BL.GetAll(EmpresaID, BE).Tables[0];
                if (Tablaparte.Rows.Count > 0)
                {
                    btn_imprimir.Enabled = true;
                    gridparte.DataSource = Tablaparte;
                    gridparte.Rows[0].Selected = false;
                    gridparte.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void Cargar_cmbParte()
 {
     var BE = new tb_pt_parte();
     var BL = new tb_pt_parteBL();
     var dt = new DataTable();
     dt = BL.GetAll(EmpresaID, BE).Tables[0];
     if (dt.Rows.Count > 0)
     {
         cmb_parteid.DataSource = dt;
         cmb_parteid.ValueMember = "parteid";
         cmb_parteid.DisplayMember = "partename";
     }
 }