Laden...
M
Maendler myCSharp.de - Member
Mürren - Schweiz Dabei seit 17.12.2011 9 Beiträge
Benutzerbeschreibung

Forenbeiträge von Maendler Ingesamt 9 Beiträge

13.03.2017 - 13:16 Uhr

Hallo MarsStein,

Ich denke nicht, dass die übergabe mit typeof(T) den Fehler verursacht, da sont auch alle PropertyChangedEvents nicht abgehohlt würden. Dies ist jedoch der in allen Datenrelevanten Properties der fall, also muss meines erachtens dies keine Rolle spielen.

Gruss Alex

13.03.2017 - 11:03 Uhr

Wieso invokest du mit einem Typ als sender?

Der void ist eigntlich protected und befindet sich in einer generischen Basisklasse für alle Views, der ich ten Typ der abgeleiteten Klasse mitgebe.

Gruss Alex

13.03.2017 - 10:22 Uhr

Hallo zusammen,

Ich habe eine Combobox, die je nach Auswahl einer andern Combobox disabled oder enabled sein soll.



<DatePicker Grid.Row="3" Grid.Column="1" SelectedDate="{Binding RangeEndTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                      IsEnabled="{Binding IsEventDurationEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" FontWeight="Bold" HorizontalAlignment="Left" 
                        VerticalAlignment="Center" Width="100" Margin="2.5"/>


Da sonst alle PropertyChangedEvents abgeholt werden, stehe ich völig auf dem Schlauch.

Der Code des PropertyChangedEvents ist;



private void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(typeof(T), new PropertyChangedEventArgs(propertyName));
        }


Blickt da jemand durch?

Gruss Alex

05.03.2017 - 08:16 Uhr

Hoi resper,

Es stellt sich die Frage, was ist MainWindow.sqlHelper.GetAllUser() ?

Ist GetAllUsers() eine Tabelle. eine ObservableCollection<T> oder eine List<T> ?

Ich würde GetAllUsers als ObservableCollection<T> implemtieren, und im MainWindow den CollectionChanged.Event abfangen. Den Event kannst du so abfangen:


private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            bool itemChanged = false;
            if(!e.OldItems.Equals(e.NewItems))
            {
                for(int i =0; i<e.OldItems.Count;i++)
                {
                    if(!e.NewItems[i].Equals (e.OldItems[i]) )
                    {
                        itemChanged = true;
                    }
                }
            }

            if (itemChanged)
            {
                // Mache etwas!!
            }
        }

Gruss Alex

02.03.2017 - 11:40 Uhr

Hoi BJA-CH

Wen du die Datan nicht aus aus dem Daatagrid, sonder aus der Tabelle und oder einer ObsevabelnCololection<T> holst, kanst du die Daten nach deinen eigenen Vorstellungen filten und sortieren.

Gruss Alex

28.02.2017 - 13:39 Uhr

Zuerst benötigt man die PrintBasis-Klasse



sing System;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
using System.Printing;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
using System.Windows.Xps.Serialization;
using sd = System.Drawing;

namespace js.WPFbase.Printing
{
    public abstract class PrintBase 
    {

        #region Const

        protected const double _LEFT_MARGIN = 60;
        protected const double _TOP_MARGIN = 80;

        protected const string _FONT_NAME = "Tahoma";
        protected const string _FORMAT_NUMBRE = "#,##0.00";
        protected const string _FORMAT_DATE = "dd, MM, yyyy";
        protected const double _ROW_HEIGHT = 7.5D;

        protected const double _TITLE_SPACE1 = 60D;
        protected const double _TITLE_SPACE = 40D;
        protected const double _HEADER_SPACE = 25D;
        protected const double _ROW_SPACE = 17D;

        protected const int _MAX_ROWS_PER_SHEET = 50;

        private const string _XPS_FILE_NAME = "C:\\temp\\tmp.xps";

        #endregion

        #region PrintFolder

        private PrintDialog _printDialog;
        private PageOrientation _pageOrientation = PageOrientation.Portrait;
        private PageMediaSizeName _pageSize = PageMediaSizeName.ISOA4;

        #endregion

        #region DocumentFolder

        private FixedDocument _fixedDoc;

        protected Dictionary<int, Canvas> _contentDictionary;


        #endregion

        #region PrivateFolder

        private int _pageCounter = 0;
        private double _top;
        private double _left;

        #endregion

