示例#1
0
        private void button4_Click(object sender, EventArgs e) // Top-N Movies by Average Rating - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            Movies m;
            int    N = Convert.ToInt32(textBox8.Text);

            if (N > 0)
            {
                m = businesstier.GetTopMoviesByAvgRating(N);
                if (m == null)
                {
                    listBox1.Items.Add("**Error, or database is empty?!");
                }
                else
                {
                    listBox1.Items.Add("S U C C E S S");
                    listBox1.Items.Add("");
                    listBox1.Items.Add("The top " + N + " Movies in the database are: ");
                    listBox1.Items.Add("");
                    foreach (Movie r in m)
                    {
                        listBox1.Items.Add(r.MovieName.ToString() + ":" + Math.Round(r.AvgRating, 2).ToString());
                    }
                }
            }
            else
            {
                listBox1.Items.Add("**Error, N cannot be negative**");
            }
            textBox8.Text = "";
        }
        //
        // File>>Load Stations:
        //
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            //
            // clear the UI of any current results:
            //
            ClearStationUI(true /*clear stations*/);

            try
            {
                BusinessTier.Business bizTier;
                bizTier = new BusinessTier.Business(this.txtDatabaseFilename.Text);

                var stations = bizTier.GetStations();

                foreach (CTAStation station in stations)
                {
                    this.lstStations.Items.Add(station.Name);
                }
                this.toolStripStatusLabel1.Text = string.Format("Number of station: {0:#,##0}", stations.Count);
            }
            catch (Exception ex)
            {
                string msg = string.Format("Error: '{0}'.", ex.Message);
                MessageBox.Show(msg);
            }
            finally
            {
            }
        }
示例#3
0
        private void cmdARMN_Click(object sender, EventArgs e) // Average Rating by Movie Name - done.
        {
            string mname = (string)textBox6.Text;

            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            Reviews review;

            review = businesstier.GetReviewsforAverage(mname);
            if (review == null)
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add("Movie not found...");
            }
            else
            {
                double avg_rate = review.AvgRating;
                string art      = Convert.ToString(Math.Round(avg_rate, 2));
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add("Average Rating for " + mname + " is: " + art);
            }
            textBox6.Text = "";
        }
示例#4
0
        private void button6_Click(object sender, EventArgs e) // Top-n Reviewed Movies - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            Movies m;
            int    N = Convert.ToInt32(textBox10.Text);

            if (N > 0)
            {
                m = businesstier.GetTopMoviesByNumReviews(N);
                if (m == null)
                {
                    listBox1.Items.Add("**Error, or database is empty?!");
                }
                else
                {
                    listBox1.Items.Add("S U C C E S S");
                    listBox1.Items.Add("");
                    listBox1.Items.Add("The top " + N + " reviewed movies in the database are: ");
                    listBox1.Items.Add("");
                    foreach (Movie r in m)
                    {
                        listBox1.Items.Add(r.MovieID.ToString() + ":" + r.NumReviews.ToString());
                    }
                }
            }
            else
            {
                listBox1.Items.Add("**Error, N cannot be negative**");
            }
            textBox10.Text = "";
        }
示例#5
0
        private void cmdARName_Click(object sender, EventArgs e) // Add review by name.
                                                                 //User ID can be of maximum 7 digits and
                                                                 //cannot be a string/mix of characters and numbers. - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            string usrid = (string)textBox3.Text;
            string mname = (string)textBox5.Text;
            int    rate  = (int)numericUpDown1.Value;

            if (businesstier.AddReview(mname, Convert.ToInt32(usrid), rate))
            {
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add("Review for " + mname + " is added to the database");
            }
            else
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add("Review for " + mname + " cannot be added to the database");
            }
            textBox3.Text = "";
            textBox5.Text = "";
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //
            // setup GUI:
            //
            this.lstStations.Items.Add("");
            this.lstStations.Items.Add("[ Use File>>Load to display L stations... ]");
            this.lstStations.Items.Add("");

            this.lstStations.ClearSelected();

            toolStripStatusLabel1.Text = string.Format("Number of stations:  0");

            try
            {
                string filename = this.txtDatabaseFilename.Text;
                BusinessTier.Business bizTier;
                bizTier = new BusinessTier.Business(filename);

                bizTier.TestConnection();
            }
            catch
            {
                //
                // ignore any exception that occurs, goal is just to startup
                //
            }
            finally
            {
            }
        }
示例#7
0
        private void button7_Click(object sender, EventArgs e) // Get Reviews by Movie ID - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            int     mov_id = Convert.ToInt32(textBox11.Text);
            Reviews review;

            review = businesstier.GetReviews(mov_id);
            if (review == null)
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add("Movie not found...");
            }
            else
            {
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add("The Reviews for Movie with MovieID " + mov_id + " are: ");
                listBox1.Items.Add("");
                foreach (Review r in review)
                {
                    listBox1.Items.Add(r.UserID.ToString() + ":" + r.Rating.ToString());
                }
            }
            textBox11.Text = "";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //
            // clear the UI of any current results:
            //
            //        ClearFindUI(true /*clear stations*/);

            try
            {
                BusinessTier.Business bizTier;
                bizTier = new BusinessTier.Business(this.txtDatabaseFilename.Text);

                string name  = this.textBox1.Text;
                var    lines = bizTier.findStations(name);

                foreach (var line in lines)
                {
                    this.listBox1.Items.Add(line);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("Error: '{0}'.", ex.Message);
                MessageBox.Show(msg);
            }
            finally
            {
            }
        }
示例#9
0
        private void Connect_Click(object sender, EventArgs e)
        {
            this.lstMovies.Items.Clear();

            this.lstMovies.Items.Clear();
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            string dbfilename2            = this.txtDatabase.Text;

            BusinessTier.Business users = new BusinessTier.Business(dbfilename2);

            foreach (BusinessTier.Movie movies in biztier.GetAllMovies())
            {
                this.lstMovies.Items.Add(string.Format("{0}", movies.MovieName));
            }


            foreach (BusinessTier.Movie movies in biztier.GetAllMovies())
            {
                this.movieBox.Items.Add(string.Format("{0}", movies.MovieName));
            }

            foreach (BusinessTier.User i in users.GetAllNamedUsers())
            {
                this.namebox.Items.Add(string.Format("{0}", i.UserName));
            }



            //  movieBox.SelectedIndex = 0;
            //   namebox.SelectedIndex = 0;
        }
示例#10
0
        private void cmdERMN_Click(object sender, EventArgs e) // Each Rating by Movie Name - Done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            string  mname = (string)textBox7.Text;
            int     total = 0;
            Reviews review;

            review = businesstier.GetReviews(mname);
            if (review == null)
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add("Movie not found...");
            }
            else
            {
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add("Each Rating for " + mname + " are: ");
                listBox1.Items.Add("");
                foreach (Review r in review)
                {
                    listBox1.Items.Add(r.Rating.ToString() + ":" + r.RatingCount.ToString());
                    total = total + r.RatingCount;
                }
                listBox1.Items.Add("Total: " + total.ToString());
            }
            textBox7.Text = "";
        }
示例#11
0
        private void button5_Click(object sender, EventArgs e) // Top-N Prolific Users - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            Users u;
            int   N = Convert.ToInt32(textBox9.Text);

            if (N > 0)
            {
                u = businesstier.GetTopUsersByNumReviews(N);
                if (u == null)
                {
                    listBox1.Items.Add("**Error, or database is empty?!");
                }
                else
                {
                    listBox1.Items.Add("S U C C E S S");
                    listBox1.Items.Add("");
                    listBox1.Items.Add("The top " + N + " Prolific users in the database are: ");
                    listBox1.Items.Add("");
                    foreach (User r in u)
                    {
                        listBox1.Items.Add(r.UserID.ToString() + ":" + r.NumReviews.ToString());
                    }
                }
            }
            else
            {
                listBox1.Items.Add("**Error, N cannot be negative**");
            }
            textBox9.Text = "";
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string stop = this.lstStops.Text;

            BusinessTier.Business bizTier;
            bizTier = new BusinessTier.Business(this.txtDatabaseFilename.Text);

            this.txtAccessible.Text = bizTier.updateHandicap(stop).ToString();
        }
示例#13
0
        private void userButton_Click(object sender, EventArgs e)
        {
            this.lstMovies.Items.Clear();
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business users = new BusinessTier.Business(dbfilename);

            foreach (BusinessTier.User i in users.GetAllNamedUsers())
            {
                this.lstMovies.Items.Add(string.Format("{0}", i.UserName));
            }
        }
示例#14
0
        private void button3_Click(object sender, EventArgs e)//Delete by ID. - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            int    mov_id = Convert.ToInt32(textBox4.Text);
            object m      = businesstier.deleteMovie(mov_id);

            listBox1.Items.Add("S U C C E S S");
            listBox1.Items.Add("");
            listBox1.Items.Add("Movie ID " + mov_id + " is deleted...");
            textBox4.Text = "";
        }
示例#15
0
        private void cmdDB_Click(object sender, EventArgs e)// Database Test Connection - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            string db_source = textBox12.Text;

            businesstier = new BusinessTier.Business("Data Source=" + db_source);
            if (businesstier.TestConnection())
            {
                listBox1.Items.Add("Connection is good and using " + db_source);
            }
            else
            {
                listBox1.Items.Add("Connection is not good and using " + db_source);
            }
        }
示例#16
0
        private void topNAvg_Click(object sender, EventArgs e)
        {
            this.secondBox.Items.Clear();
            int    Nth        = Convert.ToInt32(topN.Text);
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.movieBox.Text);


            var list = (List <Movie>)biztier.GetTopMoviesByAvgRating(Nth);


            foreach (var i in list)
            {
                secondBox.Items.Add(string.Format("{0}: {1}", i.MovieName, (biztier.GetMovieDetail(i.MovieID).AvgRating)));
            }
        }
示例#17
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.lstMovies.Items.Clear();
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);

            foreach (BusinessTier.Movie movies in biztier.GetAllMovies())
            {
                this.lstMovies.Items.Add(string.Format("{0}", movies.MovieName));
            }


            foreach (BusinessTier.Movie movies in biztier.GetAllMovies())
            {
                this.lstMovies.Items.Add(string.Format("{0}", movies.MovieName));
            }
        }
示例#18
0
        private void lstMovies_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.txtMovieID.Items.Clear();
            this.movieRating.Items.Clear();
            this.userID.Items.Clear();
            this.occupation.Items.Clear();
            this.secondBox.Items.Clear();

            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.User     user    = biztier.GetNamedUser(this.lstMovies.Text);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.lstMovies.Text);

            if (user == null)
            {
                this.txtMovieID.Items.Add(string.Format("{0}", movie.MovieID));
                var details = biztier.GetMovieDetail(movie.MovieID);
                this.movieRating.Items.Add(string.Format("{0}", details.AvgRating));


                BusinessTier.MovieDetail detail = biztier.GetMovieDetail(movie.MovieID);

                foreach (BusinessTier.Review i in detail.Reviews)
                {
                    this.secondBox.Items.Add(string.Format("{0}: {1}", i.UserID, i.Rating));
                }
            }

            if (movie == null)
            {
                this.userID.Items.Add(string.Format("{0}", user.UserID));
                this.occupation.Items.Add(string.Format("{0}", user.Occupation));

                BusinessTier.UserDetail detail = biztier.GetUserDetail(user.UserID);
                foreach (BusinessTier.Review i in detail.Reviews)
                {
                    var movieName = biztier.GetMovie(i.MovieID);
                    this.secondBox.Items.Add(string.Format("{0}-> {1}", movieName.MovieName, i.Rating));
                }
            }
        }
示例#19
0
        private void cmdAddMovie_Click(object sender, EventArgs e)// Add movie by Name - done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            string mov_name = (string)addMovieTextBox.Text;

            if (businesstier.AddMovie(mov_name))
            {
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add(mov_name + " is added to the database");
            }
            else
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add(mov_name + " cannot be added to the database");
            }
            addMovieTextBox.Text = "";
        }
