private void btnDrivers_Click(object sender, RoutedEventArgs e)
        {
            var driverRepository = new SqlDriverRepository(_connectionString);
            var driverWindow     = new DriverWindow(_customer, driverRepository.SelectAll());

            wndMainWindow.IsEnabled = false;
            driverWindow.ShowDialog();
            wndMainWindow.IsEnabled = true;
        }
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            string stationName = String.IsNullOrEmpty((string)cmbStation.SelectedItem) ? null : (string)cmbStation.SelectedItem;

            string routeNumber = String.IsNullOrEmpty((string)cmbRoute.SelectedItem) ? null : (string)cmbRoute.SelectedItem;

            var driverSqlRepository = new SqlDriverRepository(_connectionString);

            dgrDataDrivers.ItemsSource = driverSqlRepository.SearchAll(routeNumber, stationName);
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            var addDriverWindow = new AddDriverWindow(_customer);

            wndDriver.IsEnabled = false;
            addDriverWindow.ShowDialog();

            var driverRepository = new SqlDriverRepository(_connectionString);

            dgrDataDrivers.ItemsSource = driverRepository.SelectAll();

            wndDriver.IsEnabled = true;
        }
Beispiel #4
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("No driver name", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string driverName = txtName.Text;

            if (String.IsNullOrEmpty(txtSurname.Text))
            {
                MessageBox.Show("No driver surrname", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string driverSurname = txtSurname.Text;

            if (String.IsNullOrEmpty(txtBusNumber.Text))
            {
                MessageBox.Show("No bus number", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            string busNumber = txtBusNumber.Text;

            var driverRepository = new SqlDriverRepository(_connectionString);

            var driver = new Driver()
            {
                Name      = driverName,
                Surname   = driverSurname,
                BusNumber = busNumber
            };

            try
            {
                int id = driverRepository.Insert(_customer.Id, driver);

                txtName.Text      = "";
                txtSurname.Text   = "";
                txtBusNumber.Text = "";

                MessageBox.Show(String.Format("Driver {0} {1} added with id = {1}.", driverName, driverSurname, id), "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Number error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnDriver_Click(object sender, RoutedEventArgs e)
        {
            var driverRepository = new SqlDriverRepository(_connectionString);

            if (dgrDataSchedule.SelectedItem == null)
            {
                MessageBox.Show("Not selected schedule.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            int scheduleId = ((TimeTable)dgrDataSchedule.SelectedItem).Id;

            var driverWindow = new DriverWindow(_customer, driverRepository.GetDriversBySchedule(scheduleId));

            wndSchedule.Close();
            driverWindow.ShowDialog();
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            var driverRepository = new SqlDriverRepository(_connectionString);

            if (dgrDataDrivers.SelectedItem == null)
            {
                MessageBox.Show("Not selected driver.", "Selection", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Driver driver = (Driver)dgrDataDrivers.SelectedItem;

            MessageBoxResult answer = MessageBox.Show(String.Format("You really want to delete driver {0}?",
                                                                    String.Format("{0} {1}", driver.Name, driver.Surname)), "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (answer == MessageBoxResult.Yes)
            {
                driverRepository.Delete(driver.Id);
                dgrDataDrivers.ItemsSource = driverRepository.SelectAll();
            }
        }