Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Model.Stories stories = Model.MyDatabase.getStories();
            string        list    = "";

            foreach (var story in stories.getStories())
            {
                list += story.idt + ": " + story.name + "\n";
                foreach (var chap in story.getChapters())
                {
                    list += "    " + chap.idh + ": " + chap.name + " - " + chap.content + "\n";
                }
            }
            label1.Text = list;
        }
Esempio n. 2
0
        public static Stories getStories()
        {
            Stories stories = null;

            using (SqlConnection con = new SqlConnection(STR_CONNECT))
            {
                string     queryStory = "SELECT * FROM tbl_story";
                SqlCommand cmdStory   = new SqlCommand(queryStory, con);
                con.Open();
                using (SqlDataReader reader = cmdStory.ExecuteReader())
                {
                    stories = new Stories();
                    Story story;
                    while (reader.Read())
                    {
                        story      = new Story();
                        story.idt  = Int32.Parse(reader["id_story"].ToString());
                        story.name = reader["name"].ToString();
                        string     queryChap = "SELECT * FROM tbl_chap WHERE id_story = " + story.idt;
                        SqlCommand cmdChap   = new SqlCommand(queryChap, con);
                        using (SqlDataReader readchap = cmdChap.ExecuteReader())
                        {
                            Chapter chap;
                            while (readchap.Read())
                            {
                                chap         = new Chapter();
                                chap.idh     = Int32.Parse(readchap["id_chap"].ToString());
                                chap.name    = readchap["name"].ToString();
                                chap.content = readchap["contentchap"].ToString();
                                story.addChapter(chap);
                            }
                        }
                        stories.addStory(story);
                    }
                }
            }

            return(stories);
        }