protected void btnExcluir_Click(object sender, EventArgs e) { EmpresaController empresaController = new EmpresaController(); ClienteController clienteController = new ClienteController(); VendedorController vendedorController = new VendedorController(); UsuarioController usuarioController = new UsuarioController(); ContratoController contratoController = new ContratoController(); if (usuarioController.ObterTodosFuncionarios(Session["cnpjEmp"].ToString()).Count <= 0) { List<ClienteEntity> clientes = clienteController.ObterTodos(Session["cnpjEmp"].ToString()); for (int i = 0; i < clientes.Count; i++) { vendedorController.Remover(clientes[i].codCli); clienteController.Remover(clientes[i].codCli); } contratoController.Remover(Session["cpfUsu"].ToString()); if (empresaController.Remover(Session["cnpjEmp"].ToString())) { this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Empresa removida com sucesso!'); window.location.href='Login.aspx';</script>"); } } else this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Erro na remoção do registro, sua empresa ainda possui funcionários!');</script>"); }
protected void txtEmpresa_SelectedIndexChanged(object sender, EventArgs e) { txtEmpresa.Focus(); try { txtCnpj.Text = txtEmpresa.SelectedValue; if (txtEmpresa.SelectedValue != "0") { txtVendedor.Items.Clear(); UsuarioController usuarioController = new UsuarioController(); txtVendedor.DataSource = usuarioController.ObterTodosFuncionarios(txtEmpresa.SelectedValue); txtVendedor.DataTextField = "nomUsu"; txtVendedor.DataValueField = "cpfUsu"; txtVendedor.DataBind(); txtVendedor.Items.Insert(0, new ListItem("", "0")); } else { txtVendedor.Items.Clear(); txtVendedor.Items.Insert(0, new ListItem("Selecione uma empresa", "0")); txtVendedor.Items.Insert(0, new ListItem("", "0")); } } catch { } }