《ASP.NET办公自动化系统开发实例导航》人事管理模块

这一章是人事管理系统,但是技术方面和系统管理没有太大的区别.

主要一个点:如何在.NET中存取图像?

Bitmap myPic;

try

{

//从指定的文件初始化Bitmap类的新实例

//比如从上传的文件里读取,那就是new Bitmap(File1.PostedFile.InputStream)

myPic = new Bitmap(lnkPic.src);

}

catch(Exception ex)

{

return;

}

//从指定的现有图像并使用指定的大小初始化Bitmap类的新实例

Bitmap smallPic = new Bitmap(myPic, 100, 100);

//创建缓冲区

MemoryStream stream = new MemoryStream();

//设置以图片的格式写入缓冲区

picSmall.Save(stream, ImageFormat.Jpeg);

//将缓冲区内容转换为字节数组

byte[] byteArray = stream.ToArray();

PhotoAccess.UpdateEmpPic(empID, byteArray);

将数据库中的图像数据显示到页面中,可以通过Response的输出流来实现.

Response.ContentType = "image/pjepg";

Response.OutputStream.Write((byte[])dr["pic"], 0, (int)dr["pic_size"]);

Response.End();

使用DataFormatString设置指定列中的各项的显示格式字符串

比如对时间进行格式化显示:

<asp:BoundColumn DataField="logindate" HeaderText="登录时间" DataFormatString="{0:d}"></asp:BoundColumn>