using BiskLog_Point_Of_Sale.Company_Setup; using Point_Of_Sale_Managment; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BiskLog_Point_Of_Sale.Multiple_Login { public partial class ResumeSession : Form { public bool SuccessfulLogin = false; public bool ElseWhere = false; public bool DifferentUser = false; SqlConnection cn; SqlCommand cm; SqlDataReader dr; DatabaseConn conn = new DatabaseConn(); public ResumeSession() { InitializeComponent(); cn = new SqlConnection(conn.MyConnection()); } private void Label2_Click(object sender, EventArgs e) { this.DifferentUser = true; this.DialogResult = DialogResult.OK; this.Close(); } private async void BtnLogin_Click_1(object sender, EventArgs e) { Task task = new Task(available); loading.Visible = true; btnLogin.Enabled = false; task.Start(); int result = await task; if (result == 1) { this.SuccessfulLogin = true; this.ElseWhere = false; this.DialogResult = DialogResult.OK; this.Close(); } else if (result == 3) { this.SuccessfulLogin = false; this.ElseWhere = true; this.DialogResult = DialogResult.OK; this.Close(); } else if (result == 5) { string title = "Wrong password"; string message = "Sorry unable to login as you have entered a wrong password"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); } else if (result == 10) { string title = "Error Occurred"; string message = "Sorry error authenticating user, please try again later"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); } else { string title = "Multiple logins not allowed"; string message = "Sorry unable to login as user has already logged in from a different workstation"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); } loading.Visible = false; btnLogin.Enabled = true; } private void ResumeSession_Load(object sender, EventArgs e) { label5.Text = MainLogin.login_user; } public int available() { try { if (reAuth()) { cn.Open(); cm = new SqlCommand("Declare @retu varchar(50) set @retu = case when(Select username from tblUser_activity where username = @username and workstation = @workstation) " + "IS NOT NULL then 1 else 0 end Declare @active int = (Select DATEDIFF(ss, last_active, CURRENT_TIMESTAMP) from tblUser_activity where username = @username) Select " + "(case when @active >= 3 then 1 else 0 end) as CanLogin, @retu as NotElsewhere", cn); cm.Parameters.AddWithValue("@username", label5.Text); cm.Parameters.AddWithValue("@workstation", Splashscreen.macAddress); cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); dr.Read(); if (dr.HasRows) { if ((dr[0].ToString() == "1") && (dr[1].ToString() == "1")) { dr.Close(); cn.Close(); return 1; } else if ((dr[0].ToString() == "0") && (dr[1].ToString() == "1")) { dr.Close(); cn.Close(); return 2; } else if ((dr[0].ToString() == "1") && (dr[1].ToString() == "0")) { dr.Close(); cn.Close(); return 3; } else { dr.Close(); cn.Close(); return 4; } } else { dr.Close(); cn.Close(); return 0; } } else { return 5; } } catch(SqlException) { cn.Close(); return 10; } catch { cn.Close(); return 0; } } public bool reAuth() { if (passwordEncryption.Decrypt(Splashscreen.ppd).Equals(txtpassword.Text)) { return true; } else { return false; } } } }