private void LoadDataToWindow(Service service)
        {
            // Service

            LblIdService.Text = service.Id.ToString();
            LblDate.Text      = service.DateIssued.ToShortDateString();
            LblTime.Text      = service.TimeIssued.ToString();

            // Vehicle

            Vehicle vehicle = vehiclesSqlRepository.ReadById(service.Vehicle.Id);

            LblIdVehicle.Text         = vehicle.Id.ToString();
            LblMake.Text              = vehicle.Make;
            LblModel.Text             = vehicle.Model;
            LblYearOfManufacture.Text = vehicle.YearOfManufacture.ToString();
            LblInitialMileage.Text    = vehicle.InitialMileage.ToString();
            LblAvailability.Text      = vehicle.Available == true ? "Available" : "Not available";

            // Service Items

            foreach (ServiceItem serviceItem in service.ServiceItems)
            {
                ServiceItemPanel serviceItemPanel = new ServiceItemPanel(serviceItem);

                serviceItemPanel.ChBxServiceItem.Visibility = Visibility.Hidden;
                serviceItemPanel.BtnEdit.Visibility         = Visibility.Hidden;
                serviceItemPanel.BtnDelete.Visibility       = Visibility.Hidden;

                SpServiceItems.Children.Add(serviceItemPanel);
            }
        }
Пример #2
0
        private void LoadDataToWindow(TravelWarrant travelWarrant)
        {
            // Travel Warrant

            LblIdTravelWarrant.Text   = travelWarrant.Id.ToString();
            LblStatus.Text            = travelWarrant.WarrantStatus;
            LblDateTravelWarrant.Text = travelWarrant.DateIssued.ToShortDateString();
            LblTimeTravelWarrant.Text = travelWarrant.TimeIssued.ToString();

            // Driver

            Driver driver = driversSqlRepository.ReadById(travelWarrant.DriverId);

            LblIdDriver.Text             = driver.Id.ToString();
            LblFirstName.Text            = driver.FirstName;
            LblLastName.Text             = driver.LastName;
            LblPhoneNumber.Text          = driver.PhoneNumber;
            LblDriversLicenceNumber.Text = driver.DriversLicenceNumber;

            // Vehicle

            Vehicle vehicle = vehiclesSqlRepository.ReadById(travelWarrant.VehicleId);

            LblIdVehicle.Text         = vehicle.Id.ToString();
            LblMake.Text              = vehicle.Make;
            LblModel.Text             = vehicle.Model;
            LblYearOfManufacture.Text = vehicle.YearOfManufacture.ToString();
            LblInitialMileage.Text    = vehicle.InitialMileage.ToString();
            LblAvailability.Text      = vehicle.Available == true ? "Available" : "Not available";

            // Fuel Cost

            FuelCost fuelCost = fuelCostsSqlRepository.ReadById(travelWarrant.FuelCostId);

            LblIdFuelCost.Text   = fuelCost.Id.ToString();
            LblDateIssuedFc.Text = fuelCost.DateIssued.ToShortDateString();
            LblTimeIssuedFc.Text = fuelCost.TimeIssued.ToString();
            LblPosition.Text     = fuelCost.Position;
            LblAmount.Text       = fuelCost.Amount.ToString();
            LblPrice.Text        = fuelCost.Price.ToString();

            // Travel Route

            TravelRoute travelRoute = travelRoutesSqlRepository.ReadById(travelWarrant.TravelRouteId);

            LblIdTravelRoute.Text      = travelRoute.Id.ToString();
            LblDateIssuedTr.Text       = travelRoute.DateIssued.ToShortDateString();
            LblTimeIssuedTr.Text       = travelRoute.TimeIssued.ToString();
            LblOrigin.Text             = travelRoute.Origin;
            LblDestination.Text        = travelRoute.Destination;
            LblKilometersTraveled.Text = travelRoute.KilometersTraveled.ToString();
            LblAverageSpeed.Text       = travelRoute.AverageSpeed.ToString();
            LblSpentFuel.Text          = travelRoute.SpentFuel.ToString();
        }
        private void CreateVehicleService()
        {
            if (TbDate.Text != string.Empty && TbTime.Text != string.Empty && CbVehicles.Text != string.Empty && SpServiceItems.Children.Count > 0)
            {
                if (DateTime.TryParse(TbDate.Text, out DateTime date) && (TimeSpan.TryParse(TbTime.Text, out TimeSpan time)))
                {
                    if (Regex.IsMatch(TbDate.Text, @"\d\d/\d\d/\d\d\d\d") && Regex.IsMatch(TbTime.Text, @"\d\d:\d\d:\d\d"))
                    {
                        decimal            totalPrice   = 0;
                        List <ServiceItem> serviceItems = new List <ServiceItem>();

                        foreach (ServiceItemPanel serviceItemPanel in SpServiceItems.Children)
                        {
                            if (serviceItemPanel.ChBxServiceItem.IsChecked == true)
                            {
                                totalPrice += decimal.Parse(serviceItemPanel.LblPrice.Text);
                            }
                        }

                        for (int i = 0; i < SpServiceItems.Children.Count; i++)
                        {
                            ServiceItemPanel serviceItemPanel = (ServiceItemPanel)SpServiceItems.Children[i];

                            if (serviceItemPanel.ChBxServiceItem.IsChecked == true)
                            {
                                int         serviceItemId = int.Parse(serviceItemPanel.LblId.Text);
                                ServiceItem serviceItem   = serviceItemsSqlRepository.ReadById(serviceItemId);
                                serviceItems.Add(serviceItem);
                            }
                        }

                        int     vehicleId = int.Parse(CbVehicles.Text.Substring(0, CbVehicles.Text.IndexOf(' ')));
                        Vehicle vehicle   = vehiclesSqlRepository.ReadById(vehicleId);

                        Service service = new Service()
                        {
                            DateIssued = date,
                            TimeIssued = time,
                            TotalPrice = totalPrice
                        };

                        bool success = servicesSqlRepository.Create(service, vehicle, serviceItems);

                        if (success)
                        {
                            MessageBox.Show("Success");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("Fail");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Date format must be: \"MM/dd/yyyy\"\nTime format must be: \"HH:MM:ss\"");
                    }
                }
                else
                {
                    MessageBox.Show("Date format must be: \"MM/dd/yyyy\"\nTime format must be: \"HH:MM:ss\"");
                }
            }
            else
            {
                MessageBox.Show("All input fields are required");
            }
        }
