コード例 #1
0
        public static void BackupPDF(StackPanel target)
        {
            string folder = Directory.GetCurrentDirectory() + @"\Backup\";


            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            string filename = $"{DateTime.Now.ToShortDateString()} " +
                              $"{DateTime.Now.ToLongTimeString().Replace(":", ".")} ";

            filename = filename.Replace("/", "-");
            string number = "";

            int i = 1;

            while (File.Exists(folder + filename + number + ".pdf"))
            {
                number = $"({i})";
                i++;
            }

            string fullFilename = folder + filename + number + ".pdf";
            ObservableCollection <Models.TableModelN> models = new ObservableCollection <Models.TableModelN>();

            foreach (var item in target.Children)
            {
                if (item is Controls.TablesControl)
                {
                    if ((item as Controls.TablesControl).Model.HasData)
                    {
                        models.Add((item as Controls.TablesControl).Model);
                    }
                }
            }

            if (models.Count > 0)
            {
                var print = new Scripts.Print();
                print.CreatePDF(fullFilename, models);
            }

            //CreateBitmapFromVisual(target, fullFilename);
        }
コード例 #2
0
        private void Button_Print_Click(object sender, RoutedEventArgs e)
        {
            if (searchList.SelectedItems.Count <= 0)
            {
                MessageBox.Show("Du har ikke valgt nogen skoler som skal udskrives", "Ingen valgte", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            SaveFileDialog dlg   = new SaveFileDialog();
            var            print = new Scripts.Print();

            dlg.Filter = "(.pdf)|*.pdf";
            if (dlg.ShowDialog() == true)
            {
                var models = new ObservableCollection <Models.TableModelN>();
                foreach (var i in searchList.SelectedItems)
                {
                    models.Add(i as Models.TableModelN);
                }
                print.CreatePDF(dlg.FileName, models);
            }
        }