protected void btnDelAttachment_Click(object sender, EventArgs e) { try { string evenid = this.hidEvenid.Value; IList<QueryModel> qmlist = new List<QueryModel>(); qmlist.Add(MakeUtil.getQueryModel("Evenid", "'", SqlWhere.WhereOperator.Equal, evenid)); AttachmentModel am = new AttachmentModel(); am = bllAE.getModel(qmlist); if (am.PaperNo.Length > 0) { this.bllAE.del(qmlist); if (File.Exists(am.FileUrl)) { File.Delete(am.FileUrl); } Script.alertMsg("删除成功", this.Page); Script.scriptRedirect("Attachment.aspx?PaperType=" + PaperType + "&PaperNo=" + PaperNo, this.Page); } else { Script.alertMsg("文件已不存在,删除失败", this.Page); } } catch (Exception ex) { Script.alertMsg(ex.Message, this.Page); } }
public bool add( AttachmentModel list) { SqlConnection cn = null; SqlTransaction tc = null; try { cn = DbHelperSQL.getConnection(); tc = DbHelperSQL.startTransaction(cn); if (dal.add(cn, tc, list)) { DbHelperSQL.commitTransaction(tc); return true; } return false; } catch (SqlException sql) { DbHelperSQL.rollBackTransaction(tc); throw new MakeException(ExpSort.普通, sql.Message); } finally { DbHelperSQL.closeConnection(cn); } }
protected void btnEnter_Click(object sender, EventArgs e) { try { if (this.FileUpload.PostedFile != null) { string name = FileUpload.FileName; string guid = Guid.NewGuid().ToString(); string ext = name.Substring(name.LastIndexOf(".")); name = guid + ext; string path = Server.MapPath("../upload") + "\\" + name; if (File.Exists(path)) { File.Delete(path); } FileUpload.SaveAs(path); AttachmentModel am = new AttachmentModel(); IList<QueryModel> qmlist = new List<QueryModel>(); qmlist.Add(MakeUtil.getQueryModel("PaperNo", "'", SqlWhere.WhereOperator.Equal, PaperNo)); qmlist.Add(MakeUtil.getQueryModel("FileName", "'", SqlWhere.WhereOperator.Equal, name)); am = bllAE.getModel(qmlist); if (am.PaperNo.Length == 0) { am = new AttachmentModel(); am.FileName = name; am.FileUrl = path; am.PaperNo = PaperNo; am.PaperType = PaperType; am.HappenDate = DateTime.Now.Date; am.Memos = this.Desc.Text; bllAE.add(am); Script.alertMsg("上传成功", this.Page); } else { Script.alertMsg("文档已存在,上传失败", this.Page); } Script.scriptRedirect("Attachment.aspx?PaperType=" + PaperType + "&PaperNo=" + PaperNo, this.Page); } else { Script.alertMsg("上传失败", this.Page); } } catch (Exception ex) { Script.alertMsg(ex.Message, this.Page); } }
public bool updata(SqlConnection cn, SqlTransaction tc, AttachmentModel AM) { return DbHelperSQL.updateModel<AttachmentModel>(AM, "Attachment", "Evenid", AM.Evenid.ToString(), "'", cn, tc); }
public bool add(SqlConnection cn, SqlTransaction tc, AttachmentModel AM) { return DbHelperSQL.insertModel<AttachmentModel>(AM, "Attachment", cn, tc); }
public bool update(AttachmentModel list) { SqlConnection cn = null; SqlTransaction tc = null; try { cn = DbHelperSQL.getConnection(); tc = DbHelperSQL.startTransaction(cn); IList<QueryModel> qmlist = new List<QueryModel>(); dal.del(cn, tc, qmlist); dal.add(cn, tc, list); DbHelperSQL.commitTransaction(tc); return true; } catch (SqlException sqlex) { DbHelperSQL.rollBackTransaction(tc); throw new MakeException(ExpSort.普通, sqlex.Message); } finally { DbHelperSQL.closeConnection(cn); } }
public AttachmentModel getModel(IList<QueryModel> qmlist) { SqlConnection cn = null; AttachmentModel pm = new AttachmentModel(); try { cn = DbHelperSQL.getConnection(); pm = dal.getModel(cn, null, qmlist); } catch (SqlException sqlex) { throw new MakeException(ExpSort.普通, sqlex.Message); } finally { DbHelperSQL.closeConnection(cn); } return pm; }