0
Answer

Get loggedin user in all application

Sousa Pambo

Sousa Pambo

10y
735
1
Hi fellows, I have a problem with the loggedin user, I just cant do it before trying hard, Please help me solving it. Here my code
 
----------------------------------------------------------------------------------------------------------------------------------------- 
//my DAL 
 
public class loginDal
{
DAL.ConexaoGeral CnxGeral= new ConexaoGeral();
public bool podLogar(string us, string pw)      //
{
string mysql = "SELECT * FROM tb_User WHERE username = '" + us + "' and senha = '" + pw + "'";
using (SqlConnection myconn = new SqlConnection(CnxGeral.stringConexaoRH()))
{
try
{
myconn.Open();
using (SqlCommand comand = new SqlCommand(mysql, myconn))
{
SqlDataReader dtreader = comand.ExecuteReader();
if (dtreader.Read())
{
return true;
}
else
{ return false; }
}
}
catch (Exception erro)
{ throw erro; }
}
}
}
----------------------------------------------------------------------------------------------
//my login form 
 
public partial class frmLogin : Form
{
DAL.Funcionario FuncDal = new DAL.Funcionario();
public frmLogin()
{
InitializeComponent();
}
private void btCancelar_Click(object sender, EventArgs e)
{
this.Close();
}
private void btEntra_Click(object sender, EventArgs e)
{
DAL.loginDal ldDal = new DAL.loginDal();
FuncDal.namUser = tbUser.Text;
FuncDal.UserLevel = FuncDal.getFuncLevel(FuncDal.namUser);
FuncDal.func_ID = FuncDal.getFuncId(FuncDal.namUser);
if(ldDal.podLogar(tbUser.Text,tbPw.Text))
{
MessageBox.Show("usuario" + FuncDal.func_ID);
this.Hide();
UIL.frmMain fm = new UIL.frmMain();
fm.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("Usuário ou Senha Errados");
_-------------------------------------------------------------------------------------------------------

//Main form, it doesn't get username returns empty

 
public partial class frmMain : Form
{
DateTime Data_hora;
DAL.Funcionario FuncDal = new DAL.Funcionario();
frmLogin frmlog = new frmLogin();
public frmMain()
{
InitializeComponent();
}
private void btFecha_Click(object sender, EventArgs e)
{
this.Hide();
frmLogin frmlg = new frmLogin();
frmlg.ShowDialog();
this.Close();
}
private void funcionárioToolStripMenuItem_Click(object sender, EventArgs e)
{
frmFunc funcionarioFrm = new frmFunc();
funcionarioFrm.ShowDialog();
}
private void frmMain_Load(object sender, EventArgs e)
{
String NomeF = FuncDal.getFuncNam(FuncDal.getFuncId(FuncDal.namUser));
lbUserName.Text = "Nome do Usuário: " + NomeF;
MessageBox.Show("" + FuncDal.getFuncId(FuncDal.namUser));  //return "", but i want to get usename
}
private void timer1_Tick(object sender, EventArgs e)
{
Data_hora = DateTime.Now;
lbTime.Text = Data_hora.ToLongTimeString();
}
}
----------------------------------------------------------------------------------------
Sousa