Exemplo n.º 1
0
        /**Escribede un objeto de la clase CIndice*/
        public void EscribeIndicePrimario(CIndice indPri)
        {
            BinaryWriter bw;

            bw = getBw();
            bw.BaseStream.Seek(indPri.getDirInd(), SeekOrigin.Begin);

            bw.Write(indPri.getTipoInd());
            bw.Write(indPri.getTamIndPri());
            bw.Write(indPri.getIndPrim());
            bw.Write(indPri.getSigInd());
            bw.Write(indPri.getCabBloques());
            bw.Write(indPri.getDirInd());
        }
Exemplo n.º 2
0
        /**\Compara dos indices primario*/
        public int comparateTo(CIndice indB)
        {
            int res = -1;

            switch (this.getTipoInd())
            {
                case 2://Short
                    if (BitConverter.ToInt16(getIndPrim(), 0) > BitConverter.ToInt16(indB.getIndPrim(), 0))
                        res = 1;
                    else
                        if (BitConverter.ToInt16(getIndPrim(), 0) == BitConverter.ToInt16(indB.getIndPrim(), 0))
                            res = 0;
                    break;
                case 3://Int
                    if (BitConverter.ToInt32(getIndPrim(), 0) > BitConverter.ToInt32(indB.getIndPrim(), 0))
                        res = 1;
                    else
                        if (BitConverter.ToInt32(getIndPrim(), 0) == BitConverter.ToInt32(indB.getIndPrim(), 0))
                            res = 0;
                    break;
                case 5://Long 
                    if (BitConverter.ToInt64(getIndPrim(), 0) > BitConverter.ToInt64(indB.getIndPrim(), 0))
                        res = 1;
                    else
                        if (BitConverter.ToInt64(getIndPrim(), 0) == BitConverter.ToInt64(indB.getIndPrim(), 0))
                            res = 0;
                    break;
                case 7://Cadena
                    byte []cA = getIndPrim();
                    byte[] cB = indB.getIndPrim();

                    char[] cadA = new char[cA.Length];
                    char[] cadB = new char[cB.Length];
                    string claveA, claveB;

                    for (int i = 0; i < cA.Length; i++)
                        cadA[i] = (char)cA[i];

                    claveA = new string(cadA);

                    for (int i = 0; i < cB.Length; i++)
                        cadB[i] = (char)cB[i];

                    claveB = new string(cadB);

                    if (claveA.ToUpper().CompareTo(claveB.ToUpper()) > 0)
                        res = 1;
                    else
                        if (claveA.ToUpper().CompareTo(claveB.ToUpper()) == 0)
                            res = 0;

                    break;
            }

            return (res);
        }
Exemplo n.º 3
0
        private void btEliminarReg_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection reg = tablaDatos.SelectedRows;
            CBloque bloqueAux;
            long posInd;
            
            getArchivo().AbrirArchivo();
            
            for (int i = 0; i < reg.Count; i++)
            {
               
                bloqueAux = creaBloqueDatos(reg[i].Index);
                BajaOSIRec(ent, bloqueAux);
                eliminaOSI(ent, bloqueAux);
            }

            getArchivo().CerrarArchivo();

            if (reg.Count > 0)
            {
                getArchivo().AbrirArchivo();
                indPrim = getArchivo().LeerIndicePrimario(indPrim.getDirInd());
                getArchivo().CerrarArchivo();

                if (indPrim.getCabBloques() == -1)
                {
                    listaIP.Items.Clear();
                    ImprimeIndices(ent.getApCabDatos());
                    if (ent.getApCabDatos() != -1)
                        listaIP.SelectedIndex = 0;
                }
                imprimeTablaDatos(indPrim.getCabBloques());
            }
        }
Exemplo n.º 4
0
        /**Se lee del archivo de trabajo un objeto de la clase CIndice, que sera utilzado
         * en la organización secuencial indexada*/
        public CIndice LeerIndicePrimario(long pos)
        {
            BinaryReader br;
            CIndice indPri = new CIndice();

            br = getBr();

            br.BaseStream.Seek(pos, SeekOrigin.Begin);

            indPri.setTipoInd(br.ReadInt32());
            indPri.setTamIndPri(br.ReadInt32());
            indPri.setIndPrim(br.ReadBytes(indPri.getTamIndPri()));
            indPri.setSigInd(br.ReadInt64());
            indPri.setCabBloques(br.ReadInt64());
            indPri.setDirInd(br.ReadInt64());

            return (indPri);
        }
