private bool ClearAllAtt(Framework.Task.Task task, ref string errmsg) { this.BeginTran(); try { BaseDao baseDao = new BaseDao(); YwData entity = task.Entity as YwData; entity.AttachmentCount = 0; Hashtable ht = new Hashtable(); ht.Add("Did", entity.Did); baseDao.UpdateUdf("YwDataAttClear", ht); YwAttach att = new YwAttach(); att.Dataid = entity.Did; baseDao.Delete(att); this.CommitTran(); errmsg = "清空成功"; } catch (Exception ex) { this.RollbackTran(); errmsg = ex.Message; return(false); } return(true); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; HttpPostedFile file = context.Request.Files["Filedata"]; string id = context.Request["id"].Trim(); try { int temp = int.Parse(id); if (temp < 0) { context.Response.Write("0"); } string pathtemp = "" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day; string uploadPath = HttpContext.Current.Server.MapPath("upload" + "\\" + pathtemp + "\\"); //判断上传的文件是否为空 if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } YwAttach att = new YwAttach(); att.RealName = file.FileName; //保存文件 string[] arr = file.FileName.Split('.'); string fileName = ""; if (arr.Length > 1) { fileName = Guid.NewGuid().ToString() + "." + arr[arr.Length - 1]; } else { fileName = Guid.NewGuid().ToString(); } file.SaveAs(uploadPath + fileName); BaseDao baseDao = new BaseDao(); att.Dic = uploadPath; att.FileN = fileName; att.Dataid = temp; att.Type = "1"; baseDao.Insert(att); //Hashtable ht=new Hashtable(); //ht.Add("Did", temp); //baseDao.UpdateUdf("YwDataAttUpdate", ht); context.Response.Write("1"); } else { context.Response.Write("0"); } } catch { context.Response.Write("0"); } context.Response.Write("0"); }
private void DealDownAtt() { YwAttach att = new YwAttach(); att.Dataid = Entity.Did; att.Type = "2"; BaseDao baseDao = new BaseDao(); IList<YwAttach> list = baseDao.List(att); if (list.Count > 0) { YwAttach temp = list[0]; string path = temp.Dic + temp.FileN; Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("Content-Disposition", "attachment;filename=" + temp.FileN); string filename = path; Response.TransmitFile(filename); } else { errmsg = "没有附件"; } Task.Submit = false; }
private bool YwySubmit(Framework.Task.Task task, ref string errmsg) { bool result = true; this.BeginTran(); try { YwData entity = task.Entity as YwData; BaseDao baseDao = new BaseDao(); YwAttach att = new YwAttach(); att.Type = "1"; att.Dataid = entity.Did; IList <YwAttach> attList = baseDao.List(att); if (attList != null && attList.Count > 0) { entity.AttachmentCount = attList.Count; } else { entity.AttachmentCount = 0; } entity.Status = "3"; entity.YwySubmit = DateTime.Now; if (entity.Bbr.Length <= 4) { if (entity.Sfypz == "是") { YwDataService service = new YwDataService(); service.FirstCalculate(1, entity); service.SeconeCalculate(entity); } } else { YwDataService service = new YwDataService(); service.FirstCalculate(1, entity); service.SeconeCalculate(entity); } int count = baseDao.Update(entity); if (count <= 0) { errmsg = "数据在页面显示后被其他人修改过,请重新打开编辑"; task.ParentRebind = true; task.Rebind = true; task.IsClose = true; return(false); } //文件压缩 //删除压缩文件 att.Type = "2"; baseDao.DeleteUdf("YwAttachDeleteByType", att); //重新压缩附件 if (attList != null && attList.Count > 0) { string zipdic = attList[0].Dic; string zipFileN = Guid.NewGuid().ToString() + ".zip"; string path = zipdic + zipFileN; using (ZipFile zip = ZipFile.Create(@path)) { zip.BeginUpdate(); foreach (YwAttach attTemp in attList) { string pathT = attTemp.Dic + attTemp.FileN; zip.Add(@pathT, attTemp.FileN); } zip.CommitUpdate(); } att.Type = "2"; att.Dic = zipdic; att.FileN = zipFileN; att.RealName = zipFileN; att.Dataid = entity.Did; baseDao.Insert(att); } if (result == true) { errmsg = "保存成功"; task.ParentRebind = true; task.IsClose = true; } this.CommitTran(); } catch (Exception ex) { this.RollbackTran(); errmsg = ex.Message; } return(result); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { YwAttach att = new YwAttach(); att.Dataid = Entity.Did; att.Type = "1"; BaseDao baseDao = new BaseDao(); IList<YwAttach> list = baseDao.List(att); if (list.Count > 0) { string pic = System.Configuration.ConfigurationManager.AppSettings["Pic"].Trim(); string[] picArr = pic.Split('|'); int index = 0; foreach (YwAttach temp in list) { index++; string title = "<hr/><h4>附件" + index + ":" + temp.RealName + "</h4>"; string[] arr = temp.FileN.Split('.'); string tailT = arr[arr.Length - 1].Trim().ToUpper(); string[] pathArr = temp.Dic.Split('\\'); string relPath = ""; bool enter = false; for (int i = 0; i < pathArr.Length; i++) { if (pathArr[i] == "") { continue; } if (pathArr[i] == "upload" || enter == true) { relPath += pathArr[i] + "\\"; enter = true; } } bool isPic = false; foreach (string picT in picArr) { if (tailT == picT) { Image img = new Image(); img.ImageUrl = relPath + temp.FileN; title += "<a href='" + relPath + temp.FileN + "'>下载</a><hr/>"; this.panCon.Controls.Add(new LiteralControl(title)); this.panCon.Controls.Add(img); isPic = true; break; } } if (isPic == true) { continue; } HyperLink link = new HyperLink(); link.NavigateUrl = relPath + temp.FileN; link.Text = temp.RealName; title += "<a href='" + relPath + temp.FileN + "'>下载</a><hr/>"; this.panCon.Controls.Add(new LiteralControl(title)); this.panCon.Controls.Add(link); } } else { Label lab = new Label(); lab.Text = "没有附件"; this.panCon.Controls.Add(lab); } } }