예제 #1
0
        public string[,] hazCombinacionReg(string tabla2)
        {
            //ValidarLlaveForanea
            Entidad tab1 = BD.listEntidad.Find(x => x.nombre.ToUpper() == tabConPrin);
            Entidad tab2 = BD.listEntidad.Find(x => x.nombre.ToUpper() == tabla2);


            Entidad entCom = new Entidad();

            entCom.listAtrib = new List <Atributo>();

            foreach (Atributo a in tab1.listAtrib)
            {
                Atributo nu = (Atributo)a.Clone();
                nu.regAtr = new List <string>();

                entCom.listAtrib.Add(nu);
            }
            foreach (Atributo a in tab2.listAtrib)
            {
                Atributo nu = (Atributo)a.Clone();
                nu.regAtr = new List <string>();

                entCom.listAtrib.Add(nu);
            }



            string[,] arrayCombinacionT2 = new string[40, 20];

            for (int i = 0; i < tab2.listAtrib.Count; i++)
            {
                for (int j = 0; j < tab2.listAtrib.ElementAt(i).regAtr.Count; j++)
                {
                    arrayCombinacionT2[j, i] = tab2.listAtrib.ElementAt(i).regAtr.ElementAt(j);
                }
            }

            List <List <string> > listD = new List <List <string> >();

            for (int i = 0; i < tab2.listAtrib.ElementAt(0).regAtr.Count; i++)
            {
                List <string> cad = new List <string>();
                for (int j = 0; j < tab2.listAtrib.Count; j++)
                {
                    if (arrayCombinacionT2[i, j] != null)
                    {
                        cad.Add(arrayCombinacionT2[i, j]);
                    }
                }
                listD.Add(cad);
            }


            r = 0;

            string[,] arrayCombinacionT1 = new string[40, 20];



            for (int i = 0; i < tab1.listAtrib.Count; i++)
            {
                for (int j = 0; j < tab1.listAtrib.ElementAt(0).regAtr.Count; j++)
                {
                    arrayCombinacionT1[j, i] = tab1.listAtrib.ElementAt(i).regAtr.ElementAt(j);
                }
            }

            List <List <string> > listD2 = new List <List <string> >();



            for (int i = 0; i < tab1.listAtrib.ElementAt(0).regAtr.Count; i++)
            {
                List <string> cad = new List <string>();
                for (int j = 0; j < tab1.listAtrib.Count; j++)
                {
                    if (arrayCombinacionT1[i, j] != null)
                    {
                        cad.Add(arrayCombinacionT1[i, j]);
                    }
                }
                listD2.Add(cad);
            }

            r = 0;

            string[,] combFinales = formaCombinacion(listD, listD2);

            r = 0;
            return(combFinales);
        }
