コード例 #1
0
ファイル: Form2.cs プロジェクト: lowzijian/OOAD-Assign
 public UserForm(Cinema cinema)
 {
     InitializeComponent();
     this.cinema = cinema;
     memberList  = cinema.GetMemberList();
     staffList   = cinema.GetStaffList();
 }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {   //display time
            timer1.Start();
            timer2.Start();
            lblDisplayTime.Text = "Time" + DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString();

            //local variable
            int numOfSeatsAvailable;

            bool[,] seats;
            string[] rows;

            //hide the movie poster
            picSlide3.Visible = false;
            picSlide2.Visible = false;

            // to read movies' details from file
            if (File.Exists("Movie.txt"))
            {
                try
                {
                    // create an instance of StreamReader
                    StreamReader reader = new StreamReader("Movie.txt");

                    // read the name of the first movie from the text file
                    string  movieName = reader.ReadLine();
                    string  genre;
                    string  cast;
                    decimal ticketPrice;
                    string  rating;
                    string  showTime;
                    int     duration;
                    string  hall;
                    int     movieIndex = 0;

                    while (movieName != null)
                    {
                        // create local variables and assign them with the values read from the file
                        genre = reader.ReadLine();

                        cast = reader.ReadLine();

                        ticketPrice = Convert.ToDecimal(reader.ReadLine());

                        rating = reader.ReadLine();

                        showTime = reader.ReadLine();

                        duration = Convert.ToInt32(reader.ReadLine());

                        hall = reader.ReadLine();

                        // initialize the variables needed to create seats
                        numOfSeatsAvailable = 0;
                        seats = new bool[5, 6];
                        rows  = new string[5];

                        // to read the movie seats row by row
                        for (int i = 0; i < 5; i++)
                        {
                            rows[i] = reader.ReadLine();
                        }

                        // create seats of Boolean type
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < rows[i].Length; j++)
                            {
                                if (rows[i][j] == 'X')
                                {
                                    seats[i, j] = true;
                                }
                                else// (rows[i][j] == 'O')
                                {
                                    seats[i, j] = false;
                                    numOfSeatsAvailable++;
                                }
                            }
                        }

                        // add movies to the arraylist called movieList of Cinema object
                        cinema.AddMovie(movieName, genre, cast, ticketPrice, rating, showTime, duration, numOfSeatsAvailable, hall, seats, movieIndex);

                        // increase the movieIndex by one
                        movieIndex++;

                        // read the name of the next movie from the text file
                        movieName = reader.ReadLine();
                    }

                    // close the file after finish reading
                    reader.Close();
                }
                catch (IOException ioExc)
                {
                    MessageBox.Show("File error: " + ioExc.Message);
                }
                catch (SystemException sysExc)
                {
                    MessageBox.Show(sysExc.Message);
                }
            }

            // to read members' details from file
            if (File.Exists("Member.txt") && File.Exists("Seats Owned by Members.txt"))
            {
                try
                {
                    // create an instance of StreamReader
                    StreamReader reader = new StreamReader("Member.txt");

                    // read the name of the first member from the file
                    string name = reader.ReadLine();
                    int    age;
                    string ic;
                    string phoneNum;
                    string id;
                    string password;
                    int    bonusPoints;

                    while (name != null)
                    {
                        // create local variables and assign them with the values read from the file
                        age = Convert.ToInt32(reader.ReadLine());

                        ic = reader.ReadLine();

                        phoneNum = reader.ReadLine();

                        id = reader.ReadLine();

                        password = reader.ReadLine();

                        bonusPoints = Convert.ToInt32(reader.ReadLine());

                        // testing
                        //string aMember = name + " " + age + " " + ic + " " + phoneNum + " " + id
                        //                    + " " + password + " " + bonusPoints;
                        //MessageBox.Show(aMember);

                        // add members to the arraylist called memberList of Cinema object
                        cinema.AddMember(name, age, ic, phoneNum, id, password, bonusPoints);

                        // read the name of the next member from the file
                        name = reader.ReadLine();
                    }

                    // close the file after finish reading
                    reader.Close();

                    // this section is for putting seats owned by user into the array list

                    // get the memberList
                    Member[] memberList = cinema.GetMemberList();

                    for (int i = 0; i < memberList.Length; i++)
                    {
                        StreamReader reader1 = new StreamReader("Seats Owned by Members.txt");

                        string line = reader1.ReadLine();

                        while (line != null)
                        {
                            // read the first line
                            string tempId = line.Substring(0, 7);

                            if (tempId == memberList[i].Id)
                            {
                                memberList[i].SeatsOwned.Add(line.Substring(8));
                            }

                            // read the next line
                            line = reader1.ReadLine();
                        }

                        // close the file after finish reading
                        reader1.Close();
                    }

                    // load the payment histories for the current member
                    for (int i = 0; i < memberList.Length; i++)
                    {
                        StreamReader reader2 = new StreamReader("Payment Histories.txt");

                        // read the first line
                        string code = reader2.ReadLine();

                        while (code != null)
                        {
                            string  movieName           = reader2.ReadLine();
                            string  movieShowtime       = reader2.ReadLine();
                            string  seatsChosen         = reader2.ReadLine();
                            decimal pricePerTicket      = Convert.ToDecimal(reader2.ReadLine());
                            int     numOfTickets        = Convert.ToInt32(reader2.ReadLine());
                            decimal totalPrice          = Convert.ToDecimal(reader2.ReadLine());
                            string  dateOfPurchase      = reader2.ReadLine();
                            string  timeOfPurchase      = reader2.ReadLine();
                            int     originalBonusPoints = Convert.ToInt32(reader2.ReadLine());
                            int     bonusPointsGained   = Convert.ToInt32(reader2.ReadLine());
                            int     newBonusPoints      = Convert.ToInt32(reader2.ReadLine());

                            string tempId = code.Substring(0, 7);
                            // to determine if this payment history belongs to this member
                            if (tempId == memberList[i].Id)
                            {
                                memberList[i].PaymentHistories.Add(new PaymentHistory(code, movieName, movieShowtime, seatsChosen, pricePerTicket,
                                                                                      numOfTickets, totalPrice, dateOfPurchase, timeOfPurchase, originalBonusPoints, bonusPointsGained,
                                                                                      newBonusPoints));
                                memberList[i].NumOfPaymentHistories++;
                            }

                            // read the next line
                            code = reader2.ReadLine();
                        }

                        reader2.Close();
                    }
                }
                catch (IOException ioExc)
                {
                    MessageBox.Show("File error: " + ioExc.Message);
                }
                catch (SystemException sysExc)
                {
                    MessageBox.Show(sysExc.Message);
                }
            }

            // to read staff's details from file
            if (File.Exists("Staff.txt"))
            {
                try
                {
                    // create an instance of StreamReader
                    StreamReader reader = new StreamReader("Staff.txt");

                    // read the name of the first staff from the file
                    string name = reader.ReadLine();
                    int    age;
                    string ic;
                    string phoneNum;
                    string id;
                    string password;

                    while (name != null)
                    {
                        // create local variables and assign them with the values read from the file
                        age = Convert.ToInt32(reader.ReadLine());

                        ic = reader.ReadLine();

                        phoneNum = reader.ReadLine();

                        id = reader.ReadLine();

                        password = reader.ReadLine();

                        // add staff to the arraylist called staffList of Cinema object
                        cinema.AddStaff(name, age, ic, phoneNum, id, password);

                        // read the name of the next staff from the file
                        name = reader.ReadLine();
                    }

                    // close the file after finish reading
                    reader.Close();
                }
                catch (IOException ioExc)
                {
                    MessageBox.Show("File error: " + ioExc.Message);
                }
                catch (SystemException sysExc)
                {
                    MessageBox.Show(sysExc.Message);
                }
            }
        }