<?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>Program With Dave</title>
	<atom:link href="http://www.daveandrews.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveandrews.org</link>
	<description>My Programming Tutorials and Experiments</description>
	<lastBuildDate>Thu, 29 Jul 2010 06:00:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Difference Between Union and Union All</title>
		<link>http://www.daveandrews.org/2010/07/29/difference-between-union-and-union-all/</link>
		<comments>http://www.daveandrews.org/2010/07/29/difference-between-union-and-union-all/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 06:00:51 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=381</guid>
		<description><![CDATA[Sometimes it can be confusing what the difference between &#8216;union&#8217; in a SQL statement and &#8216;union all&#8217; means. The basic definition is that &#8216;union&#8217; will combine a given set (query results) with the values of a second set that don&#8217;t already exist. &#8216;Union All&#8217; will simply append the second set to the end of the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it can be confusing what the difference between &#8216;union&#8217; in a SQL statement and &#8216;union all&#8217; means. The basic definition is that &#8216;union&#8217; will combine a given set (query results) with the values of a second set that don&#8217;t already exist. &#8216;Union All&#8217; will simply append the second set to the end of the first set, which includes all the records of the first set and all the records of the second set.</p>
<p>Let&#8217;s see an example.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span> MyValue
&nbsp;
<span style="color: #993333; font-weight: bold;">UNION</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span> MyValue</pre></td></tr></table></div>

<p>Here we are combining two sets of data which each contain a single record, 1. If you execute this command, you will get back a single row which contains the value 1 in the MyValue column. This is because the new value we union in already existed in the first data set, so it did not include it.</p>
<table border = 1 style="border-collapse:collapse">
<tr>
<th>MyValue</th>
</tr>
<tr>
<td>1</td>
</tr>
</table>
<p>Let&#8217;s modify our query to use Union All.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span> MyValue
&nbsp;
<span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span> MyValue</pre></td></tr></table></div>

<p>We now get back a set with two records, the 1 from the first set AND the 1 from the second set.</p>
<table border = 1 style="border-collapse:collapse">
<tr>
<th>MyValue</th>
</tr>
<tr>
<td>1</td>
</tr>
<tr>
<td>1</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/07/29/difference-between-union-and-union-all/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Simple LINQ To SQL Queries</title>
		<link>http://www.daveandrews.org/2010/07/27/some-simple-linq-to-sql-queries/</link>
		<comments>http://www.daveandrews.org/2010/07/27/some-simple-linq-to-sql-queries/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 06:00:55 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=357</guid>
		<description><![CDATA[Given a table MyTable, with the rows ID int, Value1 varchar(100), Value2 varchar(100) and a data context (created automatically by visual studio) you can create/update/delete data very easily. I will be using LINQ To SQL here, which is somewhat out of date now with the introduction of the Entity Framework, but I will post up [...]]]></description>
			<content:encoded><![CDATA[<p>Given a table MyTable, with the rows ID int, Value1 varchar(100), Value2 varchar(100) and a data context (created automatically by visual studio) you can create/update/delete data very easily. I will be using LINQ To SQL here, which is somewhat out of date now with the introduction of the Entity Framework, but I will post up some EF examples in a later post (they&#8217;re not much different in the code.) The language is C#.</p>
<p><strong>Simple L2S Examples</strong></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
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>DBDataContext db <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DBDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// get all</span>
	var search <span style="color: #008000;">=</span> from t <span style="color: #0600FF;">in</span> dc.<span style="color: #0000FF;">MyTable</span>
		           select t<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// this will return all the records</span>
	List<span style="color: #008000;">&lt;</span>MyTable<span style="color: #008000;">&gt;</span> all <span style="color: #008000;">=</span> search.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// get all (example 2) This one doesn't use a search variable.</span>
	List<span style="color: #008000;">&lt;</span>MyTable<span style="color: #008000;">&gt;</span> all2 <span style="color: #008000;">=</span> dc.<span style="color: #0000FF;">MyTable</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// get single</span>
	var search2 <span style="color: #008000;">=</span> from t <span style="color: #0600FF;">in</span> dc.<span style="color: #0000FF;">MyTable</span>
		              where t.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span>
			      select t<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// if none is found, then record will be NULL.</span>
	MyTable record <span style="color: #008000;">=</span> search2.<span style="color: #0000FF;">SingleOrDefault</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// get single (example 2) This one uses a predicate which defines</span>
        <span style="color: #008080; font-style: italic;">// 's' as a placeholder, and then sets the conditions for s to be s.ID == 1.</span>
	MyTable record2 <span style="color: #008000;">=</span> dc.<span style="color: #0000FF;">MyTable</span>.<span style="color: #0000FF;">SingleOrDefault</span><span style="color: #000000;">&#40;</span>s <span style="color: #008000;">=&gt;</span> s.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// update a value in the record</span>
        record2.<span style="color: #0000FF;">Value1</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Hello!&quot;</span><span style="color: #008000;">;</span>
        db.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// delete the record</span>
        db.<span style="color: #0000FF;">MyTable</span>.<span style="color: #0000FF;">DeleteOnSubmit</span><span style="color: #000000;">&#40;</span>record2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        db.<span style="color: #0000FF;">SubmitChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/07/27/some-simple-linq-to-sql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inserting Results of a Query into a Table</title>
		<link>http://www.daveandrews.org/2010/07/25/inserting-results-of-a-query-into-a-table/</link>
		<comments>http://www.daveandrews.org/2010/07/25/inserting-results-of-a-query-into-a-table/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 06:00:42 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Insert]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[Tables]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=369</guid>
		<description><![CDATA[Sometimes its necessary to populate an existing table with the results of a query. This can be done very easily with an INSERT statement combined with a SELECT. A typical insert query looks like this. 1 2 3 4 5 6 7 8 9 10 INSERT INTO Person &#40;Name, Address, Phone &#41; VALUES &#40;'Test Guy', [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes its necessary to populate an existing table with the results of a query. This can be done very easily with an INSERT statement combined with a SELECT.</p>
<p>A typical insert query looks like this.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> Person 
     <span style="color: #66cc66;">&#40;</span>Name<span style="color: #66cc66;">,</span> 
      Address<span style="color: #66cc66;">,</span> 
      Phone
     <span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span> 
     <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Test Guy'</span><span style="color: #66cc66;">,</span> 
      <span style="color: #ff0000;">'123 Test St'</span><span style="color: #66cc66;">,</span> 
      <span style="color: #ff0000;">'555-5555'</span>
     <span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>This works fine for just one row. But what if we had another table which contained the information we needed, and had 100000 rows that we wanted to copy over? Let&#8217;s just combine our INSERT with a SELECT!</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="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> Person 
     <span style="color: #66cc66;">&#40;</span>Name<span style="color: #66cc66;">,</span> 
      Address<span style="color: #66cc66;">,</span> 
      Phone
     <span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
     Name<span style="color: #66cc66;">,</span>
     Address<span style="color: #66cc66;">,</span>
     Phone
<span style="color: #993333; font-weight: bold;">FROM</span>
     TableThatHasValues</pre></td></tr></table></div>

<p>It&#8217;s that easy! The SELECT query will execute and the results of that select query will be piped into the INSERT command, inserting every single row.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/07/25/inserting-results-of-a-query-into-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting data into a new table</title>
		<link>http://www.daveandrews.org/2010/07/23/selecting-data-into-a-new-table/</link>
		<comments>http://www.daveandrews.org/2010/07/23/selecting-data-into-a-new-table/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 06:00:49 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Select Queries]]></category>
		<category><![CDATA[Temp Tables]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=367</guid>
		<description><![CDATA[If you have a series of data that you want to insert into a new table, or into a temporary table, it&#8217;s very simple. This can be used to create a simple backup of records, or to take a very long and complex query and save its results for future use. If you save into [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a series of data that you want to insert into a new table, or into a temporary table, it&#8217;s very simple. This can be used to create a simple backup of records, or to take a very long and complex query and save its results for future use. If you save into a table, that table won&#8217;t have any relationships that are in the existing table, just something to keep in mind.</p>
<p>Let&#8217;s say we have a query like this.</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="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
     <span style="color: #66cc66;">*</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
     Animals a
     <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> Animal_Details ad
          <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>AnimalID <span style="color: #66cc66;">=</span> ad<span style="color: #66cc66;">.</span>AnimalID</pre></td></tr></table></div>

<p>This table will join together two tables and pull in the details of whatever animals are in the animals table. I just made this up quickly. Let&#8217;s have SQL save that to a new table.</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="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
     <span style="color: #66cc66;">*</span>
<span style="color: #993333; font-weight: bold;">INTO</span> 
     AnimalDetailsCombined
<span style="color: #993333; font-weight: bold;">FROM</span>
     Animals a
     <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> Animal_Details ad
          <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>AnimalID <span style="color: #66cc66;">=</span> ad<span style="color: #66cc66;">.</span>AnimalID</pre></td></tr></table></div>

<p>This query will create a brand new table called AnimalDetailsCombined and save the results of that query into the table. If you wanted to save to a temporary table, which would be deleted once the connection is closed, just add a hashtag (#) in front of the table name.</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="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
     <span style="color: #66cc66;">*</span>
<span style="color: #993333; font-weight: bold;">INTO</span> 
     <span style="color: #808080; font-style: italic;">#AnimalDetailsCombined</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
     Animals a
     <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> Animal_Details ad
          <span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span>AnimalID <span style="color: #66cc66;">=</span> ad<span style="color: #66cc66;">.</span>AnimalID</pre></td></tr></table></div>

<p>You now have a temporary table called #AnimalDetailsCombined with is the result of the query.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/07/23/selecting-data-into-a-new-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginning Code for iPad Game</title>
		<link>http://www.daveandrews.org/2010/05/17/beginning-code-for-ipad-game/</link>
		<comments>http://www.daveandrews.org/2010/05/17/beginning-code-for-ipad-game/#comments</comments>
		<pubDate>Tue, 18 May 2010 04:52:21 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=365</guid>
		<description><![CDATA[Today I began the development of my iPad game. I’ve chosen to do an ad-supported, free word search game. I think it will be better than the competition because I am going to make use of the entire screen for the searching field and also check for common problems in word searches such as words-within-words. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I began the development of my iPad game. I’ve chosen to do an ad-supported, free word search game. I think it will be better than the competition because I am going to make use of the entire screen for the searching field and also check for common problems in word searches such as words-within-words.</p>
<p>There will be a classic gameplay mode called casual and also an arcade mode where you find as many words as you can in a given amount of time.</p>
<p>I began development today on the classes which will populate the word field. I had to learn a few new details about NSString that I didn’t know before. I am still relatively new to objective-c and it is quite a departure from C# which I develop with every day.</p>
<p>It is going to use cocos2d in order to get some fancy graphic effects.</p>
<p>Good thing I began programming with standard c years ago or I’d be completely lost!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/05/17/beginning-code-for-ipad-game/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Change in Plans and Some Good News</title>
		<link>http://www.daveandrews.org/2010/05/13/change-in-plans-and-some-good-news/</link>
		<comments>http://www.daveandrews.org/2010/05/13/change-in-plans-and-some-good-news/#comments</comments>
		<pubDate>Fri, 14 May 2010 00:09:57 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Changing Plans]]></category>
		<category><![CDATA[Decision Making]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=363</guid>
		<description><![CDATA[So, I played the game Space Miner on the iPhone. I&#8217;ve decided I can&#8217;t compete with that. The physics are there, the control scheme is almost exactly what I had in mind, and it&#8217;s a freakin&#8217; asteroids game with all kinds of cool stuff on top of it. So, the asteroids game is out. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>So, I played the game Space Miner on the iPhone. I&#8217;ve decided I can&#8217;t compete with that. The physics are there, the control scheme is almost exactly what I had in mind, and it&#8217;s a freakin&#8217; asteroids game with all kinds of cool stuff on top of it. So, the asteroids game is out. It&#8217;s back to square one.</p>
<p>The good news is that I am now the proud owner of a shiny new iPad. The market for iPad applications is relatively small right now, also. So I am going to shift over to writing a game for the iPad. I have an idea that is going to be based off of some old code that I wrote when playing around with Irrlicht. It&#8217;s a game much like Homeworld though not quite as complex.</p>
<p>I&#8217;ve deleted my asteroids plan. I&#8217;m moving on!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/05/13/change-in-plans-and-some-good-news/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Blog About Game Development</title>
		<link>http://www.daveandrews.org/2010/04/27/new-blog-about-game-development/</link>
		<comments>http://www.daveandrews.org/2010/04/27/new-blog-about-game-development/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 00:57:56 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=360</guid>
		<description><![CDATA[I&#8217;ve started a new blog (hosted by WordPress) which will chronicle my game development ventures. I am going to cross-post every post from that blog onto this site. Here is the first post! (from http://davesgamedev.wordpress.com/) This is a blog I decided to create to chronicle my development of iPhone/iPod games. The first game I released, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started a new blog (hosted by WordPress) which will chronicle my game development ventures. I am going to cross-post every post from that blog onto this site. </p>
<p>Here is the first post! (from <a href="http://davesgamedev.wordpress.com/2010/04/27/hello-wo-rdpress/">http://davesgamedev.wordpress.com/</a>)</p>
<hr />
<p>This is a blog I decided to create to chronicle my development of iPhone/iPod games. The first game I released, Smiled Out, has been received &#8220;&#8230;okay&#8230;&#8221; by the market and I think that what it is missing is exposure. Therefore, this blog will chronicle my efforts at game development in order to attempt to build some kind of excitement about my games.</p>
<p>I will post code, plans, screenshots, etc.</p>
<p>First, my plan for my next iPhone/iPod Touch game.</p>
<p>   1. Stop watching so much television.<br />
   2. Quit getting distracted reading news sites or Wikipedia.<br />
   3. Write a design document. (I have this already in the form of notes and a few drawings..)<br />
   4. Write a technical design doc. For my next game, I will be using Cocos2D and Chipmunk, along with a version of an old engine of mine called Dusty Engine that I have ported to Objective-C.<br />
   5. Don&#8217;t focus on graphics to begin with, make the game WORK and then make it pretty.<br />
   6. Don&#8217;t ignore my wife.</p>
<p>I work full time as a business software developer so #1 and #2 are very important, as it gets easy to be distracted and burned out when writing my own code. Adhering very closely to #6 will also make the development process go much smoother.</p>
<p>My next game will be an Asteroids clone. Before you click away, I have a very good idea for controlling the ship, and with Chipmunk physics I think it will blow away the competition. I was going to call it &#8220;StarRoids&#8221; until I found out that an old Mac game from the 1980s had that exact name and I don&#8217;t want those kinds of problems. Part of the failure of Smiled Out is that I am afraid to mention &#8220;Lights Out&#8221; anywhere official with it since Lights Out is trademarked.</p>
<p>So I haven&#8217;t yet named my project. Let&#8217;s just call it &#8220;Unnamed Asteroids Clone&#8221; as a working title.</p>
<p>Check back regularly for updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/04/27/new-blog-about-game-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SQL To Accrue Values (Overtime in Time Entries)</title>
		<link>http://www.daveandrews.org/2010/03/15/using-sql-to-accrue-values-overtime-in-time-entries/</link>
		<comments>http://www.daveandrews.org/2010/03/15/using-sql-to-accrue-values-overtime-in-time-entries/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 03:37:43 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=313</guid>
		<description><![CDATA[I&#8217;ve made it an exercise recently to write SQL code that will determine overtime hours and regular hours given a list of time entries. I wanted to do this through a single (well, nested) SQL query and to not use cursors to iterate through the entries. The problem is that we have a table of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made it an exercise recently to write SQL code that will determine overtime hours and regular hours given a list of time entries. I wanted to do this through a single (well, nested) SQL query and to not use cursors to iterate through the entries.</p>
<p>The problem is that we have a table of time entries, the date the entries were made, and the employee who made them and we need to accrue the hours that employee worked in a given week. This is simple to do with iterators in code or cursors in T-SQL, but what fun would that be?</p>
<p>I&#8217;m going to simplify the problem by only looking at a single week of data. In a larger solution which looks over a larger range of dates such as a month you will need a subquery which assigns each week a number and group by that week number. In my full blown implementation of this, I used row_number() over (order by startdate) given a list of weeks with a startdate and enddate. But that is for a later post.</p>
<p>Let&#8217;s look at our week&#8217;s worth of data, which has 2 employees.</p>
<p><strong>Table TimeEntries</strong></p>
<table style="border-collapse: collapse;" border="1">
<tbody>
<tr>
<th>TimeEntryID</th>
<th>EmployeeID</th>
<th>DateWorked</th>
<th>Hours</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>2010-01-04</td>
<td>8</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>2010-01-05</td>
<td>10</td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>2010-01-06</td>
<td>7.5</td>
</tr>
<tr>
<td>4</td>
<td>1</td>
<td>2010-01-07</td>
<td>10</td>
</tr>
<tr>
<td>5</td>
<td>1</td>
<td>2010-01-08</td>
<td>10</td>
</tr>
<tr>
<td>6</td>
<td>1</td>
<td>2010-01-09</td>
<td>4</td>
</tr>
<tr>
<td>7</td>
<td>2</td>
<td>2010-01-04</td>
<td>10</td>
</tr>
<tr>
<td>8</td>
<td>2</td>
<td>2010-01-05</td>
<td>10</td>
</tr>
<tr>
<td>9</td>
<td>2</td>
<td>2010-01-06</td>
<td>10</td>
</tr>
<tr>
<td>10</td>
<td>2</td>
<td>2010-01-07</td>
<td>10</td>
</tr>
</tbody>
</table>
<p>As you can infer from the above, employee 1 worked overtime (more than 40 hours) starting on the 8th, and employee 2 worked no overtime, since the employee worked exactly 40 hours in that week.</p>
<p><strong>Problem 1: Multiple Records in a Day</strong> The first problem we must overcome is calculating the total number of hours worked in a given day. This is because we can have an employee who puts in 4 hours in the morning and 4 hours in the afternoon. If we don&#8217;t have this in a single record, it will be difficult down the line when our complicated joins and subqueries come in.</p>
<p>So we build this query which will sum up the hours in a given day. We will use this in a couple of places.</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="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
	te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
	te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
	SUM<span style="color: #66cc66;">&#40;</span>te<span style="color: #66cc66;">.</span>Hours<span style="color: #66cc66;">&#41;</span> TotalHoursInDay
<span style="color: #993333; font-weight: bold;">FROM</span>
	TimeEntries te
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
	te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
	te<span style="color: #66cc66;">.</span>DateWorked</pre></td></tr></table></div>

<p>Very simple, we&#8217;re just summing up the hours per day. We&#8217;re going to use this query in several places.</p>
<p><strong>Problem 2: Finding out which days are in overtime.</strong> The next thing we need to overcome is to come up with a means of determining which days should be in overtime. This is where &#8220;accrual&#8221; of sorts comes into play. We join each day&#8217;s record to every record before it. We then group that record and sum up the hours previous to the given day.</p>
<p>Let&#8217;s look at the query.</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
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
	te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
	te<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">,</span>
	te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
	sum<span style="color: #66cc66;">&#40;</span>previous<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">&#41;</span> HoursUpToThisPoint<span style="color: #66cc66;">,</span>
	case when te<span style="color: #66cc66;">.</span>TotalHoursInDay <span style="color: #66cc66;">+</span> SUM<span style="color: #66cc66;">&#40;</span>previous<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">40</span> then <span style="color: #ff0000;">'Y'</span>
		 else <span style="color: #ff0000;">'N'</span>
	end InOvertime
<span style="color: #993333; font-weight: bold;">FROM</span>
	<span style="color: #66cc66;">&#40;</span>
		<span style="color: #993333; font-weight: bold;">SELECT</span>
			te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
			te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
			SUM<span style="color: #66cc66;">&#40;</span>te<span style="color: #66cc66;">.</span>Hours<span style="color: #66cc66;">&#41;</span> TotalHoursInDay
		<span style="color: #993333; font-weight: bold;">FROM</span>
			TimeEntries te
		<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
			te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
			te<span style="color: #66cc66;">.</span>DateWorked
	<span style="color: #66cc66;">&#41;</span> te
	<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span>
	<span style="color: #66cc66;">&#40;</span>
		<span style="color: #993333; font-weight: bold;">SELECT</span>
			te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
			te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
			SUM<span style="color: #66cc66;">&#40;</span>te<span style="color: #66cc66;">.</span>Hours<span style="color: #66cc66;">&#41;</span> TotalHoursInDay
		<span style="color: #993333; font-weight: bold;">FROM</span>
			TimeEntries te
		<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
			te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
			te<span style="color: #66cc66;">.</span>DateWorked
	<span style="color: #66cc66;">&#41;</span> previous
		<span style="color: #993333; font-weight: bold;">ON</span>	te<span style="color: #66cc66;">.</span>EmployeeId <span style="color: #66cc66;">=</span> previous<span style="color: #66cc66;">.</span>EmployeeId <span style="color: #993333; font-weight: bold;">AND</span>
			te<span style="color: #66cc66;">.</span>DateWorked <span style="color: #66cc66;">&gt;</span> previous<span style="color: #66cc66;">.</span>DateWorked
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
	te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
	te<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">,</span>
	te<span style="color: #66cc66;">.</span>DateWorked</pre></td></tr></table></div>

<p>The first subquery, te, creates a list of each day for each employee and the total hours for that day. This is to get the total current hours for the employee for the given day. We join that to the second subquery, previous. The Previous query generates a total number for all days PRIOR to the given day. (The logic comes from our join condition, te.DateWorked > previous.DateWorked)</p>
<p>The InOvertime flag will be used later on to determine overtime hours. It lets us know when the employee has crossed the threshold. That could probably be taken out, but it simplifies the logic later on.</p>
<p>So we get these results:</p>
<table style="border-collapse: collapse;" border="1" cellspacing="4" cellpadding="4">
<tbody>
<tr>
<th>EmployeeID</th>
<th>TotalHoursInDay</th>
<th>DateWorked</th>
<th>HoursUpToThisPoint</th>
<th>InOvertime</th>
</tr>
<tr>
<td>1</td>
<td>8</td>
<td>2010-01-04</td>
<td>NULL</td>
<td>N</td>
</tr>
<tr>
<td>1</td>
<td>10</td>
<td>2010-01-05</td>
<td>8</td>
<td>N</td>
</tr>
<tr>
<td>1</td>
<td>7.5</td>
<td>2010-01-06</td>
<td>18</td>
<td>N</td>
</tr>
<tr>
<td>1</td>
<td>10</td>
<td>2010-01-07</td>
<td>25.5</td>
<td>N</td>
</tr>
<tr>
<td>1</td>
<td>10</td>
<td>2010-01-08</td>
<td>35.5</td>
<td>Y</td>
</tr>
<tr>
<td>1</td>
<td>4</td>
<td>2010-01-08</td>
<td>45.5</td>
<td>Y</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>2010-01-04</td>
<td>NULL</td>
<td>N</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>2010-01-05</td>
<td>10</td>
<td>N</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>2010-01-06</td>
<td>20</td>
<td>N</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>2010-01-07</td>
<td>30</td>
<td>N</td>
</tr>
</tbody>
</table>
<p>As you can see, this subquery determines for us the total number of hours up until the given day, and when combined with the hours worked in the given day we know if the employee is in overtime or not.</p>
<p>Let&#8217;s put one more wrapper around this which will total up the hours and tell us how many hours were regular hours and how many were overtime.</p>
<p>Here is our final query.</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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>
	EmployeeId<span style="color: #66cc66;">,</span>
	sum<span style="color: #66cc66;">&#40;</span>case when InOvertime <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'N'</span> then TotalHoursInDay
	         when InOvertime <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Y'</span> <span style="color: #993333; font-weight: bold;">AND</span> HoursUpToThisPoint <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">40</span> then  <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">-</span> HoursUpToThisPoint
		 else <span style="color: #cc66cc;">0</span>
	end<span style="color: #66cc66;">&#41;</span> RegularHours<span style="color: #66cc66;">,</span>
	sum<span style="color: #66cc66;">&#40;</span>case when InOvertime <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Y'</span> then
		 case when HoursUpToThisPoint <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">40</span> then TotalHoursInDay
			  else HoursUpToThisPoint <span style="color: #66cc66;">+</span> TotalHoursInDay <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">40</span>
		 end
		 else <span style="color: #cc66cc;">0</span>
	end<span style="color: #66cc66;">&#41;</span> OTHours
<span style="color: #993333; font-weight: bold;">FROM</span>
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span>
		te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
		te<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">,</span>
		te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
		sum<span style="color: #66cc66;">&#40;</span>previous<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">&#41;</span> HoursUpToThisPoint<span style="color: #66cc66;">,</span>
		case when te<span style="color: #66cc66;">.</span>TotalHoursInDay <span style="color: #66cc66;">+</span> SUM<span style="color: #66cc66;">&#40;</span>previous<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">40</span> then <span style="color: #ff0000;">'Y'</span>
			 else <span style="color: #ff0000;">'N'</span>
		end InOvertime
	<span style="color: #993333; font-weight: bold;">FROM</span>
		<span style="color: #66cc66;">&#40;</span>
			<span style="color: #993333; font-weight: bold;">SELECT</span>
				te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
				te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
				SUM<span style="color: #66cc66;">&#40;</span>te<span style="color: #66cc66;">.</span>Hours<span style="color: #66cc66;">&#41;</span> TotalHoursInDay
			<span style="color: #993333; font-weight: bold;">FROM</span>
				TimeEntries te
			<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
				te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
				te<span style="color: #66cc66;">.</span>DateWorked
		<span style="color: #66cc66;">&#41;</span> te
		<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span>
		<span style="color: #66cc66;">&#40;</span>
			<span style="color: #993333; font-weight: bold;">SELECT</span>
				te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
				te<span style="color: #66cc66;">.</span>DateWorked<span style="color: #66cc66;">,</span>
				SUM<span style="color: #66cc66;">&#40;</span>te<span style="color: #66cc66;">.</span>Hours<span style="color: #66cc66;">&#41;</span> TotalHoursInDay
			<span style="color: #993333; font-weight: bold;">FROM</span>
				TimeEntries te
			<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
				te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
				te<span style="color: #66cc66;">.</span>DateWorked
		<span style="color: #66cc66;">&#41;</span> previous
			<span style="color: #993333; font-weight: bold;">ON</span>	te<span style="color: #66cc66;">.</span>EmployeeId <span style="color: #66cc66;">=</span> previous<span style="color: #66cc66;">.</span>EmployeeId <span style="color: #993333; font-weight: bold;">AND</span>
				te<span style="color: #66cc66;">.</span>DateWorked <span style="color: #66cc66;">&gt;</span> previous<span style="color: #66cc66;">.</span>DateWorked
	<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
		te<span style="color: #66cc66;">.</span>EmployeeId<span style="color: #66cc66;">,</span>
		te<span style="color: #66cc66;">.</span>TotalHoursInDay<span style="color: #66cc66;">,</span>
		te<span style="color: #66cc66;">.</span>DateWorked
<span style="color: #66cc66;">&#41;</span> HoursQuery
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span>
	HoursQuery<span style="color: #66cc66;">.</span>EmployeeId</pre></td></tr></table></div>

<table style="border-collapse: collapse;" border="1" cellspacing="4" cellpadding="4">
<tr>
<th>EmployeeId</th>
<th>RegularHours</th>
<th>OTHours</th>
</tr>
<tr>
<td>1</td>
<td>40</td>
<td>9.5</td>
</tr>
<tr>
<td>2</td>
<td>40</td>
<td>0</td>
</tr>
</table>
<p>What we have done here is add some logic that acts on whether or not the a given time entry is in overtime. We group by the employee so we can aggregate hours.</p>
<p>If the record is in overtime, it might mean the employee is already over 40 hours or it might mean that the current record puts the employee over 40 hours. So we have to add a check that will take the difference as regular hours, since the hours that take the employee up to 40 are still regular hours.</p>
<p>The second check is to calculate overtime. If the time entry puts the employee over 40, then take the amount over 40 as overtime. If the employee is already over 40, then the entire entry is overtime.</p>
<p>I hope this post helps you have the mindset of doing as much as possible with your queries, rather than writing code to calculate values which can easily be queried.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/03/15/using-sql-to-accrue-values-overtime-in-time-entries/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Sending an Email in C# When Server Uses GREET_PAUSE</title>
		<link>http://www.daveandrews.org/2010/02/19/sending-an-email-in-c-when-server-uses-greet_pause/</link>
		<comments>http://www.daveandrews.org/2010/02/19/sending-an-email-in-c-when-server-uses-greet_pause/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 19:40:54 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=339</guid>
		<description><![CDATA[I wrote a process for a client which would send an email through their email server when a process completed. Their server did not require any kind of authentication or SSL, so the code to do this was very simple: 1 2 3 4 5 6 7 8 9 10 public static void SendEmail&#40;string to, [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a process for a client which would send an email through their email server when a process completed. Their server did not require any kind of authentication or SSL, so the code to do this was very simple:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> SendEmail<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> to, <span style="color: #FF0000;">string</span> from, <span style="color: #FF0000;">string</span> subject, 
                             <span style="color: #FF0000;">string</span> message, <span style="color: #FF0000;">string</span> host, <span style="color: #FF0000;">int</span> port<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    SmtpClient c <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SmtpClient<span style="color: #000000;">&#40;</span>host, port<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    MailMessage m <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MailMessage<span style="color: #000000;">&#40;</span>from, to, subject, message<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    m.<span style="color: #0000FF;">IsBodyHtml</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
&nbsp;
    c.<span style="color: #0000FF;">Send</span><span style="color: #000000;">&#40;</span>m<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Simple, eh? But it would fail. If I telnet&#8217;ed into their server and typed the SMTP commands to send an email, I would get a 550 5.0.0 Command Rejected&#8221; error message at the point where I try to send a &#8220;RCPT TO:&#8221; SMTP command. What&#8217;s the deal?!</p>
<p>Well, apparently the server did have a restriction that I had so far not known about. It had been configured with a GREET_PAUSE value for all emails. Typically that setting should only be set for incoming emails from external servers, and not for internal emails like this. But it was set for all emails.</p>
<p>GREET_PAUSE means that once an SMTP connection is made, the client who is connecting must WAIT until the server recognizes their connection before &#8220;blasting&#8221; SMTP commands through. Apparently SMTPClient just blasts the commands through. If a SINGLE character is received in that timespan, the server will reply as normal, but will reject any and all emails that are sent through.</p>
<p>I tried a couple fancy ways to make SMTPClient wait for a few seconds before sending data, but could not find an easy way. Apparently it does not support this capability out of the box (such that I could find.) So I resolved to just writing the email code myself. It&#8217;s not hard to do.</p>
<p>I added a greet_delay_ms integer to my parameters on my function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> SendEmail<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> to, <span style="color: #FF0000;">string</span> from, <span style="color: #FF0000;">string</span> subject, <span style="color: #FF0000;">string</span> message, 
                    <span style="color: #FF0000;">string</span> host, <span style="color: #FF0000;">int</span> port, <span style="color: #FF0000;">int</span> greet_delay_ms<span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>And replaced the simple SMTPClient code with this more complex code:</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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> SendEmail<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> to, <span style="color: #FF0000;">string</span> from, <span style="color: #FF0000;">string</span> subject, <span style="color: #FF0000;">string</span> message, 
                       <span style="color: #FF0000;">string</span> host, <span style="color: #FF0000;">int</span> port, <span style="color: #FF0000;">int</span> greet_delay_ms<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    TcpClient c <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TcpClient<span style="color: #000000;">&#40;</span>host, port<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    StreamWriter sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamWriter<span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">GetStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    StreamReader sr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">GetStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #FF0000;">string</span> data <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Wait the specified amount of time before sending an email</span>
    <span style="color: #008080; font-style: italic;">// could probably also just do a sr.ReadLine() and let it block</span>
    <span style="color: #000000;">System.<span style="color: #0000FF;">Threading</span></span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span>greet_delay_ms<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;helo &quot;</span> <span style="color: #008000;">+</span> from.<span style="color: #0000FF;">Substring</span><span style="color: #000000;">&#40;</span>from.<span style="color: #0000FF;">IndexOf</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    data <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MAIL FROM:&quot;</span> <span style="color: #008000;">+</span> from<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    data <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;RCPT TO:&quot;</span> <span style="color: #008000;">+</span> to<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    data <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;DATA&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    data <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Subject: &quot;</span> <span style="color: #008000;">+</span> subject<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    sw.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    data <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    c.<span style="color: #0000FF;">Client</span>.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    c.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Once I passed in 8000 or so as the time to wait, the emails poured through just fine. 8 seconds is a while to wait, but apparently that&#8217;s what this server requires.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2010/02/19/sending-an-email-in-c-when-server-uses-greet_pause/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding a Dropdown List in ASP.Net Inside a ListView</title>
		<link>http://www.daveandrews.org/2009/12/08/binding-a-dropdown-list-in-asp-net-inside-a-listview/</link>
		<comments>http://www.daveandrews.org/2009/12/08/binding-a-dropdown-list-in-asp-net-inside-a-listview/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 20:54:54 +0000</pubDate>
		<dc:creator>Dave Andrews</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.daveandrews.org/?p=283</guid>
		<description><![CDATA[I like to blog things that I have to look up. Here&#8217;s a quickie which solves a problem I was having. In my table, I have a field &#8220;PayType&#8221; which is a char(1) and has valid values &#8220;S&#8221; and &#8220;H&#8221;. These mean &#8220;Salary&#8221; and &#8220;Hourly&#8221;, respectively. I am showing this in a ListView in my [...]]]></description>
			<content:encoded><![CDATA[<p>I like to blog things that I have to look up. Here&#8217;s a quickie which solves a problem I was having.</p>
<p>In my table, I have a field &#8220;PayType&#8221; which is a char(1) and has valid values &#8220;S&#8221; and &#8220;H&#8221;. These mean &#8220;Salary&#8221; and &#8220;Hourly&#8221;, respectively.</p>
<p>I am showing this in a ListView in my screen I&#8217;m developing. So, when editing the record, I naturally wanted a dropdown box where you can choose &#8220;Hourly&#8221; or &#8220;Salary&#8221;. Note this will only work if you know what values you want in your dropdown box. If the selections are dynamic, then you will probably have to have a databound event and build the box manually.</p>
<p>I wanted it to default to the selected type for the record I&#8217;m editing when I click on edit, but could not find anything in the intellisence that looked correct for my Bind() call.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;asp:DropDownList 
      ID=&quot;ddPayType&quot; 
      runat=&quot;server&quot; 
      SelectedValue=&lt;%# Bind(&quot;PayType&quot;) %&gt;  &gt;;
          &lt;asp:ListItem Text=&quot;Salary&quot; Value = &quot;S&quot; /&gt;
          &lt;asp:ListItem Text=&quot;Hourly&quot; Value = &quot;H&quot; /&gt;
&lt;/asp:DropDownList&gt;</pre></td></tr></table></div>

<p>The answer was to Bind on the &#8220;SelectedValue&#8221; parameter. I was thrown off because SelectedValue does not seem to pull up in Visual Studio 2008 as an option on the list when writing code in the markup editor. But it correctly updates the value when the Update command is executed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveandrews.org/2009/12/08/binding-a-dropdown-list-in-asp-net-inside-a-listview/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
