96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace StacjaProb
|
|
{
|
|
public partial class LoginForm : Form
|
|
{
|
|
public LoginForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void LoginForm_Load(object sender, EventArgs e)
|
|
{
|
|
textBoxPass.MaxLength = 32;
|
|
textBoxPass.PasswordChar = '*';
|
|
|
|
string userRoot = "HKEY_CURRENT_USER\\SoftSPM";
|
|
string noSuch = (string)Microsoft.Win32.Registry.GetValue(userRoot, "COMPANY_NAME", "");
|
|
|
|
if (String.Compare(noSuch, "SoftSPM", true) == 0)
|
|
{
|
|
string vLastLoginName = Microsoft.Win32.Registry.GetValue(userRoot + "\\SPM_TST", "LAST_USER", "").ToString();
|
|
textBoxLogin.Text = vLastLoginName;
|
|
if (vLastLoginName.Length>0)
|
|
{
|
|
textBoxPass.Focus();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LogIn()
|
|
{
|
|
int index = 0;
|
|
mySqlFunctions.initConnection();
|
|
if (mySqlFunctions.OpenConnection())
|
|
{
|
|
|
|
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select USR_ID,USR_FIRST_NAME,USR_LAST_NAME,TUT_TYPE from sys_users left join tst_users_type ON TUT_USR_ID=USR_ID where USR_USERNAME='" + textBoxLogin.Text + "' and USR_PASSWORD=md5('" + textBoxPass.Text + "')", mySqlFunctions.connection);
|
|
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
|
while (dataReader.Read())
|
|
{
|
|
|
|
vGlobal.tst_usr_id = Convert.ToInt32(dataReader["USR_ID"].ToString());
|
|
vGlobal.tst_login_name = dataReader["USR_FIRST_NAME"].ToString() + " " + dataReader["USR_LAST_NAME"].ToString();
|
|
if (String.Compare(dataReader["TUT_TYPE"].ToString(), "1", true) == 0)
|
|
vGlobal.tst_login_admin_priv = true;
|
|
index++;
|
|
}
|
|
dataReader.Close();
|
|
mySqlFunctions.CloseConnection();
|
|
}
|
|
|
|
if (index > 0)
|
|
{
|
|
vGlobal.tst_login_acces = true;
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Wprowadzono błędny login lub hasło!");
|
|
textBoxPass.Text = "";
|
|
}
|
|
}
|
|
|
|
|
|
private void buttonLogin_Click(object sender, EventArgs e)
|
|
{
|
|
const string userRoot = "HKEY_CURRENT_USER\\SoftSPM";
|
|
Microsoft.Win32.Registry.SetValue(userRoot + "\\SPM_TST", "LAST_USER", textBoxLogin.Text);
|
|
|
|
LogIn();
|
|
}
|
|
|
|
private void textBoxLogin_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
LogIn();
|
|
}
|
|
|
|
private void textBoxPass_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
LogIn();
|
|
}
|
|
|
|
}
|
|
}
|