public frmMain()
 {
     InitializeComponent();
     currentUser = share.loadGeneral();
     loadUI(currentUser);
     loadTenants();
     gECTenants.Enabled = false;
     countUnpaid();
     gTenants.Visible = true;
 }
 public frmSettings()
 {
     SharedCode.appUser currentUser = new SharedCode.appUser();
     InitializeComponent();
     currentUser = share.loadGeneral();
     showData(currentUser);
     originUsername = currentUser.Name;
     isClosed = false;
     foreach(Control txtControl in tGeneral.Controls)
     {
         if(txtControl is TextBox)
         {
             txtControl.Enter += share.txtFocus;
         }
     }
 }
 private void btnT1_Save_Click(object sender, EventArgs e)
 {
     foreach(Control txtControl in tGeneral.Controls)
     {
         if(txtControl is TextBox && txtControl.Text.Trim() == string.Empty)
         {
             MessageBox.Show("Please fill out all the entries!", "Warning!");
             txtT1Username.Focus();
             return;
         }
     }
     if(txtT1Password.Text != txtT1PasswordConfirm.Text)
     {
         MessageBox.Show("Passwords do not match!", "Warning");
         txtT1Password.Text = string.Empty;
         txtT1PasswordConfirm.Text = string.Empty;
         txtT1Password.Focus();
         return;
     }
     if(share.alphanumericTest(txtT1Username.Text) == true)
     {
         MessageBox.Show("Username must be alphanumeric!", "Warning!");
         return;
     }
     if (share.alphanumericTest(txtT1Password.Text) == true)
     {
         MessageBox.Show("Password must be alphanumeric!", "Warning!");
         return;
     }
     DialogResult confirmSave = new DialogResult();
     confirmSave = MessageBox.Show("Saving these changes will log you out of this current session. Continue?", "Warning", MessageBoxButtons.OKCancel);
     if(confirmSave == System.Windows.Forms.DialogResult.Cancel)
     {
         //User doesn't want to save changes
         return;
     }
     SharedCode.appUser saveUser = new SharedCode.appUser();
     saveUser.Name = txtT1Username.Text;
     saveUser.IC = txtT1IC.Text;
     saveUser.HomeAddress = txtT1Address.Text;
     saveUser.HouseNumber = txtT1HouseNo.Text;
     saveUser.PhoneNumber = txtT1PhoneNo.Text;
     saveUser.Email = txtT1Email.Text;
     saveUser.Password = txtT1Password.Text;
     share.saveGeneral(saveUser);
     if(originUsername != saveUser.Name)
     {
         Console.WriteLine("Username changed!");
         System.IO.File.Delete(CurrentPath + Database + originUsername + ".db");
     }
     share.EncryptFile(CurrentPath + "\\saveNew.db", CurrentPath + Database + saveUser.Name + ".db", saveUser.Password);
     //Encrypt all tenants with new name
     String[] fileList;
     fileList = Directory.GetFiles(CurrentPath + Database + currentLoad, "*.db");
     //Encrypt all user tenants
     foreach (string fileName in fileList)
     {
         string tenantName;
         tenantName = Path.GetFileNameWithoutExtension(fileName);
         share.EncryptFile(fileName, CurrentPath + Database + saveUser.Name + "\\" + tenantName + ".db", saveUser.Password);
     }
     if (System.IO.File.Exists(CurrentPath + "\\saveNew.db") == true)
     {
         System.IO.File.Delete(CurrentPath + "\\saveNew.db");
     }
     properExit();
 }