⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adddocument.aspx.cs

📁 一个办公化自动平台软件
💻 CS
字号:
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;
using OfficeAutomatization;
using System.IO;

public partial class AddDocument : System.Web.UI.Page
{
	private static string FILEDIR = "\\DesktopModules\\Document\\Attachments";
    protected void Page_Load(object sender, EventArgs e)
    {
		///
	}	

	protected void AddBtn_Click(object sender, EventArgs e)
	{
		///如果页面输入内容合法
		if (Page.IsValid == true)
		{
			///定义类
			OfficeAutomatization.Document document = new OfficeAutomatization.Document();
			try
			{
				///添加新数据
				document.AddDocument(Desn.Text.Trim(),Body.Text,
					Int32.Parse(Session["UserID"].ToString()),
					Author.Text.Trim(),
					FromSource.Text,
					UploadAttachment(),
					Remark.Text);

				///显示操作结果信息
				Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
			}
			catch (Exception ex)
			{
				///显示添加操作中的失败、错误信息
				Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
					+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
					+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
			}
		}
	}

	protected void ReturnBtn_Click(object sender, EventArgs e)
	{
		///返回管理页面
		Response.Redirect("~/DesktopModules/Document/DocumentManage.aspx");
	}

	private string UploadAttachment()
	{
		if (AttachmentFile.PostedFile.ContentLength > 0)
		{
			String fileName = AttachmentFile.PostedFile.FileName.Substring(AttachmentFile.PostedFile.FileName.LastIndexOf("\\"),
				AttachmentFile.PostedFile.FileName.Length - AttachmentFile.PostedFile.FileName.LastIndexOf("\\"));

			String fileTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
				+ DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString()
				+ DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString()
				+ DateTime.Now.Millisecond.ToString();

			fileName = "\\" + fileTime + GetRandomint() + fileName.Substring(fileName.IndexOf("."), fileName.Length - fileName.IndexOf("."));
			string sFileName = Server.MapPath(Request.ApplicationPath) + FILEDIR + fileName;

			if (File.Exists(sFileName) == false)
			{
				try
				{
					//把文件存入磁盘,如果失败,导向提示页面
					AttachmentFile.PostedFile.SaveAs(sFileName);
					return ("Attachments" + fileName);
				}
				catch (Exception ex)
				{
					string sRawURL = Request.RawUrl;

					if (sRawURL.IndexOf("?") > -1)
					{
						sRawURL = sRawURL.Substring(0, sRawURL.IndexOf("?"));
					}
					Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + ex.Message.Replace("\n", " "));
				}
			}
			else
			{
				Response.Write("<script>alert(\"你上传的文件已经存在!\")</script>");
			}
		}
		else
		{
			Response.Write("<script>alert(\"你输入的文件的内容为空,请重新输入!\")</script>");
		}

		return ("");
	}

	private String GetRandomint()
	{
		Random random = new Random();
		return (random.Next(10000).ToString());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -