platform/upload/fileUpload.aspx.cs

102 lines
3.3 KiB
C#
Raw Permalink Normal View History

2024-02-18 23:33:54 +08:00
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Text;
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 DeiNiu.wms.Logical;
public partial class upload_fileUpload : PagePublic
{
private string fileType ="";
private string fileCode = "";
private string fileInfo = "";
private string empid="";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
getParameters();
try
{
if (fileUpload1.FileName.Length == 0) return;
lbuploadmessage.Text = "";
string fileName = fileUpload1.FileName;
System.Random rand = new Random();
int len = rand.Next();
fileName = empid + "T" + fileType + len +
fileName.Substring(fileName.LastIndexOf("."));
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/upload/"+fileType ));
if (!dir.Exists)
dir.Create();
string fileSavePath = Server.MapPath("~/upload/" + fileType+"/" + fileName);
fileUpload1.SaveAs(fileSavePath);
lbuploadmessage.Text = "上传成功!";
LFile _logic = new LFile();
_logic.Initialize();
_logic.GetFilesmgr.File_type = Convert.ToInt32(fileType);
_logic.GetFilesmgr.file_dest = fileName;
_logic.GetFilesmgr.File_Desc = txtFileDesc.Text;
_logic.GetFilesmgr.File_Emp = Convert.ToInt32(empid);  
if (fileType.Equals(((int)DeiNiu.Utils.FileType.Project).ToString()))
_logic.GetFilesmgr.File_Project = Convert.ToInt32(fileInfo);
if (fileType.Equals(((int)DeiNiu.Utils.FileType.ProjectDetail).ToString()))
_logic.GetFilesmgr.File_ProjectDetail = Convert.ToInt32(fileInfo);
_logic.GetFilesmgr.Add();
closewindow();
}
catch (Exception er)
{
lbuploadmessage.Text = "上传失败!";
}
}
void closewindow()
{
StringBuilder strResponse = new StringBuilder();
strResponse.Append("<script language=JavaScript>");
// strResponse.Append("alert('aaa');");
strResponse.Append("this.close();");
strResponse.Append(" </");
strResponse.Append("script>");
Response.Write(strResponse);
}
void getParameters()
{
// if (Session["uploadCode"] != null && Session["fileType"] != null && Session["fileInfo"] != null)
// if (Session["uploadCode"] != null && Session["fileType"] != null && Session["fileInfo"] != null)
// {
// string preCode = Session["uploadCode"].ToString();
fileCode = Request.QueryString["fileCode"];
fileType = Request.QueryString["fileType"];
fileInfo = Request.QueryString["fileInfo"];
empid = Request.QueryString["id"];
// fileType = Session["fileType"].ToString();
// fileInfo = Session["fileInfo"].ToString();
// if (!fileCode.Equals(preCode))
// {
// closewindow();
// }
// }
// else
// {
// closewindow();
// }
}
}