        public PrintBase()
        {
            _contentDictionary = new Dictionary<int, Canvas>();
            InitPrinter(false);
        }

        #region Document

        public FixedDocument FixedDoc { get { return _fixedDoc; } }

        #endregion

        #region Protected

        protected enum TextSize {Default, Small, Midel, Big }

        protected void AddPages()
        {
            _pageCounter++;
            _contentDictionary.Add(_pageCounter, new Canvas());

        }

        protected PageMediaSizeName PageSize
        {
            get { return _pageSize; }
            set
            {
                _pageSize = value;
                _printDialog.PrintTicket.PageMediaSize = new PageMediaSize(value);
            }
        }

        protected PageOrientation PageOrientation
        {
            get { return _pageOrientation; }
            set
            {
                _pageOrientation = value;
                _printDialog.PrintTicket.PageOrientation = value;
            }
        }

        protected int PagesCount { get { return _pageCounter; } }
        protected double MaxPrintAreaWidth { get; private set; }
        protected double MaxPrintAreaHeight { get; private set; }
        protected double Top
        {
            get
            {
                return _top == 0D ? _TOP_MARGIN : _top;

            }
            set { _top = value; }
        }
        protected double Left
        {
            get
            {
                return _left == 0D ? _LEFT_MARGIN : _left;

            }
            set { _left = value; }
        }
        protected int RowCounter { get; set; }

        protected void CreateFixedDoc(bool borderLess = false)
        {
            InitPrinter(borderLess);

            _fixedDoc = new FixedDocument();
                
            try
            {
                _fixedDoc.DocumentPaginator.PageSize = new Size(borderLess ? _printDialog.PrintableAreaWidth : 21.0D, borderLess ? _printDialog.PrintableAreaHeight : 29.7D);
                
                _fixedDoc.PrintTicket = _printDialog.PrintTicket;

                for (int i = 1; i <= _pageCounter; i++)
                {
                    FixedPage page = new FixedPage();

                    PageContent content = new PageContent();
                    ((IAddChild)content).AddChild(page);
                    page.Children.Add(_contentDictionary[i]);

                    _fixedDoc.Pages.Add(content);

                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

        }

        protected Canvas CurrentCanvas
        {
            get
            {
                return _contentDictionary[PagesCount];
            }
        }

        protected Color ForeGround { get; set; }

        protected double GetTexSize(TextSize size)
        {
            if (size == TextSize.Big) return 36D;
            if (size == TextSize.Midel) return 20D;
            if (size == TextSize.Small) return 15D;
            return 12D;
        }

        protected void PrintOut(bool borderLess, bool showPrintDlg = false)
        {

            if(showPrintDlg)
            {
                bool? result = _printDialog.ShowDialog();
                if(result==true)
                {
                    Print();
                }
            }
            else
            {
                Print();
            }

        }

        protected void RestorDocument()
        {
            _fixedDoc = new FixedDocument();
            _pageCounter = 0;
            _contentDictionary.Clear();
        }

        #endregion

        #region AddPageChildren

        protected void AddTextBlock(string text, double textBlockWidth, string FontName, Color foreGround, TextSize textSize,
            FontWeight fontWeight, System.Windows.FontStyle fontStyle, double left, double top, TextAlignment alignment)
        {
            FontFamily font = new FontFamily(FontName);
            TextBlock txt = new TextBlock();

            txt.Foreground = new SolidColorBrush(foreGround);
            txt.FontSize = GetTexSize(textSize);
            txt.Width = textBlockWidth;
            txt.TextAlignment = alignment;
            txt.FontFamily = font;
            txt.FontWeight = fontWeight;
            txt.FontStyle = fontStyle;
            txt.Text = text;
            Canvas.SetLeft(txt, left);
            Canvas.SetTop(txt, top);

            CurrentCanvas.Children.Add(txt);

        }

        protected void AddRectangle(double top, double left, double width, double height, Color color, bool fill = true)
        {
            var rect = new Rectangle();
            rect.Width = width;
            rect.Height = height;

            rect.Fill = new SolidColorBrush(color);

            Canvas.SetLeft(rect, left);
            Canvas.SetTop(rect, top);

            CurrentCanvas.Children.Add(rect);
        }

        protected void AddImage(double top, double left, double width, double height, Uri imageUri)
        {
            Image img = new Image();
            BitmapImage bmp = new BitmapImage();

            using (var fs = new FileStream(imageUri.AbsolutePath, FileMode.Open, FileAccess.Read))
            {


                bmp.BeginInit();
                bmp.StreamSource = fs;
                bmp.CacheOption = BitmapCacheOption.OnLoad;
                bmp.EndInit();

                img.Source = bmp;
            }


            img.Width = width;
            img.Height = height;

            Canvas.SetTop(img, top);
            Canvas.SetLeft(img, left);

            CurrentCanvas.Children.Add(img);

        }

        protected void AddImage(double top,double left, double width, double height, MemoryStream imgStream, Stretch strechMode)
        {
            var img = new Image();
            img.Stretch = strechMode;

            img.Width = width;
            img.Height = height;
            img.Source = BitmapFrame.Create(imgStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);

            Canvas.SetTop(img, top);
            Canvas.SetLeft(img, left);

            CurrentCanvas.Children.Add(img);

        }

        protected void AddPagIndex(string fontName, TextSize textSize, TextAlignment alignment, bool pageOf)
        {
            int maxPages = _pageCounter;
            int i = 1;
            foreach (var canvas in _contentDictionary)
            {
                _pageCounter = i;
                Top = _TOP_MARGIN + (MaxPrintAreaHeight - GetTexSize(textSize));
                Left = 0;

                var msg = !pageOf ? string.Format("Seite {0}", i) : string.Format("Seite {0} von {1}", i, maxPages);

                AddTextBlock(msg, MaxPrintAreaWidth, fontName, Colors.Black, textSize, FontWeights.Normal, FontStyles.Normal, Left, Top, alignment);

                i++;
            }
        }

        protected void ShowWindow(Window owner, string title,  ImageSource icon)
        {
            var dcv = new DocumentViewer();
            dcv.Document = _fixedDoc;

            var w = new Window();
            w.Content = dcv;
            w.Owner = owner;
            w.ShowInTaskbar = false;
            w.Title = title;
            w.Icon = icon;
            w.WindowState = WindowState.Maximized;

            w.Show();

        }

        #endregion

        #region Private

        double CentimeterToPixel(double centimeter, sd.Graphics g)
        {
            double pixel = -1;
            using (g)
            {
                pixel = centimeter * g.DpiY / 2.54d;
            }
            return pixel;
        }

        private void InitPrinter(bool borderLess)
        {

            _printDialog = new PrintDialog();
            _printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
            _printDialog.PrintTicket = _printDialog.PrintQueue.DefaultPrintTicket;
            _printDialog.PrintTicket.PageMediaSize = new PageMediaSize(PageSize);
            _printDialog.PrintTicket.PageOrientation = PageOrientation;
            
            if (!borderLess)
            {
                MaxPrintAreaWidth = _printDialog.PrintableAreaWidth - (2 * _LEFT_MARGIN);
                MaxPrintAreaHeight = _printDialog.PrintableAreaHeight - (2 * _TOP_MARGIN);
            }
        }

        private void Print()
        {
            _printDialog.PrintDocument(_fixedDoc.DocumentPaginator, null);
        }

        #endregion

    }
}



Von dieser wird die Klasse XspDocumentBase abgeleitet.



using System;
using System.IO;
using System.Printing;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Threading;
using System.Windows.Xps.Packaging;
using System.Xml;
using shp = System.Windows.Shapes;

namespace js.WPFbase.Printing
{
    public abstract class XpsDocumentBase : PrintBase
    {

        #region Readonly

        protected readonly Color _DEFAULT_FOREGROUND = Colors.Black;
        protected readonly string _docPath;

        #endregion

        #region ProtectdFolder

        protected enum FontSizees { Default, Small, Midel, Big, ExtraBig }

        protected XmlWriter _xmlWriter;
        protected int PageCounter;
        protected MultiSize _Default_Margin = new MultiSize(2.5, 2.5, 2.5, 2.5);
        protected MultiSize _Default_Pading = new MultiSize(2.5, 2.5, 2.5, 2.5);
        protected MultiSize _Default_CornrRadius = new MultiSize(5, 5, 5, 5);
        protected Task _writeTask;

        #endregion

        #region PrivateFolder

        private XpsDocument _doc;
        private IXpsFixedDocumentSequenceWriter _sequeceWriter;
        private IXpsFixedDocumentWriter _docWriter;
        private IXpsFixedPageWriter _pageWriter;
        private DispatcherTimer _deleteTimer;
        private DateTime _timerStartTime;

        #endregion

