private void button1_Click(object sender, EventArgs e) { try { Settings newsettings = new Settings(textBox1.Text, float.Parse(textBox2.Text), float.Parse(textBox3.Text), textBox4.Text, textBox5.Text.Replace("\\\\", "\\"), textBox6.Text.Replace("\\\\", "\\"),DataFormat.GetSha1(textBox7.Text)); mysql_settings.UpdateSettings(newsettings); GlobalVar.sqlsettings=mysql_settings.GetSettings(); textBox1.Text = GlobalVar.sqlsettings.RRSaddress; textBox2.Text = GlobalVar.sqlsettings.RRSlatitude.ToString(); textBox3.Text = GlobalVar.sqlsettings.RRSlongitude.ToString(); textBox4.Text = GlobalVar.sqlsettings.mapquestkey; textBox5.Text = GlobalVar.sqlsettings.RRSLinesFile.Replace("\\\\", "\\"); textBox6.Text = GlobalVar.sqlsettings.RRSHeaderFile.Replace("\\\\", "\\"); textBox7.Text = ""; } catch { GlobalVar.sqlsettings = mysql_settings.GetSettings(); textBox1.Text = GlobalVar.sqlsettings.RRSaddress; textBox2.Text = GlobalVar.sqlsettings.RRSlatitude.ToString(); textBox3.Text = GlobalVar.sqlsettings.RRSlongitude.ToString(); textBox4.Text = GlobalVar.sqlsettings.mapquestkey; textBox5.Text = GlobalVar.sqlsettings.RRSLinesFile.Replace("\\\\", "\\"); textBox6.Text = GlobalVar.sqlsettings.RRSHeaderFile.Replace("\\\\", "\\"); textBox7.Text = ""; } }
public bool UpdateSettings(Settings settings) { try { MySqlConnection theconnection = Connect(); settings.RRSaddress = settings.RRSaddress.Replace("'", ""); settings.RRSHeaderFile=settings.RRSHeaderFile.Replace("\\","\\\\"); settings.RRSLinesFile= settings.RRSLinesFile.Replace("\\", "\\\\"); string updatequery="UPDATE settings SET `RRSaddress`='"+settings.RRSaddress+"',`RRSlatitude`="+settings.RRSlatitude+",`RRSlongitude`="+settings.RRSlongitude+",`Mapquest`='"+settings.mapquestkey+"',`RRSLinesFile`='"+settings.RRSLinesFile+"',`RRSHeaderFile`='"+settings.RRSHeaderFile+"',`password`='"+settings.passwordhash+"';"; Update(updatequery, theconnection); Disconnect(); return true; } catch { Disconnect(); return false; } }
public Settings GetSettings() { try{ MySqlConnection theconnection=Connect(); MySqlDataReader rdr = Select("SELECT * FROM settings;", theconnection); rdr.Read(); Settings settings= new Settings((string)rdr[0],(float)rdr[1],(float)rdr[2],(string)rdr[3],(string)rdr[4],(string)rdr[5],(string)rdr[6]); Disconnect(); return (settings); } catch { Disconnect(); return null; } }