tijian_tieying/web/Web/SystemManage/signation2.aspx.cs
2025-02-20 12:14:39 +08:00

106 lines
3.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SystemManage_signation2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string id = Request.QueryString["ID"];
if (string.IsNullOrEmpty(id))
id = ZWL.Common.PublicMethod.GetSessionValue("UserID");
ZWL.BLL.ERPUser bll = new ZWL.BLL.ERPUser();
pic.ImageUrl = bll.GetSignation(id);
}
}
protected void btn_upload_Click(object sender, EventArgs e)
{
string id = Request.QueryString["ID"];
if (string.IsNullOrEmpty(id))
id = ZWL.Common.PublicMethod.GetSessionValue("UserID");
Boolean fileOk = false;
if (pic_upload.HasFile)//验证是否包含文件
{
//取得文件的扩展名,并转换成小写
string fileExtension = Path.GetExtension(pic_upload.FileName).ToLower();
//验证上传文件是否图片格式
fileOk = IsImage(fileExtension);
if (fileOk)
{
//对上传文件的大小进行检测限定文件最大不超过8M
if (pic_upload.PostedFile.ContentLength < 8192000)
{
string filepath = "/signation/";
string filename = Guid.NewGuid().ToString();
if (Directory.Exists(Server.MapPath(filepath)) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(Server.MapPath(filepath));
}
string virpath = filepath + filename + fileExtension;//这是存到服务器上的虚拟路径
string mappath = Server.MapPath(virpath);//转换成服务器上的物理路径
pic_upload.PostedFile.SaveAs(mappath);//保存图片
//显示图片
bool flag = new ZWL.BLL.ERPUser().SetSignation(id, virpath);
if (flag)
{
pic.ImageUrl = virpath;
lbl_pic.Text = "修改成功";
}
else
{
pic.ImageUrl = virpath;
lbl_pic.Text = "修改失败";
}
}
else
{
pic.ImageUrl = "";
lbl_pic.Text = "文件大小超出8M请重新选择";
}
}
else
{
pic.ImageUrl = "";
lbl_pic.Text = "要上传的文件类型不对!请重新选择!";
}
}
else
{
pic.ImageUrl = "";
lbl_pic.Text = "请选择要上传的图片!";
}
}
/// <summary>
/// 验证是否指定的图片格式
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public bool IsImage(string str)
{
bool isimage = false;
string thestr = str.ToLower();
//限定只能上传jpg和gif图片
string[] allowExtension = { ".jpg", ".gif", ".bmp", ".png" };
//对上传的文件的类型进行一个个匹对
for (int i = 0; i < allowExtension.Length; i++)
{
if (thestr == allowExtension[i])
{
isimage = true;
break;
}
}
return isimage;
}
}