Exemplo n.º 1
0
        private void ButtonWork_Click(object sender, RoutedEventArgs e)
        {
            comboBoxDistrict.IsEnabled = false;
            district = new District(comboBoxDistrict.Text);
            List <EconomCar> usersEconomBase = new List <EconomCar>();
            List <LuxuryCar> usersLuxuryBase = new List <LuxuryCar>();
            List <Truck>     usersTruckBase  = new List <Truck>();

            if (carTaxist is EconomCar)
            {
                WorkingWithXML.DeserializeEconomBase(ref usersEconomBase);
                user = ((EconomCar)carTaxist).UserMatchTaxistWork(usersEconomBase, district);
            }
            else if (carTaxist is LuxuryCar)
            {
                WorkingWithXML.DeserializeLuxuryBase(ref usersLuxuryBase);
                user = ((LuxuryCar)carTaxist).UserMatchTaxistWork(usersLuxuryBase, district);
            }
            else if (carTaxist is Truck)
            {
                WorkingWithXML.DeserializeTruckBase(ref usersTruckBase);
                user = ((Truck)carTaxist).UserMatchTaxistWork(usersTruckBase, district);
            }
            TaxistWorkInfo taxistWorkInfo = new TaxistWorkInfo(user);

            this.Close();
            taxistWorkInfo.ShowDialog();
        }
        private void buttonFind_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (int.Parse(tbMaxKilogramsCargo.Text) > 10000 || int.Parse(tbMaxKilogramsCargo.Text) < 100 || string.IsNullOrEmpty(tbMaxKilogramsCargo.Text))
                {
                    throw new Exception("Kilograms of cargo must be\nmore than 100 and less than 10000\nPlease, change the value");
                }
                List <Truck> trucks = new List <Truck>();
                WorkingWithXML.DeserializeTruckBase(ref trucks, @"..\..\XML\Trucks.xml");
                truck = new Truck
                {
                    KilogramsCargo = Convert.ToInt32(tbMaxKilogramsCargo.Text),
                    NumberOfSeats  = numericUpDownAmountPeople.Value
                };

                for (int i = 0; i < trucks.Count; ++i)
                {
                    if ((trucks[i].IsMatch(truck)) != null)
                    {
                        truck = trucks[i];
                        break;
                    }
                }
                DialogResult = true;
            }
            catch (Exception ex)
            {
                WindowForException windowForException = new WindowForException(ex.Message);
                windowForException.Show();
            }
        }
        private void ButtonLogin_Click(object sender, RoutedEventArgs e)
        {
            string typeCar  = "";
            string nickname = "";

            try
            {
                if (string.IsNullOrEmpty(textBoxNickname.Text) || string.IsNullOrEmpty(textBoxPassword.Password))
                {
                    throw new Exception("Some field is empty!!!");
                }

                string filePath = $@"..\..\Files\Taxists\{textBoxNickname.Text}.txt";
                if (!File.Exists(filePath))
                {
                    throw new Exception($"User with nickname: {textBoxNickname.Text}\nDoes not exist!!!");
                }
                else
                {
                    using (StreamReader reader = new StreamReader(filePath))
                    {
                        nickname = reader.ReadLine();
                        string password = reader.ReadLine();
                        typeCar = reader.ReadLine();
                        if (textBoxNickname.Text == nickname && textBoxPassword.Password == password)
                        {
                            WindowForException windowForException = new WindowForException("Successful login");
                            windowForException.ShowDialog();
                            this.Hide();
                        }
                        else
                        {
                            throw new Exception("Incorrect password\nEnter again!");
                        }
                    }
                }

                if (typeCar == "Econom")
                {
                    WorkingWithXML.DeserializeEconomCar(ref car, nickname);
                }
                else if (typeCar == "Luxury")
                {
                    WorkingWithXML.DeserializeLuxuryCar(ref car, nickname);
                }
                else if (typeCar == "Truck")
                {
                    WorkingWithXML.DeserializeTruck(ref car, nickname);
                }
                TaxistWorking taxistWorking = new TaxistWorking(car);
                taxistWorking.ShowDialog();
            }
            catch (Exception ex)
            {
                WindowForException windowForException = new WindowForException(ex.Message);
                windowForException.Show();
            }
        }
        private void buttonFind_Click(object sender, RoutedEventArgs e)
        {
            List <EconomCar> economCars = new List <EconomCar>();

            WorkingWithXML.DeserializeEconomBase(ref economCars, @"..\..\XML\EconomCars.xml");

            economCar = new EconomCar
            {
                IsChildSeat   = Convert.ToBoolean(checkBoxChildSeat.IsChecked),
                IsWheelChair  = Convert.ToBoolean(checkBoxWheelChair.IsChecked),
                NumberOfSeats = numericUpDownAmountPeople.Value
            };

            for (int i = 0; i < economCars.Count; ++i)
            {
                if ((economCars[i].IsMatch(economCar)) != null)
                {
                    economCar = economCars[i];
                    break;
                }
            }
            DialogResult = true;
        }
        private void buttonFind_Click(object sender, RoutedEventArgs e)
        {
            List <LuxuryCar> luxuryCars = new List <LuxuryCar>();

            WorkingWithXML.DeserializeLuxuryBase(ref luxuryCars, @"..\..\XML\LuxuryCars.xml");

            luxuryCar = new LuxuryCar
            {
                IsTv          = Convert.ToBoolean(checkBoxTv.IsChecked),
                IsAlcohol     = Convert.ToBoolean(checkBoxAlcohol.IsChecked),
                NumberOfSeats = numericUpDownAmountPeople.Value
            };

            for (int i = 0; i < luxuryCars.Count; ++i)
            {
                if ((luxuryCars[i].IsMatch(luxuryCar)) != null)
                {
                    luxuryCar = luxuryCars[i];
                    break;
                }
            }
            DialogResult = true;
        }
        private void ButtonRegistration_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxName.Text) ||
                    string.IsNullOrEmpty(textBoxSurname.Text) ||
                    string.IsNullOrEmpty(textBoxNickname.Text) ||
                    string.IsNullOrEmpty(textBoxPassword.Password) ||
                    string.IsNullOrEmpty(textBoxConfirmPass.Password) ||
                    string.IsNullOrEmpty(textBoxCarName.Text) ||
                    string.IsNullOrEmpty(textBoxCarModel.Text) ||
                    string.IsNullOrEmpty(textBoxCarNumber.Text))
                {
                    throw new Exception("Some field is empty!!!");
                }

                if (textBoxPassword.Password != textBoxConfirmPass.Password)
                {
                    throw new Exception("Password mismatch");
                }

                string filePath = $@"..\..\Files\Taxists\{textBoxNickname.Text}.txt";
                if (File.Exists(filePath))
                {
                    throw new Exception("Taxist with this nickname is already exist!!!");
                }
                else
                {
                    using (StreamWriter writer = new StreamWriter(filePath))
                    {
                        writer.WriteLine(textBoxNickname.Text);
                        writer.WriteLine(textBoxPassword.Password);
                        writer.WriteLine(comboBoxCarsType.Text);
                    }
                }

                taxist.Name      = textBoxName.Text;
                taxist.Surname   = textBoxSurname.Text;
                taxist.birthDate = dateTimePicker1.DisplayDate;
                taxist.Nickname  = textBoxNickname.Text;
                taxist.Password  = textBoxPassword.Password;

                car.taxist    = taxist;
                car.CarName   = textBoxCarName.Text;
                car.CarModel  = textBoxCarModel.Text;
                car.CarNumber = textBoxCarNumber.Text;

                if (comboBoxCarsType.Text == "Econom")
                {
                    WorkingWithXML.SerializeEconomCar(ref car, taxist.Nickname);
                }
                else if (comboBoxCarsType.Text == "Luxury")
                {
                    WorkingWithXML.SerializeLuxuryCar(ref car, taxist.Nickname);
                }
                else if (comboBoxCarsType.Text == "Truck")
                {
                    WorkingWithXML.SerializeTruck(ref car, taxist.Nickname);
                }
                comboBoxCarsType.IsEnabled = false;


                TaxistWorking taxistWorking = new TaxistWorking(car);
                this.Close();
                taxistWorking.ShowDialog();
            }
            catch (Exception ex)
            {
                WindowForException windowForException = new WindowForException(ex.Message);
                windowForException.Show();
            }
        }