Ejemplo n.º 1
0
        private void show_Post(object sender, RoutedEventArgs e)
        {
            try
            {
                TestRepository repository = new TestRepository();
                Test_Post      data       = repository.GetPostData();

                if (data != null)
                {
                    System.Windows.MessageBox.Show("PostId: " + data.P_Id + "\nContent: " + data.Content + "\nPostTime: " + data.postTime + "\nShopName: " + data.S_Name);
                }
                else
                {
                    System.Windows.MessageBox.Show("No Post was found.");
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Ejemplo n.º 2
0
        public Test_Post GetPostData()
        {
            Test_Post item = null;

            try
            {
                string          connStr = new SqlConnect().getConnectString();
                MySqlConnection Conn    = new MySqlConnection(connStr);
                MySqlCommand    cmd     = Conn.CreateCommand();
                Conn.Open();

                cmd.CommandText = new SqlCommand().selectCmd("post");
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int    pId      = (int)reader["P_Id"];
                        string content  = (string)reader["P_Content"];
                        string posttime = (string)reader["P_PostTime"];
                        int    sId      = (int)reader["SId"];
                        string name     = (string)reader["SName"];

                        item = new Test_Post {
                            P_Id = pId, Content = content, postTime = posttime, S_Id = sId, S_Name = name
                        };
                        break;
                    }
                }
                Conn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(item);
        }