Example #1
0
        public void InitializeResourcePage()
        {
            var DESIGN_FixedPage = DocumentHelper.GetFixedPage(new PageReportModel
            {
                Dia         = dia,
                Grade       = grade,
                Length      = length,
                Proc        = proc,
                StdNo       = stdNo,
                Weight      = weight,
                BarCodeData = barcodeData
            },
                                                               reverse: false,
                                                               noBackground: false);

            // Those 'false'es are because PrintPage handles it on its own, using documnet viewer print function
            // doesn're require getting info from settings

            Document.Pages.Add(new PageContent()
            {
                Child = DESIGN_FixedPage
            });

            DocViewer.FitToMaxPagesAcross();
        }
Example #2
0
        public void GoToTraining(string type)
        {
            var pageNumber = 0;

            switch (type)
            {
            case "Preparation.Begin":
                pageNumber = 9;
                break;

            case "Performance.Begin":
                pageNumber = 11;
                break;

            case "WorkingFrequency.Begin":
                pageNumber = 12;
                break;
            }

            if (!DocViewer.CanGoToPage(pageNumber))
            {
                return;
            }

            _comingFromTraining = true;
            DocViewer.GoToPage(pageNumber);
        }
Example #3
0
        }// end:OnClose()

        // -------------------------- PrintDocument ---------------------------
        /// <summary>
        ///   Prints the DocumentViewer's content and annotations.</summary>
        public void PrintDocument()
        {
            if (DocViewer == null)
            {
                return;
            }
            DocViewer.Print();
        }// end:PrintDocument()
Example #4
0
        private void tabControl_Viewer_TabePageClosing(object sender, TabPageEventArgs e)
        {
            SkinTabControl tb_doc = (SkinTabControl)sender;

            if (tb_doc.SelectedTab.Tag is DocViewer)
            {
                DocViewer uc_docviewer = (DocViewer)tb_doc.SelectedTab.Tag;
                uc_docviewer.doForDispose();
            }
        }
Example #5
0
        public Appointment()
        {
            InitializeComponent();
            var document = new XpsDocument(Properties.Resources.XpsDescriptionPath, FileAccess.Read);

            DocViewer.Document = document.GetFixedDocumentSequence();

            DocViewer.AddHandler(Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler(OnRequestNavigate));

            IsVisibleChanged += (s, e) => RadioView.RadioIsEnabled = (bool)e.NewValue && Radio.Visibility == Visibility.Visible;
        }
