public void getTabelaCentros()
        {
            if (myForm.CN.State == System.Data.ConnectionState.Closed)
            {
                myForm.CN.Open();
            }
            SqlCommand    sqlcmd   = new SqlCommand("SELECT * FROM centro_comercial.centro", myForm.CN);
            SqlDataReader myReader = sqlcmd.ExecuteReader();

            myForm.listBox1.Items.Clear();
            funcoesAux.ReadOnly();
            ReadOnlyCentro();
            while (myReader.Read())
            {
                Centro centro = new Centro();
                centro.ID          = myReader["ID"].ToString();
                centro.Nome        = myReader["Nome"].ToString();
                centro.Localizacao = myReader["Localizacao"].ToString();
                centro.Num_lojas   = myReader["Num_lojas"].ToString();
                centro.Area_total  = myReader["Area_total"].ToString();
                myForm.listBox1.Items.Add(centro);
            }
            myForm.CN.Close();

            myForm.CN.Open();
            foreach (Centro c in myForm.listBox1.Items)
            {
                SqlCommand cmd = new SqlCommand("SELECT dbo.fnGetNumLojas(@ID_centro)", myForm.CN);
                cmd.Parameters.AddWithValue("@ID_centro", c.ID);
                c.Num_lojas = cmd.ExecuteScalar().ToString();
            }
            myForm.CN.Close();
            myForm.centroAtual = 1;
        }
        public void MostrarCentro(string id = null)
        {
            if (id != null)
            {
                myForm.centroAtual = -1;
                foreach (Centro c in myForm.listBox1.Items)
                {
                    myForm.centroAtual += 1;
                    if (c.ID == id)
                    {
                        myForm.listBox1.SelectedIndex = myForm.centroAtual;
                        break;
                    }
                }
            }

            if (myForm.listBox1.Items.Count == 0 | myForm.centroAtual < 0)
            {
                return;
            }
            Centro centro = new Centro();

            centro = (Centro)myForm.listBox1.Items[myForm.centroAtual - 1];     // ID do centro começa em 1 (em vez de 0)
            myForm.textCentroID.Text          = centro.ID;
            myForm.textCentroNome.Text        = centro.Nome;
            myForm.textCentroLocalizacao.Text = centro.Localizacao;
            myForm.textCentroNumeroLojas.Text = centro.Num_lojas;
            myForm.textCentroArea.Text        = centro.Area_total;
        }
        public void AddCentro()
        {
            myForm.CN.Open();

            Centro c = new Centro();

            c.Nome        = myForm.textCentroNome.Text;
            c.Localizacao = myForm.textCentroLocalizacao.Text;
            c.Num_lojas   = myForm.textCentroNumeroLojas.Text;
            c.Area_total  = myForm.textCentroArea.Text;
            c.ID          = myForm.textCentroID.Text;

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "INSERT INTO centro_comercial.centro (Nome, Localizacao, Num_lojas, Area_total, ID) " + "VALUES (@Nome, @Localizacao, @Num_lojas, @Area_total, @ID)";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@Nome", c.Nome);
            cmd.Parameters.AddWithValue("@Localizacao", c.Localizacao);
            cmd.Parameters.AddWithValue("@Num_lojas", c.Num_lojas);
            cmd.Parameters.AddWithValue("@Area_total", c.Area_total);
            cmd.Parameters.AddWithValue("@ID", c.ID);

            cmd.Connection = myForm.CN;

            try
            {
                cmd.ExecuteNonQuery();
                myForm.updateIDCentro();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO: " + ex.Message);
            }
            finally
            {
                myForm.CN.Close();
                getTabelaCentros();
                MostrarCentro(c.ID);
            }
        }