Ejemplo n.º 1
0
 private void listView_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listView.SelectedItems.Count > 0)
     {
         MyItem myItem   = listView.SelectedItems[0] as MyItem;
         string fullPath = myItem.Element.AbsoluteFilePath;
         PathTextBox.Text = fullPath.Substring(Service.Sdsite.CurrentDocument.Resources.AbsoluteFilePath.Length);
         try
         {
             ImgpictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
             if (!Utility.File.IsDirectory(fullPath))
             {
                 MyFileItem myfileItem = myItem as MyFileItem;
                 if (myfileItem != null && myfileItem.ItemMediaType == MediaFileType.Pic)
                 {
                     ImgpictureBox.ImageLocation = fullPath;
                 }
             }
         }
         catch
         {
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载项目
        /// </summary>
        /// <param name="initPath"></param>
        void InitListView(SimpleExIndexXmlElement folderEle)
        {
            listView.Items.Clear();
            SdsiteXmlDocument doc = Service.Sdsite.CurrentDocument;

            //加载子文件夹
            foreach (XmlNode node in folderEle.ChildNodes)
            {
                if (node is FolderXmlElement)
                {
                    FolderXmlElement folder = (FolderXmlElement)node;
                    if (folder.IsDeleted)
                    {
                        continue;
                    }

                    MyFolderItem mylvi      = new MyFolderItem(folder);
                    string       folderPath = folder.AbsoluteFilePath.Substring(0, folder.AbsoluteFilePath.Length - 1);
                    mylvi.Text = Path.GetFileName(folderPath);
                    mylvi.Text = folder.Title;
                    listView.Items.Add(mylvi);
                }
            }
            //加载子文件
            foreach (XmlNode node in folderEle.ChildNodes)
            {
                if (node is FileSimpleExXmlElement)
                {
                    FileSimpleExXmlElement fileEle    = (FileSimpleExXmlElement)node;
                    MyFileItem             myFileItem = new MyFileItem(fileEle);
                    if (fileEle.IsDeleted)
                    {
                        continue;
                    }

                    myFileItem.Element = fileEle;
                    myFileItem.Text    = Path.GetFileName(fileEle.AbsoluteFilePath);
                    myFileItem.Text    = fileEle.Title;

                    string exfile = Path.GetExtension(fileEle.AbsoluteFilePath).ToLower();
                    switch (FileType)
                    {
                    case MediaFileType.Pic:
                    {
                        if (exfile == ".jpg" || exfile == ".jpeg" /*|| exfile == ".png"*/ || exfile == ".gif")
                        {
                            myFileItem.ItemMediaType = MediaFileType.Pic;
                            string valuestr = "";
                            if (!picFilter.TryGetValue(FilterComboBox.Text, out valuestr) || valuestr == "all")
                            {
                                listView.Items.Add(myFileItem);
                            }
                            else
                            {
                                if (exfile == valuestr)
                                {
                                    listView.Items.Add(myFileItem);
                                }
                            }
                        }
                        break;
                    }

                    case MediaFileType.Flash:
                    {
                        if (exfile == ".swf")
                        {
                            myFileItem.ItemMediaType = MediaFileType.Flash;
                            listView.Items.Add(myFileItem);
                        }
                        break;
                    }

                    case MediaFileType.Audio:
                    {
                        if (exfile == ".mp3" || exfile == ".mdi" || exfile == ".wma" || exfile == "*.wav")
                        {
                            myFileItem.ItemMediaType = MediaFileType.Audio;
                            string valuestr = "";
                            if (!audioFilter.TryGetValue(FilterComboBox.Text, out valuestr) || valuestr == "all")
                            {
                                listView.Items.Add(myFileItem);
                            }
                            else
                            {
                                if (exfile == valuestr)
                                {
                                    listView.Items.Add(myFileItem);
                                }
                            }
                        }
                        break;
                    }

                    case MediaFileType.Video:
                    {
                        if (exfile == ".rmvb" || exfile == ".rm" || exfile == ".avi" || exfile == ".wmv")
                        {
                            myFileItem.ItemMediaType = MediaFileType.Video;
                            string valuestr = "";
                            if (!mediaFilter.TryGetValue(FilterComboBox.Text, out valuestr) || valuestr == "all")
                            {
                                listView.Items.Add(myFileItem);
                            }
                            else
                            {
                                if (exfile == valuestr)
                                {
                                    listView.Items.Add(myFileItem);
                                }
                            }
                        }
                        break;
                    }
                    }
                }
            }

            //加载图标
            foreach (MyItem lvitem in listView.Items)
            {
                string fullPath = lvitem.Element.AbsoluteFilePath;
                KeyValuePair <string, Image> keyImg = GetImageAndKey(fullPath);
                if (!listView.SmallImageList.Images.ContainsKey(keyImg.Key))
                {
                    listView.SmallImageList.Images.Add(keyImg.Key, keyImg.Value);
                }
                lvitem.ImageKey = keyImg.Key;
            }
        }