Пример #4
0
        private void GenerateVehicleReport()
        {
            Vehicle v     = vehiclesSqlRepository.ReadById(vehicle.Id);
            string  make  = v.Make;
            string  model = v.Model;

            float currentlyTraveledKilometers = v.InitialMileage;

            float averageSpeed = 0;
            int   counter      = 0;

            List <TravelWarrant> travelWarrants = travelWarrantsSqlRepository.ReadAll();
            List <TravelRoute>   travelRoutes   = travelRoutesSqlRepository.ReadAll();

            foreach (TravelWarrant travelWarrant in travelWarrants)
            {
                if (travelWarrant.VehicleId == v.Id)
                {
                    TravelRoute travelRoute = travelRoutesSqlRepository.ReadById(travelWarrant.TravelRouteId);

                    currentlyTraveledKilometers += travelRoute.KilometersTraveled;
                    averageSpeed += travelRoute.AverageSpeed;
                    counter++;
                }
            }

            averageSpeed /= counter;

            var resourceName = Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(q => q.Contains("Template.html")).FirstOrDefault();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    StringBuilder  sb       = new StringBuilder();
                    List <Service> services = servicesSqlRepository.ReadAll();

                    foreach (Service service in services)
                    {
                        if (service.Vehicle.Id == v.Id)
                        {
                            sb.Append("<table>\n");
                            sb.Append("<tr>\n");

                            foreach (ServiceItem serviceItem in service.ServiceItems)
                            {
                                sb.Append("<td></br>");
                                sb.Append("Service item\n");
                                sb.Append("</br>");
                                sb.Append(serviceItem.Name + "\n");
                                sb.Append("</br>");
                                sb.Append(serviceItem.Price + "\n");
                                sb.Append("</br>");
                                sb.Append("</td>\n");
                            }

                            sb.Append("</tr>\n");
                            sb.Append("</table>\n");
                        }
                    }

                    string html = reader.ReadToEnd().Replace("$$MAKE$$", make).Replace("$$MODEL$$", model).Replace("$$CTK$$", currentlyTraveledKilometers.ToString()).Replace("$$AVERAGESPEED$$", averageSpeed.ToString()).Replace("$$SERVICEITEMS$$", sb.ToString());

                    File.WriteAllText(@"../../../DataForExport/HtmlVehicleReport.html", html);
                }
            }
            MessageBox.Show("Success");

            System.Diagnostics.Process.Start(@"C:\Development\project-adpc-vehiclemanager\DataForExport/HtmlVehicleReport.html");
        }