예제 #2
0
        //Metodo que elimina un atributo de una entidad seleccionada
        private void eliminaAtri(object sender, EventArgs e)
        {
            int inAM = comboBoxModAtri.SelectedIndex;


            if (inAM != -1)
            {
                Atributo a = ent.listAtrib.Find(x => x.nombre == comboBoxModAtri.SelectedItem.ToString());

                if (a.tipoIndi != 6)
                {
                    using (BinaryWriter bw = new BinaryWriter(File.Open(dic.nomArchivo, FileMode.Open)))
                    {
                        if (ent.listAtrib.Count != 1)
                        {
                            if (inAM - 1 != -1 && inAM + 1 < ent.listAtrib.Count())
                            {
                                bw.Seek((int)ent.listAtrib.ElementAt(inAM - 1).dirAtri + 60, SeekOrigin.Begin);
                                bw.Write(ent.listAtrib.ElementAt(inAM + 1).dirAtri);
                                r = 0;
                            }
                            else
                            {
                                if (inAM + 1 == ent.listAtrib.Count())
                                {
                                    bw.Seek((int)ent.listAtrib.ElementAt(inAM - 1).dirAtri + 60, SeekOrigin.Begin);
                                    bw.Write(-1);
                                    r = 0;
                                }
                                else
                                {
                                    bw.Seek((int)ent.dirEnti + 43, SeekOrigin.Begin);
                                    bw.Write(ent.listAtrib.ElementAt(1).dirAtri);
                                    r = 0;
                                }
                            }
                        }
                        else
                        {
                            r = 0;
                            bw.Seek((int)ent.dirEnti + 43, SeekOrigin.Begin);
                            bw.Write(-1);
                            ent.dirAtri = -1;
                        }
                    }

                    if (ent.listAtrib.Count != 1)
                    {
                        r = 0;
                        dic.actualizaDiccionario(dic.archivo);
                    }
                    else
                    {
                        ent.listAtrib.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("No puedes eliminar atributos de tipo llave foranea");
                }
            }
            else
            {
                MessageBox.Show("Selecciona un atributo, si no los hay crealos");
            }

            buttonEliAtri.Visible   = false;
            cambiaAtribu.Visible    = false;
            comboBoxModAtri.Text    = "";
            comboBoxModAtri.Visible = false;

            VerActualesAtri(this, null);
            r = 0;
        }
예제 #3
0
        //Metodo que se encarga de guardar en variables del diccionario y guardarlos en estructuras necesarias para su uso en el programa
        public void actualizaDiccionario(FileStream archivo)
        {
            r = 0;
            dic.borraDic();
            //Variables de entidad
            Byte[] idEnti;
            char[] nombreEnti;
            int    dirEnt;
            int    dirAtri;
            int    dirDat;
            int    dirSigEnt;
            string noEn = "";

            //Variables de atributos
            Byte[] idAtriL;
            char[] nombreAtriL;
            char[] tipoDL;
            int    longiL;
            int    dirAtrL;
            int    tipoIndL;
            int    dirIndL;
            int    dirSigAtL;
            string noAt        = "";
            bool   bandSigEnt  = true;
            bool   bandSigAtri = true;

            BinaryReader br = new BinaryReader(archivo);


            archivo.Seek(0, SeekOrigin.Begin);
            int dire = br.ReadInt32();

            dic.cab = dire;
            if (dic.cab != -1)
            {
                while (bandSigEnt)
                {
                    archivo.Seek(dire, SeekOrigin.Begin);
                    idEnti = br.ReadBytes(5);
                    r      = 0;
                    dire  += 5;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    nombreEnti = br.ReadChars(30);
                    r          = 0;
                    dire      += 30;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirEnt = br.ReadInt32();
                    r      = 0;
                    dire  += 8;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirAtri = br.ReadInt32();
                    r       = 0;
                    dire   += 8;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirDat = br.ReadInt32();
                    r      = 0;
                    dire  += 8;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirSigEnt = br.ReadInt32();
                    r         = 0;
                    dire      = dirAtri;
                    for (int i = 0; i < nombreEnti.Length; i++)
                    {
                        if (char.IsLetter(nombreEnti.ElementAt(i)))
                        {
                            noEn += nombreEnti.ElementAt(i);
                        }
                    }

                    Entidad ent = new Entidad(idEnti, noEn, dirEnt, dirAtri, dirDat, dirSigEnt);
                    noEn = "";
                    dic.listEntidad.Add(ent);
                    r = 0;
                    if (dirAtri != -1)
                    {
                        while (bandSigAtri)
                        {
                            r = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            idAtriL = br.ReadBytes(5);
                            dire   += 5;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            nombreAtriL = br.ReadChars(30);
                            dire       += 30;
                            r           = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            tipoDL = br.ReadChars(1);
                            dire  += 1;
                            r      = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            longiL = br.ReadInt32();
                            dire  += 4;
                            r      = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            dirAtrL = br.ReadInt32();
                            dire   += 8;
                            r       = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            tipoIndL = Int32.Parse(br.ReadInt32().ToString().Substring(0, 1));
                            dire    += 4;
                            r        = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            dirIndL = br.ReadInt32();
                            dire   += 8;
                            r       = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            dirSigAtL = br.ReadInt32();
                            dire      = dirSigAtL;
                            r         = 0;
                            for (int i = 0; i < nombreAtriL.Length; i++)
                            {
                                if (char.IsLetter(nombreAtriL.ElementAt(i)) || nombreAtriL.ElementAt(i) == '_')
                                {
                                    noAt += nombreAtriL.ElementAt(i);
                                }
                            }
                            Atributo atr = new Atributo(idAtriL, noAt, tipoDL[0], longiL, dirAtrL, tipoIndL, dirIndL, dirSigAtL);
                            noAt = "";
                            ent.listAtrib.Add(atr);
                            r = 0;


                            if (dirSigEnt == -1 && dirSigAtL == -1)
                            {
                                bandSigEnt = false;
                                r          = 0;
                            }

                            if (dirSigAtL == -1)
                            {
                                bandSigAtri = false;
                                r           = 0;
                                dire        = dirSigEnt;
                            }
                        }
                    }
                    else
                    {
                        dire = dirSigEnt;
                        if (dire == -1)
                        {
                            break;
                        }
                    }

                    bandSigAtri = true;
                }
            }
            else
            {
                MessageBox.Show("Tu archivo se encuentra vacio!!");
            }

            bandSigEnt = true;
            r          = 0;
        }
예제 #4
0
        //Metodo que se encarga de actualizar el diccionario una vez que se halla cerrado o que se necesite vericar valores
        public void actualizaDiccionario(FileStream archivolleg)
        {
            borraDic();

            int r = 0;

            Byte[] idEnti;
            char[] nombreEnti;
            int    dirEnt;
            int    dirAtri;
            int    dirDat;
            int    dirSigEnt;
            string noEn = "";

            //Variables de atributos
            Byte[] idAtriL;
            char[] nombreAtriL;
            char[] tipoDL;
            int    longiL;
            int    dirAtrL;
            int    tipoIndL;
            int    dirIndL;
            int    dirSigAtL;
            string noAt        = "";
            bool   bandSigEnt  = true;
            bool   bandSigAtri = true;



            this.archivo = File.Open(nomArchivo, FileMode.Open, FileAccess.Read);

            BinaryReader br = new BinaryReader(this.archivo);


            archivo.Seek(0, SeekOrigin.Begin);
            int dire = br.ReadInt32();

            cab = dire;
            //dire = 8;

            r = 0;
            if (cab != -1)
            {
                while (bandSigEnt)
                {
                    archivo.Seek(dire, SeekOrigin.Begin);
                    idEnti = br.ReadBytes(5);
                    r      = 0;
                    dire  += 5;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    //BinaryReader br = new BinaryReader(archivo);
                    nombreEnti = br.ReadChars(30);
                    r          = 0;
                    dire      += 30;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirEnt = br.ReadInt32();
                    r      = 0;
                    dire  += 8;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirAtri = br.ReadInt32();
                    r       = 0;
                    dire   += 8;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirDat = br.ReadInt32();
                    r      = 0;
                    dire  += 8;
                    archivo.Seek(dire, SeekOrigin.Begin);
                    dirSigEnt = br.ReadInt32();
                    r         = 0;
                    dire      = dirAtri;
                    for (int i = 0; i < nombreEnti.Length; i++)
                    {
                        if (char.IsLetter(nombreEnti.ElementAt(i)))
                        {
                            noEn += nombreEnti.ElementAt(i);
                        }
                    }
                    r = 0;
                    Entidad ent = new Entidad(idEnti, noEn, dirEnt, dirAtri, dirDat, dirSigEnt);
                    noEn = "";
                    listEntidad.Add(ent);
                    r = 0;
                    if (dirAtri != -1)
                    {
                        while (bandSigAtri)
                        {
                            r = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            idAtriL = br.ReadBytes(5);
                            dire   += 5;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            nombreAtriL = br.ReadChars(30);
                            dire       += 30;
                            r           = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            tipoDL = br.ReadChars(1);
                            dire  += 1;
                            r      = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            longiL = br.ReadInt32();
                            dire  += 4;
                            r      = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            dirAtrL = br.ReadInt32();
                            dire   += 8;
                            r       = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            tipoIndL = br.ReadInt32();
                            dire    += 4;
                            r        = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            dirIndL = br.ReadInt32();
                            dire   += 8;
                            r       = 0;
                            archivo.Seek(dire, SeekOrigin.Begin);
                            dirSigAtL = br.ReadInt32();
                            dire      = dirSigAtL;
                            r         = 0;
                            for (int i = 0; i < nombreAtriL.Length; i++)
                            {
                                if (char.IsLetter(nombreAtriL.ElementAt(i)) || nombreAtriL.ElementAt(i) == '_')
                                {
                                    noAt += nombreAtriL.ElementAt(i);
                                }
                            }
                            Atributo atr = new Atributo(idAtriL, noAt, tipoDL[0], longiL, dirAtrL, tipoIndL, dirIndL, dirSigAtL);
                            noAt = "";
                            ent.listAtrib.Add(atr);
                            r = 0;


                            if (dirSigEnt == -1 && dirSigAtL == -1)
                            {
                                bandSigEnt = false;
                                r          = 0;
                            }

                            if (dirSigAtL == -1)
                            {
                                bandSigAtri = false;
                                r           = 0;
                                dire        = dirSigEnt;
                            }
                        }
                    }
                    else
                    {
                        dire = dirSigEnt;
                        if (dire == -1)
                        {
                            break;
                        }
                    }
                    bandSigAtri = true;
                }
            }


            bandSigEnt = true;
            r          = 0;
            this.archivo.Close();
        }