private static void InitializeConnectionString() { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var connectionString = config.ConnectionStrings.ConnectionStrings["EntityDataModelESB2Container"]; if (connectionString.ConnectionString.Contains("xxxxx")) { var findDatabase = new OpenFileDialog() { Title = "Select/Create Equipment Status Board Database", Multiselect = false, AddExtension = true, DefaultExt = "sdf", Filter = "SQL CE|*.sdf", CheckFileExists = false }; findDatabase.ShowDialog(); try { connectionString.ConnectionString = connectionString.ConnectionString.Replace("xxxxx", findDatabase.FileName); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("connectionStrings"); }catch (Exception e) { ESB2ExceptionEventLog.LogExceptionEvent(e); } } }
public static User Login() { var loginDialog = new UserLoginDialog(); User user = null; try { loginDialog.ShowDialog(); if ((bool)loginDialog.DialogResult) { user = users.FirstOrDefault(u => u.Username.Equals(loginDialog.Username.ToLower())); if (user != null) { user = ProcessLogin((UserLogin)user, loginDialog.Password); } else { new InvalidUsernameDialog().ShowDialog(); ESB2UserEventLog.LogUserEvent(loginDialog.Username, EventLoggerEvents.InvalidUsername); } } }catch (Exception e) { ESB2ExceptionEventLog.LogExceptionEvent(e); } return(user); }
public static bool ChangePassword(UserLogin user, string password) { try { user.Password = PasswordEncrypter.EncryptPassword(user.Username.ToLower(), password); database.SaveChanges(); } catch (Exception e) { ESB2ExceptionEventLog.LogExceptionEvent(e); return(false); } return(true); }
public static void LogUserEvent(string username, EventLoggerEvents userEvent) { try { database.EventLogLog.Add(new EventLoggerEvent() { Timestamp = DateTime.Now, User = username, Event = userEvent }); database.SaveChanges(); } catch (Exception e) { ESB2ExceptionEventLog.LogExceptionEvent(e); } }