private void Valida_Familia(String xcod)
 {
     var BE = new tb_pt_familia();
     var BL = new tb_pt_familiaBL();
     var dt = new DataTable();
     BE.moduloid = "0320".ToString();
     BE.familiaid = xcod.Trim();
     dt = BL.GetAll(EmpresaID, BE).Tables[0];
     if (dt.Rows.Count > 0)
     {
         familiatelaid.Text = dt.Rows[0]["familiaid"].ToString();
         familiatelaname.Text = dt.Rows[0]["familianame"].ToString();
         _estructuraid = dt.Rows[0]["estructuraid"].ToString();
         _tejidoid = dt.Rows[0]["lineaid"].ToString();
     }
     else
     {
         familiatelaid.Text = string.Empty;
         familiatelaname.Text = string.Empty;
         _estructuraid = string.Empty;
         _tejidoid = string.Empty;
     }
 }
        private void Insert()
        {
            try
            {
                if (cboModuloID.SelectedIndex == -1)
                {
                    MessageBox.Show("Falta Escoger el Modulo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (familianame.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese Nombre de Familia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        if (unmed.Text.Trim().Length == 0)
                        {
                            MessageBox.Show("Ingrese Unidad de Medida", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            var BL = new tb_pt_familiaBL();
                            var BE = new tb_pt_familia();

                            BE.moduloid = cboModuloID.SelectedValue.ToString();
                            BE.familiaid = familiaid.Text.Trim().PadLeft(3, '0');
                            BE.familianame = familianame.Text.ToUpper().ToUpper();
                            if (tejidoid.SelectedValue != null && tejidoid.Text.Trim().Length > 0)
                            {
                                BE.lineaid = tejidoid.SelectedValue.ToString();
                            }
                            BE.usuar = VariablesPublicas.Usuar.Trim();
                            BE.unmed = unmed.Text.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 Delete()
        {
            try
            {
                if (familiaid.Text.Trim().Length != 3)
                {
                    MessageBox.Show("Falta Codigo Familia !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_pt_familiaBL();
                    var BE = new tb_pt_familia();

                    BE.moduloid = cboModuloID.SelectedValue.ToString();
                    BE.familiaid = familiaid.Text.Trim().PadLeft(3, '0');
                    if (BL.Delete(EmpresaID, BE))
                    {
                        SEGURIDAD_LOG("E");
                        MessageBox.Show("Datos eliminados correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        Data_Tablafamilia();
                        form_bloqueado(false);
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Data_Tablafamilia()
        {
            try
            {
                if (Tablafamilia.Rows.Count > 0)
                {
                    Tablafamilia.Rows.Clear();
                }
                var BL = new tb_pt_familiaBL();
                var BE = new tb_pt_familia();

                if (cboModuloID2.SelectedIndex != -1)
                {
                    BE.moduloid = cboModuloID2.SelectedValue.ToString();
                    BE.familianame = txt_criterio.Text.Trim().ToUpper();

                    Tablafamilia = BL.GetAll(EmpresaID, BE).Tables[0];
                    if (Tablafamilia.Rows.Count > 0)
                    {
                        btn_imprimir.Enabled = true;
                        MDI_dgb_familia1.DataSource = Tablafamilia;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Update()
        {
            try
            {
                if (familiatelasid.Text.Trim().Length != 3)
                {
                    MessageBox.Show("Falta Codigo Familia !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (familiatelasname.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese Nombre de Familia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        var BL = new tb_pt_familiaBL();
                        var BE = new tb_pt_familia();

                        BE.moduloid = cboModuloID.SelectedValue.ToString();
                        BE.familiaid = familiatelasid.Text.Trim().PadLeft(3, '0');
                        BE.familianame = familiatelasname.Text.ToUpper();
                        if (tejidoid.SelectedValue != null && tejidoid.Text.Trim().Length > 0)
                        {
                            BE.lineaid = tejidoid.SelectedValue.ToString();
                        }
                        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_familiaBL();
                var BE = new tb_pt_familia();
                var dt = new DataTable();

                BE.moduloid = cboModuloID.SelectedValue.ToString();
                if (familiatelasid.Text.Trim().Length > 0)
                {
                    BE.familiaid = familiatelasid.Text.Trim().PadLeft(3, '0');
                }
                BE.posicion = posicion.Trim();

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

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

                    familiatelasid.Text = dt.Rows[0]["familiatelaid"].ToString().Trim();
                    familiatelasname.Text = dt.Rows[0]["familiatelaname"].ToString().Trim();
                    estructuraid.SelectedValue = dt.Rows[0]["estructuraid"].ToString().Trim();

                    data_cbo_tejidoid();
                    tejidoid.SelectedValue = dt.Rows[0]["lineaid"].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);
            }
        }