private void addEditButton_Click(object sender, RoutedEventArgs e)
        {
            int tmp = Convert.ToInt32(this.Tag);
            if (addEditButton.Content == "Add")
            {
                if (mw.newsClassList.Count >= 1)
                {
                    newsClass nC = new newsClass(mw.newsClassList[mw.newsClassList.Count - 1].getId() + 1, name.Text, text.Text);
                    mw.newsClassList.Add(nC);
                    dbConn.WriteData("INSERT INTO News (ID, Title, Text, Date) VALUES (" + (mw.newsClassList[mw.newsClassList.Count - 1].getId() + 1) + ", '" + name.Text + "', '" + text.Text + "', '" + DateTime.Now + "')");
                    MessageBox.Show("Succesfuly added.", "News additing", MessageBoxButton.OK, MessageBoxImage.Information);
                    mw.startPageButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                    mw.testButton2.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                }
                else if (mw.newsClassList.Count == 0)
                {
                    newsClass nC = new newsClass(1, name.Text, text.Text);
                    mw.newsClassList.Add(nC);
                    dbConn.WriteData("INSERT INTO News (ID, Title, Text, Date) VALUES (" + 1 + ", '" + name.Text + "', '" + text.Text + "', '" + DateTime.Now + "')");
                    MessageBox.Show("Succesfuly added.", "News additing", MessageBoxButton.OK, MessageBoxImage.Information);
                    mw.startPageButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                    mw.testButton2.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                }


            }
            else if(addEditButton.Content == "Edit")
            {
                mw.newsList[tmp].newsName.Content = name.Text;
                mw.newsList[tmp].newsName.Content = text.Text;

                mw.newsClassList[tmp].setName(name.Text);
                mw.newsClassList[tmp].setText(text.Text);

                dbConn.WriteData("UPDATE News SET Title = '"+ name.Text +"', Text = '"+ text.Text +"' WHERE ID = " + mw.newsClassList[tmp].getId());
                MessageBox.Show("Succesfuly edited.", "News editing", MessageBoxButton.OK, MessageBoxImage.Information);
                mw.startPageButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                mw.testButton2.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
            }
        }
Example #2
0
        //////////////////////////////////////////////////////////////////////////////////////////Buttons
        private void startPageButton_Click(object sender, RoutedEventArgs e)
        {
            homePage.Children.Clear();
            hideOrUnhideAll(1);

            newsClassList.Clear();
            List<string> ID_News = dbConn.ReadData("select ID from News");
            List<string> Title_News = dbConn.ReadData("select Title from News");
            List<string> Text_News = dbConn.ReadData("select Text from News");
            List<string> Date_News = dbConn.ReadData("select Date from News");

            for (int i = 0; i < ID_News.Count; i++)
            {
                newsClass nC = new newsClass(Convert.ToInt32(ID_News[i]), Title_News[i], Text_News[i], Date_News[i]);
                newsClassList.Add(nC);
            }

            drawNews();
        }