示例#20
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            // string username = this.namebox.Text;
            string rate       = this.comboBox1.Text;
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.movieBox.Text);
            BusinessTier.User     user    = biztier.GetNamedUser(this.namebox.Text);


            if (movie != null && user != null && (Convert.ToInt32(rate)) <= 5 && (Convert.ToInt32(rate)) > 0)
            {
                biztier.AddReview(Convert.ToInt32(movie.MovieID), Convert.ToInt32(user.UserID), Convert.ToInt32(rate));
            }

            else
            {
                MessageBox.Show("invalid input");
            }
        }
示例#21
0
        private void button2_Click(object sender, EventArgs e)//Search by Name - Done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            string mov_name = textBox2.Text;
            Movie  m        = businesstier.GetMovie(mov_name);

            if (m == null)
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add("MovieID not found...");
            }
            else
            {
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add("ID for " + mov_name + " is -->" + m.MovieID);
            }
            textBox2.Text = "";
        }
示例#22
0
        private void button1_Click(object sender, EventArgs e)// Search by ID - Done
        {
            listBox1.Items.Clear();
            BusinessTier.Business businesstier;
            businesstier = new BusinessTier.Business("Data Source=" + textBox12.Text);
            int   movid = int.Parse((string)textBox1.Text);
            Movie m     = businesstier.GetMovie(movid);

            if (m == null)
            {
                listBox1.Items.Add("F A I L U R E");
                listBox1.Items.Add("");
                listBox1.Items.Add("Movie not found...");
            }
            else
            {
                listBox1.Items.Add("S U C C E S S");
                listBox1.Items.Add("");
                listBox1.Items.Add("MovieID " + movid + " is -->" + m.MovieName);
            }
            textBox1.Text = "";
        }
        ///
        /// <summary>
        /// Returns all the crime codes and their descriptions.
        /// </summary>
        /// <returns>List of CrimeCode objects</returns>
        ///
        public List <CrimeCode> GetCrimeCodes()
        {
            List <CrimeCode> codes = new List <CrimeCode>();
            Business         bus   = new Business("|DataDirectory|\\CrimeDB.mdf");

            //
            // TODO!
            //
            string  sql    = @"
SELECT * FROM Codes 
ORDER BY IUCR;
";
            DataSet result = dataTier.ExecuteNonScalarQuery(sql);

            foreach (DataRow row in result.Tables["TABLE"].Rows)
            {
                CrimeCode c;
                c = new CrimeCode(Convert.ToString(row["IUCR"]), Convert.ToString(row["PrimaryDesc"]), Convert.ToString(row["SecondaryDesc"]));
                codes.Add(c);
            }


            return(codes);
        }
        ///
        /// <summary>
        /// Returns a hash table of areas, and total crimes each area.
        /// </summary>
        /// <returns>Dictionary where area # is the key, and total crimes is the value</returns>
        ///
        public Dictionary <int, long> GetTotalsByArea()
        {
            Dictionary <int, long> totalsByArea = new Dictionary <int, long>();
            Business bus = new Business("|DataDirectory|\\CrimeDB.mdf");
            //
            // TODO!
            //
            string sql = @"
Select Area, Count(*) As Total
From Crimes
Where Area > 0
Group By Area
Order By Area ASC;
";


            DataSet result = dataTier.ExecuteNonScalarQuery(sql);

            foreach (DataRow row in result.Tables["TABLE"].Rows)
            {
                totalsByArea.Add(Convert.ToInt32(row["Area"]), Convert.ToInt64(row["Total"]));
            }
            return(totalsByArea);
        }