        public XpsDocumentBase()
        {
            _docPath = $"{Path.GetTempPath()}{Guid.NewGuid().ToString()}.xps";

            _deleteTimer = new DispatcherTimer();
            _deleteTimer.Interval = new TimeSpan(0, 0, 0, 0, 5);
            _deleteTimer.Tick += DeleteTimerTick;

            ForeGround = _DEFAULT_FOREGROUND;
            FontStyle = FontStyles.Normal;
            FontWeight = FontWeights.Normal;
            MarginThickness = new Thickness(2.5);
            BorderColor = Colors.Black;
            BorderBackground = new SolidColorBrush(Colors.Silver);
        }

        #region Public

        public IDocumentPaginatorSource Document { get; protected set; }

        #endregion

        #region Protected

        protected bool PrintDirect { get; set; } = false;

        protected void OpenDoc()
        {

            _doc = new XpsDocument(_docPath, FileAccess.ReadWrite);

            _sequeceWriter = _doc.AddFixedDocumentSequence();

            _docWriter = _sequeceWriter.AddFixedDocument();

            AddPage();
        }

        protected void AddPage()
        {
            _pageWriter = _docWriter.AddFixedPage();

            _xmlWriter = _pageWriter.XmlWriter;

            XmlWriter xmlWriter = _pageWriter.XmlWriter;

            xmlWriter.WriteStartElement("FixedPage");

            xmlWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/xps/2005/06");

            xmlWriter.WriteStartElement("StackPanel");

            xmlWriter.WriteAttributeString("Margin", $"{_LEFT_MARGIN},{_TOP_MARGIN},{ _LEFT_MARGIN / 2},{_TOP_MARGIN}");
            xmlWriter.WriteAttributeString("StackPanel.Width", $"{MaxPrintAreaWidth + _LEFT_MARGIN }");

            PageCounter++;
        }

        protected void ClosePage()
        {
            _xmlWriter.WriteEndElement();
            _pageWriter.Commit();
        }

        protected void ClosDocument()
        {
            // Alle Writer beenden
            _docWriter.Commit();
            _sequeceWriter.Commit();

            Document = _doc.GetFixedDocumentSequence();

            _doc.Close();

            if (PrintDirect)
            {
                PrintQueue pq = LocalPrintServer.GetDefaultPrintQueue();
                PrintTicket pt = pq.DefaultPrintTicket;
                PrintSystemJobInfo info = pq.AddJob("Documnet", _docPath, false, pt);
            };


            _timerStartTime = DateTime.Now;
            _deleteTimer.Start();

        }

        protected System.Windows.FontStyle FontStyle { get; set; }
        protected FontWeight FontWeight { get; set; }
        protected Thickness MarginThickness { get; set; }
        protected Color BorderColor { get; set; }
        protected Brush BorderBackground;

        protected double GetFontSize(FontSizees fontSize)
        {
            if (fontSize == FontSizees.Small) return 10D;
            if (fontSize == FontSizees.Midel) return 14D;
            if (fontSize == FontSizees.Big) return 18D;
            if (fontSize == FontSizees.ExtraBig) return 24D;

            return 12D;
        }

        #endregion

        #region ControlGet

        protected TextBlock GetTextBlock(string text, FontSizees fontSize, double? width = null, TextAlignment alignement = TextAlignment.Left, FontWeight? fontWeight = null)
        {

            var txt = new TextBlock();
            txt.Text = text;
            txt.FontSize = GetFontSize(fontSize);
            txt.FontStyle = FontStyle;
            txt.FontWeight = FontWeight;
            txt.Margin = MarginThickness;
            txt.Foreground = new SolidColorBrush(ForeGround);
            txt.TextAlignment = alignement;
            txt.FontWeight = fontWeight==null ? FontWeights.Normal:fontWeight.Value;
            txt.Width = width == null ? Double.NaN : width.Value;
            return txt;
        }

        protected Border GetBorder(double borderThickness = 1D, bool margin = false, MultiSize? marginSize = null, bool padding = false, MultiSize? paddingSize = null, MultiSize? cornerRadius = null)
        {
            var b = new Border();
            b.BorderBrush = new SolidColorBrush(BorderColor);
            b.BorderThickness = new Thickness(borderThickness);
            b.CornerRadius = cornerRadius == null ? new CornerRadius(_Default_CornrRadius.Size1, _Default_CornrRadius.Size2, _Default_CornrRadius.Size3, _Default_CornrRadius.Size4) : new CornerRadius(cornerRadius.Value.Size1, cornerRadius.Value.Size2, cornerRadius.Value.Size3, cornerRadius.Value.Size4);
            b.Background = BorderBackground;

            if (margin) b.Margin = marginSize == null ? new Thickness(_Default_Margin.Size1, _Default_Margin.Size2, _Default_Margin.Size3, _Default_Margin.Size4) : new Thickness(paddingSize.Value.Size1, paddingSize.Value.Size2, paddingSize.Value.Size3, paddingSize.Value.Size1);
            if (padding) b.Padding = paddingSize == null ? new Thickness(_Default_Pading.Size1, _Default_Pading.Size2, _Default_Pading.Size3, _Default_Pading.Size4) : new Thickness(paddingSize.Value.Size1, paddingSize.Value.Size2, paddingSize.Value.Size3, paddingSize.Value.Size4);

            return b;
        }

        protected shp.Rectangle GetFilledRectangle(double height, double width, Color fillColor)
        {
            var rect = new shp.Rectangle();
            rect.Height = height;
            rect.Width = width;
            rect.Fill = new SolidColorBrush(fillColor);
            return rect;
        }

        protected shp.Rectangle GetStorkedRectangle(double height, double width, Color fillColor, Color storkColor, double storkThickness = 1D)
        {
            var rect = new shp.Rectangle();
            rect.Height = height;
            rect.Width = width;
            rect.Fill = new SolidColorBrush(fillColor);
            rect.Stroke = new SolidColorBrush(storkColor);
            rect.StrokeThickness = storkThickness;
            return rect;
        }

        #endregion

        #region ControlAdd

        protected void AddTextBlock(string text, FontSizees fontSize)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize ), _xmlWriter);
        }

        protected void AddTextBlock(string text, FontSizees fontSize, double width=Double.NaN)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize, width), _xmlWriter);
        }

        protected void AddTextBlock(string text, FontSizees fontSize, double width = Double.NaN, TextAlignment aligement= TextAlignment.Left)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize, width, aligement), _xmlWriter);
        }

        protected void AddTextBlock(string text, FontSizees fontSize, double width = Double.NaN, TextAlignment aligement = TextAlignment.Left, FontWeight? fontWeight = null)
        {
            XamlWriter.Save(GetTextBlock(text, fontSize, width, aligement, fontWeight), _xmlWriter);
        }

        protected void AddFilledRectangle(double height, double width, Color fillColor)
        {
            XamlWriter.Save(GetFilledRectangle(height, width, fillColor), _xmlWriter);
        }

        protected void AddStorkedRectangle(double height, double width, Color fillColor, Color storkColor, double storkThickness = 1D)
        {
            XamlWriter.Save(GetStorkedRectangle(height, width, fillColor, storkColor, storkThickness), _xmlWriter);
        }

        protected void AddGrid(Grid grid)
        {
            XamlWriter.Save(grid, _xmlWriter);
        }

        protected void AddBorder(Border border)
        {
            XamlWriter.Save(border, _xmlWriter);
        }

        #endregion

     )

        #region Structs

        public struct MultiSize
        {
            internal MultiSize(double size1, double size2, double size3, double size4)
            {
                Size1 = size1;
                Size2 = size2;
                Size3 = size3;
                Size4 = size4;
            }

            internal double Size1 { get; private set; }
            internal double Size2 { get; private set; }
            internal double Size3 { get; private set; }
            internal double Size4 { get; private set; }
        }

        #endregion

    }
}


Implemtierug:



    public class MyReports
    {

        #region Const

        private const double _COLUMN_SMALL = 80D;
        private const double _COLUMNL_LARGE = 200D;

        // Maximale Anzahl der Zeilen pro Seite, muss wohl angepast werden
        private const int _MAX_ROW = 39;

        #endregion

        #region ReadonlyFolder

        private readonly double _maxPageWidth;
        private readonly List<TextBlock> _textBlockList;
        private readonly double _textBoxHeight;
        private readonly double _column_Large;
        private readonly double _columnLargeLeft;

        #endregion


        public MyReports()
        {
            _maxPageWidth = MaxPrintAreaWidth + _LEFT_MARGIN;
            _AccontNameWidth = _maxPageWidth - (4 * _COLUMN_SMALL) - 10D;
            _textBlockList = new List<TextBlock>();
            _textBoxHeight = TextHeight(_FONT_NAME, GetFontSize(FontSizees.Default)) + 5D;
            _data = new List<TransactionItem>();

            ForeGround = Colors.Black;
            FontWeight = FontWeights.Bold;
            OpenDoc();

            if (PageCounter == 0) AddPage();

            AddPageHeader(MainVewModlView.CurrentFiscalYear);
            AddReportHeader();
            AddData(MainVewModlView.CurrentFiscalYear);

            FontWeight = FontWeights.Normal;

            // Page und Document schliessen
            PageCounter = 0;
            ClosePage();
            ClosDocument();

        }

        public IDocumentPaginatorSource AccountDocument(DocumentDVMMV dv, ObservableCollection<AccountItem> data)
        {
            OpenDoc();

            if (PageCounter == 0) AddPage();

            AddPageHeader();
            AddReportHeader();

            foreach (var item in data)
            {

                _textBlockList.Clear();
          
                 // Hier je nach Spaltenanzahl Kode anpassen
                _textBlockList.Add(GetTextBlock(item.AccountNr.ToString(), FontSizees.Default, _COLUMN_SMALL - 5D));
                _textBlockList.Add(GetTextBlock(item.AccountType.ToString(), FontSizees.Default, _COLUMNL_LARGE - 5D));
                _textBlockList.Add(GetTextBlock(item.AccountName, FontSizees.Default, _columnLargeLeft - 5D));

                SetGridColumn();

                if (RowCounter > _MAX_ROW)
                {
                    RowCounter = 0;
                    AddPage();
                    AddPageHeader();
                    AddReportHeader();
                    AddReportFooter();
                }

                RowCounter++;
            }

            ClosDocument();
            PageCounter = 0;

            return Document;
        }   
 
        #region PrivateGrid

        private void SetGridColumn()
        {
            // Grid erzeugen und in Document einfügen
            var grid = GetGrid();

            for (int i = 0; i < _textBlockList.Count; i++)
            {
                Grid.SetColumn(_textBlockList[i], i);
                grid.Children.Add(_textBlockList[i]);

            }

            AddGrid(grid);
        }

        private Grid GetGrid()
        {

            // Grid erstellen und Salten sowie Spaltenbreite einstellen
            var g = new Grid();

            // KontoNr
            ColumnDefinition col1 = new ColumnDefinition();
            col1.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col1);

            // Kontobeschreibung
            ColumnDefinition col2 = new ColumnDefinition();
            col2.Width = new GridLength(_AccontNameWidth);
            g.ColumnDefinitions.Add(col2);

            // Kontosaldo
            ColumnDefinition col3 = new ColumnDefinition();
            col3.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col3);

            // Budget
            ColumnDefinition col4 = new ColumnDefinition();
            col4.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col4);

            ColumnDefinition col5 = new ColumnDefinition();
            col4.Width = new GridLength(_COLUMN_SMALL);
            g.ColumnDefinitions.Add(col5);

            g.Width = _maxPageWidth;

            // Der 2. Datensatz wird grau unterlegt
            if (RowCounter % 2 == 1) g.Background = new SolidColorBrush(Colors.Silver);

            return g;
        }

        #endregion

        #region Private

        private void AddPageHeader(int year)
        {
            var tb = GetTextBlock($"Butgetauszug {year} vom {DateTime.Now.ToLongDateString()}", FontSizees.Big);
            tb.Width = _maxPageWidth;
            tb.Height = TextHeight(_FONT_NAME, GetFontSize(FontSizees.Big));
            XamlWriter.Save(tb, _xmlWriter);

            var grid = GetGrid();
            grid.Height = 40D;
            AddGrid(grid);
        }

        private void AddReportHeader()
        {
            _textBlockList.Clear();
            _textBlockList.Add(GetTextBlock("KontoNr", FontSizees.Midel, _COLUMN_SMALL - 5D));
            _textBlockList.Add(GetTextBlock("Konto", FontSizees.Midel, _AccontNameWidth - 5D));
            _textBlockList.Add(GetTextBlock(string.Empty, FontSizees.Midel, _COLUMN_SMALL - 5D, TextAlignment.Right));
            _textBlockList.Add(GetTextBlock("Budget", FontSizees.Midel, _COLUMN_SMALL - 5D, TextAlignment.Right));
            _textBlockList.Add(GetTextBlock("Budgetsaldo", FontSizees.Midel, _COLUMN_SMALL - 5D, TextAlignment.Right));


            SetGridColumn();
        }

        private void AddData()
        {

            foreach(AccountItem item in MainVewModlView.FV2MainSrv.AccountSrv.Data)
            {
                bool isAccount = item.AccountType == AccountTypes.Konto;

                if (isAccount)
                {
                    var accBalance = CurrentAccountBalance(item.AccountNr);
                    var budget = AccountBudget(item.AccountNr);
                    var balance = CurrentBudgetBalance(item.AccountNr);

                    _textBlockList.Clear();

                    _textBlockList.Add(GetTextBlock(item.AccountNr.ToString(), FontSizees.Default, _COLUMN_SMALL));
                    _textBlockList.Add(GetTextBlock(item.AccountName, FontSizees.Default, _AccontNameWidth));
                    _textBlockList.Add(GetTextBlock(string.Empty, FontSizees.Default, _COLUMN_SMALL - 5, TextAlignment.Right));
                    _textBlockList.Add(GetTextBlock(budget.ToString(_FORMAT_NUMBRE), FontSizees.Default, _COLUMN_SMALL - 5, TextAlignment.Right));
                    _textBlockList.Add(GetTextBlock(balance.ToString(_FORMAT_NUMBRE), FontSizees.Default, _COLUMN_SMALL - 5, TextAlignment.Right));

                    SetGridColumn();

                    RowCounter++;
                }
            }
        }
}


Bei Fragen fragen?

Ich hoffe, dass diese 2 Basis-Klassen und die Implementierungs-Klasse dir weiterhelfen.

Gruss Alex

28.02.2017 - 10:51 Uhr

Hallo Alf,

E:\ ist ene externe Festplatte.

Gruss Alex

28.02.2017 - 10:46 Uhr

Ich denke, dass dir nicht anderse überigbleit als ein FixedDocument zu erstelle, da ein Datagrid keine Druckerfunktionen bereitstellt. Möchtest du noch eine Druckvoschau must du mit IDocumentPaginatorSource arbeiten.

Wen nötig kann ich eine eigene Basis-Klasse zur vwerfügung stellen:

Gruss Alex

28.02.2017 - 10:07 Uhr

Hallo zusammen,

Ich möchte einen Windows-Dienst installieren.

Installer-Klasse:



    [RunInstaller(true)]
    public class MailSRVInstaller : Installer
    {

        public MailSRVInstaller()
        {
            ServiceInstaller installer = new ServiceInstaller();
            ServiceProcessInstaller process = new ServiceProcessInstaller();

            installer.StartType = ServiceStartMode.Automatic;
            installer.ServiceName = "Jungfrau-Soft MailSRV";
            installer.Description = "MailMessageService for AgendaV1";

            process.Account = ServiceAccount.LocalSystem;

            Installers.Add(process);
            Installers.Add(installer);
        } 
    }


Wie aus dem Code zu ersehen ist, ist die Installer-Klasse public und mit dem RunInstallAtributte versehen, trotzdem bekomme ich beim Ausführen von InstallUtil.exe immer folgende Fehlermeldung:

Fehlermeldung:

Die Installationsphase wird gestartet.
Die Protokolldatei enthält den Fortschritt der Assembly E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll.
Die Datei befindet sich in E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.InstallLog.
Assembly E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll wird installiert.
Betroffene Parameter:
logtoconsole =
logfile = E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.InstallLog
assemblypath = E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll
Keine öffentlichen Installer mit dem RunInstallerAttribute.Yes-Attribut in der Assembly E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll gefunden.

Die Installationsphase ist abgeschlossen, und die Commitphase beginnt.
Die Protokolldatei enthält den Fortschritt der Assembly E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll.
Die Datei befindet sich in E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.InstallLog.
Assembly E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll wird ausgeführt.
Betroffene Parameter:
logtoconsole =
logfile = E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.InstallLog
assemblypath = E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll
Keine öffentlichen Installer mit dem RunInstallerAttribute.Yes-Attribut in der Assembly E:\AGENDA_WIN_SRV\js.Agenda.WinSRV\bin\Debug\js.Agenda.Services.dll gefunden.
Die InstallState-Datei wird entfernt, da keine Installer vorhanden sind.

Die Commitphase wurde erfolgreich abgeschlossen.

Die transaktive Installation ist abgeschlossen.

Kann mir jemand sagen wo der Fehler liegt, denn auch nach mehrtägiger Suche im Netz bin ich auf keine Lösung gestossen.

Gruss Alex