public string col = "info";//设置数据库表名
#region 添加处理,上传文件并写入数据
protected void btnOk_Click(object sender, System.EventArgs e)
{
int classid = 0;
classid = pub.GetAjaxClassId(Request.Form["ddl1"], Request.Form["ddl2"], Request.Form["ddl3"], Request.Form["ddl4"], Request.Form["ddl5"]);
string ti = DateTime.Now.ToString("yyyymmddhhmmss");
string path = Server.MapPath("~/Service/GraduateChannel/");
string name = FileUpload1.FileName;//获取文件名
string type = name.Substring(name.LastIndexOf(".") + 1); //获取文件类型
string ipath = path + name; //获取文件路径
string wpath = "slave//" + name;
if (type == "zip" || type == "rar")
{
FileUpload1.PostedFile.SaveAs(path + "" + wpath);
this.name.Value = name;
string sql = "";
if (id > 0)
{
sql = "insert into Upfile (Oname,Nname,Filepath,Addtime,Classid) values (@Oname,@Nname,@Filepath,@Addtime,@Classid)";
}
else
{
sql = "update " + col + " set Classid=@classid,Oname=@title,Nname=@name,Addtime=@Addtime,Filepath=@Filepath where [Infoid]=@id";
}
SqlCommand cmd = this.dbc.GetCommandBySql(sql);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = this.id;
cmd.Parameters.Add("@Oname", SqlDbType.VarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add("@Nname", SqlDbType.VarChar).Value = name;
cmd.Parameters.Add("@Filepath", SqlDbType.VarChar).Value = path + "" + wpath;
cmd.Parameters.Add("@Addtime", SqlDbType.DateTime).Value = DateTime.Now.ToShortDateString();
cmd.Parameters.Add("@Classid", SqlDbType.Int).Value = classid;
cmd.Connection.Open();
int rows = cmd.ExecuteNonQuery();
cmd.Connection.Close();
cmd.Connection.Dispose();
cmd.Dispose();
AddInfo.Enabled = false;
if (rows <= 0)
{
Response.Write("<script>alert('文件格式不对!');</script>");
return;
}
pubfun.RegisterStartupScript(Page, "PAGE", "window.location.href='" + "Info.aspx?ChannelId=" + this.channelid.ToString() + "';");
}
else
{
Response.Write("<script>alert('文件格式不对!');</script>");
}
}
#endregion