Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            identi            = false;
            textBox1.Enabled  = false;
            textBox2.Enabled  = false;
            textBox2.ReadOnly = true;

            button1.Enabled   = false;
            button2.Enabled   = false;
            Nuevo.Enabled     = true;
            button3.Enabled   = true;
            Modificar.Enabled = true;



            if (comboBox1.Text == "")
            {
                MessageBox.Show("Selecciona una entidad");
                return;
            }

            if (textBox1.Text == "" || textBox2.Text == "" || comboBox2.Text == "" || comboBox3.Text == "")
            {
                textBox1.Enabled = true;
                return;
            }


            if (comboBox3.SelectedIndex == 1)      // Revisar si algun atributo ya se selecciono como clave primaria
            {
                for (int i = 0; i < Entidades[comboBox1.SelectedIndex].Atributos.Count; i++)
                {
                    if (Entidades[comboBox1.SelectedIndex].Atributos[i].TipoIndice == true && new string(Entidades[comboBox1.SelectedIndex].Atributos[i].Nombre) != new string(charAstring(textBox1.Text)))
                    {
                        MessageBox.Show("Ya has seleccionado un atributo como clave primaria");
                        return;
                    }
                }
            }

            string p1 = new string(charAstring(textBox1.Text));

            for (int i = 0; i < Entidades[comboBox1.SelectedIndex].Atributos.Count; i++)
            {
                if (mod == false)
                {
                    string p = new string(Entidades[comboBox1.SelectedIndex].Atributos[i].Nombre);
                    if (p1 == p)
                    {
                        identi = true;
                    }
                }
            }
            if (mod == true)
            {
                for (int i = 0; i < Lat.Count; i++)
                {
                    string p = new string(Lat[i].Nombre);
                    if (p1 == p)
                    {
                        identi = true;
                    }
                }
            }



            if (identi != true)
            {
                if (mod == false)
                {
                    long     cabezera = archivo.Dame_cabecera();
                    Atributo nuevo    = new Atributo();
                    nuevo.Nombre = charAstring(textBox1.Text);
                    switch (comboBox2.SelectedIndex)
                    {
                    case 0:
                        nuevo.Tipo = 'I';
                        break;

                    case 1:
                        nuevo.Tipo = 'C';
                        break;
                    }

                    nuevo.Tam = Int16.Parse(textBox2.Text);

                    nuevo.DirAtributo = archivo.Tam_archivo();

                    if (comboBox3.SelectedIndex == 0)
                    {
                        nuevo.TipoIndice = false;
                    }
                    if (comboBox3.SelectedIndex == 1)
                    {
                        nuevo.TipoIndice = true;
                    }



                    nuevo.DirSig = -1;



                    if (Entidades[comboBox1.SelectedIndex].DirAtributos == -1)
                    {
                        archivo.modificaApuntadorDeAtributos(Entidades[comboBox1.SelectedIndex].DirEntidad, Entidades[comboBox1.SelectedIndex], nuevo.DirAtributo);
                        Entidades[comboBox1.SelectedIndex].Atributos.Add(nuevo);
                        archivo.insertaAtributo(nuevo, trabajo);
                        Entidades[comboBox1.SelectedIndex].DirAtributos = nuevo.DirAtributo;
                    }
                    else
                    {
                        Entidades[comboBox1.SelectedIndex].Atributos.Add(nuevo);
                        actualizaIndices();
                    }


                    textBox1.Text = "";
                }
                else
                {
                    Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].Nombre = charAstring(textBox1.Text);
                    Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].Tam    = Int16.Parse(textBox2.Text);

                    if (comboBox3.SelectedIndex == 0)
                    {
                        Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].TipoIndice = false;
                    }
                    else
                    {
                        Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].TipoIndice = true;
                    }

                    switch (comboBox2.SelectedIndex)
                    {
                    case 0:
                        Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].Tipo = 'I';
                        break;

                    case 1:
                        Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].Tipo = 'C';
                        break;
                    }

                    archivo.Modifica_Atributo(Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex].DirAtributo, Entidades[comboBox1.SelectedIndex].Atributos[dataGridView1.CurrentCell.RowIndex], trabajo);

                    textBox1.Text = "";
                    mod           = false;
                }
            }
            else
            {
                MessageBox.Show("El atributo ya existe");
            }

            actualizaTabla();
        }