Exemplo n.º 1
0
        private void miSettings_Click(object sender, RoutedEventArgs e)
        {
            Settings settings = new Settings();

            CommonTasks.getInstance().Hide();
            settings.Show();
        }
Exemplo n.º 2
0
        private void handleLogin()
        {
            string[] results = Database.getInstance().datasetToStringArray(Database.getInstance().select("", new string[] { "Employee as T1, EmployeeLogin as T2 " }, new string[] { "T1.EmployeeID", "T1.FirstName" }, "WHERE T1.EmployeeID = T2.EmployeeID and T2.Username", "=", txtUsername.Text + "' and T2.Password = '" + pwbPassword.Password + "", new String[] { "" }));


            if (results.Length != 0)
            {
                DataDelegate.EmployeeID      = int.Parse(results[0]);
                DataDelegate.currentUserName = results[1];

                DataDelegate.loginStart = DateTime.Now;


                MainWindow.getInstance().Show();
                MainWindow.getInstance().enableWindow();
                CommonTasks.getInstance().Show();
                this.Close();
            }
            else
            {
                failedAttempts++;
                if (failedAttempts >= 3)
                {
                    MessageBox.Show("Too many login attempts. This application will now close. Goodbye.", "Login Failed");
                    Environment.Exit(0);
                }
                else
                {
                    MessageBox.Show("Incorrect Credentials", "Access Denied");
                }
            }
        }
Exemplo n.º 3
0
 private void frmMainWindow_GotFocus(object sender, RoutedEventArgs e)
 {
     if (CommonTasks.getInstance().Topmost == false)
     {
         CommonTasks.getInstance().Topmost = true;
     }
 }
Exemplo n.º 4
0
        // Method called when a Book Service button is pressed.
        // Navigates the user to a ServiceDate page
        private void bookService_click(object sender, RoutedEventArgs e)
        {
            String   date        = "";
            String   year        = "";
            String   month       = "";
            String   day         = "";
            int      intYear     = 0;
            int      intMonth    = 0;
            int      intDay      = 0;
            DateTime serviceDate = new DateTime();

            if (sender is Button)
            {
                Button button = (Button)sender;
                date  = button.Name.Substring(2); // Date is stored in the button name.
                year  = date.Substring(0, 4);
                month = date.Substring(4, 2);
                day   = date.Substring(6, 2);
                int.TryParse(year, out intYear);
                int.TryParse(month, out intMonth);
                int.TryParse(day, out intDay);
                serviceDate = new DateTime(intYear, intMonth, intDay);
            }

            if (serviceDate.CompareTo(DateTime.Now) > 0)
            {
                CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new ServiceNew(serviceDate, VehicleVIN));
            }
            else
            {
                MessageBox.Show("There was a problem parsing the service date.\n" + serviceDate.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + date, "Service Booking Error");
            }
        }
        private void btnBookService_Click(object sender, RoutedEventArgs e)
        {
            if (ServiceTimeIsInFuture())
            {
                DateTime returnDate = new DateTime(serviceDate.Year, serviceDate.Month, serviceDate.Day, 17, 0, 0);
                if (serviceDate.Hour > 15)
                {
                    returnDate = returnDate.AddDays(1);
                }

                if (checkDatesForClashes(serviceDate, returnDate, VehicleVIN))
                {
                    MessageBox.Show("Your selected dates clash with other bookings. Please reschedule.", "Date Clash Detected");
                    return;
                }

                MessageBoxResult result = MessageBox.Show("Are you happy with these date?\nService Time : " + serviceDate.ToString("yyyy-MM-dd HH:mm") + "\nPickup Time : " + returnDate.ToString("yyyy-MM-dd HH:mm"), "Booking Confirmation", MessageBoxButton.OKCancel, MessageBoxImage.Question);

                if (result == MessageBoxResult.OK)
                {
                    int recordsInserted = Database.getInstance().insert("Service", new string[] { "VehicleVIN", "ServiceDate", "ReturnDate" }, new string[] { VehicleVIN, serviceDate.ToString("yyyy-MM-dd HH:mm:ss"), returnDate.ToString("yyyy-MM-dd HH:mm:ss") });

                    if (recordsInserted > 0)
                    {
                        CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new ServiceBookingSuccess());
                    }
                }
            }
        }
        void resultButton_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            int    length = button.Name.Length - 3;
            String strVIN = button.Name.Substring(3, length);

            CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new FleetEdit(strVIN));
        }
Exemplo n.º 7
0
        // Singleton pattern - return a static instance of the window, only.
        public static CommonTasks getInstance()
        {
            if (instance == null)
            {
                instance = new CommonTasks();
            }

            return(instance);
        }
Exemplo n.º 8
0
        void resultButton_Click(object sender, RoutedEventArgs e)
        {
            Button button     = (Button)sender;
            int    length     = button.Name.Length - 3;
            String name       = button.Name.Substring(3, length);
            int    CustomerID = int.Parse(name);

            CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomersEdit(CustomerID));
        }
 // Method to navigate to BookingsNew page.
 // If a customerID is selected, use the customerID as a parameter in the call to the page.
 private void btnBookingNew_Click(object sender, RoutedEventArgs e)
 {
     if ((CustomerID != null) && (CustomerID > 0))
     {
         CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsNew(CustomerID));
     }
     else
     {
         CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsNew());
     }
 }
Exemplo n.º 10
0
        private void miViewCommonTasks_Click(object sender, RoutedEventArgs e)
        {
            CommonTasks.getInstance().Hide();
            CommonTasks.getInstance().Show();
            this.Topmost = false;

            if (CommonTasks.getInstance().WindowState != WindowState.Normal)
            {
                CommonTasks.getInstance().WindowState = WindowState.Normal;
            }
        }
Exemplo n.º 11
0
        // Method takes the user to a BookingsEdit to see details of the selected booking.
        private void booking_click(object sender, RoutedEventArgs e)
        {
            int bookingID = 0;

            if (sender is Button)
            {
                Button button       = (Button)sender;
                string strBookingID = button.Name.Substring(2);
                int.TryParse(strBookingID, out bookingID);
            }

            CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsEdit(bookingID));
        }
Exemplo n.º 12
0
        public void print()
        {
            PrintDialog print = new PrintDialog();

            if (CommonTasks.getInstance().Topmost)
            {
                CommonTasks.getInstance().Topmost = false;

                print.ShowDialog();
                CommonTasks.getInstance().Topmost = true;
            }
            else
            {
                print.ShowDialog();
            }
        }
        // Method called when the user clicks one of the results onscreen, displayed as a button.
        void resultButton_Click(object sender, RoutedEventArgs e)
        {
            // Create a button object from the sender.
            Button button = (Button)sender;

            // Get the BookingID from the Button Name.
            // Button names can't start with numbers, so 3 characters have been added by me to get around this.
            // Create a substring from the button name, of just the characters we want, not the characters I added.
            String name = button.Name.Substring(3);

            //  and parse that substring to get the ineteger BookingID.
            int BookingID = int.Parse(name);

            // Then navigate to the BookingsEdit page, using the BookingID as a parameter.
            CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsEdit(BookingID));
        }
