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

📄 addfiles.aspx.cs

📁 勇敢者论坛全部源代码。 支持SQL2000/Access数据库
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO; 
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using doughty_cn.inputcon;
using System.Data.OleDb;
using System.Configuration;

namespace doughty_cn
{
	/// <summary>
	/// AddFiles 的摘要说明。
	/// </summary>
	public partial class AddFiles : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox Tb_BiaoTi;


        protected void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            //如果用户已登录,则显示本页面,否则转向登录
            if (User.Identity.Name == "")
            {
                if (Request.QueryString["url"] == null)
                {
                    this.Response.Redirect(this.Request.Url.ToString() + "&url=" + Server.UrlEncode(this.Request.Url.ToString()));
                }
                Panel1.Visible = false;
            }
            else
            {
                Panel2.Visible = false;
                if (Session["UserGrade"] == null)
                    Session["UserGrade"] = DBOperate.GetUserGrade(User.Identity.Name);

                Btn_Post.Enabled = false;
                if (System.Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["Enable"]) == 1 &&
                    (System.Convert.ToDateTime(System.Configuration.ConfigurationSettings.AppSettings["StartTime"]) < System.DateTime.Now
                    && System.Convert.ToDateTime(System.Configuration.ConfigurationSettings.AppSettings["EndTime"]) > System.DateTime.Now))
                    Btn_Post.Enabled = true;

                if (Session["UserGrade"].ToString() == "管理员")
                    Btn_Post.Enabled = true;

                if (Session["UserGrade"].ToString() == "黑名单")
                    Btn_Post.Enabled = false;
            }
        }

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

        protected void Button1_Click(object sender, System.EventArgs e)
        {
            //提交信息	
            int id;
            string ext;
            string fn = "";
            //string  imgpath="UpImage/";
            string imgpath = System.Configuration.ConfigurationSettings.AppSettings["UpImagePath"];
            if ((Tb_Note.Text == "") || (Tb_Content.Text == ""))
            {
                Lbl_message.Text = "标题、摘要和内容不能为空。";
                return;
            }
            //	string filepath = Server.MapPath(imgpath+Path.GetFileName(Files1.PostedFile.FileName)); 
            ext = Path.GetExtension(Files1.PostedFile.FileName);
            if (Files1.PostedFile.ContentLength > 1107200)
            {
                Span1.Text = "上传的文件不能超过1M";
                return;
            }
            else
            {
                if (Files1.PostedFile != null)
                {
                    try
                    {
                        id = CommonFuntion.getNewTableID("Files");
                        if (Files1.PostedFile.FileName.ToString() == "")
                        {
                            fn = "default.gif";
                        }
                        else
                        {
                            if (!((ext.ToLower() == ".gif") || (ext.ToLower() == ".bmp") || (ext.ToLower() == ".png") || (ext.ToLower() == ".ico") || (ext.ToLower() == ".jpg") || (ext.ToLower() == ".wmf")))
                            {
                                Span1.Text = "上传图片格式错误!(JPG/GIF/ICO/BMP/WMF/PNG)";
                                return;
                            }
                            fn = Path.GetFileName(Files1.PostedFile.FileName);
                            if (fn.Length > 20)
                                fn = fn.Substring(fn.Length - 20, 20);
                            fn = id.ToString() + "_" + fn;
                            if (File.Exists(Server.MapPath(imgpath + fn)))
                            {
                                Span1.Text = "上传文件重名,请改名后再上传!";
                                return;
                            }
                            Files1.PostedFile.SaveAs(Server.MapPath(imgpath + fn));
                        }

                        string DBtype = ConfigurationManager.AppSettings["DBtype"];
                        string s = ("INSERT INTO Questions (Q_ID, author, Q_Note, Q_content, ImageName, HiteCounter, ReleaseTime,ReferTime, BigClass_ID, SmallClass_ID) VALUES ("
                            + id + ",'" + User.Identity.Name + "',@Q_Note,@Q_content,'" + fn + "',0, '" + System.DateTime.Now.ToString() + "', '" + System.DateTime.Now.ToString() + "'," + Request.QueryString["BID"] + "," + Request.QueryString["SID"] + ")");
                        if (DBtype == "Accsee")
                        {
                            DBsql exsql = new DBsql();
                            try
                            {
                                exsql.Open();
                                OleDbCommand comcol = new OleDbCommand(s, exsql.con);
                                comcol.Parameters.Add("@Q_Note", SqlDbType.VarChar);
                                comcol.Parameters.Add("@Q_content", SqlDbType.VarChar);
                                comcol.Parameters["@Q_Note"].Value = Tb_Note.Text;
                                comcol.Parameters["@Q_content"].Value = Tb_Content.Text;
                                comcol.ExecuteNonQuery();
                                exsql.Close();
                                this.Response.Redirect("Browers.aspx?QID=" + id.ToString());
                            }
                            catch (Exception ex)
                            {
                                Span1.Text = ex.ToString();
                            }
                        }
                        else
                        {
                            SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DBConnection"]);
                            try
                            {
                                SqlCommand sqlCmd = new SqlCommand(s, sqlConnection);
                                sqlCmd.Parameters.Add("@Q_Note", System.Data.SqlDbType.Text);
                                sqlCmd.Parameters.Add("@Q_content", System.Data.SqlDbType.Text);
                                sqlCmd.Parameters["@Q_Note"].Value = Tb_Note.Text;
                                sqlCmd.Parameters["@Q_content"].Value = Tb_Content.Text;
                                sqlConnection.Open();
                                sqlCmd.ExecuteNonQuery();
                                DBOperate.ExcSQL("update users set jifen=jifen+5 where User_name='" + User.Identity.Name.ToString() + "'");
                                Span1.Text = "恭喜,提交成功!";
                                sqlConnection.Close();
                                this.Response.Redirect("Browers.aspx?QID=" + id.ToString());
                            }
                            catch (Exception exception)
                            {
                                Span1.Text = exception.ToString();
                                sqlConnection.Close();
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        Span1.Text = "保存文件时出错<b>" + fn + "</b><br>" + exc.ToString();
                        return;
                    }
                }
            }
        }

		protected void Button2_Click(object sender, System.EventArgs e)
		{
			//清除Tb_Content里的内容
			Tb_Content.Text="";
		}
	}
}

⌨️ 快捷键说明

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