示例#1
0
        public frmMain()
        {
            InitializeComponent();

            cursos = new Arquivo("D:\\maratona\\Cursos.txt");
            matriculas = new Arquivo("D:\\maratona\\Matriculas.txt");

            this.LerAqruivoCursos();
            this.LerArquivoMatriculas();

            this.PreencheComboCursos();

            cboCursos.SelectedValueChanged += delegate {
                this.cursoSelecionado = this.listaCursos[cboCursos.SelectedIndex];
            };

            btnMatricular.Click += delegate {
                if (cboCursos.CanSelect && txtNome.Text.Length > 0) {
                    this.matriculaSelecionada = new Matricula() {
                        //Cod = this.GetUltimaMatricula().Cod++,
                        Cod = this.GetUltimaMatriculaId(),
                        Nome = txtNome.Text,
                        CursoId = this.cursoSelecionado.Codigo,
                        Bolsista = chkBolsista.Checked
                    };
                    listaMatriculas.Add(this.matriculaSelecionada);
                    this.matriculas.GravaMatriculas(this.listaMatriculas);

                    txtNome.Text = "";
                    txtMatricula.Text = "";
                    chkBolsista.Checked = false;
                } else {
                    MessageBox.Show("Todos os campos devem ser preenchidos.", "Atenção");
                }
            };

            btnExibirMatricula.Click += delegate {
                if (txtMatricula.Text.Length > 0) {
                    this.matriculaSelecionada = null;
                    var cod = Convert.ToInt32(txtMatricula.Text);
                    foreach (Matricula matricula in this.listaMatriculas) {
                        if (matricula.Cod == cod)
                            this.matriculaSelecionada = matricula;
                    }

                    if (this.matriculaSelecionada != null) {
                        txtNome.Text = this.matriculaSelecionada.Nome;
                        chkBolsista.Checked = this.matriculaSelecionada.Bolsista;
                        // não sei selecionar no combo
                    } else {
                        MessageBox.Show("A matrícula não existe.", "Atenção");
                    }
                } else {
                    MessageBox.Show("Digite a matrícula.", "Atenção");
                }
            };
        }
示例#2
0
        public frmMain()
        {
            InitializeComponent();

            cursos     = new Arquivo("D:\\maratona\\Cursos.txt");
            matriculas = new Arquivo("D:\\maratona\\Matriculas.txt");

            this.LerAqruivoCursos();
            this.LerArquivoMatriculas();

            this.PreencheComboCursos();

            cboCursos.SelectedValueChanged += delegate {
                this.cursoSelecionado = this.listaCursos[cboCursos.SelectedIndex];
            };

            btnMatricular.Click += delegate {
                if (cboCursos.CanSelect && txtNome.Text.Length > 0)
                {
                    this.matriculaSelecionada = new Matricula()
                    {
                        //Cod = this.GetUltimaMatricula().Cod++,
                        Cod      = this.GetUltimaMatriculaId(),
                        Nome     = txtNome.Text,
                        CursoId  = this.cursoSelecionado.Codigo,
                        Bolsista = chkBolsista.Checked
                    };
                    listaMatriculas.Add(this.matriculaSelecionada);
                    this.matriculas.GravaMatriculas(this.listaMatriculas);

                    txtNome.Text        = "";
                    txtMatricula.Text   = "";
                    chkBolsista.Checked = false;
                }
                else
                {
                    MessageBox.Show("Todos os campos devem ser preenchidos.", "Atenção");
                }
            };

            btnExibirMatricula.Click += delegate {
                if (txtMatricula.Text.Length > 0)
                {
                    this.matriculaSelecionada = null;
                    var cod = Convert.ToInt32(txtMatricula.Text);
                    foreach (Matricula matricula in this.listaMatriculas)
                    {
                        if (matricula.Cod == cod)
                        {
                            this.matriculaSelecionada = matricula;
                        }
                    }

                    if (this.matriculaSelecionada != null)
                    {
                        txtNome.Text        = this.matriculaSelecionada.Nome;
                        chkBolsista.Checked = this.matriculaSelecionada.Bolsista;
                        // não sei selecionar no combo
                    }
                    else
                    {
                        MessageBox.Show("A matrícula não existe.", "Atenção");
                    }
                }
                else
                {
                    MessageBox.Show("Digite a matrícula.", "Atenção");
                }
            };
        }