Example #6
0
        public bool OpenEncryptedDocument(string xpsFile)
        {
            // Check to see if the document is encrypted.
            // If not encrypted, use OpenDocument().
            if (!EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(xpsFile))
                return OpenDocument(xpsFile);

            ShowStatus("Opening encrypted '" + Filename(xpsFile) + "'");

            // Get the ID of the current user log-in.
            string currentUserId;
            try
                { currentUserId = GetDefaultWindowsUserName(); }
            catch
                { currentUserId = null; }
            if (currentUserId == null)
            {
                MessageBox.Show("No valid user ID available", "Invalid User ID",
                    MessageBoxButton.OK, MessageBoxImage.Error);
                ShowStatus("   No valid user ID available.");
                return false;
            }

            ShowStatus("   Current user ID:  '" + currentUserId + "'");
            ShowStatus("   Using " + _authentication + " authentication.");
            ShowStatus("   Checking rights list for user:\n       " +
                           currentUserId);
            ShowStatus("   Initializing the environment.");

            try
            {
                string applicationManifest = "<manifest></manifest>";
                if (File.Exists("rvc.xml"))
                {
                    ShowStatus("   Reading manifest 'rvc.xml'.");
                    StreamReader manifestReader = File.OpenText("rvc.xml");
                    applicationManifest = manifestReader.ReadToEnd();
                }

                ShowStatus("   Initiating SecureEnvironment as user: \n       " +
                    currentUserId + " [" + _authentication + "]");
                if (SecureEnvironment.IsUserActivated(
                    new ContentUser(currentUserId, _authentication)))
                {
                    ShowStatus("   User is already activated.");
                    _secureEnv = SecureEnvironment.Create(applicationManifest,
                                    new ContentUser(currentUserId, _authentication));
                }
                else // if user is not yet activated.
                {
                    ShowStatus("   User is NOT activated,\n       activating now....");
                    // If using the current Windows user, no credentials are
                    // required and we can use UserActivationMode.Permanent.
                    _secureEnv = SecureEnvironment.Create(applicationManifest,
                                    _authentication, UserActivationMode.Permanent);

                    // If not using the current Windows user, use
                    // UserActivationMode.Temporary to display the Windows
                    // credentials pop-up window.
                    ///_secureEnv = SecureEnvironment.Create(applicationManifest,
                    ///     a_authentication, UserActivationMode.Temporary);
                }
                ShowStatus("   Created SecureEnvironment for user:\n       " +
                    _secureEnv.User.Name +
                    " [" + _secureEnv.User.AuthenticationType + "]");

                ShowStatus("   Opening the encrypted Package.");
                EncryptedPackageEnvelope ePackage =
                    EncryptedPackageEnvelope.Open(xpsFile, FileAccess.ReadWrite);
                RightsManagementInformation rmi =
                    ePackage.RightsManagementInformation;

                ShowStatus("   Looking for an embedded UseLicense for user:\n       " +
                           currentUserId + " [" + _authentication + "]");
                UseLicense useLicense =
                    rmi.LoadUseLicense(
                        new ContentUser(currentUserId, _authentication));

                ReadOnlyCollection<ContentGrant> grants;
                if (useLicense == null)
                {
                    ShowStatus("   No Embedded UseLicense found.\n       " +
                               "Attempting to acqure UseLicnese\n       " +
                               "from the PublishLicense.");
                    PublishLicense pubLicense = rmi.LoadPublishLicense();

                    ShowStatus("   Referral information:");

                    if (pubLicense.ReferralInfoName == null)
                        ShowStatus("       Name: (null)");
                    else
                        ShowStatus("       Name: " + pubLicense.ReferralInfoName);

                    if (pubLicense.ReferralInfoUri == null)
                        ShowStatus("    Uri: (null)");
                    else
                        ShowStatus("    Uri: " +
                            pubLicense.ReferralInfoUri.ToString());

                    useLicense = pubLicense.AcquireUseLicense(_secureEnv);
                    if (useLicense == null)
                    {
                        ShowStatus("   User DOES NOT HAVE RIGHTS\n       " +
                            "to access this document!");
                        return false;
                    }
                }// end:if (useLicense == null)
                ShowStatus("   UseLicense acquired.");

                ShowStatus("   Binding UseLicense with the SecureEnvironment" +
                         "\n       to obtain the CryptoProvider.");
                rmi.CryptoProvider = useLicense.Bind(_secureEnv);

                ShowStatus("   Obtaining BoundGrants.");
                grants = rmi.CryptoProvider.BoundGrants;

                // You can access the Package via GetPackage() at this point.

                rightsBlock.Text = "GRANTS LIST\n-----------\n";
                foreach (ContentGrant grant in grants)
                {
                    rightsBlock.Text += "USER  :"******" [" +
                        grant.User.AuthenticationType + "]\n";
                    rightsBlock.Text += "RIGHT :" + grant.Right.ToString()+"\n";
                    rightsBlock.Text += "    From:  " + grant.ValidFrom + "\n";
                    rightsBlock.Text += "    Until: " + grant.ValidUntil + "\n";
                }

                if (rmi.CryptoProvider.CanDecrypt == true)
                    ShowStatus("   Decryption granted.");
                else
                    ShowStatus("   CANNOT DECRYPT!");

                ShowStatus("   Getting the Package from\n" +
                           "      the EncryptedPackage.");
                _xpsPackage = ePackage.GetPackage();
                if (_xpsPackage == null)
                {
                    MessageBox.Show("Unable to get Package.");
                    return false;
                }

                // Set a PackageStore Uri reference for the encrypted stream.
                // ("sdk://packLocation" is a pseudo URI used by
                //  PackUriHelper.Create to define the parserContext.BaseURI
                //  that XamlReader uses to access the encrypted data stream.)
                Uri packageUri = new Uri(@"sdk://packLocation", UriKind.Absolute);
                // Add the URI package
                PackageStore.AddPackage(packageUri, _xpsPackage);
                // Determine the starting part for the package.
                PackagePart startingPart = GetPackageStartingPart(_xpsPackage);

                // Set the DocViewer.Document property.
                ShowStatus("   Opening in DocumentViewer.");
                ParserContext parserContext = new ParserContext();
                parserContext.BaseUri = PackUriHelper.Create(
                                            packageUri, startingPart.Uri);
                parserContext.XamlTypeMapper = XamlTypeMapper.DefaultMapper;
                DocViewer.Document = XamlReader.Load(
                    startingPart.GetStream(), parserContext)
                        as IDocumentPaginatorSource;

                // Enable document menu controls.
                menuFileClose.IsEnabled = true;
                menuFilePrint.IsEnabled = true;
                menuViewIncreaseZoom.IsEnabled = true;
                menuViewDecreaseZoom.IsEnabled = true;

                // Give the DocumentViewer focus.
                DocViewer.Focus();
            }// end:try
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.Message + "\n\n" +
                    ex.GetType().ToString() + "\n\n" + ex.StackTrace,
                    "Exception",
                    MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            this.Title = "RightsManagedPackageViewer SDK Sample - " +
                         Filename(xpsFile) + " (encrypted)";
            return true;
        }// end:OpenEncryptedDocument()
 private void CurrentDocViewerContainerSizeChanged(object sender, SizeChangedEventArgs e)
 {
     DocViewer.FitToWidth();
 }
