예제 #1
0
        private void buttonRegister_Click(object sender, EventArgs e)
        {
            Sound.MakeSound("ButtonClick");
            try
            {
                if (string.IsNullOrEmpty(textBoxName.Text) ||
                    string.IsNullOrEmpty(textBoxSurname.Text) ||
                    dateTimePicker1.Value == null ||
                    string.IsNullOrEmpty(textBoxNickname.Text) ||
                    string.IsNullOrEmpty(textBoxPassword.Text) ||
                    string.IsNullOrEmpty(textBoxConfirmPass.Text) ||
                    string.IsNullOrEmpty(textBoxCarName.Text) ||
                    string.IsNullOrEmpty(textBoxCarModel.Text) ||
                    string.IsNullOrEmpty(textBoxCarNumber.Text))
                {
                    throw new Exception("Some field is empty!!!");
                }

                if (textBoxPassword.Text != textBoxConfirmPass.Text)
                {
                    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.Text);
                        writer.WriteLine(comboBoxCarsType.SelectedItem.ToString());
                    }
                }

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

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

                if (comboBoxCarsType.Text == "Econom")
                {
                    XmlSerializer xmlSerializerCar = new XmlSerializer(typeof(EconomCar));
                    using (Stream stream = File.Create($@"..\..\XML\TaxistsWithCars\{taxist.Nickname}.xml"))
                    {
                        xmlSerializerCar.Serialize(stream, ((EconomCar)car));
                    }
                }
                else if (comboBoxCarsType.Text == "Luxury")
                {
                    XmlSerializer xmlSerializerCar = new XmlSerializer(typeof(LuxuryCar));
                    using (Stream stream = File.Create($@"..\..\XML\TaxistsWithCars\{taxist.Nickname}.xml"))
                    {
                        xmlSerializerCar.Serialize(stream, ((LuxuryCar)car));
                    }
                }
                else if (comboBoxCarsType.Text == "Truck")
                {
                    XmlSerializer xmlSerializerCar = new XmlSerializer(typeof(Truck));
                    using (Stream stream = File.Create($@"..\..\XML\TaxistsWithCars\{taxist.Nickname}.xml"))
                    {
                        xmlSerializerCar.Serialize(stream, ((Truck)car));
                    }
                }
                comboBoxCarsType.Enabled = false;

                this.Hide();
                TaxistWorking taxistWorking = new TaxistWorking(car, IsEnglish);
                taxistWorking.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{ex.Message}");
            }
        }
예제 #2
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            Sound.MakeSound("ButtonClick");
            string typeCar  = "";
            string nickname = "";

            try
            {
                if (string.IsNullOrEmpty(textBoxNickname.Text) || string.IsNullOrEmpty(textBoxPassword.Text))
                {
                    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.Text == password)
                        {
                            MessageBox.Show("Successful login");
                            this.Close();
                        }
                        else
                        {
                            throw new Exception("Incorrect password\nEnter again!");
                        }
                    }
                }
                this.Hide();

                if (typeCar == "Econom")
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(EconomCar));
                    using (Stream stream = File.OpenRead($@"..\..\XML\TaxistsWithCars\{nickname}.xml"))
                    {
                        car = (EconomCar)xmlSerializer.Deserialize(stream);
                    }
                }
                else if (typeCar == "Luxury")
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(LuxuryCar));
                    using (Stream stream = File.OpenRead($@"..\..\XML\TaxistsWithCars\{nickname}.xml"))
                    {
                        car = (LuxuryCar)xmlSerializer.Deserialize(stream);
                    }
                }
                else if (typeCar == "Truck")
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Truck));
                    using (Stream stream = File.OpenRead($@"..\..\XML\TaxistsWithCars\{nickname}.xml"))
                    {
                        car = (Truck)xmlSerializer.Deserialize(stream);
                    }
                }
                TaxistWorking taxistWorking = new TaxistWorking(car, IsEnglish);
                taxistWorking.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }