视频在线学习模块很多功能哦

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using System.IO;
using AxWMPLib;
using DBClenitHandle;
using DevExpress.XtraTab;
using DevExpress.XtraEditors;
using DIFautomaticTool.View.traning_model;

namespace DIFautomaticTool.View
{
    public partial class ctlDIFVideo : UserControl
    {
        public ctlDIFVideo()
        {
            InitializeComponent();
        }

        private void gridControlVideo_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                GridView gvi = sender as GridView;
                int _indexx1 = gridView1.FocusedRowHandle;
                string path = gridView1.GetRowCellValue(_indexx1, "COURSEPATH").ToString();
                string avi = ".avi";
                string pdf = ".pdf";
               
                   
              
                if (path.Contains(pdf))
                {
                    FileInfo file = new FileInfo(path);
                    file.Attributes = FileAttributes.ReadOnly;
                    // System.Diagnostics.Process.Start(sp2);
                    DXPdfView PDF = new DXPdfView(path);
                    PDF.Show();
                }
                else
                {
                    DirectoryInfo thefolder = new DirectoryInfo(path);
                    List<string> filelist = new List<string>();
                    filelist.AddRange(Directory.GetFiles(thefolder.FullName, "*.avi").ToList());
                    List<string> listvideo = new List<string>();
                    foreach (string item in filelist)
                    {
                        listvideo.Add(item.Replace(path, ""));
                    }
                    listBoxControlvideoSelect.Items.Clear();
                    listBoxControlvideoSelect.Items.AddRange(listvideo.ToArray());
                    AxWindowsMediaPlayer player = new AxWindowsMediaPlayer();
                    player.Name = "player";
                    xtraTabPageVideo.Controls.Add(player);
                    player.Dock = DockStyle.Fill;
                }
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex.Message, "格式有错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
          
            
           

        }

        private void barButtonItemCMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where coursetype ='CMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemCMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where coursetype ='CMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemIMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where coursetype ='IMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemIMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where coursetype ='IMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemDIFEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where coursetype ='DIFEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemDIFPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where coursetype ='DIFPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemAllVisible_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                // string sql = "select * from dif_tool_course t where COURSEVISIBIILITY = ";
                string sql = string.Format(@"select * from dif_tool_course t where coursevisibiility ='AllVisible'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                string sql = string.Format(@"select courseleaccturer,
                                                   coursename,
                                                   coursepath
                                                   from dif_tool_course t where courseleaccturer like  '%" + this.barEditItemQVDIO.EditValue.ToString() + "%'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
               gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemUpload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //点击按钮后在XtraTag下从新生成新的界面
            string pageName = "UpdateDo";
            if (!TabCtlPageExist(pageName))
            {
                newUploadhaha ctl = new newUploadhaha();
                CreateTabCtlPage(pageName,ctl);
            }
        }
        

        private void ribbonControl1_Click(object sender, EventArgs e)
        {

        }

        private void barButtonItemUploadPPT_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string pageName = "UpdatePPT";
            if (!TabCtlPageExist(pageName))
            {
                ctlUploadPPT ctl = new ctlUploadPPT();
                CreateTabCtlPage(pageName,ctl);
            }
        }
