前端代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChannelDocumentDetail.aspx.cs" Inherits="BioErpWeb.CRMSystem.CrmChannelDocument.ChannelDocumentDetail" %>
后端代码:
public partial class ChannelDocumentDetail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Session["Userid"] = "29"; if (!IsPostBack) { pageinfobind(); } } static byte[] filecontent = null; ////// 页面信息绑定 /// protected void pageinfobind() { if (Request.QueryString["ID"] == null) { Response.Redirect("ChannelDocumentListShow.aspx"); return; } string id = Request.QueryString["ID"].ToString(); ViewCRMChannelDocumentInfo documentinfo = new ViewCRMChannelDocumentInfo(); ChannelDocumentBLL db = new ChannelDocumentBLL(); documentinfo= db.getChannelDocumentViewByDocumentID(id); txtsubJect.Text = documentinfo.Subject; txtRemark.Text = documentinfo.Remark; txtUserName.Text = documentinfo.UserName; this.txtCHannelID.Text = documentinfo.ChannelName; this.lbName.Text = documentinfo.Name; this.lbExtendName.Text = documentinfo.ExetendName; this.lbType.Text = documentinfo.Type; this.lbSize.Text = documentinfo.DocumentSize.ToString(); this.lbUpdateTime.Text = documentinfo.UploadTime.ToString(); this.ddlLevel.Text = documentinfo.DocumentLevel.ToString(); this.lbIsDelete.Text = documentinfo.DeleteState == true ? "已删除" : "未删除"; filecontent = Comm.GetDownDocumet("dbo.BioCrmCorrelationDocument", "Content", "DocumentID=" + documentinfo.DocumentID); //文档属于当前用户或者当前用户是市场部经理角色则显示编辑按钮 if (documentinfo.UserID == int.Parse(Session["Userid"].ToString()) || Web.UserLogin.user.RoleId == 6) { this.btnSubmit.Visible = true; } else { this.btnSubmit.Visible = false; } } ////// 保存编辑内容 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { Response.Redirect("ChannelDocumentEditAndDown.aspx?ID=" + Request.QueryString["ID"].ToString()); } protected void btnReturn_Click(object sender, EventArgs e) { Response.Redirect("ChannelDocumentListShow.aspx"); } protected void lbtndown_Click(object sender, EventArgs e) { //创建弹出式Windows下载窗体 Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(this.lbName.Text)); //把二进制数组写入Http输出流 Response.BinaryWrite(filecontent); //想当前客户端缓冲区输出 Response.Flush(); //停止执行 Response.End(); } }
编辑的前端:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChannelDocumentEditAndDown.aspx.cs" Inherits="BioErpWeb.CRMSystem.CrmChannelDocument.ChannelDocumentEditAndDown" %>
后台代码:
public partial class ChannelDocumentEditAndDown : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Session["Userid"] = "29"; if (!IsPostBack) { pageinfobind(); } } static byte[] filecontent = null; ////// 页面信息绑定 /// protected void pageinfobind() { if (Request.QueryString["ID"] == null) { Response.Redirect("ChannelDocumentListShow.aspx"); return; } string id = Request.QueryString["ID"].ToString(); ViewCRMChannelDocumentInfo documentinfo = new ViewCRMChannelDocumentInfo(); ChannelDocumentBLL db = new ChannelDocumentBLL(); documentinfo = db.getChannelDocumentViewByDocumentID(id); txtsubJect.Text = documentinfo.Subject; txtRemark.Text = documentinfo.Remark; txtUserName.Text = documentinfo.UserID.ToString(); this.txtSuperChannelID.Text = documentinfo.ChannelID.ToString(); this.lbName.Text = documentinfo.Name; this.lbExtendName.Text = documentinfo.ExetendName; this.lbType.Text = documentinfo.Type; this.lbSize.Text = documentinfo.DocumentSize.ToString(); this.lbUpdateTime.Text = documentinfo.UploadTime.ToString(); this.ddlLevel.Text = documentinfo.DocumentLevel.ToString(); this.cbDelete.Checked = documentinfo.DeleteState; this.lbUser.Text = "姓名:" + documentinfo.UserName + "编号:" + documentinfo.UserID; this.lbCHannel.Text = "名称:" + documentinfo.ChannelName; this.hf_channeldocumentid.Value = documentinfo.ChannelDocumentID.ToString(); filecontent = Comm.GetDownDocumet("dbo.BioCrmCorrelationDocument", "Content", "DocumentID=" + documentinfo.DocumentID); } ////// 保存编辑内容 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { BioCrmCorrelationDocument document = new BioCrmCorrelationDocument(); document.DocumentID = int.Parse(Request.QueryString["ID"].ToString()); document.Subject = this.txtsubJect.Text; document.UserID = int.Parse(Session["Userid"].ToString()); document.Remark = this.txtRemark.Text; document.DocumentLevel = this.ddlLevel.SelectedValue; if (this.FileUpload1.HasFile) { document.Name = DateTime.Now.ToString("yyyyMMddhhmmss") + this.FileUpload1.FileName; document.Content = this.FileUpload1.FileBytes; document.Type = this.FileUpload1.PostedFile.ContentType; document.UploadTime = DateTime.Now; document.DocumentSize = this.FileUpload1.FileContent.Length; document.ExetendName = System.IO.Path.GetExtension(this.FileUpload1.FileName); } else { document.Name = this.lbName.Text; document.Content = filecontent; document.Type = this.lbType.Text; document.UploadTime = Convert.ToDateTime(lbUpdateTime.Text); document.DocumentSize = long.Parse(this.lbSize.Text); document.ExetendName = this.lbExtendName.Text; } if (this.FileUpload1.HasFile) { //物理文件上传 string filepath = Server.MapPath(@"\Files\CRMChannelFiles\"); //如果存在文件则删除 if (Comm.FileExists(filepath + this.lbName.Text)) { Comm.FileDelete(filepath + this.lbName.Text); } Comm.FileUpLoad(this.FileUpload1, filepath, document.Name); } BioCrmCorrelationDocumentBLL documentbll = new BioCrmCorrelationDocumentBLL(); //文档信息添加 包括文件上传(转换为二进制数组后上传) int count = documentbll.BioCrmCorrelationDocumentUpdate(document); //文档信息添加成功 if (count != 0) { BioErpCrmChannelDocument cd = new BioErpCrmChannelDocument(); cd.ChannelID = int.Parse(this.txtSuperChannelID.Text); cd.DocumentID = int.Parse( Request.QueryString["ID"].ToString()); cd.DeleteState = cbDelete.Checked; cd.ChannelDocumentID = int.Parse(this.hf_channeldocumentid.Value); ChannelDocumentBLL dbll = new ChannelDocumentBLL(); int count1 = dbll.BioErpCrmChannelDocumentUpdate(cd); if (count1 == 0) { ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('文档信息修改失败')", true); } else { Response.Redirect("ChannelDocumentListShow.aspx"); } } } protected void btnReturn_Click(object sender, EventArgs e) { Response.Redirect("ChannelDocumentListShow.aspx"); } }