Beispiel #1
0
        private void btn_printTicket_Click(object sender, EventArgs e)
        {
            //check the card number is valid
            if (txtBox_cardNumber.TextLength != 16)
            {
                MessageBox.Show("That is not a valid card number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Random rnd          = new Random();
                int    randomNumber = rnd.Next(1, 1000000);

                string copyFile = "data/FlyTicket" + txtBox_cardNumber.Text + randomNumber + ".txt";

                //System.IO.File.Create(copyFile);
                System.IO.File.Copy("data/FlyTicket.txt", copyFile, false);

                string ticketFile = System.IO.File.ReadAllText(copyFile);

                //get all data
                string name       = txtBox_firstName.Text;
                string surname    = txtBox_lastName.Text;
                string cardnumber = txtBox_cardNumber.Text;

                string[] itemsToEdit = { "$name", "$surname", "$cardnumber", "$ticketid", "$flightid", "$origin", "$destination", "$airline", "$date", "$time", "$price" };

                string hashedCard = "**** **** **** " + cardnumber.Substring(12, cardnumber.Length - 12);

                ticketFile = ticketFile.Replace(itemsToEdit[0], name);
                ticketFile = ticketFile.Replace(itemsToEdit[1], surname);
                ticketFile = ticketFile.Replace(itemsToEdit[2], hashedCard);
                ticketFile = ticketFile.Replace(itemsToEdit[3], flightNo + seatsAvailable);

                for (int alpha = 4; alpha <= 10; alpha++)
                {
                    ticketFile = ticketFile.Replace(itemsToEdit[alpha], FlightInfo[alpha - 4]);
                }

                System.IO.File.WriteAllText(copyFile, ticketFile);

                //updateDB("print", Encrypt(txtBox_cardNumber.Text));

                MessageBox.Show("Your ticket is being printed, please take it to the check in desk to pay.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MenuForm menu = new Fly.MenuForm();
                menu.Show();
                Close();
            }
        }
Beispiel #2
0
        private void btn_saveTicket_Click(object sender, EventArgs e)
        {
            bool validCardNo = Int64.TryParse(txtBox_cardNumber.Text, out Int64 cardNumber);

            //check the card number is valid
            if (txtBox_cardNumber.TextLength != 16 || !validCardNo)
            {
                MessageBox.Show("Card number is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //encrypt the card number and pass it onto the updatedb sub
                Ticket newTicket = new Ticket(_ticketId, txtBox_firstName.Text, txtBox_lastName.Text, Cipher.Encrypt(cardNumber.ToString()), DEFAULT_COLLECTED_VALUE, _selectedFlight.FlightId, _selectedFlight.SeatsAvailable);
                DBConnection.CreateTicket(newTicket);

                Console.WriteLine(Cipher.Encrypt(cardNumber.ToString()));

                MessageBox.Show("Your ticket was saved. To collect your ticket, click 'Collect Ticket' on the menu and follow the instructions.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MenuForm menu = new Fly.MenuForm();
                menu.Show();
                Close();
            }
        }
Beispiel #3
0
        private void btn_collect_Click(object sender, EventArgs e)
        {
            string cardNo = "";

            if (!txt_cardNo.Text.Length.Equals(16))
            {
                MessageBox.Show("Invalid card number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DBConnect("", "", true, "SELECT * FROM tickets WHERE ticketID = '" + txt_ticketID.Text + "'");

                while (Reader.Read())
                {
                    cardNo      = Decrypt(Reader["cardNumber"].ToString());
                    seatsOnBook = Reader["seatsOnBook"].ToString();

                    if (Reader["firstName"].ToString().Equals(txt_firstName.Text) && Reader["lastName"].ToString().Equals(txt_lastName.Text) && cardNo.Equals(txt_cardNo.Text))
                    {
                        if (Reader["collected"].ToString().Equals("0"))
                        {
                            Random rnd          = new Random();
                            int    randomNumber = rnd.Next(1, 1000000);

                            string copyFile = "data/FlyTicket" + cardNo + randomNumber + ".txt";

                            //System.IO.File.Create(copyFile);
                            System.IO.File.Copy("data/FlyTicket.txt", copyFile, false);

                            string ticketFile = System.IO.File.ReadAllText(copyFile);

                            //get all data

                            string[] itemsToEdit = { "$name", "$surname", "$cardnumber", "$ticketid", "$flightid", "$origin", "$destination", "$airline", "$date", "$time", "$price" };

                            string hashedCard = "**** **** **** " + cardNo.Substring(12, cardNo.Length - 12);

                            DBConnect("", "", true, "SELECT * FROM flights WHERE flightID = '" + txt_ticketID.Text.Substring(0, 5) + "'");

                            while (Reader.Read())
                            {
                                seatsAvailable = Reader["seatsAvailable"].ToString();
                                flightID       = Reader["flightID"].ToString();

                                flightInfoArray = new string[] { Reader["flightID"].ToString(), Reader["origin"].ToString(), Reader["destination"].ToString(), Reader["airline"].ToString(), Reader["dateOfFlight"].ToString(), Reader["time"].ToString(), Reader["price"].ToString() };
                            }

                            ticketFile = ticketFile.Replace(itemsToEdit[0], txt_firstName.Text);
                            ticketFile = ticketFile.Replace(itemsToEdit[1], txt_lastName.Text);
                            ticketFile = ticketFile.Replace(itemsToEdit[2], hashedCard);
                            ticketFile = ticketFile.Replace(itemsToEdit[3], flightID + seatsOnBook);

                            for (int alpha = 4; alpha <= 10; alpha++)
                            {
                                ticketFile = ticketFile.Replace(itemsToEdit[alpha], flightInfoArray[alpha - 4]);
                            }

                            System.IO.File.WriteAllText(copyFile, ticketFile);

                            //send the data to the database
                            string query = "UPDATE tickets SET collected = 1 WHERE ticketID = '" + txt_ticketID.Text + "'";
                            DBConnect("", "", true, query);

                            MessageBox.Show("Your ticket is being printed, please take it to the check in desk to pay.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            MenuForm menu = new Fly.MenuForm();
                            menu.Show();
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("This ticket has been collected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The details you have entered do not match the details associated with that ticket.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }