示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //tripID = 1; //////////// link trip to parent forum

            this.AutoSize     = true;
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            String connectionString = "SERVER=" + "ec2-54-226-9-216.compute-1.amazonaws.com" + "; DATABASE=" +
                                      "f2016_s1_user16" + ";" + "UID=" + "f2016_s1_user16" + "; " + "PASSWORD="******"f2016_s1_user16" + "; ";

            connection = new MySqlConnection(connectionString);

            try
            {
                connection.Open();
            }
            catch (MySqlException ex)
            {
                //0: Cannot connect to server.
                //1045: Invalid user name and/or password.
                switch (ex.Number)
                {
                case 0:
                    MessageBox.Show("Cannot connect to server.  Contact administrator");
                    break;


                case 1045:
                    MessageBox.Show("Invalid username/password, please try again");
                    break;
                }
            }
            // populate from DB

            string Qpop = "SELECT * FROM ROOM";
            ROOM   rm;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qpop;
            }

            MySqlDataReader dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                rm             = new ROOM();
                rm.room_id     = int.Parse(dataReader["room_id"].ToString());
                rm.room_number = int.Parse(dataReader["room_number"].ToString());
                rm.roomCat_id  = int.Parse(dataReader["roomCat_id"].ToString());
                rm.ship_id     = int.Parse(dataReader["ship_id"].ToString());

                roomList.Add(rm);
            }
            dataReader.Close();

            string         Qpoppass = "******";
            ROOM_PASSENGER rp;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qpoppass;
            }

            MySqlDataReader dataReader1 = cmd.ExecuteReader();

            while (dataReader1.Read())
            {
                rp              = new ROOM_PASSENGER();
                rp.room_id      = int.Parse(dataReader1["room_id"].ToString());
                rp.pass_id      = int.Parse(dataReader1["pass_id"].ToString());
                rp.trip_id      = int.Parse(dataReader1["trip_id"].ToString());
                rp.isBillHolder = bool.Parse(dataReader1["isBillHolder"].ToString());
                rp.roomPass_id  = int.Parse(dataReader1["roomPass_id"].ToString());

                rmpassList.Add(rp);
            }
            dataReader1.Close();

            string Qtrip = "SELECT * FROM TRIP";
            TRIP   t;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qtrip;
            }

            MySqlDataReader dataReader2 = cmd.ExecuteReader();

            while (dataReader2.Read())
            {
                t         = new TRIP();
                t.trip_id = int.Parse(dataReader2["trip_id"].ToString());
                t.ship_id = int.Parse(dataReader2["ship_id"].ToString());

                tripList.Add(t);
            }
            dataReader2.Close();

            string    Qp = "SELECT * FROM PASSENGER";
            PASSENGER p;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qp;
            }

            MySqlDataReader dataReader3 = cmd.ExecuteReader();

            while (dataReader3.Read())
            {
                p         = new PASSENGER();
                p.pass_id = int.Parse(dataReader3["pass_id"].ToString());
                p.name    = dataReader3["pass_firstname"].ToString() + " " + dataReader3["pass_lastname"].ToString();

                passList.Add(p);
            }
            dataReader3.Close();

            string Qd = "SELECT * FROM DINNER";
            DINNER din;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qd;
            }

            MySqlDataReader dataReader4 = cmd.ExecuteReader();

            while (dataReader4.Read())
            {
                din                = new DINNER();
                din.dinner_id      = int.Parse(dataReader4["dinner_id"].ToString());
                din.table_id       = int.Parse(dataReader4["table_id"].ToString());
                din.group_amount   = int.Parse(dataReader4["group_amount"].ToString());
                din.dinner_date    = Convert.ToDateTime(dataReader4["dinner_date"].ToString()).ToString("MMM dd, yyyy");
                din.dinner_sitting = int.Parse(dataReader4["dinner_sitting"].ToString());
                din.room_id        = int.Parse(dataReader4["room_id"].ToString());
                din.waiter_id      = int.Parse(dataReader4["waiter_id"].ToString());
                din.trip_id        = int.Parse(dataReader4["trip_id"].ToString());
                din.hasFee         = bool.Parse(dataReader4["hasFee"].ToString());

                dinnerList.Add(din);
            }
            dataReader4.Close();

            string Qt = "SELECT * FROM TABLE0";
            TABLE  tb;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qt;
            }

            MySqlDataReader dataReader5 = cmd.ExecuteReader();

            while (dataReader5.Read())
            {
                tb              = new TABLE();
                tb.table_id     = int.Parse(dataReader5["table_id"].ToString());
                tb.max_capacity = int.Parse(dataReader5["max_capacity"].ToString());
                tb.ship_id      = int.Parse(dataReader5["ship_id"].ToString());
                tb.area_id      = int.Parse(dataReader5["area_id"].ToString());

                tableList.Add(tb);
            }
            dataReader5.Close();

            // fill cbDeck (date of dinner; ignore misleading var names code was copied from elsewhere)

            int shipID = 0;

            for (int i = 0; i < tripList.Count; i++)
            {
                if (tripList[i].trip_id == tripID)
                {
                    shipID = tripList[i].ship_id;
                }
            }

            foreach (DINNER r in dinnerList)
            {
                if (r.trip_id == tripID)
                {
                    string deckNum = r.dinner_date;

                    bool newDeck = true;
                    for (int i = 0; i < cbDeck.Items.Count; i++)
                    {
                        if (cbDeck.GetItemText(cbDeck.Items[i]) == deckNum)
                        {
                            newDeck = false;
                        }
                    }

                    if (newDeck)
                    {
                        cbDeck.Items.Add(deckNum);
                    }
                }
            }
        }
示例#2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //tripID = 1; //////////// link trip to parent forum

            this.AutoSize     = true;
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            String connectionString = "SERVER=" + "ec2-54-226-9-216.compute-1.amazonaws.com" + "; DATABASE=" +
                                      "f2016_s1_user16" + ";" + "UID=" + "f2016_s1_user16" + "; " + "PASSWORD="******"f2016_s1_user16" + "; ";

            connection = new MySqlConnection(connectionString);

            try
            {
                connection.Open();
            }
            catch (MySqlException ex)
            {
                //0: Cannot connect to server.
                //1045: Invalid user name and/or password.
                switch (ex.Number)
                {
                case 0:
                    MessageBox.Show("Cannot connect to server.  Contact administrator");
                    break;


                case 1045:
                    MessageBox.Show("Invalid username/password, please try again");
                    break;
                }
            }
            // populate from DB

            string Qpop = "SELECT * FROM ROOM";
            ROOM   rm;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qpop;
            }

            MySqlDataReader dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                rm             = new ROOM();
                rm.room_id     = int.Parse(dataReader["room_id"].ToString());
                rm.room_number = int.Parse(dataReader["room_number"].ToString());
                rm.roomCat_id  = int.Parse(dataReader["roomCat_id"].ToString());
                rm.ship_id     = int.Parse(dataReader["ship_id"].ToString());

                roomList.Add(rm);
            }
            dataReader.Close();

            string         Qpoppass = "******";
            ROOM_PASSENGER rp;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qpoppass;
            }

            MySqlDataReader dataReader1 = cmd.ExecuteReader();

            while (dataReader1.Read())
            {
                rp              = new ROOM_PASSENGER();
                rp.room_id      = int.Parse(dataReader1["room_id"].ToString());
                rp.pass_id      = int.Parse(dataReader1["pass_id"].ToString());
                rp.trip_id      = int.Parse(dataReader1["trip_id"].ToString());
                rp.isBillHolder = bool.Parse(dataReader1["isBillHolder"].ToString());
                rp.roomPass_id  = int.Parse(dataReader1["roomPass_id"].ToString());

                rmpassList.Add(rp);
            }
            dataReader1.Close();

            string Qtrip = "SELECT * FROM TRIP";
            TRIP   t;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qtrip;
            }

            MySqlDataReader dataReader2 = cmd.ExecuteReader();

            while (dataReader2.Read())
            {
                t         = new TRIP();
                t.trip_id = int.Parse(dataReader2["trip_id"].ToString());
                t.ship_id = int.Parse(dataReader2["ship_id"].ToString());

                tripList.Add(t);
            }
            dataReader2.Close();

            string    Qp = "SELECT * FROM PASSENGER";
            PASSENGER p;

            if (connection != null)
            {
                cmd.Connection  = connection;
                cmd.CommandText = Qp;
            }

            MySqlDataReader dataReader3 = cmd.ExecuteReader();

            while (dataReader3.Read())
            {
                p         = new PASSENGER();
                p.pass_id = int.Parse(dataReader3["pass_id"].ToString());
                p.name    = dataReader3["pass_firstname"].ToString() + " " + dataReader3["pass_lastname"].ToString();

                passList.Add(p);
            }
            dataReader3.Close();

            // fill cbDeck

            List <int> decks = new List <int>();

            int shipID = 0;

            for (int i = 0; i < tripList.Count; i++)
            {
                if (tripList[i].trip_id == tripID)
                {
                    shipID = tripList[i].ship_id;
                }
            }

            foreach (ROOM r in roomList)
            {
                if (r.ship_id == shipID)
                {
                    string deckNum = r.room_number.ToString("D5").Substring(0, 1);

                    bool newDeck = true;
                    for (int i = 0; i < cbDeck.Items.Count; i++)
                    {
                        if (cbDeck.GetItemText(cbDeck.Items[i]) == deckNum)
                        {
                            newDeck = false;
                        }
                    }

                    if (newDeck)
                    {
                        cbDeck.Items.Add(deckNum);
                    }
                }
            }
        }