Пример #1
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            ALUNO oAluno = new ALUNO();

            oAluno.NOME = txtNome.Text;
            oAluno.SOBRENOME = txtSobreNome.Text;
            oAluno.NASC = dtpNasc.Value;
            oAluno.CPF = txtCPF.Text;
            oAluno.ENDERECO = txtEnd.Text;
            oAluno.BAIRRO = txtBairro.Text;
            oAluno.CIDADE = txtCidade.Text;
            oAluno.UF = cmbUF.SelectedItem.ToString();
            oAluno.PAIS = cmbPais.SelectedItem.ToString();
            oAluno.CEP = txtCEP.Text;
            oAluno.TEL_RES = txtTelRes.Text;
            oAluno.TEL_CEL = txtTelCel.Text;
            oAluno.EMAIL = txtEmail.Text;

            CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
            oProxy.Open();

            try
            {
                if (oProxy.Alterar(oAluno))
                {
                    MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LimpaCampos();

                    txtNome.Enabled = true;
                    txtSobreNome.Enabled = true;
                    txtCPF.Enabled = true;
                    dtpNasc.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        ///BOTÃO SALVAR
        /// 
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if(VerificaControles())
            {
                ALUNO oAluno = new ALUNO();

                oAluno.NOME = txtNome.Text;
                oAluno.SOBRENOME = txtSobreNome.Text;
                oAluno.NASC = dtpNasc.Value;
                oAluno.CPF = txtCPF.Text;
                oAluno.ENDERECO = txtEnd.Text;
                oAluno.BAIRRO = txtBairro.Text;
                oAluno.CIDADE = txtCidade.Text;
                oAluno.UF = cmbUF.SelectedItem.ToString();
                oAluno.PAIS = cmbPais.SelectedItem.ToString();
                oAluno.CEP = txtCEP.Text;
                oAluno.TEL_RES = txtTelRes.Text;
                oAluno.TEL_CEL = txtTelCel.Text;
                oAluno.EMAIL = txtEmail.Text;

                CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
                oProxy.Open();

                if (var == 0)
                {

                    try
                    {
                        if (oProxy.Cadastrar(oAluno))
                        {

                            MessageBox.Show("Cadastro realizado com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();

                        }
                        else
                        {
                            if (MessageBox.Show("Aluno existente! Deseja carregar os dados do aluno?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                string var = oAluno.CPF;

                                btnSalvar.Enabled = false;

                                btnDeletar.Enabled = true;

                                btnAlterar.Enabled = true;

                                ALUNO xAluno = oProxy.SelecionarCPF(var);

                                int var2 = xAluno.ID_ALUNO;

                                txtNome.Text = xAluno.NOME;
                                txtSobreNome.Text = xAluno.SOBRENOME;
                                dtpNasc.Value = xAluno.NASC;
                                txtCPF.Text = xAluno.CPF;
                                txtEnd.Text = xAluno.ENDERECO;
                                txtBairro.Text = xAluno.BAIRRO;
                                txtCidade.Text = xAluno.CIDADE;
                                cmbUF.SelectedItem = xAluno.UF;
                                cmbPais.SelectedItem = xAluno.PAIS;
                                txtCEP.Text = xAluno.CEP;
                                txtTelRes.Text = xAluno.TEL_RES;
                                txtTelCel.Text = xAluno.TEL_CEL;
                                txtEmail.Text = xAluno.EMAIL;
                                txtID.Text = Convert.ToString(var2);

                                DesabilitaCampos();
                            }
                            else
                            {
                                LimpaCampos();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
                else
                {

                        try
                        {
                            if (oProxy.Alterar(oAluno))
                            {
                                MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                LimpaCampos();

                                btnAlterar.Enabled = false;

                                HabilitaCampos();

                                var = 0;

                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                }
            }
            else
            {
                MessageBox.Show("Preencha todos os campos!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }