IMPORTANT: Because of the upgrade you need to login with your DISPLAY NAME, So members will need to use their =GEN=YOURNAME to login

Sign in to follow this  
Followers 0
=GEN=Looseminded

For Timber - My ADV C# Final Project

7 posts in this topic

XD7P7xe.png

 

 

 

 

// Occupancies Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final_Project
{
    class Occupancies
    {
        public string ClientID { get; set; }
        public string RoomNumber { get; set; }
    }
}


// Client Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final_Project
{
    class Client
    {
        // I couldn't figure out how to get the door prizes to work without throwing object reference
        // exceptions or out of bounds of array exceptions.
        public string[] doorPrizes = { "Free night's stay", "Complementary breakfast", "Dinner on us",
                                         "Free cab ride" };
        public string ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
        public long PhoneNumber { get; set; }
        public string DoorPrizeWon { get; set; }
        public bool DoesSmoke { get; set; }
    }
}

// Suite Class inheriting from Room Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final_Project
{
    class Suite : Room
    {
        public int NumberOfRooms { get; set; }
        public string NumberOfRoomsInfo { get; set; }
    }
}


// Basic Class inheriting from Room Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final_Project
{
    class Basic : Room
    {
        public bool Smoking { get; set; }
    } 
}

// Room Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final_Project
{
    abstract class Room
    {
        public string RoomNumber { get; set; }
        public bool Balcony { get; set; }
        public bool DownForRepair { get; set; }
        public int NumberOfBeds { get; set; }
        public string BalconyInfo { get; set; }
        public string DownForRepairInfo { get; set; }
        public string NumberOfBedsInfo { get; set; }
    }
}

// Main Program

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

/* This program is the database of sorts for a ficticious hotel.  What the program is SUPPOSED to do is be able to read in a list of clients, rooms, and occupancies,
 * be able to save clients, rooms, and occupancies, and be able to display all this information with clients assigned to rooms as needed until the hotel is full.
 * After the hotel is full, the way this program is written, you cannot add anybody else to the hotel.  There are 150 total rooms assuming each suite only has one room,
 * however the information will display more than that as each suite has a random (between 1 and 3) number of rooms.  I'm unsure of how to manage this properly aside
 * from making the loop I have running for rooms larger, but that has potential to cause issues further down the line.  At the time of writing this comment 
 * (9:33pm on Thursday May, 14), my entire goal for this project is simply to get all the fields written out and the majority of the program working as intended. */

/* Congratulations Chris, you have broken me and I am not worthy of you */

namespace Final_Project
{
    public partial class Form1 : Form
    {
        string fileNameGeneration;
        string roomGeneration;
        string suiteGeneration;
        ArrayList client;
        ArrayList rooms;
        ArrayList suites;
        Stack<Client> occupancyStack;
        Stack<Client> temp;
        Queue<Room> availableRooms;
        Client clientInfo;
        Basic basicRoom;
        Suite suiteRoom;
        Occupancies occupied;
        public Form1()
        {
            InitializeComponent();
            fileNameGeneration = @"C:\ClientList.txt";
            roomGeneration = @"C:\BasicRoomList.txt";
            suiteGeneration = @"C:\SuiteRoomList.txt";
            occupancyStack = new Stack<Client>();
            temp = new Stack<Client>();
            availableRooms = new Queue<Room>();
            basicRoom = new Basic();
            suiteRoom = new Suite();
            occupied = new Occupancies();
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                long phone = 3609786544;
                string[] firstName = { "Bob", "Dylan", "Josh", "Nick", "Chris", "Allen", "Tim", "Steve",
                                     "John", "Jose" };
                string[] lastName = { "Winters", "Bryant", "Smith", "White", "Verchovsky", "Cosgrove", 
                                    "Axel", "Moran", "Martin", "Johnson" };
                Random rand = new Random();

                // Writes random names and phone numbers to file to allow program to run smoothly.  Also writes rooms.
                using (StreamWriter writer = new StreamWriter(fileNameGeneration))
                {
                    for (int i = 1; i < 131; i++)
                    {
                        int doorPrize;
                        int doorPrizeRoll;
                        int counter = 0;
                        doorPrizeRoll = rand.Next(0, 3);
                        doorPrize = rand.Next(0, 4);
                        writer.Write("Client ID#: " + i + ",");
                        writer.Write(firstName[rand.Next(0, 10)] + ",");
                        writer.Write(lastName[rand.Next(0, 10)] + ",");
                        // Lets assume they all live in the same apartment complex for ease.
                        writer.Write("1500 Edwards Avenue Apartment: " + i + " Bellingham Washington 98225" + ",");
                        writer.Write(phone + (i * rand.Next(500)));
                        
                        writer.WriteLine();
                    }
                }

                using (StreamWriter writer = new StreamWriter(roomGeneration))
                {
                    int roomStatus;
                    int roomStatus1;
                    for (int i = 1; i <= 140; i++)
                    {
                        // Balcony Status
                        roomStatus = rand.Next(2);
                        basicRoom.NumberOfBeds = 2;
                        if (i < 31)
                        {
                            basicRoom.Smoking = true;
                            if (roomStatus == 0)
                            {
                                // Down for Repair
                                roomStatus1 = rand.Next(2);
                                basicRoom.Balcony = false;
                                if (roomStatus1 == 0)
                                {
                                    basicRoom.DownForRepair = false;
                                    writer.WriteLine("Smoking Room: " + i + ", Balcony: " + basicRoom.Balcony.ToString() + ", Down for repair: "
                                                 + basicRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString());
                                }
                                if (roomStatus1 == 1)
                                {
                                    basicRoom.DownForRepair = true;
                                    writer.WriteLine("Smoking Room: " + i + ", Balcony: " + basicRoom.Balcony.ToString() + ", Down for repair: "
                                                 + basicRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString());
                                } 
                            }
                            if (roomStatus == 1)
                            {
                                // Down for repair
                                roomStatus1 = rand.Next(2);
                                basicRoom.Balcony = true;
                                if (roomStatus1 == 0)
                                {
                                    basicRoom.DownForRepair = false;
                                    writer.WriteLine("Smoking Room: " + i + ", Balcony: " + basicRoom.Balcony.ToString() + ", Down for repair: "
                                                 + basicRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString());
                                }
                                if (roomStatus1 == 1)
                                {
                                    basicRoom.DownForRepair = true;
                                    writer.WriteLine("Smoking Room: " + i + ", Balcony: " + basicRoom.Balcony.ToString() + ", Down for repair: "
                                                 + basicRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString());
                                }
                            }
                        }
                        if (i > 30 && i <= 140)
                        {
                            basicRoom.NumberOfBeds = 2;
                            basicRoom.Smoking = false;
                            // Balcony
                            roomStatus = rand.Next(2);
                            if (roomStatus == 0)
                            {
                                basicRoom.Balcony = false;
                                basicRoom.DownForRepair = false; 
                                // We'll say that because smokers aren't in the room, it doesn't need repairing outside
                                // of basic hotel requirements (cleaning before/after tenants enter/leave)
                                writer.WriteLine("Non-Smoking Room: " + i + ", Balcony: " + basicRoom.Balcony.ToString() + ", Down for repair: "
                                                 + basicRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString());
                            }
                            if (roomStatus == 1)
                            {
                                basicRoom.Balcony = true;
                                basicRoom.DownForRepair = false;
                                // We'll say that because smokers aren't in the room, it doesn't need repairing outside
                                // of basic hotel requirements (cleaning before/after tenants enter/leave)
                                writer.WriteLine("Non-Smoking Room: " + i + ", Balcony: " + basicRoom.Balcony.ToString() + ", Down for repair: "
                                                 + basicRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString());
                            }
                        }
                    }
                }

                using (StreamWriter writer = new StreamWriter(suiteGeneration))
                {
                    for (int i = 140; i <= 150; i++)
                    {
                        int roomStatus;
                        suiteRoom.Balcony = true;
                        suiteRoom.DownForRepair = false;
                        suiteRoom.NumberOfBeds = 3;
                        roomStatus = rand.Next(1, 4);
                        suiteRoom.NumberOfRooms = roomStatus;
                        writer.WriteLine("Suite: " + i + ", Balcony: " + suiteRoom.Balcony.ToString() + ", Down for repair: "
                                         + suiteRoom.DownForRepair.ToString() + ", Number of beds: " + basicRoom.NumberOfBeds.ToString()
                                         + ", Number of Rooms: " + suiteRoom.NumberOfRooms);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        // Reads clients in.  May randomly assign rooms later.  You will need to click this after saving clients to update the information.
        private void btnReadClients_Click(object sender, EventArgs e)
        {
            try
            {
                using (StreamReader reader = new StreamReader(fileNameGeneration))
                {
                    client = new ArrayList();
                    listBox1.Items.Clear();
                    string[] clients = File.ReadAllLines(fileNameGeneration);
                    
                    
                    // write lines to listbox
                    // match arraylist to listbox
                    foreach (string clientinformation in clients)
                    {
                        // split array on comma
                        string[] clientStuff = clientinformation.Split(',');
                        clientInfo = new Client();
                        clientInfo.ID = clientStuff[0];
                        clientInfo.FirstName = clientStuff[1];
                        clientInfo.LastName = clientStuff[2];
                        clientInfo.Address = clientStuff[3];
                        clientInfo.PhoneNumber = Convert.ToInt64(clientStuff[4]);
                        client.Add(clientInfo);

                    }

                    // add each person to listbox
                    foreach (Client c in client)
                    {
                        listBox1.Items.Add(c.ID + ", " + c.FirstName + ", " + c.LastName + ", "
                            + c.Address + ", " + c.PhoneNumber);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        // Read Rooms & assigns clients to them
        private void btnReadRooms_Click(object sender, EventArgs e)
        {
            try
            {
                using (StreamReader reader = new StreamReader(roomGeneration))
                {
                    suites = new ArrayList();
                    rooms = new ArrayList();
                    listBox3.Items.Clear();
                    string[] roomsInfo = File.ReadAllLines(roomGeneration);

                    // Write lines to listbox
                    // match arraylist to listbox
                    foreach (string roomInfo in roomsInfo)
                    {
                        // Split array on comma
                        string[] roomStuff = roomInfo.Split(',');
                        if (!roomStuff.Contains("Suite"))
                        {
                            basicRoom = new Basic();
                            basicRoom.RoomNumber = roomStuff[0];
                            // Info strings to hold the boolean and int values as they're set upon generation.
                            basicRoom.BalconyInfo = roomStuff[1];
                            basicRoom.DownForRepairInfo = roomStuff[2];
                            basicRoom.NumberOfBedsInfo = roomStuff[3];
                            rooms.Add(roomStuff);
                        }
                    }

                    string[] suiteStuffs = File.ReadAllLines(suiteGeneration);
                    foreach (string suiteInfo in suiteStuffs)
                    {
                        // Split array on comma
                        string[] suiteStuff = suiteInfo.Split(',');
                        if (suiteStuff.Contains("Suite"))
                        {
                            suiteRoom = new Suite();
                            suiteRoom.RoomNumber = suiteStuff[0];
                            // Info strings to hold the boolean and int values as they're set upon generation.
                            suiteRoom.BalconyInfo = suiteStuff[1];
                            suiteRoom.DownForRepairInfo = suiteStuff[2];
                            suiteRoom.NumberOfBedsInfo = suiteStuff[3];
                            suiteRoom.NumberOfRoomsInfo = suiteStuff[4];
                            suites.Add(suiteStuff);
                        }
                    }

                

                    foreach (Basic b in rooms) // Throws exception here
                    {
                        listBox3.Items.Add("Room #:" + b.RoomNumber + " Balcony: " + b.BalconyInfo
                            + " Down For Repair?: " + b.DownForRepairInfo + " Number of Beds: "
                            + b.NumberOfBedsInfo);
                    }

                    foreach (Suite s in suites) // Does nothing when above is commented out?
                    {
                        listBox3.Items.Add("Room #:" + s.RoomNumber + " Balcony: " + s.BalconyInfo
                            + " Down For Repair?: " + s.DownForRepairInfo + " Number of Beds: "
                            + s.NumberOfBedsInfo + " Number of Rooms: " + s.NumberOfRoomsInfo);
                    }
            
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        // Read Occupancies, should be done after loading clients and rooms and assigning each.
        private void btnReadOccupancies_Click(object sender, EventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        // Removes a client.
        private void btnRemove_Click(object sender, EventArgs e)
        {
            /* This is supposed to remove a client and then save the file, however it would appear that this does not happen
             * and I'm not sure why */
            try
            {
                if (listBox1.SelectedIndex != -1)
                {
                    listBox1.Items.RemoveAt(listBox1.SelectedIndex); // remove from listbox
                    client.RemoveAt(client.IndexOf(listBox1.SelectedIndex)); // remove from client stack
                    foreach (Client c in client)
                        temp.Push(c); // push new client stack to a temp stack.
                    availableRooms.Dequeue(); // dequeue room

                    FileStream output = new FileStream(fileNameGeneration, FileMode.Create, FileAccess.Write);

                    // Intended to save the current clients in the listbox and remaining in client to the file.  Does not work as intended.
                    using (StreamWriter writer = new StreamWriter(output))
                    {
                        foreach (string cli in client)
                        {
                            writer.WriteLine(cli.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        // Saves occupancies to a separate file to be read at a later date.
        private void btnSaveOccupancies_Click(object sender, EventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        // Saves rooms to C:\RoomList.txt . WARNING: DO NOT PRESS THE GENERATE BUTTON AFTER USING THIS IF YOU DO NOT WANT TO LOSE
        // YOUR ROOMS!!!
        private void btnSaveRooms_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (Client c in client)
                {
                    occupancyStack.Push(c);
                }
                foreach (Room r in rooms)
                {
                    // This needs more work as currently all rooms are empty due to being unable to be assigned
                    availableRooms.Enqueue(r);
                }

                FileStream output = new FileStream(roomGeneration, FileMode.Create, FileAccess.Write);

                using (StreamWriter writer = new StreamWriter(output))
                {
                    // Save current status of all rooms, requires the read rooms button to work, currently doesn't.
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        // Saves removed and added clients to C:\ClientList.txt . WARNING: DO NOT PRESS THE GENERATE BUTTON AFTER USING THIS IF YOU DO NOT WANT TO LOSE
        // YOUR CLIENTS!!!
        private void btnSaveClients_Click(object sender, EventArgs e)
        {
            try
            {
                Random rand = new Random();
                int clientNumber;
                clientNumber = rand.Next(200, 10000);

                string FName = txtFirstName.Text + ",";
                string LName = txtLastName.Text + ",";
                string Address = txtAddress.Text + ",";
                string PNumber = txtPNumber.Text;

                FileStream output = new FileStream(fileNameGeneration, FileMode.Append, FileAccess.Write);

                // Writes client to file
                using (StreamWriter writer = new StreamWriter(output))
                {
                    writer.Write("Client ID#: " + clientNumber + "," + FName + LName + Address + PNumber);
                    writer.WriteLine();
                }
                // Clears textboxes
                txtFirstName.Clear();
                txtLastName.Clear();
                txtPNumber.Clear();
                txtAddress.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }



        // Read in initial lists of rooms, clients, and occupancies from file.

        // Allow addition and removal of rooms (This does not), clients, and occupancies from file.

        // Throw vacant rooms into a queue.

        // Display all rooms available with current status.  Use ArrayList (DAMNIT)

        // Display list of all clients and the rooms they occupy.  Use ArrayList (DAMNIT)

        // Stack of door prizes.  Use rand.Next(0, 3) to give approximately one prize every three customers.  (Maybe only add 4 prizes
        // for the sake of simplicity.) (Could not make this work and I am a broken man.)
    }
}

 

 

 

This program is so broken I'm embarassed in regards to it because I know I can do better, time just got away from me with the other classes I was taking assigning so much work towards the end.

Share this post


Link to post
Share on other sites

Very cool loose. A lot of hard work there. I am looking forward to getting to some actual programming in my study to. Just learning coding basics at the moment for me. Keep at it mate. Good stuff.

Share this post


Link to post
Share on other sites

Computer tip of the day...

 

Most web browsers have a function for removing browsing history. use that and you wont get caught watching porn..

Share this post


Link to post
Share on other sites

Computer tip of the day...

 

Most web browsers have a function for removing browsing history. use that and you wont get caught watching porn..

 

 

Pisser...

Share this post


Link to post
Share on other sites

I saw code that was a derivative of C and threw up a little in my mouth.

 

(I have a long hate/hate relationship with all things C / derivative there of ...)

 

Good for you though :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0