Ejemplo n.º 1
0
        /// <summary>
        /// 显示文件,不包括PDF文件
        /// </summary>
        /// <param name="FileDataAttachmentGuid"></param>
        public void OpenFile(string FileDataAttachmentGuid)
        {
            FileDataManage FileDataManage = new FileDataManage();
            DataTable      dtl            = FileDataManage.GetFileDataAttachmentByAttachmentGuid(FileDataAttachmentGuid);

            if (dtl.Rows.Count > 0)
            {
                Byte[] bytes             = (Byte[])dtl.Rows[0]["FileContent"];
                string strFileSourceName = dtl.Rows[0]["FileSourceName"].ToString();

                Random ran = new Random();
                int    num = ran.Next(1, 10);

                //先将文件下载到本地
                txtFilePath.Text = Application.StartupPath + @"\FileAttachment\" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + num.ToString() + strFileSourceName;
                FileStream fs = new FileStream(txtFilePath.Text, FileMode.OpenOrCreate, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();

                try
                {
                    //打开文件
                    Process p = new Process();
                    p.StartInfo.FileName  = txtFilePath.Text;
                    p.StartInfo.Arguments = "/FileAttachment";
                    p.Start();
                }
                catch
                {
                    this.ShowAlertMessage("当前文件无法打开,本地没有安装此文件的安装程序!");
                }
            }
        }
Ejemplo n.º 2
0
        //下载
        private void repositoryItemButtonEdit2_Click(object sender, EventArgs e)
        {
            //获取当前文件的FileDataAttachmentGuid
            if (gridView2.RowCount > 0)
            {
                //得到当前登陆人员所在部门
                EmployeeManage EmployeeManage = new EmployeeManage();
                string         strDept        = EmployeeManage.GetEmpDeptByEmpName(SysParams.UserName);

                string strEmpGuid = EmployeeManage.GetEmpGuIDByEmpName(SysParams.UserName);

                string strFileGuID = ((DataRowView)(gridView1.GetFocusedRow())).Row["FileGuid"].ToString();

                if (rightgroupManage.IsOperateRightByUserID(SysParams.UserID, "FileAllView", "Qry") == false)
                {
                    //判断是否有下载权限
                    FileApplyManage FileApplyManage = new FileApplyManage();
                    if (FileApplyManage.IsDownloadByUserID(strEmpGuid, strDept, strFileGuID) == false)
                    {
                        this.ShowAlertMessage("你没有权限下载此文件!");
                        return;
                    }


                    // this.ShowAlertMessage("你没有权限下载此文件!");
                    // return;
                }



                string guid = ((DataRowView)(gridView2.GetFocusedRow())).Row["FileDataAttachmentGuid"].ToString();



                FileDataManage FileDataManage = new FileDataManage();
                DataTable      dtl            = FileDataManage.GetFileDataAttachmentByAttachmentGuid(guid);

                if (dtl.Rows.Count > 0)
                {
                    Byte[] bytes = (Byte[])dtl.Rows[0]["FileContent"];


                    //先将文件下载到本地
                    SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
                    SaveFileDialog1.FileName = dtl.Rows[0]["FileSourceName"].ToString();
                    SaveFileDialog1.Filter   = "All   files   (*.*)|*.* ";

                    SaveFileDialog1.RestoreDirectory = true;

                    if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        string     strfilepath = SaveFileDialog1.FileName;
                        FileStream fs          = new FileStream(strfilepath, FileMode.OpenOrCreate, FileAccess.Write);
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Close();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 显示pdf文件
        /// </summary>
        /// <param name="FileDataAttachmentGuid"></param>
        public void ViewPDF(string FileDataAttachmentGuid)
        {
            FileDataManage FileDataManage = new FileDataManage();
            DataTable      dtl            = FileDataManage.GetFileDataAttachmentByAttachmentGuid(FileDataAttachmentGuid);

            if (dtl.Rows.Count > 0)
            {
                Byte[] bytes = (Byte[])dtl.Rows[0]["FileContent"];

                Random ran = new Random();
                int    num = ran.Next(1, 10);


                //先将文件下载到本地
                //判断目录是否存在,如果不存在,则创建
                if (Directory.Exists(Application.StartupPath + @"\FileAttachment") == false)
                {
                    Directory.CreateDirectory(Application.StartupPath + @"\FileAttachment");
                }

                txtFilePath.Text = Application.StartupPath + @"\FileAttachment\" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + num.ToString() + ".pdf";
                FileStream fs = new FileStream(txtFilePath.Text, FileMode.OpenOrCreate, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();


                //加密PDF文件,加密后不可复制与打印---此方法有些版本pdf会报错
                // PDFSecurity(txtFilePath.Text, txtFilePath.Text, false, "P@ssw0rd");


                //加密PDF文件,加密后不可复制与打印
                pdfreadonly(txtFilePath.Text);

                //载入pdf文件
                axAcroPDF1.LoadFile(txtFilePath.Text);
                axAcroPDF1.setShowToolbar(false);
                axAcroPDF1.setZoom(100);

                this.ShowDialog();
            }
        }