示例#1
0
        /// <summary>
        /// Da de alta un atributo de una entidad
        /// </summary>
        /// <param name="nomEnt">Entidad en la que se va a crear el atributo</param>
        /// <param name="nombreAtr">nombre del atributo</param>
        /// <param name="tipo">tipo del atributo</param>
        /// <returns></returns>
        public bool altaAtributo(Entidad ent, Atributo atr, bool orden)
        {
            bool band = false;

            //            if (this.activeUser.permisos[1] == true)
            //            {
            if (this.buscaAtributo(ent, atr.nombre) == null)
            {
                if (orden)
                {
                    band = this.insertaAtrPrincipio(ent, atr);
                }
                else
                {
                    band = this.insertaAtrFinal(ent, atr);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Ya existe un atributo con el mismo nombre");
            }
            /*            }
                                    else
                                    {
                                        System.Windows.Forms.MessageBox.Show("No tienes permiso para altas");
                                    }
            */

            return band;
        }
示例#2
0
        /// <summary>
        /// Verifica si no existe una entidad con el mismo nombre
        /// e inserta la entidad.
        /// </summary>
        /// <param name="nomEnt">nombre del archivo</param>
        /// <returns>si se insertó correctamente regresa true</returns>
        public bool altaEntidad(Entidad ent)
        {
            bool band = false;
            long pos;

            if (this.usuario.permisos[1] == true)
            {
                if (!this.existeEntidad(ent.nombre))
                {
                    pos = this.insertaEntidad(ent);
                    this.ligaEntidad(pos);
                    band = true;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Entidad ya existente");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("No tienes permiso para altas");
            }

            return band;
        }
示例#3
0
        //por ahora se va a tomar en cuenta una organizacion secuencial
        /// <summary>
        /// Recupera los datos guardados en el archivo y los pone en el control
        /// </summary>
        /// <param name="ent"></param>
        public void insertaDatosDataGrid(Entidad ent)
        {
            long posIt = (ent as EntSecuencial).apBloq;
            byte[] bloq;
            int tam;

            (base.controlPrincipal as DataGridView).Rows.Clear();
            ent.agregaAtributos(this.f.org.listaAtributos(ent.nombre));
            tam = Bloque.calculaTamBloque(ent.listAtr);
            if (ent.listAtr.Count > 0)
            {
                while (posIt != -1)
                {
                    bloq = this.f.org.leeBloque(tam, posIt);
                    posIt = Bloque.leeApBloq(bloq);
                    this.insertaDatosDataGridFila(bloq, ent.listAtr);
                }
            }
        }
示例#4
0
        private void cbEnt_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.selectedEnt = this.f.org.buscaEntidad(this.cbEnt.SelectedItem.ToString());

            selectedEnt.agregaAtributos(this.f.org.listaAtributos(selectedEnt.nombre));
            selectedAtr = selectedEnt.listAtr.Find(a => a.llave.Equals(Atributo.KP));

            dgvConsulta.Rows.Clear();
            dgvConsulta.Columns.Clear();
            cbRel.Items.Clear();
            foreach (Relacion rel in selectedAtr.listRel)
            {
                cbRel.Items.Add(rel.nomEnt);
            }
            if (cbRel.Items.Count > 0)
            {
                cbRel.SelectedIndex = 0;
            }
        }
示例#5
0
        /// <summary>
        /// Busca un bloque que contenga el dato recibido como parametro
        /// </summary>
        /// <param name="ent">la entidad a la que pertenecen los datos</param>
        /// <param name="listAtr"> lista de atributos de la entidad</param>
        /// <param name="dato">dato a buscar en los bloques</param>
        /// <param name="nomAtr">nombre del atributo en el que se va a buscar la igualdad</param>
        /// <returns>si se encontro regresa el bloque en caso contrario regresa null</returns>
        public override byte[] buscaBloque(Entidad ent, List<Atributo> listAtr, string nomAtr, string dato,string path)
        {
            ent.agregaAtributos(listAtr);
            List<byte[]> listBloq = this.listaBloques(ent,path);
            byte[] bloq = null;
            int posAtr = listAtr.FindIndex(a => a.nombre.Equals(nomAtr));

            foreach (byte[] b in listBloq)
            {
                if (Bloque.comparaDato(b, dato, posAtr, listAtr))
                {
                    bloq = b;
                    break;
                }
            }

            return bloq;
        }
示例#6
0
 public virtual bool altaBloque(Entidad ent, byte[] b)
 {
     return false;
 }
示例#7
0
 protected virtual long insertaEntidad(Entidad ent)
 {
     return -1;
 }
示例#8
0
 public virtual List<byte[]> listaBloques(Entidad ent,string path)
 {
     return null;
 }
示例#9
0
 public virtual bool eliminaRegistro(Entidad ent, byte[] b)
 {
     return false;
 }
示例#10
0
 public virtual Atributo buscaAtributo(Entidad ent, string nomAtr,string path)
 {
     return null;
 }
示例#11
0
        /// <summary>
        /// Inserta al final y liga el atributo
        /// </summary>
        /// <param name="ent">Entidad que va a tener el atributo</param>
        /// <param name="atr"> atributo a insertar</param>
        /// <param name="atr"> Ruta del archivo</param>
        /// <returns>true si se insertó correctamente</returns>
        private bool insertaAtrFinal(Entidad ent, Atributo atr)
        {
            bool band = false;
            long posAtr, posIt, posEnt;
            Atributo aAtr;

            posAtr = this.insertaAtributo(atr);
            if (posAtr != 0)
            {
                band = true;
            }
            if ((ent as EntSecuencial).apAtr == -1)
            {
                (ent as EntSecuencial).apAtr = posAtr;
                posEnt = this.buscaPosEntidad(ent.nombre);
                if (posEnt != -1)
                {
                    band = this.reescribeEntidad(ent, posEnt);
                }
            }
            else
            {
                posIt = (ent as EntSecuencial).apAtr;
                do
                {
                    aAtr = this.leeAtributo(posIt);
                    if (aAtr.sigAtr != -1)
                    {
                        posIt = aAtr.sigAtr;
                    }
                } while (aAtr.sigAtr != -1);
                aAtr.sigAtr = posAtr;
                band = this.reescribeAtributo(aAtr, posIt);
            }

            return band;
        }
示例#12
0
        //  <=============Cuidado al reescribir el  nombre==========
        /// <summary>
        /// Reescribe la entidad en el archivo
        /// </summary>
        /// <param name="path"></param>
        /// <param name="ent"></param>
        /// <param name="pos"></param>
        protected override bool reescribeEntidad(Entidad ent, long pos)
        {
            bool band = false;

            try
            {
                using (FileStream fs = new FileStream(base.ruta, FileMode.Open, FileAccess.Write))
                {
                    fs.Seek(pos, SeekOrigin.Begin);
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(ent.nombre);
                        bw.Write((ent as EntSecuencial).apAtr);
                        bw.Write((ent as EntSecuencial).apBloq);
                        bw.Write((ent as EntSecuencial).apRef);
                        bw.Write(ent.sigEnt);
                    }
                }
                band = true;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

            return band;
        }
示例#13
0
        /// <summary>
        /// Graba en el archivo la entidad
        /// </summary>
        /// <param name="path">Ruta del archivo</param>
        /// <param name="ent">Entidad a grabar en el archivo</param>
        /// <returns></returns>
        protected override long insertaEntidad(Entidad ent)
        {
            long pos = 0;

            try
            {
                using (FileStream fs = new FileStream(base.ruta, FileMode.Append))
                {
                    pos = fs.Position;
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(ent.nombre);
                        bw.Write((ent as EntSecuencial).apAtr);
                        bw.Write((ent as EntSecuencial).apBloq);
                        bw.Write((ent as EntSecuencial).apRef);
                        bw.Write(ent.sigEnt);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

            return pos;
        }
示例#14
0
        /// <summary>
        /// regresa todos los registros de la entidad
        /// </summary>
        /// <param name="ent">Entidad con sus atributos</param>
        public override List<byte[]> listaBloques(Entidad ent,string path)
        {
            List<byte[]> listBloq = new List<byte[]>();
            byte[] bloq;

            long pos = (ent as EntSecuencial).apBloq;
            int tamBloq = Bloque.calculaTamBloque(ent.listAtr);

            while (pos != -1)
            {
                bloq = Archivo.leeBloque(path, tamBloq, pos);
                listBloq.Add(bloq);
                pos = Bloque.leeApBloq(bloq);
            }

            return listBloq;
        }
示例#15
0
        public override bool eliminaRegistro(Entidad ent, byte[] bloq)
        {
            bool band = false;
            byte[] bloqAnt=null;
            List<byte[]> listBloq= this.listaBloques(ent);
            long pos = -1;

            for(int i=0;i<listBloq.Count && !band;i++)
            {
                band = Bloque.comparaBloque(listBloq[i], bloq,ent.listAtr);
                if (band)
                {
                    if (i == 0)
                    {
                        (ent as EntSecuencial).apBloq = Bloque.leeApBloq(listBloq[i]);
                        this.reescribeEntidad(ent, this.buscaPosEntidad(ent.nombre));
                    }
                    else
                    {
                        Bloque.reescribeApSigBloq(Bloque.leeApBloq(listBloq[i]), bloqAnt);
                        Archivo.reescribeBloque(base.ruta,bloqAnt, pos);
                        band = true;
                    }
                }
                if (i == 0)
                {
                    pos = (ent as EntSecuencial).apBloq;
                }
                else
                {
                    pos = Bloque.leeApBloq(bloqAnt);
                }
                bloqAnt = listBloq[i];
            }

            return band;
        }
示例#16
0
 public void agregaEntidad(Entidad ent)
 {
     ((ListBox)base.controlPrincipal).Items.Add(ent.nombre);
 }
示例#17
0
        /// <summary>
        /// Inserta al principio y liga el atributo
        /// </summary>
        /// <param name="ent"> Entidad que va a tener el atributo</param>
        /// <param name="atr"> atributo a insertar</param>
        /// <param name="atr"> Ruta del archivo</param>
        /// <returns>true si se insertó correctamente</returns>
        private bool insertaAtrPrincipio(Entidad ent, Atributo atr)
        {
            bool band = false;
            long posAtr, posEnt;

            atr.sigAtr = (ent as EntSecuencial).apAtr;
            posAtr = this.insertaAtributo(atr);
            (ent as EntSecuencial).apAtr = posAtr;
            posEnt = base.buscaPosEntidad(ent.nombre);
            if (posEnt != -1)
            {
                band = this.reescribeEntidad(ent, posEnt);
            }

            return band;
        }
示例#18
0
 /// <summary>
 /// Busca un bloque que contenga el dato recibido como paramentro
 /// </summary>
 /// <param name="ent">la entidad a la que pertenecen los datos</param>
 /// <param name="listAtr"> lista de atributos de la entidad</param>
 /// <param name="dato">dato a buscar en los bloques</param>
 /// <param name="path">ruta del archivo donde se va a buscar</param>
 /// <returns>si se encontro regresa el bloque en caso contrario regresa null</returns>
 public virtual byte[] buscaBloque(Entidad ent, List<Atributo> listAtr, string nomAtr, string dato,string path)
 {
     return null;
 }
示例#19
0
        private bool ligaBloque(Entidad ent, long pos)
        {
            bool band = false;
            long posEnt, posIt;
            byte[] bloq = null;
            long apSigBloq;

            if ((ent as EntSecuencial).apBloq == -1)
            {
                (ent as EntSecuencial).apBloq = pos;
                posEnt = this.buscaPosEntidad(ent.nombre);
                if (posEnt != -1)
                {
                    band = this.reescribeEntidad(ent, posEnt);
                }
            }
            else
            {
                posIt = (ent as EntSecuencial).apBloq;
                do
                {
                    bloq = Archivo.leeBloque(base.ruta, Bloque.calculaTamBloque(ent.listAtr), posIt);
                    apSigBloq = Bloque.leeApBloq(bloq);
                    if (apSigBloq != -1)
                    {
                        posIt = apSigBloq;
                    }
                } while (apSigBloq != -1);
                Bloque.reescribeApSigBloq(pos, bloq);
                band = Archivo.reescribeBloque(base.ruta, bloq, posIt);
            }

            return band;
        }
示例#20
0
 public virtual List<byte[]> listaBloques(Entidad ent)
 {
     return null;
 }
示例#21
0
        public override bool altaBloque(Entidad ent, byte[] b)
        {
            long pos;
            bool band;

            pos = Archivo.escribeBloque(base.ruta, b);
            band = this.ligaBloque(ent, pos);

            return band;
        }
示例#22
0
        public bool modificaBloque(Entidad ent, byte[] bloqViejo,byte[] bloqNuevo)
        {
            bool band = false;

            if (this.eliminaRegistro(ent, bloqViejo))
            {
                band = this.altaBloque(ent, bloqNuevo);
            }

            return band;
        }
示例#23
0
 private void agregaAtributosDataGrid(Entidad ent, DataGridView dgv)
 {
     this.rowAddedActivate = false;
     foreach (Atributo atr in ent.listAtr)
     {
         dgv.Rows.Add(atr.llave.Equals('P')|| atr.llave.Equals('F')?"K"+ atr.llave:"None", atr.nombre, atr.tipo, atr.campo, atr.comentario);
     }
     this.rowAddedActivate = true;
 }
示例#24
0
 protected virtual bool reescribeEntidad(Entidad ent, long pos)
 {
     return false;
 }
示例#25
0
        private bool buscaRelacion(Entidad ent,DataGridViewRow r)
        {
            Atributo atr;
            bool band = false;
            string datoComp;

            atr = ent.listAtr.Find(a => a.llave.Equals(Atributo.KP));
            if (atr != null)
            {
                datoComp = (base.controlPrincipal as DataGridView)[atr.nombre, r.Index].Value.ToString();
                band = this.buscaRelacion(atr,datoComp);
            }

            return band;
        }
示例#26
0
        private bool eliminaRegistro(Entidad ent)
        {
            bool band = false;
            byte[] bloq;

            ent.agregaAtributos(this.f.org.listaAtributos(ent.nombre));
            foreach (DataGridViewRow r in (base.controlPrincipal as DataGridView).SelectedRows)
            {
                if (!buscaRelacion(ent,r))
                {
                    bloq = Bloque.creaBloque(ent.listAtr, r);
                    band = this.f.org.eliminaRegistro(ent, bloq);

                }
            }

            return band;
        }
示例#27
0
        public override Atributo buscaAtributo(Entidad ent, string nomAtr,string path)
        {
            Atributo aAtr = null;
            long pos;

            if (ent != null)
            {
                pos = (ent as EntSecuencial).apAtr;
                if (pos != -1)
                {
                    do
                    {
                        aAtr = this.leeAtributo(pos,path);
                        pos = aAtr.sigAtr;
                    }
                    while (!nomAtr.Equals(aAtr.nombre) && pos != -1);
                    if (!nomAtr.Equals(aAtr.nombre))
                    {
                        aAtr = null;
                    }
                }
            }

            return aAtr;
        }