protected void botaoCadastraGarcons_Click(object sender, EventArgs e) { if (Page.IsValid) { GerenciarGarconsController controller = new GerenciarGarconsController(); Garcon garcon = new Garcon(); garcon.nome = campoNomeGarcons.Text; garcon.idade = Int32.Parse(campoIdadeGarcons.Text); garcon.cpf = campoCpfGarcons.Text; garcon.email = campoEmailGarcons.Text; garcon.telefone = campoTelefoneGarcons.Text; garcon.sexo = campoSexoGarcons.Text; String mensagem = null; if (controller.pesquisarGarconCpf(garcon.cpf) != null) { mensagem = "Já existe um garçon com este cpf! \\n"; } if (controller.pesquisarGarcon(garcon.email) != null) { mensagem += "Já existe um garçon com este email! \\n"; } if (mensagem != null) { Response.Write("<script language='javascript'> alert('" + mensagem + "'); window.location=('gerenciargarcons.aspx'); </script>"); } else { controller.cadastrar(garcon); Response.Write("<script language='javascript'> alert('Garcon cadastrado com Sucesso!'); window.location=('gerenciargarcons.aspx'); </script>"); } } }
protected void botaoAlterarGarcons_Click(object sender, EventArgs e) { botaoAlterarGarcons.Visible = false; botaoCadastraGarcons.Visible = true; if (Page.IsValid) { GerenciarGarconsController controller = new GerenciarGarconsController(); Garcon garcon = new Garcon(); garcon.garcon_id = Int32.Parse(TabelaGarcons.SelectedRow.Cells[0].Text); garcon.nome = campoNomeGarcons.Text; garcon.idade = Int32.Parse(campoIdadeGarcons.Text); garcon.telefone = campoTelefoneGarcons.Text; garcon.sexo = campoSexoGarcons.Text; if (TabelaGarcons.SelectedRow.Cells[2].Text.Equals(campoCpfGarcons.Text)) { garcon.cpf = campoCpfGarcons.Text; } else { if (controller.pesquisarGarconCpf(campoCpfGarcons.Text) == null) { garcon.cpf = campoCpfGarcons.Text; } } if (TabelaGarcons.SelectedRow.Cells[6].Text.Equals(campoEmailGarcons.Text)) { garcon.email = campoEmailGarcons.Text; } else { if (controller.pesquisarGarcon(campoEmailGarcons.Text) == null) { garcon.email = campoEmailGarcons.Text; } } if (garcon.cpf != null && garcon.email != null) { controller.atualizar(garcon); Response.Write("<script language='javascript'> alert('Garcon alterado com Sucesso!'); window.location=('gerenciargarcons.aspx'); </script>"); } else { Response.Write("<script language='javascript'> alert('Erro: Garcon não pode ser alterado!'); window.location=('gerenciargarcons.aspx'); </script>"); } } }