private void MenuItem_Click_Connect(object sender, RoutedEventArgs e) { var user = _connectionSettings.User; var password = _connectionSettings.Password; var connectionString = _connectionSettings.ConnectionString; var configFile = _connectionSettings.ConfigFile; var alias = _connectionSettings.Alias; if (LogonDlgHandler.Show( ref user, ref password, ref connectionString, ref configFile, ref alias, _settings.AppName, this)) { _connectionSettings.User = user; _connectionSettings.Password = password; _connectionSettings.ConnectionString = connectionString; _connectionSettings.ConfigFile = configFile; _connectionSettings.Alias = alias; try { try { //Progress.Start(); UpdateDisconnectStatus(); UpdateConnectionString(connectionString); CheckInit(); _connectionSettings.WriteToCfg(); UpdateConnectStatus(); _services = _factory.CreateAll <IService>(); FillModules(_services); } finally { //Progress.Finish(); Activate(); } } catch (SqlException ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace, this); } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace, this); } } }
private void RegClick(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(this.password.Password) && !string.IsNullOrWhiteSpace(this.username.Text)) { string empty1 = string.Empty; string empty2 = string.Empty; try { if (this._xElement == null | this.Alias.SelectedItem == null) { return; } foreach (var data in this._xElement.Elements((XName)"machine").Where <XElement>((Func <XElement, bool>)(d => d.Attribute((XName)"alias").Value == this.Alias.SelectedItem.ToString())).Select(d => { var data = new { server = d.Element((XName)"server"), database = d.Element((XName)"database") }; return(data); }).Take(1)) { empty1 = data.server.Value; empty2 = data.database.Value; } this.connectionString = string.Format("server={0};uid={1};pwd={2};database={3};Application Name={4}", (object)empty1, "Administrator", "123456789", (object)empty2, (object)this.AppName); int res = 0; var _connection = new SqlConnection(this.connectionString); using (var command = new SqlCommand(AddNewUser.Replace("@Pass", this.password.Password).Replace("@User", this.username.Text).Replace("@Base", empty2), _connection)) { //if (!command.Parameters.Contains("@Pass")) //{ // command.Parameters.AddWithValue("@Pass", this.password.Password); //} //if (!command.Parameters.Contains("@User")) //{ // command.Parameters.AddWithValue("@User", this.username.Text); //} //if (!command.Parameters.Contains("@Base")) //{ // command.Parameters.AddWithValue("@Base", (object)empty2); //} _connection.Open(); res = Convert.ToInt32(command.ExecuteScalar()); _connection.Close(); } MessageBox.Show("Пользователь успешно создан, осуществляется вход в систему."); OKClick(null, null); } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace, this); } } }
private void OKClick(object sender, RoutedEventArgs e) { string empty1 = string.Empty; string empty2 = string.Empty; try { if (this._xElement == null | this.Alias.SelectedItem == null) { return; } foreach (var data in this._xElement.Elements((XName)"machine").Where <XElement>((Func <XElement, bool>)(d => d.Attribute((XName)"alias").Value == this.Alias.SelectedItem.ToString())).Select(d => { var data = new { server = d.Element((XName)"server"), database = d.Element((XName)"database") }; return(data); }).Take(1)) { empty1 = data.server.Value; empty2 = data.database.Value; } if (string.IsNullOrWhiteSpace(this.username.Text) & !string.IsNullOrWhiteSpace(this.password.Password)) { this.username.Focus(); throw new Exception("Введите имя."); } if (string.IsNullOrWhiteSpace(this.password.Password) & !string.IsNullOrWhiteSpace(this.password.Password)) { this.password.Focus(); throw new Exception("Введите пароль."); } string str; if (!string.IsNullOrWhiteSpace(this.password.Password) || !string.IsNullOrWhiteSpace(this.username.Text)) { str = string.Format("server={0};uid={1};pwd={2};database={3};Application Name={4}", (object)empty1, (object)this.username.Text.Trim(), (object)this.password.Password.Trim(), (object)empty2, (object)this.AppName); } else { str = string.Format("server={0};database={1};Integrated Security=true;Application Name={2}", (object)empty1, (object)empty2, (object)this.AppName); } this.connectionString = str; this.DialogResult = true; } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace, this); } }
public static void Main() { try { using (var container = new WindsorContainer()) { var bootstrapper = new Bootstrapper(container); bootstrapper.Install(); bootstrapper.RunApplication(); } } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace); } }
private void SetAlias(string fileName, string alias) { this.Alias.Items.Clear(); try { this._xElement = XElement.Load(fileName); foreach (XAttribute xattribute in (IEnumerable <XAttribute>) this._xElement.Elements((XName)"machine").Attributes((XName)nameof(alias)).OrderBy <XAttribute, string>((Func <XAttribute, string>)(a1 => a1.Value))) { this.Alias.Items.Add((object)xattribute.Value); } this.Alias.SelectedIndex = this.Alias.Items.IndexOf((object)alias.Trim()); } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace, this); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { var processModule = Process.GetCurrentProcess().MainModule; CommonSettings.AssVersion = processModule.FileVersionInfo.ProductVersion; this.Title = "Загрузчик " + CommonSettings.AssVersion + " " + _settings.AppVersion; } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace); } }
public void RunApplication() { try { InitializeCulture(); var mainView = _container.Resolve <IWindow>(); if (mainView is null) { throw new NullReferenceException(); } else { ((Window)mainView).ShowDialog(); } } catch (Exception ex) { CtmMessageBox.Show("Ошибка", ex.Message, ex.StackTrace); } }
protected void ExecutionShield(Action action, Action onFinally = null) { try { action(); } catch (SqlException ex) { CtmMessageBox.Show(@"Ошибка SQL запуска сервиса", ex.Message, ex.StackTrace); } catch (Exception ex) { CtmMessageBox.Show(@"Ошибка запуска сервиса", ex.Message, ex.StackTrace); } finally { if (onFinally != null) { onFinally(); } } }
protected TResult ExecutionShield <TResult>(Func <TResult> action, Action onFinally = null) { try { return(action()); } catch (SqlException ex) { CtmMessageBox.Show(@"Ошибка SQL запуска сервиса", ex.Message, ex.StackTrace); } catch (Exception ex) { CtmMessageBox.Show(@"Ошибка запуска сервиса", ex.Message, ex.StackTrace); } finally { if (onFinally != null) { onFinally(); } } return(default(TResult)); }
private void ProcessUnhandledException(object sender, UnhandledExceptionEventArgs ex) { CtmMessageBox.Show("Ошибка приложения", "Информация в StackTrace", ex.ExceptionObject.ToString()); }