コード例 #1
0
ファイル: Form1.cs プロジェクト: koshibad/FiapWCF
        private async void btnEnviar_Click(object sender, EventArgs e)
        {
            //using (NotasServiceClient client = new NotasServiceClient("WSHttpBinding_INotasService"))
            //{
            //    var nota = new Nota()
            //    {
            //        AlunoId = (int)cboAluno.SelectedValue,
            //        DisciplinaId = (int)cboDisciplina.SelectedValue,
            //        Pontos = Convert.ToDecimal(txtNota.Text)
            //    };

            //    await client.EnviarNotasAsync(nota);

            //    client.Close();
            //}

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                using (NotasServiceClient client = new NotasServiceClient("WSHttpBinding_INotasService"))
                {
                    try
                    {
                        var nota = new EscolaService.Nota()
                        {
                            AlunoId      = (int)cboAluno.SelectedValue,
                            DisciplinaId = (int)cboDisciplina.SelectedValue,
                            Pontos       = Convert.ToDecimal(txtNota.Text)
                        };

                        await client.EnviarNotasAsync(nota);

                        ts.Complete();
                    }
                    catch (FaultException <ErroProcessamento> ex)
                    {
                        MessageBox.Show("FaultException<ErroProcessamento> throw by service.\r\n Exception type: FaultException<ErroProcessamento>" +
                                        "\r\nReason:" + ex.Message +
                                        "\r\nCodigo:" + ex.Detail.Codigo +
                                        "\r\nMessagem:" + ex.Detail.Messagem +
                                        "\r\nData:" + ex.Detail.Data);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Exception throw by service.\r\n Exception type: " + ex.GetType().Name +
                                        "\r\nMessage:" + ex.Message);

                        ts.Dispose();
                    }
                    finally
                    {
                        client.Close();
                    }
                }
        }
コード例 #2
0
        private async void btnEnviar_Click(object sender, EventArgs e)
        {
            using (NotasServiceClient client =
                       new NotasServiceClient("WSHttpBinding_INotasService"))
            {
                var nota = new Nota()
                {
                    AlunoId      = (int)cboAluno.SelectedValue,
                    DisciplinaId = (int)cboDisciplina.SelectedValue,
                    Pontos       = Convert.ToDecimal(txtNota.Text)
                };

                await client.EnviarNotasAsync(nota);

                client.Close();
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: koshibad/FiapWCF
        private async void Form1_Load(object sender, EventArgs e)
        {
            cboAluno.DropDownStyle = cboDisciplina.DropDownStyle = ComboBoxStyle.DropDownList;

            cboAluno.ValueMember   = "Id";
            cboAluno.DisplayMember = "Nome";

            cboDisciplina.ValueMember   = "Id";
            cboDisciplina.DisplayMember = "Nome";

            using (NotasServiceClient proxy = new NotasServiceClient("WSHttpBinding_INotasService"))
            {
                cboAluno.DataSource = await proxy.GetAlunosAsync();

                cboDisciplina.DataSource = await proxy.GetDisciplinasAsync();

                proxy.Close();
            }
        }