Exemplo n.º 14
0
        public bool initialiseScanner()
        {
            for (int i = 0; i < deviceManager.DeviceInfos.Count; i++)
            {
                try
                {
                    if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
                    {
                        continue;
                    }
                    else
                    {
                        scannerInfo = deviceManager.DeviceInfos[i];
                        break;
                    }
                }
                catch (Exception e)
                {
                    DataDelegate.errorMessages.Add(e.Message.ToString());
                }
            }



            if (scannerInfo == null)
            {
                if (StephenGlasspell_CarRental.CommonTasks.getInstance().Topmost == true)
                {
                    System.Windows.MessageBox.Show(CommonTasks.getInstance(), "No Scanner Found", "Error");
                }
                else
                {
                    System.Windows.MessageBox.Show(new MainWindow(), "No Scanner Found", "Error");
                }


                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 15
0
        // Method to insert the booking data into the database
        private void btnConfirmBooking_Click(object sender, RoutedEventArgs e)
        {
            string strSHBDT = collectionDateTime.ToString("yyyy-MM-dd HH:mm:ss");
            string strSHRDT = returnDateTime.ToString("yyyy-MM-dd HH:mm:ss");

            // Databse insert method call. Returns the number of changed records.
            int success = Database.getInstance().insert("Booking ", new string[] { "VehicleVIN", "CustomerID", "EmployeeID", "ScheduledHireBeginDateTime", "ScheduledHireReturnDateTime", "TotalBill" }, new string[] { VehicleVIN, CustomerID.ToString(), DataDelegate.EmployeeID.ToString(), strSHBDT, strSHRDT, txtTotalCharge.Text });

            if (success > 0) // If the numbers of inserted records is more than zero.
            {
                // Navigate to BookingCreatedSuccess page.
                clearForm();
                CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingCreatedSuccess());
            }
            else // No records were inserted.
            {
                // Show the error message.
                MessageBox.Show("There were problems entering the data into the database.", "Error");
            }
        }
        // Method to delete the selected booking.
        // Warns the user with a MessageBox and sends a delete statement to the database.
        private void btnCancelBooking_Click(object sender, RoutedEventArgs e)
        {
            // Warning.
            MessageBoxResult result = MessageBox.Show("Are you sure you want to cancel the booking?\nThe record will be permanently deleted.", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);

            if (result == MessageBoxResult.Yes)
            {
                if (decTotalPaid > 0)
                {
                    // Refund any payments made.
                    int recordsInserted = Database.getInstance().insert("Payment", new string[] { "BookingID", "Amount", "DateOfPayment" }, new string[] { bookingID.ToString(), (-decTotalPaid).ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });

                    if (recordsInserted > 0)
                    {
                        MessageBox.Show(decTotalPaid.ToString("C") + " has been refunded to the customer.", "Payment Refunded");
                    }
                    else
                    {
                        MessageBox.Show("There was a problem refunding the payment throught the database.", "Refund failed.");
                    }
                }

                //Send SQL statement to database.
                int recordsUpdated = Database.getInstance().update("Booking", new string[] { "CancelledDateTime" }, new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }, "WHERE BookingID", "=", bookingID.ToString());

                // Show confirmation.
                if (recordsUpdated > 0)
                {
                    MessageBox.Show("Booking Deleted", "Success");

                    // Navigate back to the List of Bookings page.

                    CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsList());
                }
                else
                {
                    MessageBox.Show("There was a problem cancelling the booking in the database.", "Database Error");
                }
            }
        }
        private void btnNewBooking_Click(object sender, RoutedEventArgs e)
        {
            String custName = txtFirstName.Text + " " + txtLastName.Text;

            CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsNew(customerID, custName));
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (isDrivingLicenseNumberAlreadyInDatabase())
            {
                MessageBox.Show("The Driving License you entered is already in the database. No duplicates allowed.", "Driving License Duplicate");
                txtDrivingLicenseNumber.Focus();
                txtDrivingLicenseNumber.SelectAll();
                return;
            }

            bool allFieldsAreVaild = true;

            foreach (FormField field in fields)
            {
                if (field.successTextBox.Text != DataDelegate.SUCCESS)
                {
                    allFieldsAreVaild = false;
                    break;
                }
            }

            if (!allFieldsAreVaild)
            {
                MessageBox.Show("Please recheck your entries.", "Your form contains invalid data.");
            }
            else
            {
                List <String> tables = new List <String>();

                foreach (FormField field in fields)
                {
                    if (!tables.Contains(field.databaseTable))
                    {
                        tables.Add(field.databaseTable);
                    }
                }

                foreach (String table in tables)
                {
                    List <String> DBfields = new List <String>();
                    List <String> DBvalues = new List <String>();

                    for (int index = 0; index < fields.Count; index++)
                    {
                        if (fields[index].databaseTable == table)
                        {
                            DBfields.Add(fields[index].databaseFieldName);
                            DBvalues.Add(fields[index].userEntryText);
                        }

                        if (index == fields.Count - 1)
                        {
                            String[] databaseFields = DBfields.ToArray();
                            String[] databaseValues = DBvalues.ToArray();

                            if (Database.getInstance().update(table, databaseFields, databaseValues, " WHERE CustomerID", " = ", txtCustomerID.Text) == 0)
                            {
                                MessageBox.Show("There were some errors updating the database.", "Database Error");
                                return;
                            }
                            DBfields.Clear();
                            DBvalues.Clear();
                        }
                    }
                }
            }


            CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomerUpdateSuccess(customerID));
        }
