upload_photo.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:3k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class web_personnel_curricula_vitae_upload_photo : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void BtnUpload_Click(object sender, EventArgs e)
- {
- DateMgr mgr = new DateMgr();
- string time = mgr.getTime();
- if (this.uploadFile(time) && Request.QueryString["e_id"] != null)
- {
- string save_name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- string name = FileUpload1.FileName;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("update OA_EMPLOYEE set photo_name='"+name+
- "', photo_save_name='"+save_name+"' where id="+Request.QueryString["e_id"], conn);
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("select emp_name from OA_EMPLOYEE where id="+Request.QueryString["e_id"], conn);
- HlEmployeeShow.Text = "查看" + cmd.ExecuteScalar().ToString() + "的資料";
- HlEmployeeShow.NavigateUrl = "employee_show.aspx?e_id="+Request.QueryString["e_id"];
- HlEmployeeList.Text = "查看本部門員工列表";
- HlEmployeeList.NavigateUrl = "employee_list.aspx";
- conn.Close();
- Response.Write("<script language='javascript'>alert('上傳檔案成功');</script>");
- Photo.ImageUrl = "../../employee_photo/" + save_name;
- }
- }
- protected bool uploadFile(string time)
- {
- bool flag = false;
- string directory = Server.MapPath("~/web/employee_photo/");
- Response.Write("<script language='javascript'>alert('"+directory+"');</script>");
- if (FileUpload1.HasFile)
- {
- bool extenstion = false;
- string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- string[] allowedExtensions =
- { ".gif", ".jpg" };
- for (int i = 0; i < allowedExtensions.Length; i++)
- {
- if (fileExtension == allowedExtensions[i])
- {
- extenstion = true;
- break;
- }
- }
- if (!extenstion)
- {
- Response.Write("<script language='javascript'>alert('只允許上傳格式為gif, jpg的檔案!');</script>");
- return false;
- }
- else
- {
- string name = FileUpload1.FileName.Substring(0, FileUpload1.FileName.Length - 4) + time + System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
- FileUpload1.PostedFile.SaveAs(directory + name);
- ContentLength.Value = FileUpload1.PostedFile.ContentLength.ToString();
- flag = true;
- }
- }
- return flag;
- }
- protected void BtnUnUpload_Click(object sender, EventArgs e)
- {
- Response.Redirect("employee_list_index.aspx");
- }
- }