private void lvwServices_SelectionChanged(object sender, SelectionChangedEventArgs e) { SqlServiceClass selectedService = (SqlServiceClass)lvwServices.SelectedItem; if (selectedService != null) { string text = selectedService.State; if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(text, "", false) == 0) { return; } if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(text, "Stopped", false) == 0) { this.cmdStop.IsEnabled = false; this.cmdStart.IsEnabled = true; this.cmdRestart.IsEnabled = false; } else if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(text, "Running", false) == 0) { this.cmdStop.IsEnabled = true; this.cmdStart.IsEnabled = false; this.cmdRestart.IsEnabled = true; } else { this.cmdStop.IsEnabled = false; this.cmdStart.IsEnabled = false; this.cmdRestart.IsEnabled = false; } } return; }
private void cmdRestart_Click(object sender, RoutedEventArgs e) { SqlServiceClass selectedService = (SqlServiceClass)lvwServices.SelectedItem; if (selectedService != null) { string text = selectedService.State; string serviceName = selectedService.RealName; if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(text, "", false) != 0) { this.RestartService(serviceName); } this.ServiceSQL(); } }
public void ServiceSQL() { ObservableCollection <SqlServiceClass> SqlServiceCollection = new ObservableCollection <SqlServiceClass>(); ServiceController[] services = ServiceController.GetServices(); //this.lvwServices.Items.Clear(); try { ServiceController[] serviceControllerArray = services; int index = 0; while (index < serviceControllerArray.Length) { ServiceController serviceController = serviceControllerArray[index]; if (serviceController.ServiceName.Contains(this.txtSQLServiceName1.ToUpper()) | serviceController.ServiceName.Contains(this.txtSQLServiceName2.ToUpper()) | serviceController.ServiceName.Contains(this.txtSQLServiceName3.ToUpper())) { SqlServiceClass serviceItem = new SqlServiceClass(); serviceItem.DisplayName = serviceController.DisplayName; serviceItem.RealName = serviceController.ServiceName; serviceItem.State = serviceController.Status.ToString(); SqlServiceCollection.Add(serviceItem); } checked { ++index; } } lvwServices.ItemsSource = SqlServiceCollection; } catch (Exception ex) { ProjectData.SetProjectError(ex); int num = (int)MessageBox.Show("Không tìm thấy Services SQL. Hãy kiểm tra lại", "Thông báo: " + ex.Source); ProjectData.ClearProjectError(); } finally { } //this.cmdStart.Enabled = false; //this.cmdStop.Enabled = false; }