/// <summary> /// 准备数据源用于表格显示,主要功能:自动生成显示图标。 /// </summary> public void DoPrepareDataSource() { if (_attachmentStorage == null) { return; } //临时显示字段 if (_attachmentStorage.Columns.IndexOf(tb_sys_AttachFile.IconLarge) < 0) { _attachmentStorage.Columns.Add(tb_sys_AttachFile.IconLarge, typeof(byte[])); } if (_attachmentStorage.Columns.IndexOf(tb_sys_AttachFile.IconSmall) < 0) { _attachmentStorage.Columns.Add(tb_sys_AttachFile.IconSmall, typeof(byte[])); } Icon large; Icon small; foreach (DataRow R in _attachmentStorage.Rows) { if (R.RowState == DataRowState.Deleted) { continue; } if (R[tb_sys_AttachFile.IconSmall] != DBNull.Value) { continue; } AttachTool.CreateFileIcon(R, out large, out small, true); //创建图标,用于表格显示 } }
public void AddFile(string fileFullName) { FileStream fs = null; try { string ext = Path.GetExtension(fileFullName); //扩展名 string fileName = Path.GetFileName(fileFullName); //显示文件名称 fs = new FileStream(fileFullName, FileMode.Open); byte[] bs = new byte[fs.Length]; //文件内容 fs.Read(bs, 0, (int)fs.Length); //读取文件内容 decimal size = decimal.Round((decimal)(fs.Length / 1024.00), 2); //文件大小 kb fs.Close(); //显示文件的图标 Icon large; Icon small; AttachTool.CreateFileIcon(ext, out large, out small); //获取文件的图标 TAttachFile file = new TAttachFile(); //附件对象 file.FileName = fileName; file.FileTitle = fileName; //文件标题 file.FileType = ext; ////扩展名 file.FileSize = size; file.FileBody = bs; file.IconLarge = AttachTool.ImageToByte(large.ToBitmap()); //大图标 file.IconSmall = AttachTool.ImageToByte(small.ToBitmap()); //小图标 this.AddFile(file); //保存数据 } catch { if (fs != null) { fs.Close(); } } }