// Opens and refreshes storepage private void returnToStore(object sender, MouseEventArgs e) { this.Close(); prev.Show(); prev.Enabled = true; prev.reinitalizeUser(); }
private void registerButton(object sender, EventArgs e) { Boolean exists = false; long n = DateTimeOffset.Now.ToUnixTimeSeconds(); // Check that everything has been filled in if (UsernameBox.Text == "" || PasswordBox.Text == "" || FundsBox.Text == "" || AddressBox.Text == "") { MessageBox.Show("Please enter your information in every field"); return; } // Turns user textbox into a filepath string user = Path.Combine(storeClasses.generalFilePath, "Users", UsernameBox.Text + ".txt"); string pass = PasswordBox.Text; string projectPath = Path.Combine(storeClasses.generalFilePath, "Users"); if (loginPage != null) { // Checks for file existance foreach (string itemFile in Directory.EnumerateFiles(projectPath)) { if (itemFile == user) { MessageBox.Show("User already exists"); exists = true; return; } } // Creates a file to write to if file doesn't already exist. if (exists == false) { // Creates a file to write to. StreamWriter create = File.CreateText(user); string funds = FundsBox.Text; string address = AddressBox.Text; string[] data = { pass, n.ToString(), funds, address }; create.WriteLine(pass); create.WriteLine(n); create.WriteLine(funds); create.WriteLine(address); create.Close(); loginPage.Enabled = true; this.Close(); } } //Editing else if (storefront != null) { // Deletes file to then remake File.Delete(user); StreamWriter create = File.CreateText(user); string funds = FundsBox.Text; string address = AddressBox.Text; string[] data = { pass, n.ToString(), funds, address }; create.WriteLine(pass); create.WriteLine(n); create.WriteLine(funds); create.WriteLine(address); create.Close(); storefront.Enabled = true; this.Close(); viewingUser.wallet = double.Parse(funds); viewingUser.address = address; storefront.reinitalizeUser(); } }