예제 #1
0
 public void AddNews(Newsarticle newsarticle)
 {
     con.Open();
     cmd             = con.CreateCommand();
     cmd.CommandText = "insert into tb_newsarticle(type,title,content,author,addtime) values(@type,@title,@content,@author,now())";
     cmd.Parameters.AddWithValue("@type", newsarticle.Typename);
     cmd.Parameters.AddWithValue("@title", newsarticle.Title);
     cmd.Parameters.AddWithValue("@content", newsarticle.Content);
     cmd.Parameters.AddWithValue("@author", newsarticle.Author);
     cmd.ExecuteNonQuery();
     con.Close();
 }
예제 #2
0
 public void UpdateNews(Newsarticle newsarticle)
 {
     con.Open();
     cmd             = con.CreateCommand();
     cmd.CommandText = "update tb_newsarticle set type=@typename,title=@title,content=@content,author=@author,addtime=now() where newsid=@newsid";
     cmd.Parameters.AddWithValue("@typename", newsarticle.Typename);
     cmd.Parameters.AddWithValue("@title", newsarticle.Title);
     cmd.Parameters.AddWithValue("@content", newsarticle.Content);
     cmd.Parameters.AddWithValue("@author", newsarticle.Author);
     cmd.Parameters.AddWithValue("@newsid", newsarticle.Newid);
     cmd.ExecuteNonQuery();
     con.Close();
 }
예제 #3
0
파일: Add.cs 프로젝트: yousaoqifaker/NEWS
        private void button1_Click(object sender, EventArgs e)
        {
            Newsarticle newsarticle = new Newsarticle();

            newsarticle.Title = textBox1.Text;
            //MessageBox.Show(comboBox1.SelectedIndex.ToString());
            //switch (comboBox1.SelectedIndex.ToString())
            //{
            //    case "1":
            //        newsarticle.Typename = "1";
            //        break;
            //    case "体育":
            //        newsarticle.Typename = "2";
            //        break;
            //    case "财经":
            //        newsarticle.Typename = "3";
            //        break;
            //    case "社会":
            //        newsarticle.Typename = "4";
            //        break;
            //    case "教育":
            //        newsarticle.Typename = "5";
            //        break;
            //    case "娱乐":
            //        newsarticle.Typename = "6";
            //        break;
            //    case "军事":
            //        newsarticle.Typename = "7";
            //        break;
            //    default:
            //        MessageBox.Show("请选择分类");
            //        break;
            //}
            newsarticle.Typename = comboBox1.SelectedIndex.ToString();
            newsarticle.Author   = textBox2.Text;
            newsarticle.Content  = richTextBox1.Text;

            if (i == 2)
            {
                newsarticle.Newid = news.Newid;
                db.UpdateNews(newsarticle);
            }
            else
            {
                db.AddNews(newsarticle);
            }
            this.Close();
        }
예제 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            var         dataselect = this.dataGridView1.SelectedRows;
            Newsarticle news       = new Newsarticle();

            //判断是否选中数据
            if (dataselect.Count > 0)
            {
                //遍历选中的数据
                foreach (DataGridViewRow row in dataselect)
                {
                    ////colunm命名为name的值
                    //String name2 = Convert.ToString(row.Cells["name"].Value);
                    ////colunm命名为name的值
                    //String code2 = Convert.ToString(row.Cells["code"].Value);
                    ////第一列数据的值
                    //String value0 = Convert.ToString(row.Cells[0].Value);
                    ////第二列数据的值转为int类型
                    //int value1 = Convert.ToInt32(row.Cells[1].Value.ToString());
                    news.Newid    = Convert.ToInt32(row.Cells[0].Value);
                    news.Title    = row.Cells[2].Value.ToString();
                    news.Typename = row.Cells[1].Value.ToString();
                    news.Content  = row.Cells[3].Value.ToString();
                    news.Author   = row.Cells[4].Value.ToString();
                }
                Add          a            = new Add(2, news);
                DialogResult dialogResult = a.ShowDialog();
                if (dialogResult == DialogResult.Cancel)
                {
                    DataSet adapter = db.GetNewsList(0);
                    dataGridView1.DataSource = adapter.Tables[0];
                    dataGridView1.ClearSelection();
                }
            }
            else
            {
                MessageBox.Show("请选择要修改的内容");
            }
        }
예제 #5
0
파일: Add.cs 프로젝트: yousaoqifaker/NEWS
 public Add(int i, Newsarticle news)
 {
     this.news = news;
     this.i    = i;
     InitializeComponent();
 }