private static bool Load() { string path = Environment.CurrentDirectory + @"\Database.xml"; lock (syncObj) { Stream fStream = null; try { fStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read); if (fStream.Length == 0) { fStream.Close(); } XmlSerializer format = new XmlSerializer(typeof(DbConnectString));//创建二进制序列化器 connString = (DbConnectString)format.Deserialize(fStream); fStream.Close(); } catch (System.Exception ex) { connString = new DbConnectString(); MessageBox.Show(ex.Message); return(false); } finally { if (fStream != null) { fStream.Close(); } } } return(true); }
public static string GetString() { if (connString == null) { connString = DbConnectString.GetString(); } return(connString); }
private void SetConnForm_Load(object sender, EventArgs e) { DbConnectString dcs = DbConnectString.Get(); textBoxIp.Text = dcs.server; textBoxPort.Text = dcs.port.ToString(); textBoxUser.Text = dcs.user; textBoxPassword.Text = dcs.password; }
public static void Reset(string ip, int port, string user, string password, string schema) { connString = new DbConnectString() { server = ip, port = port, user = user, password = password, schema = schema, }; Save(); }
private void buttonOK_Click(object sender, EventArgs e) { DbConnectString.Reset(textBoxIp.Text, Convert.ToInt32(textBoxPort.Text), textBoxUser.Text, textBoxPassword.Text, "shuiwen"); this.Close(); Application.Exit(); }