public void MostrarPrestador(string nif = null)
        {
            if (nif != null)
            {
                myForm.prestadorAtual = -1;
                foreach (Prestador2 p in myForm.listBox4.Items)
                {
                    myForm.prestadorAtual += 1;
                    if (p.NIF == nif)
                    {
                        myForm.listBox4.SelectedIndex = myForm.prestadorAtual;
                        break;
                    }
                }
            }

            if (myForm.listBox4.Items.Count == 0 | myForm.prestadorAtual < 0)
            {
                return;
            }
            Prestador2 prestador = new Prestador2();

            prestador = (Prestador2)myForm.listBox4.Items[myForm.prestadorAtual];
            myForm.prestadores1.setTextNIF(prestador.NIF);
            myForm.prestadores1.setTextServico(prestador.Servico);
            myForm.prestadores1.setTextEmpresa(prestador.Empresa);
            myForm.prestadores1.setTextHoras(prestador.Horas_mensais);
            myForm.prestadores1.setTextCusto(prestador.Custo_mensal);
        }
        public void getTabelaPrestadores()
        {
            myForm.CN.Open();
            SqlCommand cmd = new SqlCommand("spPrestadores", myForm.CN);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@ID_centro", myForm.textCentroID.Text));
            SqlDataReader rdr = cmd.ExecuteReader();

            myForm.listBox4.Items.Clear();

            try
            {
                while (rdr.Read())
                {
                    Prestador2 prestador = new Prestador2();
                    prestador.NIF           = rdr["NIF"].ToString();
                    prestador.Custo_mensal  = rdr["Custo_mensal"].ToString();
                    prestador.Empresa       = rdr["Empresa"].ToString();
                    prestador.Horas_mensais = rdr["Horas_mensais"].ToString();
                    prestador.Servico       = rdr["Servico"].ToString();
                    myForm.listBox4.Items.Add(prestador);
                }
                myForm.prestadorAtual = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO: " + ex.Message);
            }
            finally
            {
                rdr.Close();
                myForm.CN.Close();
            }
        }
        // Adicionar prestadores
        public void AddPrestadores()
        {
            myForm.CN.Open();

            Prestador2 prt = new Prestador2();

            prt.NIF           = myForm.prestadores1.getTextNIF();
            prt.Empresa       = myForm.prestadores1.getTextEmpresa();
            prt.Horas_mensais = myForm.prestadores1.getTextHoras();
            prt.Servico       = myForm.prestadores1.getTextServico();
            prt.Custo_mensal  = myForm.prestadores1.getTextCusto();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "INSERT centro_comercial.prestador (NIF, Empresa, Horas_mensais, Servico, Custo_mensal) " + "VALUES (@NIF, @Empresa, @Horas_mensais, @Servico, @Custo_mensal) ";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@NIF", prt.NIF);
            cmd.Parameters.AddWithValue("@Empresa", prt.Empresa);
            cmd.Parameters.AddWithValue("@Horas_mensais", prt.Horas_mensais);
            cmd.Parameters.AddWithValue("@Servico", prt.Servico);
            cmd.Parameters.AddWithValue("@Custo_mensal", prt.Custo_mensal);
            cmd.Connection = myForm.CN;

            try
            {
                cmd.ExecuteNonQuery();
                AddInterage(prt.NIF);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO: " + ex.Message);
            }
            finally
            {
                myForm.CN.Close();
                getTabelaPrestadores();
                MostrarPrestador(prt.NIF);
            }
        }