Example #1
0
 public virtual bool altaRelacionEnKF(string nomEnt, Atributo atr, Relacion rel)
 {
     return false;
 }
Example #2
0
        public bool cambiaClaveAtributo(string nomEnt,string nomAtr,char claveNueva)
        {
            bool band = false;
            string nomBd, nomEntRel, nomAtrRel;
            Atributo atr;
            Entidad entRel;
            Relacion rel;

            atr = this.buscaAtributo(this.buscaEntidad(nomEnt), nomAtr);

            switch (claveNueva)
            {
                case Atributo.KP:
                    if (claveNueva == atr.llave)
                    {
                        if (atr.listRel.Count > 0)
                        {
                            System.Windows.Forms.MessageBox.Show("Imposible borrar, contiene relaciones establecidas");
                        }
                        else
                        {
                            claveNueva = Atributo.None;
                        }
                    }
                    else
                    {
                        atr.llave = claveNueva;
                    }
                    band = true;
                break;
                case Atributo.KF:
                    if (atr.llave == Atributo.None)
                    {
                        using (ClaveForanea cf = new ClaveForanea(this))
                        {
                            cf.ShowDialog();
                            if (cf.DialogResult == System.Windows.Forms.DialogResult.OK)
                            {
                                nomBd = cf.db();
                                nomEntRel = cf.ent();
                                entRel = this.buscaEntidad(nomEntRel, Archivo.path +'\\'+ this.tipo + '\\' + nomBd);
                                nomAtrRel = cf.atr();
                                rel = new Relacion(nomBd, nomEntRel, nomAtrRel, -1);
                                if (this.altaRelacionEnKF(nomEnt, atr, rel))
                                {

                                    if (this.altaRelacionEnKP(nomEntRel, this.buscaAtributo(entRel, nomAtrRel, Archivo.path + '\\' + this.tipo + '\\' + nomBd), new Relacion(this.nombre, nomEnt, nomAtr, -1)))
                                    {
                                        atr.llave = claveNueva;
                                        atr.comentario = atr.comentario + "\t:" + rel.bd + ':' + rel.nomEnt + ':' + rel.nomAtr;
                                        band = true;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        atr.llave = Atributo.None;
                        System.Windows.Forms.MessageBox.Show("Borrar relacion aun no implementada");
                        atr.comentario = atr.comentario.Remove(atr.comentario.IndexOf('\t'));
                        band = true;
                    }
                break;
                case Atributo.None:
                    atr.llave = claveNueva;
                    atr.comentario = atr.comentario.Remove(atr.comentario.IndexOf('\t'));
                    band = true;
                break;
            }
            if (band)
            {
                this.reescribeAtributo(atr, this.buscaPosAtributo(nomEnt, atr.nombre));
            }

            return band;
        }
Example #3
0
 public void agregaRelacion(Relacion rel)
 {
     if (rel.bd != "" && rel.nomEnt != "" && rel.nomAtr != "")
     {
         this.ListRel.Add(rel);
     }
 }
Example #4
0
        public Relacion leeRelacion(long pos)
        {
            long sigRel = -1;
            string bd = "";
            string ent = "";
            string nomAtr = "";
            Relacion rel;

            try
            {
                using (FileStream fs = new FileStream(base.ruta, FileMode.Open))
                {
                    fs.Seek(pos, SeekOrigin.Begin);
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        bd = br.ReadString();
                        ent = br.ReadString();
                        nomAtr = br.ReadString();
                        sigRel = br.ReadInt64();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            rel = new Relacion(bd, ent, nomAtr, sigRel);

            return rel;
        }
Example #5
0
        public long insertaRelacion(Relacion rel)
        {
            long pos = 0;

            try
            {
                using (FileStream fs = new FileStream(base.ruta, FileMode.Append))
                {
                    pos = fs.Position;
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(rel.bd);
                        bw.Write(rel.nomEnt);
                        bw.Write(rel.nomAtr);
                        bw.Write(rel.apSigRef);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                pos = 0;
            }

            return pos;
        }
Example #6
0
        /// <summary>
        /// guarda una relacion para un atributo que es KP
        /// </summary>
        /// <param name="nomEnt"></param>
        /// <param name="atr">atributo  que es KP</param>
        /// <param name="rel">relacion a guardar</param>
        /// <returns>true si se guardo false si hubo error</returns>
        public override bool altaRelacionEnKP(string nomEnt,Atributo atr,Relacion rel)
        {
            bool band = false;
            long pos, posAtr;

            //            if (this.activeUser.permisos[1] == true)
            //            {
            rel.apSigRef = atr.sigRel;
            pos = this.insertaRelacion(rel);
            if (pos != 0)
            {
                atr.sigRel = pos;
                posAtr = this.buscaPosAtributo(nomEnt, atr.nombre, Archivo.path +'\\'+ base.tipo + '\\' + rel.bd );
                band = this.reescribeAtributo(atr, posAtr,Archivo.path +'\\'+ base.tipo + '\\' + rel.bd);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Error al guardar relacion");
            }

            /*            }
                                    else
                                    {
                                        System.Windows.Forms.MessageBox.Show("No tienes permiso para altas");
                                    }
            */

            return band;
        }