Example #1
0
        /// <summary>
        /// 导入word文档
        /// </summary>
        /// <param name="tpj_name"></param>
        private void ImportWordFile(string tpj_name)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.RestoreDirectory = true;
            op.Filter           = "Word(*.doc)|*.doc";
            bool?b = op.ShowDialog();

            StringBuilder sqlStr = new StringBuilder();

            if (b == true)
            {
                MessageBoxResult result = MessageBox.Show("确定导入?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    byte[] file = wordConvertByte(op.FileName);
                    sqlStr.Append("select * from PC_XTPJ_REPORT where MC = '" + tpj_name + "'");
                    bool isExist = DbHelperOleDb.ExecuteReader(sqlStr.ToString()).HasRows;
                    sqlStr.Clear();
                    if (isExist)
                    {
                        sqlStr.Append("Delete from PC_XTPJ_REPORT where MC = '" + tpj_name + "'");
                        DbHelperOleDb.ExecuteSql(sqlStr.ToString());
                        sqlStr.Clear();
                    }
                    sqlStr.Append("INSERT INTO PC_XTPJ_REPORT (MC,XNBG) VALUES ('" + tpj_name + "',@XNBG)");
                    DbHelperOleDb.ExecuteSqlInsertImg(sqlStr.ToString(), file);
                    MessageBox.Show("导入成功!");
                }
                else
                {
                    return;
                }
            }
        }