private void LogOut() { SQLConnectionSetUp conObj = new SQLConnectionSetUp(); var Con = conObj.GetConn(); try { Con.Open(); SqlCommand cmd = new SqlCommand("LogOut", Con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", Helper.LoggedInUserName); cmd.ExecuteNonQuery(); } catch (Exception Ex) { } finally { Con.Close(); } }
private bool ValidateUser() { bool flag = false; SQLConnectionSetUp conObj = new SQLConnectionSetUp(); var Con = conObj.GetConn(); try { Con.Open(); SqlCommand cmd = new SqlCommand("ValidateUser", Con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", textBoxUsername.Text.Trim()); cmd.Parameters.AddWithValue("@Password", textBoxPassword.Text.Trim()); if (Convert.ToInt32(cmd.ExecuteScalar()) == 1) { Helper.LoggerInUserIsAdmin = true; Helper.LoggedInUserName = textBoxUsername.Text; flag = true; } else if (Convert.ToInt32(cmd.ExecuteScalar()) == 0) { Helper.LoggerInUserIsAdmin = false; Helper.LoggedInUserName = textBoxUsername.Text; flag = true; } else { flag = false; } } catch (Exception Ex) { flag = false; } finally { Con.Close(); } return(flag); }
private void button2_Click(object sender, EventArgs e) { string error = ""; if (textBoxPassword.Text == "" && textBoxUserName.Text == "") { error = "Either UserName OR Password is Blank"; labeMessage.Text = error; } if (error == "") { SQLConnectionSetUp conObj = new SQLConnectionSetUp(); var Con = conObj.GetConn(); try { Con.Open(); SqlCommand cmd = new SqlCommand("Insert_User", Con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", textBoxUserName.Text.Trim()); cmd.Parameters.AddWithValue("@Password", textBoxPassword.Text.Trim()); cmd.Parameters.AddWithValue("@IsActive", 1); cmd.Parameters.AddWithValue("@isInUse", 0); cmd.Parameters.AddWithValue("@IsAdmin", checkBox1.Checked); if (Convert.ToInt32(cmd.ExecuteScalar()) == 1) { labeMessage.Text = "User Name Already Exist"; } else { labeMessage.Text = "User Created Sucessufully"; } } catch (Exception Ex) { } finally { Con.Close(); } } }
private void SetIP(string SystemName, string IpAddress) { bool flag; SQLConnectionSetUp conObj = new SQLConnectionSetUp(); var Con = conObj.GetConn(); try { Con.Open(); SqlCommand cmd = new SqlCommand("SetSystems", Con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SystemName", SystemName.Trim()); cmd.Parameters.AddWithValue("@IPAddress", IpAddress.Trim()); cmd.Parameters.AddWithValue("@UserIdLoggedIn", 1); var k = Convert.ToInt32(cmd.ExecuteScalar()); //MessageBox.Show("System Info Saved"); } catch (Exception Ex) { MessageBox.Show("Syteme Info Could Not Be saved " + "Error Message " + Ex.Message); } finally { Con.Close(); } }