Exemplo n.º 19
0
 private void btnCustomerEdit_Click(object sender, RoutedEventArgs e)
 {
     DataDelegate.previousCursor = Mouse.OverrideCursor;
     Mouse.OverrideCursor        = Cursors.Wait;
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomerList());
 }
Exemplo n.º 20
0
 private void btnCustomerNew_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomersNew());
 }
 private void btnGoToCustomerEdit_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomersEdit(CustomerID));
 }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            bool allFieldsAreVaild = true;

            foreach (FormField field in fields)
            {
                if (field.successTextBox.Text != SUCCESS)
                {
                    allFieldsAreVaild = false;
                    break;
                }
            }

            if (!allFieldsAreVaild)
            {
                MessageBox.Show("Please recheck your entries.", "Your form contains invalid data.");
            }
            else
            {
                List <String> tables = new List <String>();

                foreach (FormField field in fields)
                {
                    if (!tables.Contains(field.databaseTable))
                    {
                        tables.Add(field.databaseTable);
                    }
                }

                int CustomerID = Database.getInstance().getNextCustID();

                foreach (String table in tables)
                {
                    List <String> DBfields = new List <String>();
                    List <String> DBvalues = new List <String>();



                    int errors = 0;

                    for (int index = 0; index < fields.Count; index++)
                    {
                        if (fields[index].databaseTable == table)
                        {
                            DBfields.Add(fields[index].databaseFieldName);
                            DBvalues.Add(fields[index].userEntryText);
                        }

                        if (index == fields.Count - 1)
                        {
                            String[] databaseFields = DBfields.ToArray();
                            String[] databaseValues = DBvalues.ToArray();

                            if (Database.getInstance().insert(table, databaseFields, databaseValues) == 0)
                            {
                                errors++;
                            }
                            DBfields.Clear();
                            DBvalues.Clear();
                        }
                    }
                    if (errors > 0)
                    {
                        MessageBox.Show("There were some errors inserting data into the database.", "Database Error");
                    }
                    else
                    {
                        //  MessageBox.Show("Record created successfully.", "Database Updated.");
                        CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomerUpdateSuccess(CustomerID));
                    }
                }
                clearForm();
            }
        }
 private void btnNewVehicle_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new FleetNew());
 }
