Exemplo n.º 1
0
        private CommonData.FileType GetFileType(string FileExName)
        {
            CommonData.FileType fileType = new CommonData.FileType();
            try
            {
                switch (FileExName)
                {
                case "pdf":
                    fileType = CommonData.FileType.Pdf;
                    break;

                case "txt":
                    fileType = CommonData.FileType.TXT;
                    break;

                case "ini":
                    fileType = CommonData.FileType.Video;
                    break;

                case "jpg":
                case "bmp":
                case "png":
                    fileType = CommonData.FileType.Image;
                    break;

                case "pcb":
                    fileType = CommonData.FileType.PCB;
                    break;

                case "webini":
                    fileType = CommonData.FileType.Web;
                    break;

                default:
                    fileType = CommonData.FileType.None;
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] Error  " + ex.Message);
                MessageBox.Show(ex.Message);
            }
            return(fileType);
        }
Exemplo n.º 2
0
        private void initFrom()
        {
            try
            {
                lbAD.Text = Global.ConfigInfoList[Global.ConfigInfo.YeMeiMsg];
                string initFilePath = Global.ConfigInfoList[Global.ConfigInfo.InitAddr];

                if (string.IsNullOrEmpty(initFilePath))
                {
                    return;
                }
                string fullpath          = Application.StartupPath + "\\" + initFilePath.Substring(initFilePath.IndexOf("File"));
                string tempstr           = Path.GetFileNameWithoutExtension(initFilePath);
                string filenameExtension = tempstr.Substring(tempstr.IndexOf('.') + 1);
                initFilePath = fullpath.Substring(0, fullpath.LastIndexOf(".")) + ".temp";
                TreeNode tn = new TreeNode();
                //取出文件拓展名
                //string filenameExtension = Path.GetFileNameWithoutExtension(initFilePath).Substring(initFilePath.IndexOf('.') + 1);
                CommonData.FileType fileType = GetFileType(filenameExtension);
                switch (fileType)
                {
                case CommonData.FileType.Pdf:
                {
                    //pdfControl.DisplayPDFFile(filepath);
                    pdfFoxControl.DisplayPDFFile(initFilePath);
                    MyPanel.Controls.Clear();
                    MyPanel.Controls.Add(pdfFoxControl);
                    IsPicOrTxt(false);
                }
                break;

                case CommonData.FileType.Video:
                {
                    //INIClass ini = new INIClass(fullPath + ".temp");
                    INIClass ini        = new INIClass(initFilePath);
                    string   videoValue = ini.IniReadValue("MyVideoMsg", "VideoPath");
                    if (!string.IsNullOrEmpty(videoValue))
                    {
                        //webBrowserControl.SetVideoValue(videoValue);
                        MyPanel.Controls.Clear();
                        MyPanel.Controls.Add(webBrowserControl);
                        IsPicOrTxt(false);
                    }
                    else
                    {
                        throw new Exception("视频地址为空");
                    }
                }
                break;

                case CommonData.FileType.TXT:
                {
                    //txtControl.DisplayTxt(fullPath + ".temp");
                    txtControl.DisplayTxt(initFilePath);
                    MyPanel.Controls.Clear();
                    MyPanel.Controls.Add(txtControl);
                    IsPicOrTxt(false);
                }
                break;

                case CommonData.FileType.Image:
                {
                    picControl.SetPicPath(initFilePath);
                    MyPanel.Controls.Clear();
                    MyPanel.Controls.Add(picControl);
                    IsPicOrTxt(true);
                }
                break;

                case CommonData.FileType.PCB:
                {
                    pcbControl.ShowPcb(initFilePath);
                    MyPanel.Controls.Clear();
                    MyPanel.Controls.Add(pcbControl);
                    IsPicOrTxt(false);
                }
                break;
                }
            }
            catch (Exception ex)
            {
                Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex);
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void Tv_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                //HideBox();
                TreeNode            tn       = e.Node;
                CommonData.FileType filetype = new CommonData.FileType();
                if (tn.Tag == null)
                {
                    return;
                }
                filetype = (CommonData.FileType)tn.Tag;
                string filepath = tn.Name;
                if (filetype != CommonData.FileType.Folder && filetype != CommonData.FileType.None)
                {
                    string name     = tn.Text;
                    string fullPath = Global.SysFilePath + "\\" + tn.FullPath;
                    webBrowserControl.ClearVideo();
                    switch (filetype)
                    {
                    case CommonData.FileType.Pdf:
                    {
                        //pdfControl.DisplayPDFFile(filepath);
                        pdfFoxControl.DisplayPDFFile(filepath);
                        MyPanel.Controls.Clear();
                        MyPanel.Controls.Add(pdfFoxControl);
                        IsPicOrTxt(false);
                    }
                    break;

                    case CommonData.FileType.Video:
                    {
                        //INIClass ini = new INIClass(fullPath + ".temp");
                        INIClass ini        = new INIClass(filepath);
                        string   videoValue = ini.IniReadValue("MyVideoMsg", "VideoPath");
                        if (!string.IsNullOrEmpty(videoValue))
                        {
                            webBrowserControl.SetVideoValue(videoValue);
                            MyPanel.Controls.Clear();
                            MyPanel.Controls.Add(webBrowserControl);
                            IsPicOrTxt(false);
                        }
                        else
                        {
                            throw new Exception("视频地址为空");
                        }
                    }
                    break;

                    case CommonData.FileType.TXT:
                    {
                        //txtControl.DisplayTxt(fullPath + ".temp");
                        txtControl.DisplayTxt(filepath);
                        MyPanel.Controls.Clear();
                        MyPanel.Controls.Add(txtControl);
                        IsPicOrTxt(false);
                    }
                    break;

                    case CommonData.FileType.Image:
                    {
                        picControl.SetPicPath(filepath);
                        MyPanel.Controls.Clear();
                        MyPanel.Controls.Add(picControl);
                        IsPicOrTxt(true);
                    }
                    break;

                    case CommonData.FileType.PCB:
                    {
                        pcbControl.ShowPcb(filepath);
                        MyPanel.Controls.Clear();
                        MyPanel.Controls.Add(pcbControl);
                        IsPicOrTxt(false);
                    }
                    break;

                    case CommonData.FileType.Web:
                    {
                        INIClass ini = new INIClass(filepath);
                        string   url = ini.IniReadValue("MyWebMsg", "URL");
                        webControl.DisplayWeb(url);
                        MyPanel.Controls.Clear();
                        MyPanel.Controls.Add(webControl);
                        IsPicOrTxt(false);
                    }
                    break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex);
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
        //方法需传入绝对路径,以及Treeview的Name的Nodes属性
        private void GetNodeValue(string path, TreeNodeCollection tc, bool IsFirst = true)
        {
            try
            {
                //加载选定文件夹下的文件的名字
                string[] FilePath = Directory.GetDirectories(path);
                tv.ImageList = filesIcons;
                //获得文件的名字
                string filename = string.Empty;
                //获得文件夹的名字
                for (int i = 0; i < FilePath.Length; i++)
                {
                    filename = Path.GetFileNameWithoutExtension(FilePath[i]);
                    if (filename == "temp")
                    {
                        continue;
                    }
                    if (IsFirst)
                    {
                        if (!Global.userMsgData.FilePermission.Contains(filename))
                        {
                            continue;
                        }
                    }
                    TreeNode tn = new TreeNode
                    {
                        Text               = filename,
                        ImageIndex         = IconIndexes.ClosedFolder,
                        SelectedImageIndex = IconIndexes.ClosedFolder,
                        Tag = CommonData.FileType.Folder
                    };
                    //在treeview节点下存下每个节点的路径
                    tc.Add(tn);
                    //if()
                    //这里遇到了递归,遇到文件夹,先进入文件夹里面去遍历,将大的tr,替换为小的tr
                    GetNodeValue(FilePath[i], tn.Nodes, false);
                }
                //因为目录名不能被点击,获得目录下的文件
                //获得文件夹下文件的名字,
                string[] Newfilepath = Directory.GetFiles(path);
                for (int i = 0; i < Newfilepath.Length; i++)
                {
                    //filename = Path.GetFileName(Newfilepath[i]);
                    CommonData.MainFormFile myfile = new CommonData.MainFormFile();
                    filename = Path.GetFileNameWithoutExtension(Newfilepath[i]);
                    if (Path.GetExtension(Newfilepath[i]) != ".temp")
                    {
                        continue;
                    }
                    TreeNode tn = new TreeNode
                    {
                        ImageIndex = -1
                    };

                    //取出文件拓展名
                    string filenameExtension     = filename.Substring(filename.IndexOf('.') + 1);
                    CommonData.FileType fileType = GetFileType(filenameExtension);
                    switch (fileType)
                    {
                    case CommonData.FileType.Pdf:
                    {
                        tn.ImageIndex         = IconIndexes.PDFFile;
                        tn.SelectedImageIndex = IconIndexes.PDFFile;
                    }
                    break;

                    case CommonData.FileType.Video:
                    {
                        tn.ImageIndex         = IconIndexes.VideoFile;
                        tn.SelectedImageIndex = IconIndexes.VideoFile;
                    }
                    break;

                    case CommonData.FileType.TXT:
                    {
                        tn.ImageIndex         = IconIndexes.TXTFile;
                        tn.SelectedImageIndex = IconIndexes.TXTFile;
                    }
                    break;

                    case CommonData.FileType.Image:
                    {
                        tn.ImageIndex         = IconIndexes.PicFile;
                        tn.SelectedImageIndex = IconIndexes.PicFile;
                    }
                    break;

                    case CommonData.FileType.PCB:
                    {
                        tn.ImageIndex         = IconIndexes.PCBFile;
                        tn.SelectedImageIndex = IconIndexes.PCBFile;
                    }
                    break;

                    case CommonData.FileType.Web:
                    {
                        tn.ImageIndex         = IconIndexes.WebFile;
                        tn.SelectedImageIndex = IconIndexes.WebFile;
                    }
                    break;
                    }
                    tn.Text = Path.GetFileNameWithoutExtension(filename);
                    tn.Name = Newfilepath[i];
                    //在treeview节点下存下每个节点的路径
                    tn.Tag = fileType;
                    myfile.FileLocalPath = Newfilepath[i];
                    myfile.FileName      = Path.GetFileNameWithoutExtension(filename);
                    myfile.FileType      = fileType;
                    tc.Add(tn);
                    LocalFileList.Add(myfile);
                    //fileInfo.Add(tn.Text)
                    //}
                }
            }
            catch (Exception ex)
            {
                Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex);
                MessageBox.Show(ex.Message);
            }
        }