/// <summary>
/// 添加方法
/// </summary>
public void add()
{
string alert = "";
ResourcesTB Re = new ResourcesTB("");
string rand = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
//获取图片信息
FileInfo DeleteimgInfo = new FileInfo(Server.MapPath("UpLoad/") + Path.GetFileName(Re.ImageUrl));
FileUpload imgUp = FileUploadImg;
string ImageUrl = "~/Admin/UpLoad/" + Path.GetFileNameWithoutExtension(imgUp.PostedFile.FileName) + rand + Path.GetExtension(imgUp.PostedFile.FileName);
FileInfo imginfo = new FileInfo(Server.MapPath("UpLoad/") + Path.GetFileNameWithoutExtension(imgUp.PostedFile.FileName) + rand + Path.GetExtension(imgUp.PostedFile.FileName));
string imgType = Path.GetExtension(imgUp.PostedFile.FileName);
//获取资源信息
FileInfo DeletefileInfo = new FileInfo(Server.MapPath("UpLoad/") + Path.GetFileName(Re.FileUrl));
FileUpload fileUp = FileUploadFile;
string FileUrl = "/Admin/UpLoad/" + Path.GetFileNameWithoutExtension(fileUp.PostedFile.FileName) + rand + Path.GetExtension(fileUp.PostedFile.FileName);
FileInfo fileinfo = new FileInfo(Server.MapPath("UpLoad/") + Path.GetFileNameWithoutExtension(fileUp.PostedFile.FileName) + rand + Path.GetExtension(fileUp.PostedFile.FileName));
string fileType = Path.GetExtension(fileUp.PostedFile.FileName);
Re.Name = ReplaceBadChar(this.TB_Name.Text.Trim());
Re.ImageUrl = ImageUrl;
Re.Content = ReplaceBadChar(this.TB_Content.Text.Trim());
Re.AddTime = Convert.ToDateTime(this.TB_AddData.Text.ToString());
Re.DownLoadPoint = Convert.ToInt32(this.TB_Point.Text.ToString());
Re.FileUrl = FileUrl;
Re.TypeId = Convert.ToInt32(this.DDL_Type.SelectedValue.ToString());
if (imgType != ".jpg" && imgType != ".JPG" && imgType != ".gif" && fileType != ".GIF" && imgType != ".png" && imgType != ".PNG")
{
Page.RegisterStartupScript("", "<script> alert('上传图片格式只能是jpg、gif、png');</script>");
}
else if (imginfo.Exists)
{
Page.RegisterStartupScript("", "<script> alert('上传文件名已存在,请更改文件名!');</script>");
}
else if ((imgUp.PostedFile.ContentLength / (1024 * 1024)) > 1)
{
Page.RegisterStartupScript("", "<script> alert('上传图片大小不允许超过1M!');</script>");
}
if (fileType != ".zip" && fileType != ".ZIP" && fileType != ".rar" && fileType != ".RAR" && fileType != ".doc" && fileType != ".txt")
{
Page.RegisterStartupScript("", "<script> alert('上传资源格式只能是zip、rar、doc、txt');</script>");
}
else if (imginfo.Exists)
{
Page.RegisterStartupScript("", "<script> alert('上传文件名已存在,请更改文件名!');</script>");
}
else if ((imgUp.PostedFile.ContentLength / (1024 * 1024)) > 10)
{
Page.RegisterStartupScript("", "<script> alert('上传资源大小不允许超过10M!');</script>");
}
else if (Re.Add())
{
imgUp.PostedFile.SaveAs(Server.MapPath("UpLoad/") + Path.GetFileNameWithoutExtension(imgUp.PostedFile.FileName) + rand + Path.GetExtension(imgUp.PostedFile.FileName));
fileUp.PostedFile.SaveAs(Server.MapPath("UpLoad/") + Path.GetFileNameWithoutExtension(fileUp.PostedFile.FileName) + rand + Path.GetExtension(fileUp.PostedFile.FileName));
alert = "添加成功!";
celear();
}
else
{
alert = "添加失败!";
}
querycondition = SearchCondition();
Page.RegisterStartupScript("", "<script> alert('" + alert + "');</script>");
this.dataBindToRepResouce(querycondition);
}