/** <summary> Write credentials into an XML file. </summary> */
 public void WriteXML(DBLoginEncrypted login)
 {
     System.Xml.Serialization.XmlSerializer writer =
         new System.Xml.Serialization.XmlSerializer(typeof(DBLoginEncrypted));
     System.IO.FileStream file = System.IO.File.Create(
         this.credentialsFilepath);
     writer.Serialize(file, login);
     file.Close();
 }
        /** <summary> Read credentials from an XML file. </summary> */
        public DBLoginEncrypted ReadXML()
        {
            System.Xml.Serialization.XmlSerializer reader =
                new System.Xml.Serialization.XmlSerializer(typeof(DBLoginEncrypted));
            StreamReader file = new System.IO.StreamReader(
                this.credentialsFilepath);
            DBLoginEncrypted credentials = (DBLoginEncrypted)reader.Deserialize(file);

            file.Close();
            return(credentials);
        }
        /** <summary> Event handler for the "Connect" button. </summary> */
        private void Connect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var cs = "server=" + this.dbIP.Text + ";" +
                         "port=" + this.dbPort.Text + ";" +
                         "uid=" + this.dbUsername.Text + ";" +
                         "pwd=" + this.dbPassword.Password;
                var con = new MySqlConnection(cs);
                con.Open();
                con.Close();
                DBLoginEncrypted login = new DBLoginEncrypted();
                login.Username = Protect(this.dbUsername.Text);
                login.Password = Protect(this.dbPassword.Password);
                login.IP       = Protect(this.dbIP.Text);
                login.Port     = Protect(this.dbPort.Text);
                WriteXML(login);
            }
            catch (MySqlException ex)
            {
                MessageBox.Show("Unable to connect to a DB.\n" +
                                ex.Number.ToString() + " - " + ex.Message,
                                "FAI Secretary", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to connect to a DB.",
                                "FAI Secretary", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Control window = new Control(this.dbUsername.Text,
                                         this.dbPassword.Password, this.dbIP.Text, this.dbPort.Text);

            App.Current.MainWindow = window;
            this.Close();
            window.Show();
        }