private void likeTipButton_Click(object sender, RoutedEventArgs e)
        {
            int index = tipGrid.SelectedIndex;

            if (index == -1)
            {
                index = 0;
            }

            UserTips tempTip = tipGrid.Items.GetItemAt(index) as UserTips;

            using (var connection = new NpgsqlConnection(buildConnectionString()))
            {
                connection.Open();
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandText = "UPDATE tip SET likes = likes + 1 WHERE tip_text = '" + tempTip.tipText + "';";
                    cmd.ExecuteNonQuery();
                }
                connection.Close();
            }

            tipGrid.Items.Remove(tempTip);
            tempTip.likes += 1;
            tipGrid.Items.Insert(index, tempTip);
        }
        private void addTips()
        {
            List <UserTips> tips = new List <UserTips>();

            tipGrid.Items.Clear();
            using (var connection = new NpgsqlConnection(buildConnectionString()))
            {
                connection.Open();
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandText = "SELECT tip.day, tip.month, tip.year, tip.hour, tip.minute, tip.second, tip.tip_text, tip.likes, users.name FROM tip, users " +
                                      "WHERE tip.business_id = '" + this.selectedBusiness.bid + "' and tip.user_id = users.user_id "; // ORDER BY tip.tipdate desc";

                    try
                    {
                        var reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            DateTime dat  = convertToDate(reader.GetInt32(2), reader.GetInt32(1), reader.GetInt32(0), reader.GetInt32(3), reader.GetInt32(4), reader.GetInt32(5));
                            var      data = new UserTips()
                            {
                                //day = reader.GetInt32(0),
                                //month = reader.GetInt32(1),
                                //year = reader.GetInt32(2),
                                //minute = reader.GetInt32(4), // 3 = hour
                                //hour = reader.GetInt32(3), // 5 = sec
                                //second = reader.GetInt32(5), // 4 = min
                                date      = dat,
                                tipText   = reader.GetString(6),
                                likes     = reader.GetInt32(7),
                                user_name = reader.GetString(8)
                            };
                            tips.Add(data);
                            // tipGrid.Items.Add(data);
                        }
                        tips.Sort((x, y) => y.date.CompareTo(x.date));
                        foreach (var tip in tips)
                        {
                            tipGrid.Items.Add(tip);
                        }
                    }
                    catch (NpgsqlException ex)
                    {
                        Console.WriteLine(ex.Message.ToString());
                        MessageBox.Show("SQL Error - " + ex.Message.ToString());
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
        }
        private void addTipButton_Click(object sender, RoutedEventArgs e)
        {
            if (currentUser.name == null)
            {
                MessageBox.Show("Select a user in 'User Information' before adding tips!");
            }
            else if (tipTextBox.Text.Length < 1)
            {
                MessageBox.Show("Must insert tip in 'Insert Tip' text box first!");
            }
            else
            {
                using (var connection = new NpgsqlConnection(buildConnectionString()))
                {
                    connection.Open();
                    using (var cmd = new NpgsqlCommand())
                    {
                        var te = new UserTips()
                        {
                            user_name = currentUser.name, likes = 0, tipText = tipTextBox.Text, day = DateTime.Now.Day, month = DateTime.Now.Month, year = DateTime.Now.Year, hour = DateTime.Now.Hour, minute = DateTime.Now.Minute, second = DateTime.Now.Second
                        };
                        cmd.Connection = connection;

                        cmd.CommandText = "INSERT INTO tip(user_id, business_id, tip_text, likes, day, month, year, hour, minute, second) VALUES('" +
                                          currentUser.userID + "', '" + selectedBusiness.bid + "',  '" + te.tipText + "', " + te.likes.ToString() + ",  " + te.day.ToString() +
                                          ", " + te.month.ToString() + ", " + te.year.ToString() + ", " + te.hour.ToString() + ", " + te.minute.ToString() + ", " + te.second.ToString() + ");";

                        try
                        {
                            cmd.ExecuteNonQuery();
                            te.date = new DateTime(te.year, te.month, te.day, te.hour, te.minute, te.second);
                            tipGrid.Items.Insert(0, te);
                        }
                        catch (NpgsqlException ex)
                        {
                            Console.WriteLine(ex.Message.ToString());
                            MessageBox.Show("SQL Error - " + ex.Message.ToString());
                        }
                        finally
                        {
                            connection.Close();
                        }
                    }
                }
                tipTextBox.Clear();
            }
        }