• ERP系统上传文档信息下载(十八)


    下载的公用方法:

     /// <summary>
           /// 下载文档
           /// </summary>
           /// <param name="TableName">查询表</param>
           /// <param name="column">查询列</param>
           /// <param name="condition">查询条件</param>
           /// <returns>byte[]</returns>
           public static byte[] GetDownDocumet(string TableName,string column,string condition) 
           {
               long  datalen = 0;
               System.Data.SqlClient.SqlDataReader reader= SqlComm.GetDataReaderByCondition(TableName, column, condition);
               byte[] data = null;
               try
               {
                   while (reader.Read())
                   {
                       //读取数据的长度
                       datalen = reader.GetBytes(0, 0, data, 0, 1);
                       //分配缓区
                       data = new byte[datalen];
                       //读取数据
                       datalen = reader.GetBytes(0, 0, data, 0, (int)datalen);
                   }
                   reader.Close();
                   return data;
               }
               catch (Exception ex)
               {
                   return null;
               }
       
           }
    

     下载:

    获取文档二进制流:

     filecontent = Comm.GetDownDocumet("BioCrmCorrelationDocument", "Content", " DocumentID=" + id);
    

     下载的具体步骤:

    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();
    
            }
    

     修改的后台代码:

     static byte[] filecontent = null;
            private void Pageinfoband()
            {
                if (Request.QueryString["ID"] != null)
                {
                    string id = Request.QueryString["ID"].ToString();
                    BioCrmCorrelationDocumentBLL dbll = new BioCrmCorrelationDocumentBLL();
                    DocumentInfoView dv = new DocumentInfoView();
                    dv=dbll.getDocumentViewByID(id);
                    this.txtsubJect.Text = dv.Subject;
                    this.txtRemark.Text = dv.Remark;
                    this.lbType.Text = dv.Type;
                    this.txtCustomerID.Text = dv.CustomerID.ToString();
                    this.ddlLevel.SelectedItem.Text = dv.DocumentLevel;
                    this.cbDelete.Checked = dv.DeleteState;
                    this.lbExtendName.Text = dv.ExetendName;
                    this.lbName.Text = dv.Name;
                    filecontent = Comm.GetDownDocumet("BioCrmCorrelationDocument", "Content", " DocumentID=" + id);
                    this.lbSize.Text = dv.DocumentSize.ToString();
                    this.txtUserName.Text = dv.UserID.ToString();
                    this.hf_CustomerDocumentID.Value = dv.CustomerDocumentID.ToString();
                    lbUpdateTime.Text = dv.UploadTime.ToString();
                    
    
                }
            }
            
            /// <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("yyyyMMdd hhmmss") + 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;
                }
    
        
                //物理文件上传
                string filepath = Server.MapPath(@"FilesCRMFiles");
                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)
                {
                    BioCrmCustomerDocument customerdocument = new BioCrmCustomerDocument();
                    customerdocument.CustomerDocumentID = int.Parse(this.hf_CustomerDocumentID.Value);
                    customerdocument.CustomerID = int.Parse(this.txtCustomerID.Text);
                    customerdocument.DeleteState =cbDelete.Checked;
                    customerdocument.DocumentID = document.DocumentID;
                    BioCrmCustomerDocumentBLL customerdocumentbll = new BioCrmCustomerDocumentBLL();
                       int count1= customerdocumentbll.BioCrmCustomerDocumentUpdate(customerdocument);
                       if (count1 == 0)
                       {
                           SqlComm.DeleteTableByCondition("BioCrmCorrelationDocument", "where DocumentID=" + document.DocumentID);
                       }
                       else
                       {
                           Response.Redirect("DocumentListShow.aspx");
                       }
                }
            }
    

     不同角色查询不同的文档:

             /// <summary>
            /// 查询所有联系人信息
            /// </summary>
            private void getallPageList()
            {
                string id = Session["Userid"].ToString();
                condition = " and UserID=" + id;
                if (UserLogin.user.RoleId == 8)
                {
                    condition = " or UserID !=" + id;
                }
                this.AspNetPager1.RecordCount = SqlComm.getDataCountByCondition("dbo.View_DoucmentInfo", condition);
                this.AspNetPager1.PageSize = pagesize;
                this.GridView1.DataSource = SqlComm.getDataByPageIndex("dbo.View_DoucmentInfo", "*", "DocumentID", condition, pageindex, pagesize);
                this.GridView1.DataBind();           
            }
    
  • 相关阅读:
    scala文件读取报错“java.nio.charset.MalformedInputException: Input length = 1”
    关于sparksql操作hive,读取本地csv文件并以parquet的形式装入hive中
    区别window.location.Reload()和window.location.href=window.location.href;
    datagrid GridView Repeater 绑定 序号 逐一递增的实现
    品牌机用Vista光盘分区
    网络路径结点回溯分析工具
    几种流行的AJAX框架jQuery,Mootools,Dojo,Ext JS的对比
    Ubuntu Linux 设置
    sql server中为某个整数前加上一定数量的0,如1,要返回00001
    本地测试域名
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/6071666.html
Copyright © 2020-2023  润新知