private void frmLoginInfo_Closing(object sender, System.ComponentModel.CancelEventArgs e) { /* * Serialize Logins */ if (this.DialogResult == DialogResult.OK) { TextWriter twXML = new StreamWriter(sConnectionsFile); ((FormMain)this.Owner).ShowInfoMessage("Serializing connection preferences..."); SqlLogin slLastConnection = new SqlLogin(); slLastConnection.Address = cbServer.Text; slLastConnection.Login = txtLogin.Text; slLastConnection.IsLastUsed = true; if (!cbServer.Items.Contains(slLastConnection)) { cbServer.Items.Insert(0, slLastConnection); } else { SqlLogin slFound; slFound = cbServer.Items[cbServer.Items.IndexOf(slLastConnection)] as SqlLogin; slFound.IsLastUsed = true; } while (cbServer.Items.Count > SqlLoginPool.MAXLOGINS) { cbServer.Items.RemoveAt(cbServer.Items.Count - 1); } SqlLoginPool slpLogins = new SqlLoginPool(); cbServer.Items.CopyTo(slpLogins.LoginPool, 0); XmlSerializer xsLogins = new XmlSerializer(typeof(SqlLoginPool)); xsLogins.Serialize(twXML, slpLogins); twXML.Close(); } }
private void frmLoginInfo_Load(object sender, System.EventArgs e) { /* * Deserialize Logins */ FileStream fsXML = null; try { fsXML = new FileStream(sConnectionsFile, FileMode.Open); ((FormMain)this.Owner).ShowInfoMessage("Deserializing connection preferences..."); XmlSerializer xsLogins = new XmlSerializer(typeof(SqlLoginPool)); SqlLoginPool slpLogins = (SqlLoginPool)xsLogins.Deserialize(fsXML); foreach (SqlLogin slItem in slpLogins.LoginPool) { if (slItem != null) { cbServer.Items.Add(slItem); if (slItem.IsLastUsed) { cbServer.SelectedItem = slItem; } slItem.IsLastUsed = false; } } } catch (FileNotFoundException) { ((FormMain)this.Owner).ShowInfoMessage("Nothing to deserialize."); } finally { if (fsXML != null) { fsXML.Close(); } } cbServer_SelectedIndexChanged(null, null); }
private void frmLoginInfo_Closing(object sender, System.ComponentModel.CancelEventArgs e) { /* * Serialize Logins */ if (this.DialogResult == DialogResult.OK) { TextWriter twXML = new StreamWriter(sConnectionsFile); ((FormMain)this.Owner).ShowInfoMessage("Serializing connection preferences..."); SqlLogin slLastConnection = new SqlLogin(); slLastConnection.Address = cbServer.Text; slLastConnection.Login = txtLogin.Text; slLastConnection.IsLastUsed = true; if (!cbServer.Items.Contains(slLastConnection)) { cbServer.Items.Insert(0, slLastConnection); } else { SqlLogin slFound; slFound = cbServer.Items[cbServer.Items.IndexOf(slLastConnection)] as SqlLogin; slFound.IsLastUsed = true; } while (cbServer.Items.Count > SqlLoginPool.MAXLOGINS) { cbServer.Items.RemoveAt(cbServer.Items.Count-1); } SqlLoginPool slpLogins = new SqlLoginPool(); cbServer.Items.CopyTo(slpLogins.LoginPool, 0); XmlSerializer xsLogins = new XmlSerializer(typeof(SqlLoginPool)); xsLogins.Serialize(twXML, slpLogins); twXML.Close(); } }