コード例 #1
0
        private void Find_vehicle(object sender, RoutedEventArgs e)
        {
            Error_msg.Content = string.Empty;
            found             = _check.Reg_check(tb_sc_vehicle_rg.Text).Item1;
            vehicle_typ       = _check.Reg_check(tb_sc_vehicle_rg.Text).Item2;


            if (found)
            {
                var dict_value = IUserDataAccess.GetVehicleInfo(tb_sc_vehicle_rg.Text, vehicle_typ);
                tb_sc_vehicle_rg.IsReadOnly = true;
                AProperties vehicleProperties = (AProperties)dict_value;


                edit_sp_fordontyp.Visibility = 0;
                edit_sp_regdate.Visibility   = 0;
                edit_sp_brand.Visibility     = 0;
                edit_sp_model.Visibility     = 0;
                edit_sp_Odometer.Visibility  = 0;
                edit_sp_fuel.Visibility      = 0;

                grid_edit_add.Visibility = 0;


                tb_sc_fordontyp.Text        = vehicleProperties.Vehicle_Type;
                tb_sc_vehicle_brand.Text    = vehicleProperties.Brand;
                tb_sc_vehicle_modell.Text   = vehicleProperties.Model;
                tb_sc_vehicle_odometer.Text = vehicleProperties.Odometer.ToString();
                cb_sc_fuel.Text             = vehicleProperties.Fuel_Type;
                tb_sc_regdate.Text          = vehicleProperties.Registration_Date.ToString();

                if (vehicleProperties.Vehicle_Type == Enum.GetName(typeof(IUserDataAccess.File_Type), 5))
                {
                    edit_sp_typcar.Visibility = 0;
                    edit_sp_hook.Visibility   = 0;
                    var bil = (Car)vehicleProperties;
                    cb_sc_car_option.Text = bil.Type_Of_Car.ToString();
                    cb_sc_car_hook.Text   = bil.Dragkrok.ToString();
                }
                else if (vehicleProperties.Vehicle_Type == Enum.GetName(typeof(IUserDataAccess.File_Type), 6))
                {
                    edit_sp_maxlast.Visibility = 0;
                    var lastbil = (Truck)vehicleProperties;
                    tb_sc_weight.Text = lastbil.Max_Load.ToString();
                }
                else if (vehicleProperties.Vehicle_Type == Enum.GetName(typeof(IUserDataAccess.File_Type), 7))
                {
                    edit_sp_passanger.Visibility = 0;
                    var buss = (Bus)vehicleProperties;
                    tb_sc_passanger.Text = buss.Max_Passengers.ToString();
                }
            }
            else
            {
                Error_msg.Content     = Wrong_msg;
                tb_sc_vehicle_rg.Text = string.Empty;
            }
        }
コード例 #2
0
        private void Change_vehicle_info(object sender, RoutedEventArgs e)
        {
            var lisence = IUserDataAccess.Read <string, string>(Enum.GetName(typeof(IUserDataAccess.File_Type), 9));

            var dict = IUserDataAccess.GetVehicleInfo(tb_sc_vehicle_rg.Text, vehicle_typ);

            AProperties currentVehicleinfo = (AProperties)dict;

            string msg    = $"Vill du ändra {vehicle_typ} info ?";
            string result = MessageBox.Show(msg, "Bekräftelse", MessageBoxButton.YesNo, MessageBoxImage.Question).ToString();


            bool odometer_bool  = Int32.TryParse(tb_sc_vehicle_odometer.Text, out int odometer);
            bool passanger_bool = Int32.TryParse(tb_sc_passanger.Text, out int passanger);
            bool weight_bool    = Int32.TryParse(tb_sc_weight.Text, out int weight);



            if (result.Equals("Yes") && odometer_bool && odometer >= currentVehicleinfo.Odometer)
            {
                currentVehicleinfo.Fuel_Type = cb_sc_fuel.Text;
                currentVehicleinfo.Odometer  = odometer;


                if (vehicle_typ == Enum.GetName(typeof(IUserDataAccess.File_Type), 4))
                {
                    Motorcycle castedMc = (Motorcycle)currentVehicleinfo;

                    Dictionary <string, Motorcycle> mc = IUserDataAccess.Read <string, Motorcycle>(Enum.GetName(typeof(IUserDataAccess.File_Type), 4));

                    mc.Remove(tb_sc_vehicle_rg.Text);
                    lisence.Remove(tb_sc_vehicle_rg.Text);


                    mc.Add(castedMc.Registration_Nr, castedMc);
                    lisence.Add(castedMc.Registration_Nr, castedMc.Vehicle_Type);
                    IUserDataAccess.Write(mc, vehicle_typ);
                }
                else if (vehicle_typ == Enum.GetName(typeof(IUserDataAccess.File_Type), 5))
                {
                    Dictionary <string, Car> car = IUserDataAccess.Read <string, Car>(Enum.GetName(typeof(IUserDataAccess.File_Type), 5));
                    car.Remove(tb_sc_vehicle_rg.Text);
                    lisence.Remove(tb_sc_vehicle_rg.Text);


                    Car castedCar = (Car)currentVehicleinfo;
                    castedCar.Dragkrok    = cb_sc_car_hook.Text.Equals("Ja");
                    castedCar.Type_Of_Car = cb_sc_car_option.Text;


                    car.Add(castedCar.Registration_Nr, castedCar);
                    lisence.Add(castedCar.Registration_Nr, castedCar.Vehicle_Type);
                    IUserDataAccess.Write(car, vehicle_typ);
                }
                else if (vehicle_typ == Enum.GetName(typeof(IUserDataAccess.File_Type), 6))
                {
                    if (weight_bool)
                    {
                        Dictionary <string, Truck> truck = IUserDataAccess.Read <string, Truck>(Enum.GetName(typeof(IUserDataAccess.File_Type), 6));
                        truck.Remove(tb_sc_vehicle_rg.Text);
                        lisence.Remove(tb_sc_vehicle_rg.Text);


                        Truck castedTruck = (Truck)currentVehicleinfo;
                        castedTruck.Max_Load = weight;

                        truck.Add(castedTruck.Registration_Nr, castedTruck);
                        lisence.Add(castedTruck.Registration_Nr, castedTruck.Vehicle_Type);
                        IUserDataAccess.Write(truck, vehicle_typ);
                    }
                    else
                    {
                        Error_msg.Content = Wrong_msg;
                        return;
                    }
                }
                else if (vehicle_typ == Enum.GetName(typeof(IUserDataAccess.File_Type), 7))
                {
                    if (passanger_bool)
                    {
                        Dictionary <string, Bus> bus = IUserDataAccess.Read <string, Bus>(Enum.GetName(typeof(IUserDataAccess.File_Type), 7));
                        bus.Remove(tb_sc_vehicle_rg.Text);
                        lisence.Remove(tb_sc_vehicle_rg.Text);


                        Bus castedBus = (Bus)currentVehicleinfo;
                        castedBus.Max_Passengers = passanger;

                        bus.Add(castedBus.Registration_Nr, castedBus);
                        lisence.Add(castedBus.Registration_Nr, castedBus.Vehicle_Type);
                        IUserDataAccess.Write(bus, vehicle_typ);
                    }
                    else
                    {
                        Error_msg.Content = Wrong_msg;
                        return;
                    }
                }
                NavigationService.Navigate(new Add_vehicle());
            }
            else if (result.Equals("No"))
            {
                return;
            }
            else
            {
                Error_msg.Content = Wrong_msg;
            }
        }