private void button1_Click(object sender, EventArgs e) { try { if (textBox1.Text.Trim() != "") { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var conn = (ConnectionStringsSection)config.GetSection("connectionStrings"); conn.ConnectionStrings["ConectionSellerPro"].ConnectionString = "Data Source=" + textBox1.Text + ";Initial Catalog=DBSellerPro;Persist Security Info=True;User ID=sa;Password=sa"; config.Save(); ConfigurationManager.RefreshSection("connectionStrings"); SystemInfoCurrent.initialize(); new FrmLogin().Show(); Hide(); } else { MessageBox.Show("Prencha o campo"); } } catch (Exception r) { MessageBox.Show("error: " + r.Message); } }
private void bunifuThinButton24_Click(object sender, EventArgs e) { if (txtUser.Text.Trim() != "" && !hint) { if (txtPassword.Text.Trim() != "" && !hint2) { System.Configuration.Configuration c = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); User us; try { if (UserCurrent.getCurrentUser() != null) { usController = new UserController(); } us = usController.Logar(txtUser.Text, txtPassword.Text); if (us != null) { SystemInfoCurrent.initialize(); UserCurrent.initialize(us); if (us.FlagFirstLogin) { new FrmUserFirstLogin(us, this).Show(); } else { new Main(this).Show(); } txtUser.Focus(); txtUser.Select(0, 0); Hide(); txtPassword.Clear(); txtUser.Clear(); } else { MessageBox.Show("usuario ou senha incorrestos,\n TRY AGAIN"); txtPassword.Clear(); txtUser.Clear(); txtUser.Focus(); } } catch (Exception error) { MessageBox.Show(error.Message); us = null; } } else { MessageBox.Show("Insira a senha"); txtPassword.Focus(); } } else { MessageBox.Show("Insira o usuario"); } }
public SplashNew() { InitializeComponent(); try { /* * string path = Application.StartupPath + @"/config.json"; * var json = new JavaScriptSerializer(); * StreamReader reader = new StreamReader(path); * string jsons = ""; * string server = ""; * while (!reader.EndOfStream) * { * jsons += reader.ReadLine().ToString(); * * } * dynamic datas = json.DeserializeObject(jsons); * reader.Dispose(); * * foreach (KeyValuePair<string, object> item in datas) * { * server = item.Value as string; * } */ string server = Environment.MachineName; var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var conn = (ConnectionStringsSection)config.GetSection("connectionStrings"); conn.ConnectionStrings["ConectionSellerPro"].ConnectionString = "Data Source=" + server + ";Initial Catalog=DBSellerPro;Persist Security Info=True;User ID=sa;Password=sa"; config.Save(); ConfigurationManager.RefreshSection("connectionStrings"); SystemInfoCurrent.initialize(); /// FrmLogin frLogin = new FrmLogin(); // frLogin.Show(); this.Hide(); } catch (System.ObjectDisposedException error) { Visible = false; MessageBox.Show("erro na conexão com o banco de dados, verifica se o servidor está correcto"); } catch (Exception r) { Visible = false; MessageBox.Show("Erro: Entre em contacto com o suporte - " + r.Message); } finally { } labelCopyright.Text = "Copyright © 2020-" + DateTime.Now.Year.ToString(); }
public void load() { try { string path = Application.StartupPath + @"/config.json"; var json = new JavaScriptSerializer(); StreamReader reader = new StreamReader(path); string jsons = ""; string server = ""; while (!reader.EndOfStream) { jsons += reader.ReadLine().ToString(); } dynamic datas = json.DeserializeObject(jsons); reader.Dispose(); foreach (KeyValuePair <string, object> item in datas) { server = item.Value as string; } var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var conn = (ConnectionStringsSection)config.GetSection("connectionStrings"); conn.ConnectionStrings["ConectionSellerPro"].ConnectionString = "Data Source=" + server + ";Initial Catalog=DBSellerPro;Persist Security Info=True;User ID=sa;Password=sa"; config.Save(); ConfigurationManager.RefreshSection("connectionStrings"); SystemInfoCurrent.initialize(); } catch (System.ObjectDisposedException er) { MessageBox.Show("erro na conexão com o banco de dados,Feche e abre aplicação"); error = true; }catch (System.Data.SqlClient.SqlException rr) { MessageBox.Show("erro"); error = true; } catch (Exception r) { MessageBox.Show("Erro: Entre em contacto com o suporte - " + r.Message); error = true; } finally { finished = true; } }