Beispiel #1
0
        //上传type
        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定上传目录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                MySqlConnection mySqlConnection = MysqlConn.getConn();
                MySqlCommand    mySqlCommand;
                String          sql;
                try
                {
                    mySqlConnection.Open();
                    for (int i = 0; i < dictionaryList.Count; i++)
                    {
                        sql          = "insert into t_type(name) values('" + dictionaryList[i].Name + "');";
                        mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                        if (mySqlCommand.ExecuteNonQuery() > 0)
                        {
                        }
                    }
                    MessageBox.Show("上传成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("上传失败:" + ex.Message);
                }
                finally
                {
                    MysqlConn.closeConn();
                }
            }
        }
Beispiel #2
0
        //清空blog数据表
        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定清空?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                MySqlConnection mySqlConnection = MysqlConn.getConn();
                MySqlCommand    mySqlCommand;
                String          sql;
                try
                {
                    mySqlConnection.Open();
                    sql          = "SET FOREIGN_KEY_CHECKS=0";
                    mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                    mySqlCommand.ExecuteNonQuery();
                    sql          = "truncate table t_blog";
                    mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                    mySqlCommand.ExecuteNonQuery();
                    sql          = "SET FOREIGN_KEY_CHECKS=1";
                    mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                    mySqlCommand.ExecuteNonQuery();
                    MessageBox.Show("数据已经清除!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("清空失败:" + ex.Message);
                }
                finally
                {
                    MysqlConn.closeConn();
                }
            }
        }
Beispiel #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            MySqlConnection mySqlConnectionRead = MysqlConn.getConnRead();
            MySqlCommand    mySqlCommand;
            String          sql;

            try
            {
                if (textBox3.Text != "")
                {
                    Convert.ToInt32(textBox3.Text);
                    sql = "select title,create_time,t.name from t_blog b,t_type t where b.type_id = t.id and b.id=" + textBox3.Text;
                }
                else
                {
                    sql = "select title,create_time,t.name from t_blog b,t_type t where b.type_id = t.id;";
                }
                mySqlCommand = new MySqlCommand(sql, mySqlConnectionRead);
                mySqlConnectionRead.Open();

                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();

                while (mySqlDataReader.Read())
                {
                    for (int i = 0; i <= 2; i++)
                    {
                        textBox2.Text += mySqlDataReader.GetString(i);
                        textBox2.Text += "  ";
                    }
                    textBox2.Text += "\r\n";
                }
            }
            catch (Exception ex)
            {
                textBox2.Text += "The data does not exists:" + ex.Message;
                textBox2.Text += "\r\n";
            }
            finally
            {
                MysqlConn.closeConnRead();
            }
        }
Beispiel #4
0
        //上传blog数据表
        private void button5_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定上传blog?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                MySqlConnection mySqlConnection     = MysqlConn.getConn();
                MySqlConnection mySqlConnectionRead = MysqlConn.getConnRead();
                MySqlCommand    mySqlCommand;
                MySqlDataReader mySqlDataReader;
                String          sql;
                int             type_id;
                try
                {
                    mySqlConnection.Open();
                    for (int i = 0; i < fileNameList.Count; i++)
                    {
                        mySqlConnectionRead.Open();
                        sql             = "select id from t_type where name='" + fileNameList[i].FatherDictionary + "'";
                        mySqlCommand    = new MySqlCommand(sql, mySqlConnectionRead);
                        mySqlDataReader = mySqlCommand.ExecuteReader();
                        mySqlDataReader.Read();
                        type_id = mySqlDataReader.GetInt32(0);
                        MysqlConn.closeConnRead();

                        sql = "insert into t_blog(create_time,update_time, content, title,user_id,type_id,  description) " +
                              "VALUES (@Createtime,@Updatetime,@Content,@Title,1,@Type_id,@Description);";
                        mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                        mySqlCommand.Prepare();

                        MySqlParameter p1 = new MySqlParameter("@Createtime", MySqlDbType.DateTime);
                        p1.Value = fileNameList[i].Createtime;
                        MySqlParameter p2 = new MySqlParameter("@Content", MySqlDbType.LongText);
                        p2.Value = fileNameList[i].Content;
                        MySqlParameter p3 = new MySqlParameter("@Title", MySqlDbType.VarChar);
                        p3.Value = fileNameList[i].Title;
                        MySqlParameter p4 = new MySqlParameter("@Type_id", MySqlDbType.Int64);
                        p4.Value = type_id;
                        MySqlParameter p5 = new MySqlParameter("@Description", MySqlDbType.VarChar);
                        MySqlParameter p6 = new MySqlParameter("@Updatetime", MySqlDbType.DateTime);
                        p6.Value = fileNameList[i].Updatetime;
                        p5.Value = fileNameList[i].Description;
                        mySqlCommand.Parameters.Add(p1);
                        mySqlCommand.Parameters.Add(p2);
                        mySqlCommand.Parameters.Add(p3);
                        mySqlCommand.Parameters.Add(p4);
                        mySqlCommand.Parameters.Add(p5);
                        mySqlCommand.Parameters.Add(p6);

                        if (mySqlCommand.ExecuteNonQuery() > 0)
                        {
                        }
                    }
                    MessageBox.Show("blog上传成功!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("上传失败:" + ex.Message);
                }
                finally
                {
                    MysqlConn.closeConn();
                }
            }
        }