public IList <DownAttach> Getlist2(object num)//取DownAttach表社科版(cid=0)中前num个记录,以列表的形式返回 { List <DownAttach> list = new List <DownAttach>(); if (num != null && num.ToString() != "") { sql = "select top " + num + " * from DownAttach where cid=2 order by id desc"; } else { sql = "select * from DownAttach where cid=2 order by id desc"; } ds = DbHelperSQL.GetDataSet(sql); if (ds == null) { return(null); } else { foreach (DataRow dr in ds.Tables[0].Rows) { DownAttach a = new DownAttach(); a.AddDate = Convert.ToInt32(dr["AddDate"].ToString()); a.Type = Convert.ToSingle(dr["type"]); a.Id = dr["id"]; a.Title = dr["Title"].ToString(); list.Add(a); } return(list); } }
public IList <DownAttach> Getlist1()//取NoticeArticle表中前num个记录,以列表的形式返回 { List <DownAttach> list = new List <DownAttach>(); sql = "select distinct adddate from DownAttach where cid=2 "; ds = DbHelperSQL.GetDataSet(sql); if (ds == null) { return(null); } else { foreach (DataRow dr in ds.Tables[0].Rows) { DownAttach a = new DownAttach(); a.AddDate = Convert.ToInt32(dr["adddate"].ToString()); list.Add(a); } return(list); } }
public void DateBind(object id)//绑定要修改的信息 { DownAttachBLL downbll = new DownAttachBLL(); DownAttach da = new DownAttach(); da = downbll.GetDownAttach(id); TxtTitle.Text = da.Title; TxtWriter.Text = da.Writer; TxtFileName.Text = da.FileSaveName; TxtDate.Text = da.AddDate.ToString("d"); this.classification.SelectedValue = da.Cid.ToString(); }
protected void DataList1_DeleteCommand(object sender, DataListCommandEventArgs e) { DownAttachBLL downbll3 = new DownAttachBLL();; string id = e.CommandArgument.ToString(); DownAttach downatt = new DownAttach(); downatt = downbll3.GetDownAttach(id); string filename = downatt.FileSaveName; //获得所要删除的文件名 if (downbll3.Delete(id)) { string url1 = "~/Attach/" + filename; string webFilePath1 = Server.MapPath(url1);//用来删除原有文件资料 System.IO.FileInfo file1 = new System.IO.FileInfo(webFilePath1); if (file1.Exists) { file1.Delete();//删除 } Response.Write("<script>alert('删除成功');</script>"); } this.Response.Redirect(this.Request.Url.ToString()); }
public DownAttach Find(object id) { a = new DownAttach(); string sql = string.Format("select * from DownAttach where id='{0}'", id); dr = DbHelperSQL.GetDateRow(sql); try { a.AddDate = Convert.ToInt32(dr["AddDate"].ToString()); a.Title = dr["title"].ToString(); a.Id = dr["id"]; a.Cid = dr["cid"]; a.Writer = dr["writer"].ToString(); a.FileSaveName = dr["filesavename"].ToString(); a.Count = Convert.ToInt32(dr["count"].ToString()); a.Type = Convert.ToSingle(dr["type"].ToString()); return(a); } catch { return(null); } }
public bool Update(DownAttach a) { sql = string.Format("update DownAttach set addDate='{0}',filesavename='{1}',writer='{2}',title='{3}',cid='{4}' where id='{5}'", a.AddDate, a.FileSaveName, a.Writer, a.Title, a.Cid, a.Id); return(DbHelperSQL.ExecSqlCommand(sql)); }
public bool Add(DownAttach a) { sql = string.Format("insert into DownAttach (addDate,writer,title,filesavename,cid,count,type,fileid) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", a.AddDate, a.Writer, a.Title, a.FileSaveName, a.Cid, a.Count, a.Type, a.FileId); return(DbHelperSQL.ExecSqlCommand(sql)); }
public bool Update(DownAttach da) { return(DownAttachDao.Update(da)); }
public bool Add(DownAttach da) { return(DownAttachDao.Add(da)); }
protected void Add_Click(object sender, EventArgs e) { DownAttach da = new DownAttach(); DownAttachBLL downattachbll = new DownAttachBLL(); string filename = FileUp.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string name = DateTime.Now.ToString("yyyyMMddhhmmss") + lastName; //name = FileUp.FileName; // 客户端文件路径 string webFilePath = Server.MapPath("/Attach/" + name); // 服务器端文件路径 if (FileUp.HasFile) { //以下是上传资料的格式检验 FileInfo file = new FileInfo(FileUp.PostedFile.FileName); if (file.Extension.ToLower() != ".doc" && file.Extension.ToLower() != ".txt" && file.Extension.ToLower() != ".zip" && file.Extension.ToLower() != ".rar" && file.Extension.ToLower() != ".pdf") { Response.Write("<script>alert('上传的资料格式应为doc/txt/zip/rar/pdf格式');history.back(-1);</script>"); return; } //double size = FileUp.PostedFile.ContentLength;//文件大小 //if (size >= 20480000) //{ // Response.Write("<script>alert('上传失败!(资料容量请不要超过20MB)');history.back();</script>"); // return; //} if (!File.Exists(webFilePath)) { FileUp.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 } else { Response.Write("<script>alert('上传失败,请重试!')</script>"); } } else { Response.Write("文件名称为空,请填写要上传文件的名称"); return; } da.AddDate = Convert.ToInt32(TxtDate.Text.Trim() ); da.Writer = Server.HtmlEncode(TxtWriter.Text.Trim()); da.Title = Server.HtmlEncode(TxtTitle.Text.Trim()); da.FileSaveName = name; da.FileId = TextBox1.Text.Trim(); if (classification.SelectedItem.Text == "自然版过刊") { da.Cid = 1; if (classfenqi.SelectedItem.Text == "第一期") { da.Type = 1.1F; } else if (classfenqi.SelectedItem.Text == "第二期") { da.Type = 1.2F; } else if (classfenqi.SelectedItem.Text == "第三期") { da.Type = 1.3F; } else if (classfenqi.SelectedItem.Text == "第四期") { da.Type = 1.4F; } else if (classfenqi.SelectedItem.Text == "第五期") { da.Type = 1.5F; } else if (classfenqi.SelectedItem.Text == "第六期") { da.Type = 1.6F; } } else if (classification.SelectedItem.Text == "社科版过刊") { da.Cid = 2; if (classfenqi.SelectedItem.Text == "第一期") { da.Type = 2.1F; } else if (classfenqi.SelectedItem.Text == "第二期") { da.Type = 2.2F; } else if (classfenqi.SelectedItem.Text == "第三期") { da.Type = 2.3F; } else if (classfenqi.SelectedItem.Text == "第四期") { da.Type = 2.4F; } else if (classfenqi.SelectedItem.Text == "第五期") { da.Type = 2.5F; } else if (classfenqi.SelectedItem.Text == "第六期") { da.Type = 2.6F; } } //else if (classification.SelectedItem.Text == "BBS资料") //{ da.Cid = 4; } else { da.Cid = 3; } da.Count = 1; if (downattachbll.Add(da)) { Response.Write("<script>alert('添加成功');window.location.href='DownMgr.aspx';</script>"); } else { Response.Write("<script>alert('添加失败');history.back();</script>"); } }
protected void Save_Click(object sender, EventArgs e) { object id = Request.QueryString["id"];//有待改善不安全 DownAttach da = new DownAttach(); DownAttachBLL downbll = new DownAttachBLL(); // da.AddDate = Convert.ToInt32(dr["AddDate"].ToString()); ; da.Writer = Server.HtmlEncode(TxtWriter.Text.Trim()); da.Title = Server.HtmlEncode(TxtTitle.Text.Trim()); da.Id = id; if (classification.SelectedItem.Text == "自然版过刊") { da.Cid = 1; } else if (classification.SelectedItem.Text == "社科版过刊") { da.Cid = 2; } //else if (classification.SelectedItem.Text == "TRIZ书籍") //{ // da.Cid = 3; //} //else if (classification.SelectedItem.Text == "BBS资料") //{ // da.Cid = 4; //} if (FileUp.PostedFile.ContentLength == 0) { da.FileSaveName = TxtFileName.Text; } else { //以下是上传资料的格式检验 FileInfo file1 = new FileInfo(FileUp.PostedFile.FileName); if (file1.Extension.ToLower() != ".doc" && file1.Extension.ToLower() != ".txt" && file1.Extension.ToLower() != ".zip" && file1.Extension.ToLower() != ".rar") { Response.Write("<script>alert('上传的资料格式应为doc/txt/zip/rar格式');history.back(-1);</script>"); return; } string filename = FileUp.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string name = TxtTitle.Text.Trim() + DateTime.Now.ToString("hhmmss") + lastName; string webFilePath = Server.MapPath("~/Attach/" + TxtFileName.Text); //用来删除原有的资料 string newpath = Server.MapPath("~/Attach/" + name); //用来保存新上传的资料 System.IO.FileInfo file = new System.IO.FileInfo(webFilePath); if (file.Exists) { file.Delete();//删除 } if (!File.Exists(newpath)) { FileUp.SaveAs(newpath); // 使用 SaveAs 方法保存文件 } da.FileSaveName = name; } if (downbll.Update(da)) { Response.Write("<script>alert('修改成功');window.location.href='DownMgr.aspx';</script>"); } else { Response.Write("<script>alert('修改失败');history.back();</script>"); } }