C # Windows Forms - Get a User ID Logged in

-1

I need to get the ID of a user already logged in to the application to create another product. How do I do this?

So,soon,andwiththeemailandpasswordlogged,IwanttofindtheIDloggedinwhenIregisterthecar,itpullsthatIDandregister.IhavealreadytriedusingThread.CurrentPrincipal.Identity.IsAuthenticated,Environment.UserNameandtheWindowsIdentity.GetCurrent()buttheseonlytakethenameofthepersonloggedinwindows,nottheapplication.

Login

Empresaempresa=newEmpresa();empresa.Email=txtEmail.Text;empresa.Senha=txtSenha.Text;if(EmpresaDAO.BuscarEmpresaPorEmailESenha(empresa)!=null){empresa=EmpresaDAO.BuscarEmpresaPorEmailESenha(empresa);this.Close();MenuEmpresamenuEmpresa=newMenuEmpresa();menuEmpresa.ShowDialog();}

CarRegistration

try{if(WindowsIdentity.GetCurrent().IsAuthenticated){empresa.Email=WindowsIdentity.GetCurrent().Name;}carro.Empresa=EmpresaDAO.BuscarEmpresaPorEmail(empresa);carro.Nome=txtNome.Text;carro.Cambio=txtCambio.Text;carro.Cor=txtCor.Text;carro.Marca=txtMarca.Text;carro.Quilometragem=txtQuilometragem.Text;carro.Placa=txtPlaca.Text;carro.Portas=int.Parse(txtPorta.Text);carro.Ano=int.Parse(txtPorta.Text);carro.Preco=txtPreco.Text;CarroDAO.Incluir(carro);MessageBox.Show("O cadastro do carro: " + carro.Nome + " foi concluido com sucesso", "Cadastrado");
            }

I tried to do as much as possible to asp.NET, because I did not understand how I will do this in C #.

ASP.NET

Usuario usu = new Usuario();
            ItemVenda itemv = new ItemVenda();
            if (Request.IsAuthenticated)
            {
                usu.Login = HttpContext.User.Identity.Name;
            }
            venda.Usuario = UsuarioDAO.BuscarUsuarioPorLogin(usu);
    
asked by anonymous 13.11.2017 / 02:48

1 answer

1

Believing that the page that has to make the registration of the car is the MenuEmpresa pass the login of the user that is the variable empresa by parameter at the moment of constructing the object MenuEmpresa :

In the login section:

Empresa empresa = new Empresa();
empresa.Email = txtEmail.Text;
empresa.Senha = txtSenha.Text;
if(EmpresaDAO.BuscarEmpresaPorEmailESenha(empresa) != null)
{
    empresa = EmpresaDAO.BuscarEmpresaPorEmailESenha(empresa);
    this.Close();
    MenuEmpresa menuEmpresa = new MenuEmpresa(empresa); // <<<<<<<<< AQUI
    menuEmpresa.ShowDialog();  
}

But the ideal would be to work with some kind of session, I'll let the C # devs complete it!

Ah! and remember in the constructor of class MinhaEmpresa there should be the declaration of the variable empresa

    
13.11.2017 / 03:15