コード例 #1
0
ファイル: Main.cs プロジェクト: AmberCode/RentalTracker
        private void DownloadAndPreviewButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (GDGridView.CurrentRow == null)
                {
                    return;
                }

                var gdFile = (GoogleDriveFileModel)GDGridView.CurrentRow.DataBoundItem;

                UploadDocumentLoadingPictureBox.Visible = true;

                var pdfDocMemoryStream = _googleDriveService.DownloadDocument(gdFile.Id);

                using (StreamWriter writer = new StreamWriter(pdfDocMemoryStream))
                {
                    pdfDocMemoryStream.Seek(0, SeekOrigin.Begin);

                    using (FileStream fs = new FileStream(gdFile.Name, FileMode.OpenOrCreate))
                    {
                        pdfDocMemoryStream.CopyTo(fs);
                        fs.Flush();
                    }
                }

                var pdfPreviewForm = new PdfDocPreviewForm(gdFile.Name);

                pdfPreviewForm.ShowDialog(this);

                if (System.IO.File.Exists(gdFile.Name))
                {
                    System.IO.File.Delete(gdFile.Name);
                }
            }
            catch (Exception)
            {
                //log ex
                MessageBox.Show("System error has occurred", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                UploadDocumentLoadingPictureBox.Visible = false;
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: AmberCode/RentalTracker
        private void PreviewAgreementButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (TenantGridView.CurrentRow == null || PropertyGridView.CurrentRow == null)
                {
                    return;
                }

                var tenant = (TenantModel)TenantGridView.CurrentRow.DataBoundItem;

                var property = (PropertyModel)PropertyGridView.CurrentRow.DataBoundItem;

                var pdfService = new PdfService();

                var pdfDoc = pdfService.GenerateRentalDocument(property.OwnerName, tenant.Name);

                var pdfFileName = $"rental_agreement_{property.OwnerName}_{tenant.Name}.pdf";

                System.IO.File.WriteAllBytes(pdfFileName, pdfDoc);

                var pdfPreviewForm = new PdfDocPreviewForm(pdfFileName);

                pdfPreviewForm.ShowDialog(this);

                if (System.IO.File.Exists(pdfFileName))
                {
                    System.IO.File.Delete(pdfFileName);
                }
            }
            catch (Exception ex)
            {
                //log ex
                MessageBox.Show("System error has occurred", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }