ERP渠道文档详细和修改(二十五)

前端代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChannelDocumentDetail.aspx.cs" Inherits="BioErpWeb.CRMSystem.CrmChannelDocument.ChannelDocumentDetail"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Styles/ERPBaseStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/CalenderStyle.css" rel="stylesheet" type="text/css" />  
    <script src="../../JS/CustomerName.js" type="text/javascript"></script>
    <script src="../../JS/CheckUserName.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/ValidateMessage_ZW.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#form1").validate();
        });
    
    </script>
    <style type="text/css">
        .style1
        {
            height: 20px;
        }
        .style2
        {
            height: 22px;
        }
        .style3
        {
            height: 17px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <table class="maintable">
      <tr>
       <td colspan="2" class="titlebar"><span>渠道文档详细信息</span></td>
      </tr>
       <tr>
           <td class="style1">主题</td><td class="style1"><asp:Label ID="txtsubJect" runat="server"></asp:Label></td>
       </tr>
       <tr>
           <td class="style1">文件名</td><td class="style1">
           <asp:Label ID="lbName" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">文件扩展名</td><td class="style1">
           <asp:Label ID="lbExtendName" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">文件类型</td><td class="style1">
           <asp:Label ID="lbType" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">文件大小</td><td class="style1">
           <asp:Label ID="lbSize" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">上传时间</td><td class="style1">
           <asp:Label ID="lbUpdateTime" runat="server" Text=""></asp:Label></td>
       </tr>
       <tr>
           <td class="style1">上传用户</td><td class="style1">

            <asp:Label ID="txtUserName" runat="server"></asp:Label> </td>
       </tr>
      <tr>
            <td>
                文档等级</td>
          <td>
           <asp:Label ID="ddlLevel" runat="server"></asp:Label>
             
          </td>
      </tr>
        <tr>
            <td class="style2">
                文档下载</td>
          <td class="style2">
              <asp:LinkButton ID="lbtndown" runat="server" onclick="lbtndown_Click">下载此文档</asp:LinkButton>
          </td>
      </tr>
          <tr>
            <td>
                所属渠道
          </td>
          <td >
              <asp:Label ID="txtCHannelID" runat="server"></asp:Label> </td> 
      </tr>
          <tr>
            <td class="style3">
                说明</td>
          <td class="style3" >
              <asp:Label ID="txtRemark"  runat="server" ></asp:Label>
          </td> 
      </tr>
          <tr>
            <td>
                是否删除</td>
          <td >
          <asp:Label ID="lbIsDelete" runat="server" ></asp:Label>
             
          </td> 
      </tr>
         <tr>
             <td colspan="2" class="bottomtd">
             
                 <asp:HiddenField ID="hf_CustomerDocumentID" runat="server" />
             
                 <asp:Button ID="btnReturn" runat="server" UseSubmitBehavior="false" Text="返回列表" onclick="btnReturn_Click" 
                     />
                 <asp:Button ID="btnSubmit" runat="server" Text="文档编辑" 
                     onclick="btnSubmit_Click" />                     
             </td>
         </tr>

     </table>
        <br />
    </div>
    </form>
</body>
</html>

 后端代码:

  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;

        /// <summary>
        /// 页面信息绑定
        /// </summary>
        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;
            }
        }
  
        /// <summary>
        /// 保存编辑内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Styles/ERPBaseStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/CalenderStyle.css" rel="stylesheet" type="text/css" />  
    <script src="../../JS/ChannelChoose.js" type="text/javascript"></script>
    <script src="../../JS/CheckUserName.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.metadata.js" type="text/javascript"></script>
    <script src="../../Scripts/ValidateMessage_ZW.js" type="text/javascript"></script>

    <script type="text/javascript">
        $().ready(function () {
            $("#form1").validate();
        });
    
    </script>
    <style type="text/css">
        .style1
        {
            height: 20px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <table class="maintable">
      <tr>
       <td colspan="2" class="titlebar"><span>渠道文档信息编辑/下载</span></td>
      </tr>
       <tr>
           <td class="style1">主题</td><td class="style1"><asp:TextBox ID="txtsubJect" runat="server" CssClass="required"></asp:TextBox></td>
       </tr>
       <tr>
           <td class="style1">文件名</td><td class="style1">
           <asp:Label ID="lbName" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">文件扩展名</td><td class="style1">
           <asp:Label ID="lbExtendName" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">文件类型</td><td class="style1">
           <asp:Label ID="lbType" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">文件大小</td><td class="style1">
           <asp:Label ID="lbSize" runat="server" Text=""></asp:Label>
           </td>
       </tr>
       <tr>
           <td class="style1">上传时间</td><td class="style1">
           <asp:Label ID="lbUpdateTime" runat="server" Text=""></asp:Label></td>
       </tr>
       <tr>
           <td class="style1">上传用户</td><td class="style1">

            <asp:TextBox ID="txtUserName" runat="server" CssClass="{required:true,number:true, min:1}"></asp:TextBox><input type="button" value="选择" style=" 100px;" onclick="showDialog2()" />
            (原来用户:)<asp:Label
                  ID="lbUser" runat="server" Text="Label"></asp:Label>
           </td>
       </tr>
      <tr>
            <td>
                文档等级</td>
          <td>
              <asp:DropDownList ID="ddlLevel" runat="server">
                  <asp:ListItem Selected="True">一般文件</asp:ListItem>
                  <asp:ListItem>重要文件</asp:ListItem>
                  <asp:ListItem>非常重要文件</asp:ListItem>
                  <asp:ListItem>特别重要</asp:ListItem>
              </asp:DropDownList>
          </td>
      </tr>
        <tr>
            <td>
                文档选择</td>
          <td>
              <asp:FileUpload ID="FileUpload1" runat="server" />
          </td>
      </tr>
          <tr>
            <td>
                所属渠道
          </td>
          <td >
              <asp:TextBox ID="txtSuperChannelID" CssClass="{required:true,number:true, min:1}" runat="server"></asp:TextBox><input type="button" value="选择" style=" 100px;" onclick="showChannel()" />(原来渠道:)<asp:Label
                  ID="lbCHannel" runat="server" Text="Label"></asp:Label>
          </td> 
      </tr>
          <tr>
            <td>
                说明</td>
          <td >
              <asp:TextBox ID="txtRemark" TextMode="MultiLine" Rows="5" runat="server" 
                  Width="380px"></asp:TextBox>
          </td> 
      </tr>
          <tr>
            <td>
                是否删除</td>
          <td >
              <asp:CheckBox ID="cbDelete" runat="server" />
          </td> 
      </tr>
         <tr>
             <td colspan="2" class="bottomtd">
             
                 <asp:HiddenField ID="hf_channeldocumentid" runat="server" />
             
                 <asp:Button ID="btnSubmit" runat="server" Text="文档编辑保存" 
                     onclick="btnSubmit_Click" />
                                  
                 <asp:Button ID="btnReturn" runat="server" UseSubmitBehavior="false" Text="返回列表" onclick="btnReturn_Click" 
                     />
             </td>
         </tr>
     </table>
        <br />
    </div>
    </form>
</body>
</html>

 后台代码:

 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;
        /// <summary>
        /// 页面信息绑定
        /// </summary>
        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);
        }
  
        /// <summary>
        /// 保存编辑内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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(@"FilesCRMChannelFiles");
                //如果存在文件则删除
                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");
        }
    }
原文地址:https://www.cnblogs.com/sunliyuan/p/7191799.html