C # Windows Form - Questions about Session

0

I need to save an information by the time the user is logged in to my software, I searched and saw that for web pages made with ASP.NET there is the object SESSION , but for Windows Form?

The information I need and the user name, I have the ID of it inserted in the login screen. but I need to display the user name in a form.

    
asked by anonymous 21.07.2016 / 15:15

1 answer

3

I found the solution, below:

Source: link

On the Windows Forms platform, people find it difficult to maintain this type of session with variables and information, however, there is a simple way to record session using the desktop platform without any problem.

Working with Session is simple and smooth. Soon after entering the user and password, the variables need to be filled in and saved in the session for future use or verification.

Using Windows Forms, the first step is to create a public and static type class.

Creating Class

Right-click on your project or inside a UTIL folder, choose Add / New Item ...

Aftergivingthename(Session.system.cs)andclickingtheAddbutton,putthefollowingdata:

Step1:PutthewordPublicStaticatthebeginningoftheclass.

publicstaticclassSessaoSistema{}

Step2:GenerateGetandSetvariableswithintheclass.TheyshouldbestaticwithintheSessionSystemclass.

//usuarioprivatestaticInt32_usuarioId;privatestaticString_nomeUsuario;privatestaticString_emailUsuario;//getesetpublicstaticStringUsuarioId{get{returnSessaoSistema._usuarioId;}set{SessaoSistema._usuarioId=value;}}publicstaticStringNomeUsuario{get{returnSessaoSistema._nomeUsuario;}set{SessaoSistema._nomeUsuario=value;}}publicstaticStringEmailUsuario{get{returnSessaoSistema._emailUsuario;}set{SessaoSistema._emailUsuario=value;}}

UsingSessionClass

Nowontheloginscreen,afterenteringtheusernameandpasswordforthedesktopsystem,fillintheinformationasfollows.

//depoisdologinokSessaoSistema.NomeUsuario=txtNomeUsuario.text;SessaoSistema.UsuarioId=usuarioId;SessaoSistema.EmailUsuario=txtEmail.text;

Anywhereinthesystemyoucanpickupthedatastoredintheuser'sLoginafterjusttypingandSystem.Sessionvariable.Property(forexample:SystemSession.UserName.

Source: link

More information:

link

    
21.07.2016 / 15:19