Exemplo n.º 5
0
        /**Elimian un bloque del archivo implementado en la organización*/
        public  void eliminaBloque(ref CIndice ind, CBloque b)
        {
            CBloque bloAux, bloAnt;
            long ptrAux, ptrAnt;
            int tamB;

            bloAux = bloAnt = null;
            ptrAux = ptrAnt = -1;
            tamB = b.getTamBlo();
            ptrAux = ind.getCabBloques();

            while (ptrAux != -1)//Se ubica el registro en el archivo
            {
                bloAux = getArchivo().leerBloque(ptrAux, tamB);

                if (b.ComparateTo(bloAux) != 0)
                {
                    ptrAnt = ptrAux;
                    bloAnt = bloAux;
                    bloAnt.setTamBlo(tamB);
                    ptrAux = bloAux.getSigBlo();
                }
                else
                    break;
            }

            if (ptrAux == ind.getCabBloques())//Se actualiza la cabecera de datos de la entidad en caso de que sea el primero
            {
                ind.setCabBloques( bloAux.getSigBlo());
                getArchivo().EscribeIndicePrimario(ind);
            }
            else
            {
                bloAnt.setSigBlo(bloAux.getSigBlo());
                bloAnt.setTamBlo(tamB);
                getArchivo().EscribeBloque(bloAnt, ptrAnt);
            }
        }
Exemplo n.º 6
0
        /** Se elimina un indice primiraio*/
        public void eliminaIndicePrimario(CNodoEntidad e, CIndice ind)
        {
            CIndice bloAux, bloAnt;
            long ptrAux, ptrAnt;

            bloAux = bloAnt = null;
            ptrAux = ptrAnt = -1;

            ptrAux = e.getApCabDatos();

            while (ptrAux != -1)
            {
                bloAux = getArchivo().LeerIndicePrimario(ptrAux);

                if (ind.comparateTo(bloAux) != 0 )
                {
                    ptrAnt = ptrAux;
                    bloAnt = bloAux;
                    ptrAux = bloAux.getSigInd();
                }
                else
                    break;
            }

            if (ptrAux == e.getApCabDatos())
            {
                e.setApCabDatos(bloAux.getSigInd());
                getArchivo().escribeEntidad(e, e.getDir());
            }
            else
            {
                bloAnt.setSigInd(bloAux.getSigInd());
                getArchivo().EscribeIndicePrimario(bloAnt);
            }
        }
Exemplo n.º 7
0
        /**Inserta el bloque de datos, accediendo a la estructura de datos implementada en el archivo*/
        public int insBloque(CIndice ind, CBloque nuevo, long posB)
        {
            CBloque bAux, bAnt = null;
            long ptrAux, ptrAnt = -1; 
            int band = -1;

            ptrAux = ind.getCabBloques();
            
            while (ptrAux != -1)
            {
                bAux = getArchivo().leerBloque(ptrAux, nuevo.getTamBlo());

                if ((band = nuevo.ComparateTo(bAux)) > 0)
                {
                    ptrAnt = ptrAux;
                    bAnt = bAux;
                    bAnt.setTamBlo(nuevo.getTamBlo());
                    ptrAux = bAux.getSigBlo();
                }
                else
                    break;
            }

            if (band == 0)
                return 0;
            else
             if (ptrAux == ind.getCabBloques())
                {
                    ind.setCabBloques(posB);
                    getArchivo().EscribeIndicePrimario(ind);
                }
                else
                {
                    bAnt.setSigBlo(posB);
                    getArchivo().EscribeBloque(bAnt, ptrAnt);
                }

                nuevo.setSigBlo(ptrAux);
                getArchivo().EscribeBloque(nuevo, posB);
            
            return (band);
        }
Exemplo n.º 8
0
        /**Se realiza una busqueda de un indice primario, que sera utilizado como entrada
         * en al inserción del nuevo bloque*/
        private void buscaIndicePri(ref CIndice ind, string nameInd)
        {
            long ptrAux = ent.getApCabDatos();
            string cad;

            getArchivo().AbrirArchivo();

            while (ptrAux != -1)
            {
                ind = getArchivo().LeerIndicePrimario(ptrAux);
                cad = dameIndPri(ind);

                if (cad.CompareTo(nameInd) == 0)
                    break;
                else
                    ptrAux = ind.getSigInd();
            }

            getArchivo().CerrarArchivo();
        }
Exemplo n.º 9
0
        /* Inserta un indice primario en la lista de indices*/
        private void insIndicePri(CNodoEntidad e, ref CIndice nuevo, long posInd)
        {
            CIndice indAux, indAnt = null;
            long ptrAux, ptrAnt = -1;

            ptrAux = e.getApCabDatos();
            
            while (ptrAux != -1)
            {
                indAux = getArchivo().LeerIndicePrimario(ptrAux);

                if (indAux.comparateTo(nuevo) < 0)
                {
                    ptrAnt = ptrAux;
                    indAnt = indAux;
                    ptrAux = indAux.getSigInd();
                }
                else
                    break;
            }

            if (ptrAux == e.getApCabDatos())
            {
                e.setApCabDatos(posInd);
                getArchivo().escribeEntidad(e, e.getDir());
            }
            else
            {
                indAnt.setSigInd(posInd);
                getArchivo().EscribeIndicePrimario(indAnt);
            }

            nuevo.setDirInd(posInd);
            nuevo.setSigInd(ptrAux);
            getArchivo().EscribeIndicePrimario(nuevo);
        }
