예제 #1
0
 private void btnGetExtensionIcon_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(this.txtExtension.Text))
     {
         //获取扩展名图标
         Icon ico = IconReaderHelper.ExtractIconForExtension(this.txtExtension.Text, true);
         this.pictureBox2.Image = Bitmap.FromHicon(ico.Handle);
     }
 }
예제 #2
0
        public void BindData()
        {
            ClearData();

            if (!this.DesignMode)
            {
                List <FileUploadInfo> fileList = new List <FileUploadInfo>();
                if (ShowOwnerData)
                {
                    if (!string.IsNullOrEmpty(this.AttachmentGUID))
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetByOwnerAndAttachGUID(this.OwerId, this.AttachmentGUID, this.pager1.PagerInfo);
                    }
                    else
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetByOwner(this.OwerId, this.pager1.PagerInfo);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(this.AttachmentGUID))
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetByAttachGUID(this.AttachmentGUID, this.pager1.PagerInfo);
                    }
                    else
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetAllByUser(this.UserId, this.AttachmentDirectory, this.pager1.PagerInfo);
                    }
                }

                int k = 0;
                System.Drawing.Icon icon = null;
                foreach (FileUploadInfo fileInfo in fileList)
                {
                    string file      = fileInfo.FileName;
                    string extension = FileUtil.GetExtension(file);

                    #region 取缩略图存到 imageList1 的操作
                    //如果是图片,取得它的图片数据作为缩略图
                    bool isImage = ValidateUtil.IsImageFile(fileInfo.FileExtend);
                    if (isImage)
                    {
                        try
                        {
                            FileUploadInfo tmpInfo = BLLFactory <FileUpload> .Instance.Download(fileInfo.ID, 48, 48);

                            if (tmpInfo != null && tmpInfo.FileData != null)
                            {
                                this.imageList1.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                                this.imageList2.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                            }
                            else
                            {
                                icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                                this.imageList1.Images.Add(icon);
                                icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                                this.imageList2.Images.Add(icon);
                            }
                        }
                        catch (Exception ex)
                        {
                            icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                            this.imageList1.Images.Add(icon);
                            icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                            this.imageList2.Images.Add(icon);

                            LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(BizAttachment));
                            MessageDxUtil.ShowError(ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                        this.imageList1.Images.Add(icon);
                        icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                        this.imageList2.Images.Add(icon);
                    }
                    #endregion

                    if (!imageDict.ContainsKey(file))
                    {
                        imageDict.Add(file, k++);
                    }
                }

                foreach (FileUploadInfo fileInfo in fileList)
                {
                    ListViewItem item = listView1.Items.Add(fileInfo.FileName);

                    double fileSize = ConvertHelper.ToDouble(fileInfo.FileSize / 1024, 1);
                    item.SubItems.Add(fileSize.ToString("#,#KB"));
                    item.SubItems.Add(fileInfo.AddTime.ToShortDateString());
                    item.ImageIndex = GetImageKey(fileInfo.FileName);
                    item.Tag        = fileInfo.ID;
                }
                listView1.Refresh();
            }
        }
예제 #3
0
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindData()
        {
            if (!this.DesignMode)
            {
                ClearData();

                List <FileUploadInfo> fileList = new List <FileUploadInfo>();
                if (ShowOwnerData)
                {
                    if (!string.IsNullOrEmpty(this.AttachmentGUID))
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetByOwnerAndAttachGUID(this.OwerId, this.AttachmentGUID, this.pager1.PagerInfo);
                    }
                    else
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetByOwner(this.OwerId, this.pager1.PagerInfo);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(this.AttachmentGUID))
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetByAttachGUID(this.AttachmentGUID, this.pager1.PagerInfo);
                    }
                    else
                    {
                        fileList = BLLFactory <FileUpload> .Instance.GetAllByUser(this.UserId, this.AttachmentDirectory, this.pager1.PagerInfo);
                    }
                }

                int  k    = 0;
                Icon icon = null;
                foreach (FileUploadInfo fileInfo in fileList)
                {
                    string file      = fileInfo.FileName;
                    string extension = FileUtil.GetExtension(file);

                    #region 取缩略图存到 imageList1 的操作
                    //如果是图片,取得它的图片数据作为缩略图
                    bool isImage = MyHelper.IsImageFile(fileInfo.FileExtend);
                    if (isImage)
                    {
                        try
                        {
                            FileUploadInfo tmpInfo = BLLFactory <FileUpload> .Instance.Download(fileInfo.ID, 48, 48);

                            if (tmpInfo != null && tmpInfo.FileData != null)
                            {
                                this.imageList1.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                                this.imageList2.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                            }
                            else
                            {
                                icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                                this.imageList1.Images.Add(icon);
                                icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                                this.imageList2.Images.Add(icon);
                            }
                        }
                        catch
                        {
                            icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                            this.imageList1.Images.Add(icon);
                            icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                            this.imageList2.Images.Add(icon);
                        }
                    }
                    else
                    {
                        icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                        this.imageList1.Images.Add(icon);
                        icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                        this.imageList2.Images.Add(icon);
                    }
                    #endregion
                }

                int i = 0;
                foreach (FileUploadInfo fileInfo in fileList)
                {
                    ListViewItem item = listView1.Items.Add(fileInfo.FileName);

                    double fileSize = ConvertHelper.ToDouble(fileInfo.FileSize / 1024, 1);
                    item.SubItems.Add(fileSize.ToString("#,#KB"));
                    item.SubItems.Add(fileInfo.AddTime.ToShortDateString());
                    item.ImageIndex = i++;
                    item.Tag        = fileInfo.ID;
                }
                listView1.Refresh();
            }
        }