Exemplo n.º 24
0
        // Method to check all the inputs are valid and send them to the database if valid.
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            bool allFieldsAreVaild = true;

            foreach (FormField field in fields)
            {
                if (field.successTextBox.Text != DataDelegate.SUCCESS)
                {
                    // Only display this error message if in debug mode.
                    if (DataDelegate.debugMode)
                    {
                        MessageBox.Show(field.name.ToString(), "Field not valid");
                    }
                    allFieldsAreVaild = false;
                    break;
                }
            }

            if (!allFieldsAreVaild)
            {
                MessageBox.Show("Please recheck your entries.", "Your form contains invalid data.");
                return;
            }
            else
            {
                // New list of tables. These relate to the tables in the database.
                List <String> tables = new List <String>();

                // Iterate through every field in the fields list.
                foreach (FormField field in fields)
                {
                    //If the table for the selected datafield is not in the list, add it to the list.
                    if (!tables.Contains(field.databaseTable))
                    {
                        tables.Add(field.databaseTable);
                    }
                }

                // Find out what the next customerId in the database should be.
                // TODO - shouldn't this be auto incremented? FIX THIS.
                int CustomerID = Database.getInstance().getNextCustID();

                // For every table in the list, make lists of fields and values (Properties and values)
                foreach (String table in tables)
                {
                    List <String> DBfields = new List <String>();
                    List <String> DBvalues = new List <String>();

                    DBfields.Add("CustomerID");
                    DBvalues.Add(CustomerID.ToString());

                    // Count any errors.
                    int errors = 0;

                    // This code is to build lists of Database fields and their associated values, per table in the databse.
                    for (int index = 0; index < fields.Count; index++)
                    {
                        if (fields[index].databaseTable == table)
                        {
                            DBfields.Add(fields[index].databaseFieldName);
                            DBvalues.Add(fields[index].userEntryText);
                        }

                        // When you get to the end of the list of fields,
                        if (index == fields.Count - 1)
                        {
                            // Create string arrays from the lists...
                            String[] databaseFields = DBfields.ToArray();
                            String[] databaseValues = DBvalues.ToArray();

                            // .. and include them in the SQL statement to the database.
                            //                  Array of tables
                            //                   \/      Array of fields
                            //                            \/            Array of values
                            if (Database.getInstance().insert(table, databaseFields, databaseValues) == 0)
                            {
                                errors++;
                            }
                            DBfields.Clear();
                            DBvalues.Clear();
                        }
                    }
                    if (errors > 0) // There were errors.
                    {
                        MessageBox.Show("There were some errors inserting data into the database.", "Database Error");
                        return;
                    }
                    else  // No errors found
                    {
                        // Navigate to the Customer Update Success page.
                        CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomerUpdateSuccess(CustomerID));
                    }
                }
                clearForm();
            }
        }
Exemplo n.º 25
0
 private void btnNewBooking_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsNew(CustomerID, CustomerName));
 }
 private void btnServiceHistory_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new ServiceHistory(VehicleVIN));
 }
 private void btnBookService_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CalendarMonth(VehicleVIN));
 }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            int errors = 0;

            bool allFieldsAreVaild = true;

            foreach (FormField field in fields)
            {
                if (field.successTextBox.Text != DataDelegate.SUCCESS)
                {
                    allFieldsAreVaild = false;
                    break;
                }
            }

            if (!allFieldsAreVaild)
            {
                MessageBox.Show("Please recheck your entries.", "Your form contains invalid data.");
                return;
            }
            else
            {
                List <String> tables = new List <String>();

                foreach (FormField field in fields)
                {
                    if (!tables.Contains(field.databaseTable))
                    {
                        tables.Add(field.databaseTable);
                    }
                }

                foreach (String table in tables)
                {
                    List <String> DBfields = new List <String>();
                    List <String> DBvalues = new List <String>();

                    for (int index = 0; index < fields.Count; index++)
                    {
                        if (fields[index].databaseTable == table)
                        {
                            DBfields.Add(fields[index].databaseFieldName);
                            DBvalues.Add(fields[index].userEntryText);
                        }

                        if (index == fields.Count - 1)
                        {
                            String[] databaseFields = DBfields.ToArray();
                            String[] databaseValues = DBvalues.ToArray();

                            if (Database.getInstance().update(table, databaseFields, databaseValues, " WHERE VehicleVIN", " = ", "'" + VehicleVIN + "'") == 0)
                            {
                                errors++;
                            }
                            DBfields.Clear();
                            DBvalues.Clear();
                        }
                    }
                }
            }
            if (errors > 0)
            {
                MessageBox.Show("There were some errors updating the database.", "Database Error");
            }
            else
            {
                CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new VehicleUpdateSuccess(VehicleVIN));
            }
        }
 private void btnShowAllBookings_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new CustomerBookings(customerID));
 }
 private void btnCollections_Click(object sender, RoutedEventArgs e)
 {
     CommonTasks.getInstance().frmCommonTasksMainFrame.Navigate(new BookingsList());
 }