示例#25
0
        private void eachRating_Click(object sender, EventArgs e)
        {
            this.secondBox.Items.Clear();
            string dbfilename = this.txtDatabase.Text;

            BusinessTier.Business biztier = new BusinessTier.Business(dbfilename);
            BusinessTier.User     user    = biztier.GetNamedUser(this.lstMovies.Text);
            BusinessTier.Movie    movie   = biztier.GetMovie(this.lstMovies.Text);



            if (user == null)
            {
                var           bb      = biztier.GetMovieDetail(biztier.GetMovie(Convert.ToInt32(movie.MovieID)).MovieID).Reviews;
                List <Review> ListRev = new List <Review>();
                foreach (var f in bb)
                {
                    ListRev.Add(f);
                }

                int one = 0, two = 0, three = 0, four = 0, five = 0;

                foreach (var b in ListRev)
                {
                    if (b.Rating == 1)
                    {
                        one++;
                    }

                    if (b.Rating == 2)
                    {
                        two++;
                    }

                    if (b.Rating == 3)
                    {
                        three++;
                    }

                    if (b.Rating == 4)
                    {
                        four++;
                    }

                    if (b.Rating == 5)
                    {
                        five++;
                    }
                }

                int totel = one + two + three + four + five;
                secondBox.Items.Add(string.Format("{0}", movie.MovieName));
                secondBox.Items.Add(string.Format(" "));
                secondBox.Items.Add(string.Format("5: {0}", five));
                secondBox.Items.Add(string.Format("4: {0}", four));
                secondBox.Items.Add(string.Format("3: {0}", three));
                secondBox.Items.Add(string.Format("2: {0}", two));
                secondBox.Items.Add(string.Format("1: {0}", one));
                secondBox.Items.Add(string.Format("Totel: {0}", totel));
            }

            else
            {
                MessageBox.Show("Please select a Movie from the movie list");
            }
        }
        //
        // user has clicked on a stop for more info:
        //
        private void lstStops_SelectedIndexChanged(object sender, EventArgs e)
        {
            // sometimes this event fires, but nothing is selected...
            if (this.lstStops.SelectedIndex < 0)   // so return now in this case:
            {
                return;
            }

            //
            // clear GUI in case this fails:
            //
            ClearStopUI();

            //
            // now display info about this stop:
            //
            string stopName = this.lstStops.Text;

            stopName = stopName.Replace("'", "''");

            SqlConnection db = null;

            try
            {
                db = new SqlConnection(BuildConnectionString());
                db.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = db;

                //
                // Let's get some info about the stop:
                //
                // NOTE: we want to use station id, not stop name,
                // because stop name is not unique.  Example: the
                // stop "Damen (Loop-bound)".s
                //
                string sql = string.Format(@"
SELECT StopID, Direction, ADA, Latitude, Longitude
FROM Stops
WHERE Name = '{0}' AND
      StationID = {1};
", stopName, this.txtStationID.Text);

                //MessageBox.Show(sql);

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataSet        ds      = new DataSet();

                cmd.CommandText = sql;
                adapter.Fill(ds);

                System.Diagnostics.Debug.Assert(ds.Tables["TABLE"].Rows.Count == 1);
                DataRow R = ds.Tables["TABLE"].Rows[0];


                BusinessTier.Business bizTier;
                bizTier = new BusinessTier.Business(this.txtDatabaseFilename.Text);

                // handicap accessible?
                this.txtAccessible.Text = bizTier.getHandicapInfo(stopName).ToString();

                // direction of travel:
                this.txtDirection.Text = bizTier.getDirection(stopName).ToString();

                // lat/long position:
                this.txtLocation.Text = bizTier.getLocation(stopName).ToString();

                //
                // now we need to know what lines are associated
                // with this stop:
                //
                int stopID = Convert.ToInt32(R["StopID"]);

                sql = string.Format(@"
SELECT Color
FROM Lines
INNER JOIN StopDetails ON Lines.LineID = StopDetails.LineID
INNER JOIN Stops ON StopDetails.StopID = Stops.StopID
WHERE Stops.StopID = {0}
ORDER BY Color ASC;
", stopID);

                //MessageBox.Show(sql);

                ds.Clear();

                cmd.CommandText = sql;
                adapter.Fill(ds);

                // lines for each stop:
                var stops = bizTier.getLines(stopName);

                foreach (var stop in stops)
                {
                    this.lstLines.Items.Add(stop);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("Error: '{0}'.", ex.Message);
                MessageBox.Show(msg);
            }
            finally
            {
                if (db != null && db.State == ConnectionState.Open)
                {
                    db.Close();
                }
            }
        }
        //
        // User has clicked on a station for more info:
        //
        private void lstStations_SelectedIndexChanged(object sender, EventArgs e)
        {
            // sometimes this event fires, but nothing is selected...
            if (this.lstStations.SelectedIndex < 0)   // so return now in this case:
            {
                return;
            }

            //
            // clear GUI in case this fails:
            //
            ClearStationUI();

            //
            // now display info about selected station:
            //
            string stationName = this.lstStations.Text;

            stationName = stationName.Replace("'", "''");

            SqlConnection db = null;

            try
            {
                db = new SqlConnection(BuildConnectionString());
                db.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = db;

                //
                // We need total overall ridership for %:
                //
                string sql = string.Format(@"
SELECT Sum(Convert(bigint,DailyTotal)) As TotalOverall
FROM Riderships;
");

                //MessageBox.Show(sql);

                cmd.CommandText = sql;
                object result       = cmd.ExecuteScalar();
                long   totalOverall = Convert.ToInt64(result);

                //
                // now we need total and avg for this station:
                //
                sql = string.Format(@"
SELECT Sum(DailyTotal) As TotalRiders, 
       Avg(DailyTotal) As AvgRiders
FROM Riderships
INNER JOIN Stations ON Riderships.StationID = Stations.StationID
WHERE Name = '{0}';
", stationName);

                //MessageBox.Show(sql);

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataSet        ds      = new DataSet();

                cmd.CommandText = sql;
                adapter.Fill(ds);

                System.Diagnostics.Debug.Assert(ds.Tables["TABLE"].Rows.Count == 1);
                DataRow R = ds.Tables["TABLE"].Rows[0];

                int    stationTotal = Convert.ToInt32(R["TotalRiders"]);
                double stationAvg   = Convert.ToDouble(R["AvgRiders"]);
                double percentage   = ((double)stationTotal) / totalOverall * 100.0;


                BusinessTier.Business bizTier;
                bizTier = new BusinessTier.Business(this.txtDatabaseFilename.Text);

                this.txtTotalRidership.Text    = bizTier.getTotalRidership(stationName).ToString("#,##0");
                this.txtAvgDailyRidership.Text = bizTier.getAvgRidership(stationName).ToString("#,##0/day");
                this.txtPercentRidership.Text  = bizTier.getPercentage(stationName).ToString("0.00%");

                //
                // now ridership values for Weekday, Saturday, and
                // sunday/holiday:
                //
                sql = string.Format(@"
SELECT Riderships.StationID, TypeOfDay, Sum(DailyTotal) AS Total
FROM Stations
INNER JOIN Riderships
ON Stations.StationID = Riderships.StationID
WHERE Name = '{0}'
GROUP BY Riderships.TypeOfDay, Riderships.StationID
ORDER BY Riderships.TypeOfDay;
", stationName);

                //MessageBox.Show(sql);

                ds.Clear();

                cmd.CommandText = sql;
                adapter.Fill(ds);

                //
                // we should get back 3 rows:
                //   row 0:  "A" for saturday
                //   row 1:  "U" for sunday/holiday
                //   row 2:  "W" for weekday
                //
                System.Diagnostics.Debug.Assert(ds.Tables["TABLE"].Rows.Count == 3);

                DataRow R1 = ds.Tables["TABLE"].Rows[0];
                DataRow R2 = ds.Tables["TABLE"].Rows[1];
                DataRow R3 = ds.Tables["TABLE"].Rows[2];

                int stationID = Convert.ToInt32(R1["StationID"]);  // all rows have same station ID:

                this.txtStationID.Text              = bizTier.getStationID(stationName).ToString();
                this.txtWeekdayRidership.Text       = bizTier.getWeekdayRidership(stationName).ToString("#,##0");
                this.txtSaturdayRidership.Text      = bizTier.getSaturdayRidership(stationName).ToString("#,##0");
                this.txtSundayHolidayRidership.Text = bizTier.getSundayRidership(stationName).ToString("#,##0");

                //
                // finally, what stops do we have at this station?
                //
                ds.Clear();

                var stops = bizTier.GetStops(stationID);

                foreach (CTAStop stop in stops)
                {
                    this.lstStops.Items.Add(stop.Name);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("Error: '{0}'.", ex.Message);
                MessageBox.Show(msg);
            }
            finally
            {
                if (db != null && db.State == ConnectionState.Open)
                {
                    db.Close();
                }
            }
        }