예제 #4
0
        private void BindData()
        {
            this.listView1.CheckBoxes = chkSelect.Checked;
            this.listView1.Items.Clear();
            this.imageList1.Images.Clear();
            this.imageList2.Images.Clear();
            imageDict.Clear();//刷新需要清除

            List <FileUploadInfo> fileList = BLLFactory <FileUpload> .Instance.GetByAttachGUID(this.AttachmentGUID);

            int k = 0;

            System.Drawing.Icon icon = null;
            foreach (FileUploadInfo fileInfo in fileList)
            {
                string file      = fileInfo.FileName;
                string extension = FileUtil.GetExtension(file);

                #region 取缩略图存到 imageList1 的操作
                //如果是图片,取得它的图片数据作为缩略图
                bool isImage = ValidateUtil.IsImageFile(fileInfo.FileExtend);
                if (isImage)
                {
                    try
                    {
                        FileUploadInfo tmpInfo = BLLFactory <FileUpload> .Instance.Download(fileInfo.ID, 48, 48);

                        if (tmpInfo != null && tmpInfo.FileData != null)
                        {
                            this.imageList1.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                            this.imageList2.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                        }
                        else
                        {
                            icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                            this.imageList1.Images.Add(icon);
                            icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                            this.imageList2.Images.Add(icon);
                        }
                    }
                    catch (Exception ex)
                    {
                        icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                        this.imageList1.Images.Add(icon);
                        icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                        this.imageList2.Images.Add(icon);

                        LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmAttachmentGroupView));
                        MessageDxUtil.ShowError(ex.Message);
                    }
                }
                else
                {
                    icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                    this.imageList1.Images.Add(icon);
                    icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                    this.imageList2.Images.Add(icon);
                }
                #endregion

                if (!imageDict.ContainsKey(file))
                {
                    imageDict.Add(file, k++);
                }
            }

            foreach (FileUploadInfo fileInfo in fileList)
            {
                ListViewItem item = listView1.Items.Add(fileInfo.FileName);

                double fileSize = ConvertHelper.ToDouble(fileInfo.FileSize / 1024, 1);
                item.SubItems.Add(fileSize.ToString("#,#KB"));
                item.SubItems.Add(fileInfo.AddTime.ToShortDateString());
                item.ImageIndex = GetImageKey(fileInfo.FileName);
                item.Tag        = fileInfo.ID;
            }
        }
        private void BindData()
        {
            this.listView1.CheckBoxes = chkSelect.Checked;
            this.listView1.Items.Clear();
            this.imageList1.Images.Clear();
            this.imageList2.Images.Clear();

            List <FileUploadInfo> fileList = BLLFactory <FileUpload> .Instance.GetByAttachGUID(this.AttachmentGUID);

            int  k    = 0;
            Icon icon = null;

            foreach (FileUploadInfo fileInfo in fileList)
            {
                string file      = fileInfo.FileName;
                string extension = FileUtil.GetExtension(file);

                #region 取缩略图存到 imageList1 的操作
                //如果是图片,取得它的图片数据作为缩略图
                bool isImage = MyHelper.IsImageFile(fileInfo.FileExtend);
                if (isImage)
                {
                    try
                    {
                        FileUploadInfo tmpInfo = BLLFactory <FileUpload> .Instance.Download(fileInfo.ID, 48, 48);

                        if (tmpInfo != null && tmpInfo.FileData != null)
                        {
                            this.imageList1.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                            this.imageList2.Images.Add(ImageHelper.BitmapFromBytes(tmpInfo.FileData));
                        }
                        else
                        {
                            icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                            this.imageList1.Images.Add(icon);
                            icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                            this.imageList2.Images.Add(icon);
                        }
                    }
                    catch
                    {
                        icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                        this.imageList1.Images.Add(icon);
                        icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                        this.imageList2.Images.Add(icon);
                    }
                }
                else
                {
                    icon = IconReaderHelper.ExtractIconForExtension(extension, true);  //大图标
                    this.imageList1.Images.Add(icon);
                    icon = IconReaderHelper.ExtractIconForExtension(extension, false); //小图标
                    this.imageList2.Images.Add(icon);
                }
                #endregion
            }

            int i = 0;
            foreach (FileUploadInfo fileInfo in fileList)
            {
                ListViewItem item = listView1.Items.Add(fileInfo.FileName);

                double fileSize = ConvertHelper.ToDouble(fileInfo.FileSize / 1024, 1);
                item.SubItems.Add(fileSize.ToString("#,#KB"));
                item.SubItems.Add(fileInfo.AddTime.ToShortDateString());
                item.ImageIndex = i++;
                item.Tag        = fileInfo.ID;
            }
        }