private void btn_save_Click(object sender, RoutedEventArgs e) { string accountString = "update accounts set "; bool updateable = true; if (tb_firstname.Text != "") { accountString += "firstname = '" + tb_firstname.Text + "', "; } else { updateable = false; } if (tb_lastname.Text != "") { accountString += "lastname = '" + tb_lastname.Text + "', "; } else { updateable = false; } if (tb_mail.Text != "") { accountString += "email = '" + tb_mail.Text + "'"; } else { updateable = false; } if (tb_password.Password != "") { if (tb_password.Password == tb_confpassword.Password) { accountString += ", password = '******'"; } } if (new TextRange(tb_desc.Document.ContentStart, tb_desc.Document.ContentEnd).Text != "'") { accountString += ", description = '" + new TextRange(tb_desc.Document.ContentStart, tb_desc.Document.ContentEnd).Text + "'"; } if (!worker_saveAccountSettings.IsBusy && updateable) { btn_save.IsEnabled = false; accountString += " where acc_id = " + MainWindow.account.id + ";"; worker_saveAccountSettings.RunWorkerAsync(accountString); } }
public MainWindow() { InitializeComponent(); this.ShowIconOnTitleBar = false; this.HamburgerMenuControl.SelectedIndex = 0; this.selectedIndex = 0; MainWindow.instance = this; cnn = new SqlConnection(connectionString); worker = new BackgroundWorker(); worker.DoWork += Worker_AddProjectToDatabase; Properties.Settings.Default.RememberUserName = Certify.Encrypt(MainWindow.account.email); Properties.Settings.Default.Save(); }
private void RunStatement() { while (!threadHasToStop) { if (sqlStatementIsRunning) { sqlStatementIsRunning = false; try { bool registered = false; SqlCommand command = cnn.CreateCommand(); command.CommandText = "select email from accounts;"; SqlDataReader reader; cnn.Open(); reader = command.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { if (mail == reader.GetValue(i).ToString()) { registered = true; } } } if (!registered) { reader.Close(); command.CommandText = "insert into accounts(firstname, lastname, email, password, businessusage, lastpayment, description) values('" + firstname + "', '" + lastname + "', '" + mail + "', '" + Certify.Encrypt(password) + "', '" + businessusage + "', CONVERT (date, GETDATE()), null);"; command.ExecuteNonQuery(); Dispatcher.Invoke(new Action(() => { lbl_msg.Content = (string)FindResource("msg_succ"); lbl_msg.Foreground = Brushes.Green; lbl_msg.Visibility = Visibility.Visible; progring.IsActive = false; threadHasToStop = true; })); } } catch (Exception ex) { } } } }