コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        private void buttonFindCar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxCurrentAdress.Text) || string.IsNullOrEmpty(textBoxFinalAddress.Text))
                {
                    throw new Exception("Some field is empty");
                }

                if (comboBoxCarsType.SelectedIndex == -1)
                {
                    throw new Exception("Make choice of car type");
                }

                if (comboBoxCarsType.Text == "Econom")
                {
                    UserEconomSettings economSettings = new UserEconomSettings();
                    if (economSettings.ShowDialog() == true)
                    {
                        car = economSettings.economCar;
                    }
                }
                else if (comboBoxCarsType.Text == "Luxury")
                {
                    UserLuxurySettings luxurySettings = new UserLuxurySettings();
                    if (luxurySettings.ShowDialog() == true)
                    {
                        car = luxurySettings.luxuryCar;
                    }
                }
                else if (comboBoxCarsType.Text == "Truck")
                {
                    UserTruckSettings truckSettings = new UserTruckSettings();
                    if (truckSettings.ShowDialog() == true)
                    {
                        car = truckSettings.truck;
                    }
                }
                this.Hide();
                DetailsArrivalCar detailsArrivalCar = new DetailsArrivalCar(car);
                detailsArrivalCar.ShowDialog();
            }
            catch (Exception ex)
            {
                WindowForException windowForException = new WindowForException(ex.Message);
                windowForException.Show();
            }
        }
コード例 #4
0
 private void buttonOk_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (int.Parse(tbMaxKilogramsCargo.Text) > 10000 || int.Parse(tbMaxKilogramsCargo.Text) < 100)
         {
             throw new Exception("Kilograms of cargo must me more than 100 and less than 10000\nPlease, change the value");
         }
         truck.MaxKilogramsOfCargo = Convert.ToInt32(tbMaxKilogramsCargo.Text);
         truck.NumberOfSeats       = numericUpDownAmountPeople.Value;
         this.Close();
     }
     catch (Exception ex)
     {
         WindowForException windowForException = new WindowForException(ex.Message);
         windowForException.Show();
     }
 }
コード例 #5
0
        private void buttonRegister_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))
                {
                    throw new Exception("Some field is empty!!!");
                }

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

                string filePath = $@"..\..\Files\Users\{textBoxNickname.Text}.txt";
                if (File.Exists(filePath))
                {
                    throw new Exception("User already exist!!!");
                }
                else
                {
                    using (StreamWriter writer = new StreamWriter(filePath))
                    {
                        writer.WriteLine(textBoxNickname.Text);
                        writer.WriteLine(textBoxPassword.Password);
                    }
                    MessageBox.Show("Successful registration");
                }
                this.Close();
            }
            catch (Exception ex)
            {
                WindowForException windowForException = new WindowForException(ex.Message);
                windowForException.Show();
            }
        }
コード例 #6
0
        private void ButtonLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxNickname.Text) || string.IsNullOrEmpty(textBoxPassword.Password))
                {
                    throw new Exception("Some field is empty!!!");
                }

                string filePath = $@"..\..\Files\Users\{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))
                    {
                        string nickname = reader.ReadLine();
                        string password = reader.ReadLine();
                        if (textBoxNickname.Text == nickname && textBoxPassword.Password == password)
                        {
                            WindowForException windowForException = new WindowForException("Successful login");
                            windowForException.ShowDialog();
                            this.Close();
                        }
                        else
                        {
                            throw new Exception("Incorrect password\nEnter again!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WindowForException windowForException = new WindowForException(ex.Message);
                windowForException.Show();
            }
        }
コード例 #7
0
        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();
            }
        }