Beispiel #1
0
        private void openFileViewer(Int32 fileID)
        {
            string connectionStringPBox  = DBSource.ConnectionStringPBox;
            string connectionStringPData = DBSource.ConnectionStringPData;
            string commandText           = @"SELECT file_id,file_name,file_type,file_size,file_nodeid FROM FileMemo where file_id = " + fileID;

            helperPBox = new dBHelper(connectionStringPBox);
            if (helperPBox.Load(commandText, "") == true)
            {
                if (fileID > 0 && helperPBox.DataSet.Tables[0].Rows.Count > 0)
                {
                    DataRow       dataRow    = helperPBox.DataSet.Tables[0].Select("file_id=" + fileID)[0];
                    string        filename   = dataRow["file_name"].ToString();
                    string        filetype   = dataRow["file_type"].ToString();
                    List <Byte[]> l_fileData = new FileDBHelper().getFileData(fileID);
                    if (l_fileData.Count == 0)
                    {
                        MessageBoxEx.Show("找不到对应数据文件!");
                        return;
                    }
                    SkinTabPage tp = new SkinTabPage();
                    tp.Text = filename;
                    switch (filetype)
                    {
                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".gif":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            try
                            {
                                Bitmap    bmap         = new Bitmap(Application.StartupPath + "\\temp\\" + filename + filetype);
                                PicViewer uc_picviewer = new PicViewer();
                                uc_picviewer.showPic(filename, bmap);
                                uc_picviewer.Dock = DockStyle.Fill;
                                tp.Controls.Add(uc_picviewer);
                                tabControl_Viewer.TabPages.Add(tp);
                            }
                            catch (Exception exp) { }
                        }
                        break;
                    }

                    case ".doc":
                    case ".docx":
                    case ".xls":
                    case ".xlsx":
                    case ".ppt":
                    case ".pptx":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            DocViewer uc_docviewer = new DocViewer();
                            tp.Tag            = uc_docviewer;
                            uc_docviewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(uc_docviewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            uc_docviewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".txt":
                    case ".sql":
                    case ".log":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            StreamReader sr        = new StreamReader(Application.StartupPath + "\\temp\\" + filename + filetype, Encoding.Default);
                            TxtViewer    txtViewer = new TxtViewer();
                            txtViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(txtViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            txtViewer.showTxt(sr.ReadToEnd());
                            sr.Close();
                        }
                        break;
                    }

                    case ".htm":
                    case ".html":
                    case ".mht":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            WebViewer webViewer = new WebViewer();
                            webViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(webViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            webViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".pdf":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            PDFViewer pdfViewer = new PDFViewer();
                            pdfViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(pdfViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            pdfViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".mp4":
                    case ".avi":
                    case ".rm":
                    case ".rmvb":
                    case ".flv":
                    case ".xr":
                    case ".wmv":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                        }
                        FrmPlayer aplayer = new FrmPlayer();
                        aplayer.Text = filename;
                        aplayer.Show();
                        aplayer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        break;
                    }
                    }
                    tabControl_Viewer.SelectedTab = tp;
                }
            }
        }
        private void AddPlayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmPlayer frm = new FrmPlayer();

            frm.Show();
        }
        private void BtnPlayers_Click(object sender, EventArgs e)
        {
            var playerForm = new FrmPlayer(this.playerboard);

            playerForm.ShowDialog();
        }