private void LoginScreen_Load(object sender, EventArgs e) { UsernameTextBox.Select(); //If the file exists, and there are users in the file if (File.Exists(path) && new FileInfo(path).Length > 0) { //Every line is split using the $. Each part is stored to userInfo and corresponds to a user;s username, level, etc. foreach (var line in File.ReadLines(path)) { char[] seperator = { '$' }; string[] userInfo = line.Split(seperator, 5); bool exists = false; //The following loads the users from the text file to the List. //It searches the whole List. If the user is not found there, it adds the user found in the specific line of file to the List. Then goes to the next line etc. foreach (user u in users) { if (userInfo[0] == u.Username) { exists = true; } } if (!exists) { users.Add(new user(userInfo[0], int.Parse(userInfo[1]), int.Parse(userInfo[2]), DateTime.Parse(userInfo[3]), int.Parse(userInfo[4]))); } } } }
private void LoginButton_Click(object sender, EventArgs e) { string username = UsernameTextBox.Text; string password = PasswordTextBox.Text; if (login(username, password)) { NewStockForm newStockForm = new NewStockForm(user); newStockForm.Show(); } else { MessageBox.Show("Username dan password tidak cocok", "Maaf"); PasswordTextBox.Text = ""; UsernameTextBox.Text = ""; UsernameTextBox.Select(); } }
private void InitAll() { Activate(); UsernameTextBox.Select(); }
public LoginForm() { InitializeComponent(); UsernameTextBox.Select(); }