예제 #1
1
    protected void botMigrateModel_Click(object sender, EventArgs e)
    {
        lblStatus.Text = "Start Migration";
        DBHelper.ConnectionString = txtSourceConnection.Text;

        ModeloCompetencias _modelo = ModeloCompetencias.getDBModelo("JC", int.Parse(DDLModelos.SelectedValue));
        // agora vai criar o modelo na base de dados de produção
        _modelo.loadFull("JC", null);

        DBHelper.ConnectionString = this.txtDestConnection.Text;

        // cria o modelo
        ModeloCompetencias NovoModelo = new ModeloCompetencias();
        NovoModelo = _modelo;
        NovoModelo.reset();
        NovoModelo.updateDBModelo("JC");

        for (int i = 0; i < _modelo.Familias.Count; i++)
        {
            FamiliaCompetencias novaFam = new FamiliaCompetencias(NovoModelo);
            novaFam = NovoModelo.Familias.Values[i];
            novaFam.Modelo = NovoModelo;
            novaFam.reset();
            novaFam.SortIndex = i;
            novaFam.cloneDBFamilia("JC");
            for (int j = 0; j < _modelo.Familias.Values[i].Competencias.Count; j++)
            {
                Competencia novaComp = new Competencia();
                novaComp = NovoModelo.Familias.Values[i].Competencias.Values[j];
                novaComp.reset();
                novaComp.SortIndex = j;
                novaComp.Familia = novaFam;
                novaComp.cloneDBCompetencia("JC");
                for (int k = 0; k < _modelo.Familias.Values[i].Competencias.Values[j].Praticas.Count; k++)
                {
                    Pratica novaPrat = new Pratica();
                    novaPrat = NovoModelo.Familias.Values[i].Competencias.Values[j].Praticas.Values[k];
                    novaPrat.Competencia = novaComp;
                    novaPrat.reset();
                    novaPrat.SortIndex = k;
                    novaPrat.cloneDBPratica("JC");

                    for (int l = 0; l < _modelo.Familias.Values[i].Competencias.Values[j].Praticas.Values[k].Perguntas.Count; l++)
                    {
                        Pergunta novaPerg = new Pergunta();
                        novaPerg = NovoModelo.Familias.Values[i].Competencias.Values[j].Praticas.Values[k].Perguntas.Values[l];
                        novaPerg.reset();
                        novaPerg.Pratica = novaPrat;
                        novaPerg.SortIndex = l;
                        novaPerg.cloneDBPergunta("JC");
                    }

                }
            }
        }

        lblStatus.Text = "Migration Ended";
        // depois volta a colocar a limpar a coisa
        DBHelper.ConnectionString = "";
    }