Exemplo n.º 10
0
        /* Crea el indice primario correspondiente al bloque*/
        public CIndice generaIndPri(CBloque nuevoB)
        {
            CIndice nuevo = new CIndice();
            byte[] indAux = null;
            int num, tamInd = 0;
            long num2;

            switch (nuevoB.getTipoCA())
            {
                case 3://Clave Primaria de Tipo entera
                    num = BitConverter.ToInt32(nuevoB.dameClave(), 0);
                    indAux = BitConverter.GetBytes((num / 10) * 10);
                    tamInd = 4;
                break;
                case 5://Clave primaria de tipo Long
                    num2 = BitConverter.ToInt64(nuevoB.dameClave(), 0);
                    indAux = BitConverter.GetBytes((num2 / 10) * 10);
                    tamInd = 8;
                break;
                case 7://Clave Primaria de Tipo Cadena
                    indAux = new byte[1];//Se saca el primer caracter
                    indAux[0] = nuevoB.dameClave()[0];
                    tamInd = 1;
                break;
            }

            nuevo.setTipoInd(nuevoB.getTipoCA());
            nuevo.setTamIndPri(tamInd);
            nuevo.setIndPrim(indAux);
       
            return (nuevo);
        }
Exemplo n.º 11
0
        /**\brief Inserta un bloque de datos a la organización*/
        public int AltaOSI(CNodoEntidad e, CBloque nuevo, long posB)
        {
            CIndice indPri, indAux = null;
            int res;
            long ptrAux, posInd;

            
            indPri = generaIndPri(nuevo);
            getArchivo().AbrirArchivo();
            
            ptrAux = e.getApCabDatos();
            
            while (ptrAux != -1)
            {
                indPrim = getArchivo().LeerIndicePrimario(ptrAux);
                if (indPrim.comparateTo(indPri) != 0)
                    ptrAux = indPrim.getSigInd();
                else
                    break;
            }

            if (ptrAux == -1)
            {
                posInd = getArchivo().getFS().Length;
                insIndicePri(e, ref indPri,posInd);
                posB = getArchivo().getFS().Length;
                indPrim = indPri;
                res = insBloque(indPri, nuevo, posB);
            }
            else
                res = insBloque(indPrim, nuevo, posB);
           
            getArchivo().CerrarArchivo();
            return (res);
        }
Exemplo n.º 12
0
        /**Se obtiene el Id de un indice primario*/
        public string dameIndPri(CIndice ind)
        {
            string cad = null;

            switch (ind.getTipoInd())
            {
                case 3://Tipo Entero
                    cad = BitConverter.ToInt32(ind.getIndPrim(), 0).ToString();
                break;
                case 5://Clave primaria de tipo Long
                    cad = BitConverter.ToInt64(ind.getIndPrim(), 0).ToString();
                break;
                case 7://Tipo cadena
                  char []car = new char[1];
                  
                  car[0] = (char)ind.getIndPrim()[0];
                  cad = new string(car);
                break;
            }

            return (cad);
        }
Exemplo n.º 13
0
        /**Función de Mantenimiento para la Organizacion Secuencial indexada*/
        public void MantenimientoSecInd(CArchivo fileOri, CArchivo fileNew, CNodoEntidad ent, CNodoEntidad entC, int tamBloque)
        {
            List<CBloque> listBloque;
            List<CIndice> listaInd;
            CIndice indPri,nuevoInd;
            long aux;
            
            listaInd = new List<CIndice>();
            
            aux = ent.getApCabDatos();
            
            while (aux != -1)
            {
                indPri = fileOri.LeerIndicePrimario(aux);
                nuevoInd = new CIndice();

                nuevoInd.setIndPrim(indPri.getIndPrim());
                nuevoInd.setTamIndPri(indPri.getTamIndPri());
                nuevoInd.setTipoInd(indPri.getTipoInd());

                listBloque = new List<CBloque>();
                
                CopiarSec(fileOri, fileNew, indPri.getCabBloques(), tamBloque, ref listBloque);
                
                nuevoInd.setDirInd(fileNew.ENDF());
                nuevoInd.setCabBloques(listBloque[0].getDir());
                fileNew.EscribeIndicePrimario(nuevoInd);
                
                listaInd.Add(nuevoInd);
                
                aux = indPri.getSigInd();
            }

            for (int i = 0; i < listaInd.Count - 1; i++)
            {
                listaInd[i].setSigInd(listaInd[i + 1].getDirInd());
                fileNew.EscribeIndicePrimario((listaInd[i]));
            }
            
            entC.setApCabDatos(listaInd[0].getDirInd());
            fileNew.escribeEntidad(entC, ent.getDir());
        }