Ejemplo n.º 1
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();
                }
            }
        }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
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();
                }
            }
        }