#region 在Pagetab下显示新页面
        private bool   TabCtlPageExist(string pageName)
        {
            //生成新界面转换所需代码
            bool result = false;
            try
            {
                if (VideoXtraTab.TabPages.Count > 0)
                {
                    foreach (XtraTabPage xtabPage in VideoXtraTab.TabPages)
                    {
                        if (xtabPage.Name==pageName)
                        {
                            VideoXtraTab.SelectedTabPage = xtabPage;
                            result = true;
                            break;
                        }
                    }
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("[TabCtlPageExist( string pageName)] " + ex.Message + ex.StackTrace);
            }
            return result;
        }
        private void CreateTabCtlPage(string pageName, Control ctl)
        {
            //生成新界面转换所需代码
            try
            {
                XtraTabPage tabPagex = new XtraTabPage();
                tabPagex.Text = pageName;
                tabPagex.Name = pageName;
                VideoXtraTab.TabPages.Add(tabPagex);
                VideoXtraTab.SelectedTabPage = tabPagex;
                ctl.Dock = DockStyle.Fill;
                tabPagex.Controls.Add(ctl);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("[CreateTabCtlPage(string pageName,Control ctl)] " + ex.Message + ex.StackTrace);
            }
        }
        #endregion

        private void barButtonItemPPTCMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where coursetype ='CMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLCMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where courseleccturer ='CMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLCMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where courseleccturer ='CMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLIMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where courseleccturer ='IMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLIMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where courseleccturer ='IMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLDIFPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where courseleccturer ='DIFPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLDIFEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                //string sql = "select * from dif_tool_course t where COURSELEACCTURER like '%" + this.textEdit11.Text.ToString().Trim() + "% ';";
                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_course t where courseleccturer ='DIFEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemPPTCMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where coursetype ='CMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemPPTIMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where coursetype ='IMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemPPTIMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where coursetype ='IMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemPPTDIFEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where coursetype ='DIFEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemPPTDIFPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where coursetype ='DIFPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLPPTCMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where courseleaccturer ='CMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLPPTCMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where courseleaccturer ='CMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLPPTIMPPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where courseleaccturer ='IMPPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLPPTIMPEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where courseleaccturer ='IMPEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLPPTDIFPE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where courseleaccturer ='DIFPE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItemLPPTDIFEE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {

                string sql = string.Format(@"select COURSENAME,COURSEPATH,COURSELEACCTURER,CLASSTYPE from dif_tool_courseppt t where courseleaccturer ='DIFEE'");
                DataTable dt = MFDM10.DBGetSqlTable(sql);
                gridControlVideo.DataSource = dt;
                gridView1.BestFitColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBClenitHandle;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
using System.IO;
using DevExpress.XtraEditors;

namespace DIFautomaticTool.View.traning_model
{
    public partial class ctlUploadPPT : UserControl
    {
        public ctlUploadPPT()
        {
            InitializeComponent();
        }

        private void textEditPath_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void textEditPath_Click(object sender, EventArgs e)
        {

            //选择路径
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Multiselect = true;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        this.textEditPath.Text = dialog.FileName;
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                }
            }
        }

        private void simpleButtonUploadPPt_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(textEditName.Text))
                {
                    throw new Exception($"文件名不能为空!");

                }
                if (string.IsNullOrWhiteSpace(textEditPath.Text))
                {
                    throw new Exception($"文件路径不能为空!");
                }
                if (string.IsNullOrWhiteSpace(comboBoxEditCourseType.Text))
                {
                    throw new Exception($"课程类型不能为空!");
                }
                if (string.IsNullOrWhiteSpace(textEditLecturer.Text))
                {
                    throw new Exception($"课程讲师不能为空!");
                }
                if (string.IsNullOrWhiteSpace(textEditVisbility.Text))
                {
                    throw new Exception($"课程可见度不能为空!");
                }
                string sql = @"insert into dif_tool_courseppt(coursename,coursepath,courseleaccturer,videotemperature,coursetype)values('" + this.textEditName.Text.ToString() + "','"
                                                                      + this.textEditPath.Text.ToString() + "','"
                                                                      + this.textEditLecturer.Text.ToString() + "','"
                                                                      + this.textEditVisbility.Text.ToString() + "','"
                                                                      + this.comboBoxEditCourseType.Text.ToString() + "')";
                //DataTable dt = MFDM10.DBGetSqlTable(sql);
                
                string result = MFDM10.DBUpdate(sql);
                string sourthPathone = $@"{this.textEditPath.Text.ToString()}";
                string PDFpath =Path.GetDirectoryName(sourthPathone);//获取文件路径
                string PDFfilename = Path.GetFileName(sourthPathone);//获取文件名
                string pathone = @"Z:\training message ppt\";
                string xiegang = @"\";
                string type = $@"{this.comboBoxEditCourseType.Text.ToString()}";
                string sourthPathlast = $"{pathone}{type}{xiegang}{PDFfilename}.pdf";//目的路径文件
                string sourthPathTime = $"{Path.GetTempPath()}{PDFfilename}.pdf";//临时文件夹下的目标文件
                string ppt = ".ppt";
                string excel = ".xls";
                string world = ".doc";
                if (PDFfilename.Contains(ppt))//如果是ppt文件
                {
                    try
                    {
                        PPTConvertToPDF(sourthPathone, sourthPathlast);
                    //PPTConvertToPDF(sourthPathone, sourthPathTime);//将文件存入临时文件夹
                    // FileInfo file = new FileInfo(sourthPathTime);//将文件存到临时文件夹并打开
                    MessageBox.Show("转换成功");
                    FileInfo file = new FileInfo(sourthPathlast);
                    file.Attributes = FileAttributes.ReadOnly;
                    // System.Diagnostics.Process.Start(sp2);
                    DXPdfView PDF = new DXPdfView(sourthPathlast);
                    PDF.Show();
                    }
                    catch (Exception ex)
                    {

                        XtraMessageBox.Show(ex.Message, "对不起,转换失败! 请将格式改为.xls格式,如果还不可以请联系管理员!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    

                         
                            
                     }
                if (PDFfilename.Contains(excel))//如果是excel文件
                {
                    try
                    {
                        XLSConvertToPDF(sourthPathone,sourthPathlast);
                        success(sourthPathlast);
                    }
                    catch (Exception ex)
                    {

                        XtraMessageBox.Show(ex.Message, "对不起,转换失败! 请将格式改为.xls格式,如果还不可以请联系管理员!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (PDFfilename.Contains(world))//如果是world文件
                {
                    try
                    {
                        DOCConvertToPDF(sourthPathone,sourthPathlast);
                        success(sourthPathlast);
                    }
                    catch (Exception ex)
                    {

                        XtraMessageBox.Show(ex.Message, "对不起,转换失败! 请将格式改为.xls格式,如果还不可以请联系管理员!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex.Message,("添加失败请联系管理员"),MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }
        #region Word转换成pdf
        ///Word转换成pdf
        ///<summary>
        /// 把Word文件转换成为PDF格式文件
        ///</summary>
        ///<param name="sourcePath">源文件路径</param>
        ///<param name="targetPath">目标文件路径</param> 
        ///<returns>true=转换成功</returns>
        private bool DOCConvertToPDF(string sourcePath, string targetPath)
        {
            bool result = false;
            Word.WdExportFormat exportFormat = Word.WdExportFormat.wdExportFormatPDF;
            object paramMissing = Type.Missing;
            Word.ApplicationClass wordApplication = new Word.ApplicationClass();
            Word.Document wordDocument = null;
            try
            {
                object paramSourceDocPath = sourcePath;
                string paramExportFilePath = targetPath;
                Word.WdExportFormat paramExportFormat = exportFormat;
                bool paramOpenAfterExport = false;
                Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
                Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
                int paramStartPage = 0;
                int paramEndPage = 0;
                Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
                bool paramIncludeDocProps = true;
                bool paramKeepIRM = true;
                Word.WdExportCreateBookmarks paramCreateBookmarks = Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
                bool paramDocStructureTags = true;
                bool paramBitmapMissingFonts = true;
                bool paramUseISO19005_1 = false;
                wordDocument = wordApplication.Documents.Open(
                ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing);
                if (wordDocument != null)
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                    paramExportFormat, paramOpenAfterExport,
                    paramExportOptimizeFor, paramExportRange, paramStartPage,
                    paramEndPage, paramExportItem, paramIncludeDocProps,
                    paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                    paramBitmapMissingFonts, paramUseISO19005_1,
                    ref paramMissing);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordDocument = null;
                }
                if (wordApplication != null)
                {
                    wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordApplication = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return result;
        }
        #endregion
        #region 把Excel文件转换成PDF格式文件
        ///<summary>
        /// 把Excel文件转换成PDF格式文件
        ///</summary>
        ///<param name="sourcePath">源文件路径</param>
        ///<param name="targetPath">目标文件路径</param> 
        ///<returns>true=转换成功</returns>
        private bool XLSConvertToPDF(string sourcePath, string targetPath)
        {
            bool result = false;
            Excel.XlFixedFormatType targetType = Excel.XlFixedFormatType.xlTypePDF;
            object missing = Type.Missing;
            Excel.ApplicationClass application = null;
            Excel.Workbook workBook = null;
            try
            {
                application = new Excel.ApplicationClass();
                object target = targetPath;
                object type = targetType;
                workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
                        missing, missing, missing, missing, missing, missing, missing, missing, missing);
                workBook.ExportAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (workBook != null)
                {
                    workBook.Close(true, missing, missing);
                    workBook = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return result;
        }
        #endregion

#region 把PowerPoint文件转换成PDF格式文件
        ///<summary>
        /// 把PowerPoint文件转换成PDF格式文件
        ///</summary>
        ///<param name="sourcePath">源文件路径</param>
        ///<param name="targetPath">目标文件路径</param> 
        ///<returns>true=转换成功</returns>
        private bool PPTConvertToPDF(string sourcePath, string targetPath)
        {
            bool result;
            PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;
            PowerPoint.ApplicationClass application = null;
            PowerPoint.Presentation persentation = null;
            try
            {
                application = new PowerPoint.ApplicationClass();
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return result;
        }
        # endregion

        private bool success(string path)
        {
            bool result=true;
            MessageBox.Show("恭喜您转换成功!");
            FileInfo file = new FileInfo(path);
            file.Attributes = FileAttributes.ReadOnly;
            DXPdfView PDF = new DXPdfView(path);
            PDF.Show();
            return result;
        }
        
    }
}

PDF播放容器

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraBars;

namespace DIFautomaticTool.View
{
    public partial class DXPdfView : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public DXPdfView()
        {
            InitializeComponent();
        }
        public DXPdfView(string filePath):this()
        {
            pdfViewer1.DocumentFilePath = filePath;
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBClenitHandle;
using System.IO;
using DevExpress.XtraEditors;
using DIFautomaticTool.common_GUI;

namespace DIFautomaticTool.View
{
    public partial class newUploadhaha : UserControl
    {
        public newUploadhaha()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(textEditName.Text))
                {
                    throw new Exception($"文件名不能为空!");
          
                }
                if (string.IsNullOrWhiteSpace(textEditPath.Text))
                {
                    throw new Exception($"文件路径不能为空!");
                }
                if (string.IsNullOrWhiteSpace(comboBoxEditCourseType.Text))
                {
                    throw new Exception($"课程类型不能为空!");
                }
                if (string.IsNullOrWhiteSpace(textEditLecturer.Text))
                {
                    throw new Exception($"课程讲师不能为空!");
                }
                if (string.IsNullOrWhiteSpace(textEditVisbility.Text))
                {
                    throw new Exception($"课程可见度不能为空!");
                }
                string sql = @"insert into dif_tool_course(coursename,coursepath,courseleaccturer,videotemperature,coursetype)values('" + this.textEditName.Text.ToString() + "','"
                                                                  + this.textEditPath.Text.ToString() + "','"
                                                                  + this.textEditLecturer.Text.ToString() + "','"
                                                                  + this.textEditVisbility.Text.ToString() + "','"
                                                                  + this.comboBoxEditCourseType.Text.ToString() + "')";
                string result = MFDM10.DBUpdate(sql);
                //DataTable dt = MFDM10.DBGetSqlTable(sql);
                simpleButtonCopy_Click(null, null);
                XtraMessageBox.Show("上传成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex.Message, "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void textEditPath_DoubleClick(object sender, EventArgs e)
        {
            //选择路径
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Multiselect = true;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        this.textEditPath.Text = dialog.FileName;
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                }
            }
        }

        private void simpleButtonCopy_Click(object sender, EventArgs e)
        {
            WaitingForm wait = new WaitingForm();
         
            wait.Show("正在拼命上传请耐心等待");
            string sourceDir = $@"{this.textEditPath.Text.ToString()}";
            //string path = sourceDir.Substring(0, sourceDir.LastIndexOf(@"\") + 1);//获取文件路径
            //string filename = sourceDir.Substring(sourceDir.LastIndexOf(@"\")+1);//获取文件名
            string path = Path.GetDirectoryName(sourceDir);//获取文件路径
            string filename = Path.GetFileName(sourceDir);//获取文件名
            string Newfilename = @"Z:\training message\" + this.comboBoxEditCourseType.Text.ToString() + @"\" + filename;
            try
            {
                string[] files = Directory.GetFiles(path);
                foreach (string file in files)
                {
                    if (file.Contains(filename))
                    {
                        FileInfo fileinfo = new FileInfo(file);
                        try
                        {
                            string fileName = file.Replace(sourceDir, "");
                            File.Copy(file, Newfilename);

                        }
                        catch (IOException copyError)
                        {
                            Console.WriteLine(copyError.Message);
                        }
                    }

                }
            }
            catch (DirectoryNotFoundException dirNotFound)
            {
                Console.WriteLine(dirNotFound.Message);
            }
            finally
            {
                wait.Close();
            }

        }

    }
}

 

转载于:https://my.oschina.net/u/3736209/blog/1581364

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值