Example #8
0
        private void openFileViewer(Int32 fileID)
        {
            string connectionStringPBox  = DBSource.ConnectionStringPBox;
            string connectionStringPData = DBSource.ConnectionStringPData;
            string commandText           = @"SELECT file_id,file_name,file_type,file_size,file_nodeid FROM FileMemo where file_id = " + fileID;

            helperPBox = new dBHelper(connectionStringPBox);
            if (helperPBox.Load(commandText, "") == true)
            {
                if (fileID > 0 && helperPBox.DataSet.Tables[0].Rows.Count > 0)
                {
                    DataRow       dataRow    = helperPBox.DataSet.Tables[0].Select("file_id=" + fileID)[0];
                    string        filename   = dataRow["file_name"].ToString();
                    string        filetype   = dataRow["file_type"].ToString();
                    List <Byte[]> l_fileData = new FileDBHelper().getFileData(fileID);
                    if (l_fileData.Count == 0)
                    {
                        MessageBoxEx.Show("找不到对应数据文件!");
                        return;
                    }
                    SkinTabPage tp = new SkinTabPage();
                    tp.Text = filename;
                    switch (filetype)
                    {
                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".gif":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            try
                            {
                                Bitmap    bmap         = new Bitmap(Application.StartupPath + "\\temp\\" + filename + filetype);
                                PicViewer uc_picviewer = new PicViewer();
                                uc_picviewer.showPic(filename, bmap);
                                uc_picviewer.Dock = DockStyle.Fill;
                                tp.Controls.Add(uc_picviewer);
                                tabControl_Viewer.TabPages.Add(tp);
                            }
                            catch (Exception exp) { }
                        }
                        break;
                    }

                    case ".doc":
                    case ".docx":
                    case ".xls":
                    case ".xlsx":
                    case ".ppt":
                    case ".pptx":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            DocViewer uc_docviewer = new DocViewer();
                            tp.Tag            = uc_docviewer;
                            uc_docviewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(uc_docviewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            uc_docviewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".txt":
                    case ".sql":
                    case ".log":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            StreamReader sr        = new StreamReader(Application.StartupPath + "\\temp\\" + filename + filetype, Encoding.Default);
                            TxtViewer    txtViewer = new TxtViewer();
                            txtViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(txtViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            txtViewer.showTxt(sr.ReadToEnd());
                            sr.Close();
                        }
                        break;
                    }

                    case ".htm":
                    case ".html":
                    case ".mht":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            WebViewer webViewer = new WebViewer();
                            webViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(webViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            webViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".pdf":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            PDFViewer pdfViewer = new PDFViewer();
                            pdfViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(pdfViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            pdfViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".mp4":
                    case ".avi":
                    case ".rm":
                    case ".rmvb":
                    case ".flv":
                    case ".xr":
                    case ".wmv":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                        }
                        FrmPlayer aplayer = new FrmPlayer();
                        aplayer.Text = filename;
                        aplayer.Show();
                        aplayer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        break;
                    }
                    }
                    tabControl_Viewer.SelectedTab = tp;
                }
            }
        }
Example #9
0
        } // end:OnClose()

        // -------------------------- PrintDocument ---------------------------
        /// <summary>
        ///     Prints the DocumentViewer's content and annotations.
        /// </summary>
        public void PrintDocument()
        {
            DocViewer?.Print();
        } // end:PrintDocument()