<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Biggle&#039;s Blog &#187; CSharp</title>
	<atom:link href="http://www.biggle.de/blog/tag/csharp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.biggle.de/blog</link>
	<description>Web- und Software Development</description>
	<lastBuildDate>Tue, 07 Feb 2012 13:08:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Bedingte Formatierung im Datagrid &#8211; WPF Quicky</title>
		<link>http://www.biggle.de/blog/bedingte-formatierung-im-datagrid-wpf</link>
		<comments>http://www.biggle.de/blog/bedingte-formatierung-im-datagrid-wpf#comments</comments>
		<pubDate>Mon, 14 Feb 2011 18:39:13 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[CodeSnippet]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=6237</guid>
		<description><![CDATA[Die Frage auf Codekicker lautete: Wie kann ich in einem DataGrid eine Zelle je nach Inhalt formatieren? So wie die Bedingte Formatierung in Excel oder Access, also rot bei negativen Werten und grün bei positiven Werten. Hab schon mein Glück mit einem Converter versucht, aber das klappt irgendwie nicht. Ich habe dazu einen Converter geschrieben, [...]]]></description>
			<content:encoded><![CDATA[<p>Die Frage auf <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGVraWNrZXIuZGUvZnJhZ2VuL3dwZi1EYXRhR3JpZC1aZWxsZS1JbmhhbHQtZm9ybWF0aWVyZW4tZGF0YWdyaWQtYmVkaW5ndGUtY29udmVydGVyLWZvcm1hdGllcnVuZy16ZWxsZS84NzQjYTI5NzA=">Codekicker</a> lautete:</p>
<p><em> Wie kann ich in einem DataGrid eine Zelle je nach Inhalt formatieren? So wie die Bedingte Formatierung in Excel oder Access, also rot bei negativen Werten und grün bei positiven Werten. Hab schon mein Glück mit einem Converter versucht, aber das klappt irgendwie nicht.</em></p>
<p>Ich habe dazu einen Converter geschrieben, der den Wert entgegen nimmt, diesen auf kleiner 0 prüft und das Resultat als Brush für den Hintergrund zurück gibt. Ist der Wert kleiner 0 wird grün, ist der Wert größer 0 wir rot zurück gegeben.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> object Convert<span style="color: #009900;">&#40;</span>object value<span style="color: #339933;">,</span> Type targetType<span style="color: #339933;">,</span> object parameter<span style="color: #339933;">,</span> <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Globalization<span style="color: #339933;">.</span>CultureInfo culture<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>value<span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> String<span style="color: #339933;">.</span><span style="color: #990000;">Empty</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    decimal val <span style="color: #339933;">=</span> decimal<span style="color: #339933;">.</span>Parse<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>val <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? Brushes<span style="color: #339933;">.</span>Red <span style="color: #339933;">:</span> Brushes<span style="color: #339933;">.</span>Green<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> object ConvertBack<span style="color: #009900;">&#40;</span>object value<span style="color: #339933;">,</span> Type targetType<span style="color: #339933;">,</span> object parameter<span style="color: #339933;">,</span> <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Globalization<span style="color: #339933;">.</span>CultureInfo culture<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> value<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Im XAML muss in der Windows Resource der Converter referenziert werden:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Window<span style="color: #339933;">.</span>Resources<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>Converters<span style="color: #339933;">:</span>SignedUnsignedConverter x<span style="color: #339933;">:</span><span style="color: #990000;">Key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SignedUnsigned&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>Window<span style="color: #339933;">.</span>Resources<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Das DataGrid verwendet den Converter wie folgt:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>DataGrid Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dataGrid&quot;</span> AutoGenerateColumns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;False&quot;</span> MouseDoubleClick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dataGrid_MouseDoubleClick&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>DataGrid<span style="color: #339933;">.</span>Columns<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>DataGridTextColumn <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Name&quot;</span> Binding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Name}&quot;</span> <span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>DataGridTemplateColumn <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Price&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>DataGridTemplateColumn<span style="color: #339933;">.</span>CellTemplate<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>DataTemplate<span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>TextBlock Text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Price}&quot;</span> Background<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Price, Converter={StaticResource SignedUnsigned}}&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;/</span>DataTemplate<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>DataGridTemplateColumn<span style="color: #339933;">.</span>CellTemplate<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>DataGridTemplateColumn<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>DataGrid<span style="color: #339933;">.</span>Columns<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>DataGrid<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Auch in einer TextBox kann der Converter verwendet werden:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>TextBox Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;textBox&quot;</span> Background<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding ElementName=textBox, Path=Text, Converter={StaticResource SignedUnsigned}}&quot;</span><span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

<p><br class="spacer_" /></p>
<p>Viel Spaß beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6237" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>19. Februar 2009 -- <a href="http://www.biggle.de/blog/regex-sonderzeichen-entfernen-c-quicky" title="Regex Sonderzeichen entfernen &#8211; C# Quicky">Regex Sonderzeichen entfernen &#8211; C# Quicky</a></li><li>8. November 2008 -- <a href="http://www.biggle.de/blog/listview-eintrag-in-zwischenablage-kopieren-quicky-c" title="Listview-Eintrag in Zwischenablage kopieren &#8211; Quicky C#">Listview-Eintrag in Zwischenablage kopieren &#8211; Quicky C#</a></li><li>8. November 2008 -- <a href="http://www.biggle.de/blog/mit-enter-bestatigen-quicky-csharp" title="Mit ENTER bestätigen &#8211; Quicky C#">Mit ENTER bestätigen &#8211; Quicky C#</a></li><li>2. Juli 2008 -- <a href="http://www.biggle.de/blog/validatezipcode-c" title="ValidateZipCode C#">ValidateZipCode C#</a></li><li>1. Juli 2008 -- <a href="http://www.biggle.de/blog/validateemail-c" title="ValidateEmail C#">ValidateEmail C#</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/bedingte-formatierung-im-datagrid-wpf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLite Datenbanken in C# Applikationen verwenden</title>
		<link>http://www.biggle.de/blog/sqlite-datenbanken-in-csharp-applikationen-verwenden</link>
		<comments>http://www.biggle.de/blog/sqlite-datenbanken-in-csharp-applikationen-verwenden#comments</comments>
		<pubDate>Mon, 07 Feb 2011 20:12:11 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SQlite]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=6168</guid>
		<description><![CDATA[System.Data.SQlite aus dem Hause phxsoftware bietet eine Schnittstelle zur Verwendung von portablen Datenbanken im SQLite Format. Im Folgenden möchte ich zeigen, wie man diese auf unterschiedlicher Weise, in C# Applikationen verwenden kann. Um eine SQLite Datenbank zu erstellen, gibt es eine Menge von Managementapplikationen oder auch Browsererweiterungen, z.b für den Firefox. Ich verwende, um mir erstmalig [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NxbGl0ZS5waHhzb2Z0d2FyZS5jb20v">System.Data.SQlite</a> aus dem Hause phxsoftware bietet eine Schnittstelle zur Verwendung von portablen Datenbanken im <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5zcWxpdGUub3JnLw=="><strong>SQLite</strong></a> Format. Im Folgenden möchte ich zeigen, wie man diese auf unterschiedlicher Weise, in <strong>C#</strong> Applikationen verwenden kann.</p>
<p>Um eine <strong>SQLite Datenbank zu erstellen</strong>, gibt es eine Menge von Managementapplikationen oder auch Browsererweiterungen, z.b für den <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9hZGRvbnMubW96aWxsYS5vcmcvZW4tVVMvZmlyZWZveC9hZGRvbi9zcWxpdGUtbWFuYWdlci8=">Firefox</a>. Ich verwende, um mir erstmalig eine Datenbank zu erstellen, den kostenlosen <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NxbGl0ZWJyb3dzZXIuc291cmNlZm9yZ2UubmV0Lw==">SQLiteBrowser</a>. Die erstellte Datenbank speichere ich dann in meinem TestProjekt, mit welchem ich auf diese zugreifen möchte.</p>
<p>Als erstes holen wir uns die Installation oder die <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NvdXJjZWZvcmdlLm5ldC9wcm9qZWN0cy9zcWxpdGUtZG90bmV0Mi9maWxlcy9TUUxpdGUlMjBmb3IlMjBBRE8uTkVUJTIwMi4wLzEuMC42Ni4wLw==">Binaries</a>. Je nach Architektur wird dann im Projekt, auf die entsprechende dll referenziert. Ich verwende die System.Data.SQLite.dll für x86, welche sich im <strong>bin </strong>Ordner befindet.</p>
<h2>SQLiteCommand</h2>
<p>Im ersten Beispiel, verwende ich die SQLiteCommand-Klasse, um auf die Datenbank zugreifen.</p>
<p>Nach dem Einbinden des Namespace &#8220;<strong>using System.Data.SQLite;</strong>&#8221; stehen uns die Klassen <strong>SQLiteConnection </strong>und <strong>SQLiteCommand </strong>zur Verfügung. (Mehr benötigen wir erstmal in unserem Beispiel nicht.)</p>
<p>Den Pfad, zur zuvor angelegten Datenbank lege ich in der app.config fest, damit dieser konfigurierbar bleibt:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>configuration<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>appSettings<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>add <span style="color: #990000;">key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;DATASOURCE&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../../DataBase/data&quot;</span> <span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;/</span>appSettings<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>configuration<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>im Code dann (namens DataProvider.cs), holen wir uns den Pfad über den ConfigurationManager in eine KlassenVariable. Hier muss explizit auf <em>System.Configuration</em> referenziert werden</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> string DataSource <span style="color: #339933;">=</span> ConfigurationManager<span style="color: #339933;">.</span>AppSettings<span style="color: #339933;">.</span>Get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DATASOURCE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Das Speichern, Emitteln und Löschen erledigen wir über das SQLiteCommand. Zum Öffnen und Schließen der SQLiteConnection habe ich mir zwei Methoden geschrieben:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">SQLiteConnection connection<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> void OpenConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    connection <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SQLiteConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    connection<span style="color: #339933;">.</span>ConnectionString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Data Source=&quot;</span> <span style="color: #339933;">+</span> DataSource<span style="color: #339933;">;</span>
    connection<span style="color: #339933;">.</span>Open<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> void CloseConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    connection<span style="color: #339933;">.</span>Close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    connection<span style="color: #339933;">.</span>Dispose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span style="text-decoration: underline;">Speichern von Einträgen</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">OpenConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> command <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SQLiteCommand<span style="color: #009900;">&#40;</span>connection<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    command<span style="color: #339933;">.</span>CommandText <span style="color: #339933;">=</span> string<span style="color: #339933;">.</span>Format<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO Entities (Beschreibung, HtmlName, Unicode, Zeichen) VALUES('{0}', '{1}', '{2}', '{3}')&quot;</span><span style="color: #339933;">,</span>
                    entity<span style="color: #339933;">.</span>Beschreibung<span style="color: #339933;">,</span> entity<span style="color: #339933;">.</span>HtmlName<span style="color: #339933;">,</span> entity<span style="color: #339933;">.</span>Unicode<span style="color: #339933;">,</span> entity<span style="color: #339933;">.</span>Zeichen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    command<span style="color: #339933;">.</span>ExecuteNonQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
CloseConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span style="text-decoration: underline;">Ermitteln von Einträgen</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">OpenConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
List<span style="color: #339933;">&lt;</span>HtmlEntity<span style="color: #339933;">&gt;</span> entities <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>HtmlEntity<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> command <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SQLiteCommand<span style="color: #009900;">&#40;</span>connection<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    command<span style="color: #339933;">.</span>CommandText <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM Entities&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    using <span style="color: #009900;">&#40;</span>SQLiteDataReader reader <span style="color: #339933;">=</span> command<span style="color: #339933;">.</span>ExecuteReader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>reader<span style="color: #339933;">.</span>Read<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            entities<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> HtmlEntity
            <span style="color: #009900;">&#123;</span>
                Beschreibung <span style="color: #339933;">=</span> reader<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                HtmlName <span style="color: #339933;">=</span> reader<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                Unicode <span style="color: #339933;">=</span> reader<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                Zeichen <span style="color: #339933;">=</span> reader<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        reader<span style="color: #339933;">.</span>Close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
CloseConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span style="text-decoration: underline;">Löschen von Einträgen</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">OpenConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> command <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SQLiteCommand<span style="color: #009900;">&#40;</span>connection<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    command<span style="color: #339933;">.</span>CommandText <span style="color: #339933;">=</span> string<span style="color: #339933;">.</span>Format<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM Entities WHERE Beschreibung = '{0}' AND HtmlName = '{1}' AND Unicode = '{2}' AND Zeichen =  '{3}'&quot;</span><span style="color: #339933;">,</span>
        entity<span style="color: #339933;">.</span>Beschreibung<span style="color: #339933;">,</span> entity<span style="color: #339933;">.</span>HtmlName<span style="color: #339933;">,</span> entity<span style="color: #339933;">.</span>Unicode<span style="color: #339933;">,</span> entity<span style="color: #339933;">.</span>Zeichen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    command<span style="color: #339933;">.</span>ExecuteNonQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
CloseConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Achtung!</strong> Es ist möglich, das die SQLite Assembly sich nicht mit dem 4.0 .NET  kompilieren lässt. (<em>Mixed mode assembly is built against version &#8216;v2.0.50727&#8242; of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information</em>), hier kann man sich aber mit folgendem Eintrag, innerhalb des &#8220;configuration-Knoten&#8221; in der app.config behelfen</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>startup useLegacyV2RuntimeActivationPolicy<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>supportedRuntime version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;v4.0&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>startup<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Tipp via: <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0YWNrb3ZlcmZsb3cuY29tL3F1ZXN0aW9ucy8yNjA1NDkwL3N5c3RlbS1kYXRhLXNxbGl0ZS1uZXQtNA==">stackoverflow</a></p>
<p><br class="spacer_" /></p>
<h2>SQLite &amp; Entity Framework</h2>
<p>Es ist auch möglich, eine SQLite Datenbank als Datensource für ein Entity-Framework-Model anzugeben. Das erstelle Entity FrameworkModel stellt uns nun den Kontext bereit, Einträge zu persistieren, zu ermitteln und zu löschen.</p>
<p>Eintrag speichern</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> void  InsertData<span style="color: #009900;">&#40;</span>HtmlEntity entity<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlEntityEntities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        context<span style="color: #339933;">.</span>AddToEntities<span style="color: #009900;">&#40;</span>entity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        context<span style="color: #339933;">.</span>SaveChanges<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Einträge ermitteln</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>HtmlEntity<span style="color: #339933;">&gt;</span> GetAllHtmlEntities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    List<span style="color: #339933;">&lt;</span>HtmlEntity<span style="color: #339933;">&gt;</span> entities<span style="color: #339933;">;</span>
&nbsp;
    using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlEntityEntities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        entities <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>from e in context<span style="color: #339933;">.</span>Entities
                    select e<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ToList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>         
&nbsp;
    <span style="color: #b1b100;">return</span> entities<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Eintrag löschen</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> void DeleteData<span style="color: #009900;">&#40;</span>HtmlEntity entity<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlEntityEntities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        HtmlEntity obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HtmlEntity<span style="color: #009900;">&#41;</span>context<span style="color: #339933;">.</span>GetObjectByKey<span style="color: #009900;">&#40;</span>entity<span style="color: #339933;">.</span>EntityKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        context<span style="color: #339933;">.</span>DeleteObject<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        context<span style="color: #339933;">.</span>SaveChanges<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>LINQ to SQLite</h2>
<p>Wie wir an den EF Methoden gesehen haben, können wir nun einfach mit LINQ die Operationen ausführen.</p>
<p>Am Beispiel &#8220;Einträge ermitteln&#8221; wurde LINQ bereits verwendet, diese kann dann natürlich auch durch eine Where-Klausel erweitert werden:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">using <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HtmlEntityEntities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>  
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>from e in context<span style="color: #339933;">.</span>Entities                        
            where e<span style="color: #339933;">.</span>Beschreibung <span style="color: #339933;">==</span> keyword                      
            select e<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>FirstOrDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Auch wenn es so scheint, dass die System.Data.SQLite.Linq.dll wichtig für den Zugriff mit LINQ ist, wir benötigen diese dll nicht, denn durch das generieren des EF Models, steht uns hier LINQ aus dem Framework zu Verfügung.</p>
<p>Fragen? Einfach in den Kommentaren damit. Viel Spaß beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6168" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>9. Januar 2011 -- <a href="http://www.biggle.de/blog/mehrfachvererbung-ein-beispiel-in-c" title="Mehrfachvererbung – Ein Beispiel in C#">Mehrfachvererbung – Ein Beispiel in C#</a></li><li>22. Januar 2010 -- <a href="http://www.biggle.de/blog/praktische-muster-commands" title="Praktische Muster &#8211; Commands">Praktische Muster &#8211; Commands</a></li><li>17. Januar 2010 -- <a href="http://www.biggle.de/blog/attribute-mittels-reflektion-abfragen" title="Attribute mittels Reflektion abfragen">Attribute mittels Reflektion abfragen</a></li><li>4. Januar 2010 -- <a href="http://www.biggle.de/blog/webservices-auf-erreichbarkeit-pruefen" title="Webservices auf Erreichbarkeit prüfen">Webservices auf Erreichbarkeit prüfen</a></li><li>5. November 2009 -- <a href="http://www.biggle.de/blog/geschwindigkeitsvorteile-mit-vorkompilierten-linq-queries" title="Geschwindigkeitsvorteile mit vorkompilierten LINQ-Queries">Geschwindigkeitsvorteile mit vorkompilierten LINQ-Queries</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/sqlite-datenbanken-in-csharp-applikationen-verwenden/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Mehrfachvererbung – Ein Beispiel in C#</title>
		<link>http://www.biggle.de/blog/mehrfachvererbung-ein-beispiel-in-c</link>
		<comments>http://www.biggle.de/blog/mehrfachvererbung-ein-beispiel-in-c#comments</comments>
		<pubDate>Sun, 09 Jan 2011 14:49:46 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=6069</guid>
		<description><![CDATA[Angestichelt durch Ilker sein Blogpost, bin ich der Sache mit der Mehrfachvererbung unter .NET mal etwas auf den Grund gegangen. Der Ansatz mit Mixin, Interfaces und ExtensionMethods scheint ja schon seit .NET 3.0 zu bestehen und scheint mir bisher auch der Beste zu sein. Einen weiteren schönen Artikel kann man bei Galileo Computing lesen. Hier ein Beispiel [...]]]></description>
			<content:encoded><![CDATA[<p>Angestichelt durch <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2lsa2VyLmRlL21laHJmYWNodmVyZXJidW5nLWluLWM=">Ilker sein Blogpost</a>, bin ich der Sache mit der <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlLndpa2lwZWRpYS5vcmcvd2lraS9NZWhyZmFjaHZlcmVyYnVuZw==">Mehrfachvererbung</a> unter .NET mal etwas auf den Grund gegangen. Der Ansatz mit <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9NaXhpbg==">Mixin</a>, Interfaces und ExtensionMethods scheint ja schon seit .NET 3.0 zu bestehen und scheint mir bisher auch der Beste zu sein. Einen weiteren schönen Artikel kann man bei <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL29wZW5ib29rLmdhbGlsZW9jb21wdXRpbmcuZGUvb29wL29vcF9rYXBpdGVsXzA1XzAwNC5odG0jbWo0NzQ0YTgwYWMwZmY1MjAxNjdkMDEyNGQ3M2RiYTJiMg==">Galileo Computing</a> lesen.</p>
<p>Hier ein Beispiel wie ich das verstanden habe und umsetzen würde.</p>
<p>Interfaces</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IMixinDateTime
<span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IMixinOneMoreInterface
<span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ExtensionMethods</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">class</span> MixinExtensionMethods
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> static int GetYearDiff<span style="color: #009900;">&#40;</span>this IMixinDateTime mxDateMethod<span style="color: #339933;">,</span> DateTime dateTime<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span>DateTime<span style="color: #339933;">.</span>Now<span style="color: #339933;">.</span>Subtract<span style="color: #009900;">&#40;</span>dateTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>Ticks<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>Year <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static void OneMoreMethod<span style="color: #009900;">&#40;</span>this IMixinOneMoreInterface mxOneMoreMethod<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//implement method here ...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Klassen, welche die Interfaces erben (ggf. implementieren)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Car <span style="color: #339933;">:</span> IMixinDateTime
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> DateTime Baujahr <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #339933;">:</span> IMixinDateTime<span style="color: #339933;">,</span> IMixinOneMoreInterface
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> DateTime Birthday <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Verwendung</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">Person person <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
person<span style="color: #339933;">.</span>Birthday <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1973</span><span style="color: #339933;">,</span> <span style="color: #208080;">01</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> personAge <span style="color: #339933;">=</span> person<span style="color: #339933;">.</span>GetYearDiff<span style="color: #009900;">&#40;</span>person<span style="color: #339933;">.</span>Birthday<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Car car <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Car<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
car<span style="color: #339933;">.</span>Baujahr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2000</span><span style="color: #339933;">,</span> <span style="color: #208080;">01</span><span style="color: #339933;">,</span> <span style="color: #208080;">01</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> carAge <span style="color: #339933;">=</span> car<span style="color: #339933;">.</span>GetYearDiff<span style="color: #009900;">&#40;</span>car<span style="color: #339933;">.</span>Baujahr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
person<span style="color: #339933;">.</span>OneMoreMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Da beliebig viele Interfaces geerbt werden können, erschließt sich hier, wie das Prinzip funktioniert. Weitere Meinungen, Ergänzungen oder Ansätze sind gerne als Kommentar gesehen.</p>
<p>Viel Spaß beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6069" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>7. Februar 2011 -- <a href="http://www.biggle.de/blog/sqlite-datenbanken-in-csharp-applikationen-verwenden" title="SQLite Datenbanken in C# Applikationen verwenden">SQLite Datenbanken in C# Applikationen verwenden</a></li><li>3. Dezember 2010 -- <a href="http://www.biggle.de/blog/biggle-ist-kein-palindrom" title="Biggle ist kein Palindrom">Biggle ist kein Palindrom</a></li><li>22. Januar 2010 -- <a href="http://www.biggle.de/blog/praktische-muster-commands" title="Praktische Muster &#8211; Commands">Praktische Muster &#8211; Commands</a></li><li>17. Januar 2010 -- <a href="http://www.biggle.de/blog/attribute-mittels-reflektion-abfragen" title="Attribute mittels Reflektion abfragen">Attribute mittels Reflektion abfragen</a></li><li>4. Januar 2010 -- <a href="http://www.biggle.de/blog/webservices-auf-erreichbarkeit-pruefen" title="Webservices auf Erreichbarkeit prüfen">Webservices auf Erreichbarkeit prüfen</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/mehrfachvererbung-ein-beispiel-in-c/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generic.List sortieren &#124; C# Quicky</title>
		<link>http://www.biggle.de/blog/generic-list-sortieren-csharp-quicky</link>
		<comments>http://www.biggle.de/blog/generic-list-sortieren-csharp-quicky#comments</comments>
		<pubDate>Mon, 07 Jun 2010 15:40:47 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Quicky]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=4683</guid>
		<description><![CDATA[Um eine generische Liste zu sortieren kann man die Sort Methode auf folgender Art und Weise überschreiben: 1 2 3 public List&#60;Begegnung&#62; Begegnungen &#123; get; set; &#125; &#160; Begegnungen.Sort&#40;&#40;x, y&#41; =&#62; DateTime.Compare&#40;&#40;DateTime&#41; x.Spiel.DatumUhrzeit, &#40;DateTime&#41; y.Spiel.DatumUhrzeit&#41;&#41;; Beispiel 1 2 3 4 5 6 7 8 9 10 11 12 13 Begegnungen = new List&#60;Begegnung&#62; &#123; new [...]]]></description>
			<content:encoded><![CDATA[<p>Um eine generische Liste zu sortieren kann man die Sort Methode auf folgender Art und Weise überschreiben:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Begegnung<span style="color: #339933;">&gt;</span> Begegnungen <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
Begegnungen<span style="color: #339933;">.</span><span style="color: #990000;">Sort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> DateTime<span style="color: #339933;">.</span>Compare<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>DateTime<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">.</span>Spiel<span style="color: #339933;">.</span>DatumUhrzeit<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>DateTime<span style="color: #009900;">&#41;</span> y<span style="color: #339933;">.</span>Spiel<span style="color: #339933;">.</span>DatumUhrzeit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><br class="spacer_" /></p>
<p>Beispiel</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">Begegnungen <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>Begegnung<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</span> Begegnung <span style="color: #009900;">&#123;</span> Spiel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Spiel<span style="color: #009900;">&#123;</span>DatumUhrzeit <span style="color: #339933;">=</span> DateTime<span style="color: #339933;">.</span>Now<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">new</span> Begegnung <span style="color: #009900;">&#123;</span> Spiel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Spiel<span style="color: #009900;">&#123;</span>DatumUhrzeit <span style="color: #339933;">=</span> DateTime<span style="color: #339933;">.</span>Today<span style="color: #339933;">.</span>AddDays<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> 
    <span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">new</span> Begegnung<span style="color: #009900;">&#123;</span>Spiel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Spiel<span style="color: #009900;">&#123;</span>DatumUhrzeit <span style="color: #339933;">=</span> DateTime<span style="color: #339933;">.</span>Today<span style="color: #339933;">.</span>AddHours<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">new</span> Begegnung<span style="color: #009900;">&#123;</span>Spiel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Spiel<span style="color: #009900;">&#123;</span>DatumUhrzeit <span style="color: #339933;">=</span> DateTime<span style="color: #339933;">.</span>Today<span style="color: #339933;">.</span>AddMinutes<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">66</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
Begegnungen<span style="color: #339933;">.</span><span style="color: #b1b100;">ForEach</span><span style="color: #009900;">&#40;</span>b <span style="color: #339933;">=&gt;</span> Console<span style="color: #339933;">.</span>WriteLine<span style="color: #009900;">&#40;</span>b<span style="color: #339933;">.</span>Spiel<span style="color: #339933;">.</span>DatumUhrzeit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Begegnungen<span style="color: #339933;">.</span><span style="color: #990000;">Sort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> DateTime<span style="color: #339933;">.</span>Compare<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>DateTime<span style="color: #009900;">&#41;</span> x<span style="color: #339933;">.</span>Spiel<span style="color: #339933;">.</span>DatumUhrzeit<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>DateTime<span style="color: #009900;">&#41;</span> y<span style="color: #339933;">.</span>Spiel<span style="color: #339933;">.</span>DatumUhrzeit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Console<span style="color: #339933;">.</span>WriteLine<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;---&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Begegnungen<span style="color: #339933;">.</span><span style="color: #b1b100;">ForEach</span><span style="color: #009900;">&#40;</span>b <span style="color: #339933;">=&gt;</span> Console<span style="color: #339933;">.</span>WriteLine<span style="color: #009900;">&#40;</span>b<span style="color: #339933;">.</span>Spiel<span style="color: #339933;">.</span>DatumUhrzeit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">internal <span style="color: #000000; font-weight: bold;">class</span> Begegnung
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> Spiel Spiel <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
internal <span style="color: #000000; font-weight: bold;">class</span> Spiel
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> DateTime DatumUhrzeit <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Viel Spass beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=4683" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>25. Oktober 2009 -- <a href="http://www.biggle.de/blog/string-nach-pascal-und-camelcase-c-quicky" title="String nach Pascal- und CamelCase &#8211; C# Quicky">String nach Pascal- und CamelCase &#8211; C# Quicky</a></li><li>21. Januar 2010 -- <a href="http://www.biggle.de/blog/extension-method-string-reverse-csharp" title="Extension Method String.Reverse() &#8211; C# Quicky ">Extension Method String.Reverse() &#8211; C# Quicky </a></li><li>22. Dezember 2009 -- <a href="http://www.biggle.de/blog/windows-neu-starten-wpf-quicky" title="Windows neu starten &#8211; WPF Quicky">Windows neu starten &#8211; WPF Quicky</a></li><li>22. Dezember 2009 -- <a href="http://www.biggle.de/blog/restart-neustart-wpf-applikation" title="Restart einer WPF Applikation">Restart einer WPF Applikation</a></li><li>12. Oktober 2009 -- <a href="http://www.biggle.de/blog/linq-tools" title="LINQ Tools">LINQ Tools</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/generic-list-sortieren-csharp-quicky/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Praktische Muster &#8211; Commands</title>
		<link>http://www.biggle.de/blog/praktische-muster-commands</link>
		<comments>http://www.biggle.de/blog/praktische-muster-commands#comments</comments>
		<pubDate>Fri, 22 Jan 2010 07:48:01 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Interfaces]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=3673</guid>
		<description><![CDATA[Ein schönes Beispiel für ein praktisches Entwurfsmuster habe ich im Archiv der dot.net gefunden. In der Ausgabe 1/2009 beschreibt Marc André Zhou mit einem einfachen Beispiel, wie man ein Muster für Commands implementiert. Hierzu definiert er ein Interface ICommand, welches die Methode Execute() festlegt. 1 2 3 4 public interface ICommand &#123; void Execute&#40;&#41;; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>Ein schönes Beispiel für ein praktisches Entwurfsmuster habe ich im <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2l0LXJlcHVibGlrLmRlL2RvdG5ldC9kb3RuZXQtbWFnYXppbi1hdXNnYWJlbi8=">Archiv der dot.net</a> gefunden.</p>
<p>In der Ausgabe 1/2009 beschreibt Marc André Zhou mit einem einfachen Beispiel, wie man ein Muster für Commands implementiert.</p>
<p>Hierzu definiert er ein Interface ICommand, welches die Methode Execute() festlegt.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ICommand
<span style="color: #009900;">&#123;</span>
    void Execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Die Klassen, die das Interface implementieren, öffnen jeweils eine Applikation</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CMDNotepad <span style="color: #339933;">:</span> ICommand
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> void Execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Process process <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Process<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        process<span style="color: #339933;">.</span>StartInfo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ProcessStartInfo<span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #0000ff;">&quot;notepad.exe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        process<span style="color: #339933;">.</span>Start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> override string ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;notepad.exe&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Im MainProgramm dann, werden die einzelnen Commands einer Liste vom Typ ICommand hinzugefügt </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> commands <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> List<span style="color: #339933;">&lt;</span>ICommand<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
commands<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CMDNotepad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
commands<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CMDIExplorer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
commands<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CMDCalc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>und anschliessend ausgegeben.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span>ICommand cmd in commands<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    Console<span style="color: #339933;">.</span>WriteLine<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Start command: {0}&quot;</span><span style="color: #339933;">,</span> cmd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    cmd<span style="color: #339933;">.</span>Execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ich finde das Beispiel auch als eine sehr gute Erklärung, wie ein Interface arbeitet und an welcher Stelle man eins einsetzen sollte.</p>
<p>Viel Spass beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=3673" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>7. Februar 2011 -- <a href="http://www.biggle.de/blog/sqlite-datenbanken-in-csharp-applikationen-verwenden" title="SQLite Datenbanken in C# Applikationen verwenden">SQLite Datenbanken in C# Applikationen verwenden</a></li><li>9. Januar 2011 -- <a href="http://www.biggle.de/blog/mehrfachvererbung-ein-beispiel-in-c" title="Mehrfachvererbung – Ein Beispiel in C#">Mehrfachvererbung – Ein Beispiel in C#</a></li><li>17. Januar 2010 -- <a href="http://www.biggle.de/blog/attribute-mittels-reflektion-abfragen" title="Attribute mittels Reflektion abfragen">Attribute mittels Reflektion abfragen</a></li><li>4. Januar 2010 -- <a href="http://www.biggle.de/blog/webservices-auf-erreichbarkeit-pruefen" title="Webservices auf Erreichbarkeit prüfen">Webservices auf Erreichbarkeit prüfen</a></li><li>5. November 2009 -- <a href="http://www.biggle.de/blog/geschwindigkeitsvorteile-mit-vorkompilierten-linq-queries" title="Geschwindigkeitsvorteile mit vorkompilierten LINQ-Queries">Geschwindigkeitsvorteile mit vorkompilierten LINQ-Queries</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/praktische-muster-commands/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

