예제 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            string dbDir = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "TaskConqueror");

            AppDomain.CurrentDomain.SetData("DataDirectory", dbDir);

            try
            {
                using (SqlCeConnection connection = new SqlCeConnection(ConfigurationManager.ConnectionStrings["TaskConquerorSql"].ConnectionString))
                {
                    CreateDatabase(dbDir);

                    connection.Open();
                    UpdateDatabaseSchema(GetDatabaseSchemaVersion(connection), connection);
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                WPFMessageBox.Show(TaskConqueror.Properties.Resources.Error_Encountered, "Error encountered while preparing database: " + ex.Message, WPFMessageBoxButtons.OK, WPFMessageBoxImage.Error);
                Application.Current.Shutdown();
            }

            MainWindow window = new MainWindow();

            _viewModel = new MainWindowViewModel();

            // When the ViewModel asks to be closed,
            // close the window.
            EventHandler handler = null;

            handler = delegate
            {
                _viewModel.RequestClose -= handler;
                window.Close();
            };
            _viewModel.RequestClose += handler;

            // Allow all controls in the window to
            // bind to the ViewModel by setting the
            // DataContext, which propagates down
            // the element tree.
            window.DataContext = _viewModel;

            window.Show();
        }
        /// <summary>
        /// Prints the report content.  This method is invoked by the PrintCommand.
        /// </summary>
        public void Print()
        {
            const double Inch = 96;

            // Create a PrintDialog
            System.Windows.Controls.PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            // Create IDocumentPaginatorSource from a copy of our flowdocument content
            MemoryStream stream         = new MemoryStream();
            TextRange    sourceDocument = new TextRange(Content.ContentStart, Content.ContentEnd);

            sourceDocument.Save(stream, System.Windows.DataFormats.Xaml);

            FlowDocument flowDocumentCopy  = new FlowDocument();
            TextRange    copyDocumentRange = new TextRange(flowDocumentCopy.ContentStart, flowDocumentCopy.ContentEnd);

            copyDocumentRange.Load(stream, System.Windows.DataFormats.Xaml);

            double xMargin = (1.25 * Inch);
            double yMargin = (1 * Inch);

            // Set the page padding
            flowDocumentCopy.PagePadding = new Thickness(yMargin, xMargin, xMargin, yMargin);

            IDocumentPaginatorSource idpSource = flowDocumentCopy;

            try
            {
                // Call PrintDocument method to send document to printer
                printDlg.PageRangeSelection   = PageRangeSelection.AllPages;
                printDlg.UserPageRangeEnabled = true;
                if (printDlg.ShowDialog() == true)
                {
                    printDlg.PrintDocument(idpSource.DocumentPaginator, Title);
                    this.OnRequestClose();
                }
            }
            catch (Exception printError)
            {
                WPFMessageBox.Show(Properties.Resources.Error_Encountered, Properties.Resources.CannotPrint + " " + printError.Message, WPFMessageBoxButtons.OK, WPFMessageBoxImage.Error);
            }
        }
예제 #3
0
 protected override bool ShouldClose()
 {
     return(IsSaved || WPFMessageBox.Show("Confirm Cancel", "Cancel without saving changes?", WPFMessageBoxButtons.YesNo, WPFMessageBoxImage.Question) == WPFMessageBoxResult.Yes);
 }