<?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>MexiCode</title>
	<atom:link href="http://www.mexicode.com.mx/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.mexicode.com.mx</link>
	<description>Ideas en codigo</description>
	<lastBuildDate>Mon, 22 Mar 2010 08:54:17 +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>MySQL INSERT statement with steroids</title>
		<link>http://www.mexicode.com.mx/?p=151</link>
		<comments>http://www.mexicode.com.mx/?p=151#comments</comments>
		<pubDate>Mon, 22 Mar 2010 05:25:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=151</guid>
		<description><![CDATA[Do you remember when you first learned about basic SQL statements? INSERT, UPDATE, DELETE and SELECT? While SELECT is a whole different beast, the other three are pretty much the same across different database engines, so you usually learn the basics only. The thing is, you should REALLY read the documentation for your specific engine, [...]]]></description>
			<content:encoded><![CDATA[<p>Do you remember when you first learned about basic SQL statements? INSERT, UPDATE, DELETE and SELECT?</p>
<p>While SELECT is a whole different beast, the other three are pretty much the same across different database engines, so you usually learn the basics only.</p>
<p>The thing is, you should <strong><em>REALLY</em></strong> read the documentation for your specific engine, because most of the time, each engine adds cool functionality to the standards (OK, this will break your code when you change from database X to Y, but in the meantime, it makes development so much easier)</p>
<p>How many times, have you written code that looks like this:</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="csharp" style="font-family:monospace;"><span style="color: #FF0000;">bool</span> exist <span style="color: #008000;">=</span> CheckIfDuplicate<span style="color: #000000;">&#40;</span>key<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>exist<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">//insert</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">//update</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I hope not as many as me... This is the day I learned about:</p>
<ul>
<li><a href="http://dev.mysql.com/doc/refman/5.1/en/replace.html">REPLACE</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.1/en/insert.html#id1852705">INSERT IGNORE</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html">INSERT ... ON DUPLICATE KEY UPDATE</a></li>
</ul>
<p>So if you are not familiar with this syntax and you're a heavy MySQL user, please go read the documentation. <strong>Go</strong>. <strong><u>Now</u></strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=151</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drag &amp; Drop from ListView to TreeView</title>
		<link>http://www.mexicode.com.mx/?p=120</link>
		<comments>http://www.mexicode.com.mx/?p=120#comments</comments>
		<pubDate>Tue, 09 Mar 2010 19:44:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=120</guid>
		<description><![CDATA[I started working on a new project at work. This is the "fun stage" of the project: the prototypes and the investigation part. One of the UI requirements was to drag and drop elements from a ListView to a TreeNode. So, this is how to enable Drag&#038;Drop: First, you have to enable the AllowDrop property [...]]]></description>
			<content:encoded><![CDATA[<p>I started working on a new project at work. This is the "fun stage" of the project: the prototypes and the investigation part.</p>
<p>One of the UI requirements was to drag and drop elements from a <code>ListView </code>to a <code>TreeNode</code>. So, this is how to enable Drag&#038;Drop:</p>
<p>First, you have to enable the <code>AllowDrop </code>property for your <code>TreeView</code></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">treeView1.<span style="color: #0000FF;">AllowDrop</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span></pre></div></div>

<p>Then, in your ListView, you have to add code to the ItemDrag event:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">listView1.<span style="color: #0000FF;">DoDragDrop</span><span style="color: #000000;">&#40;</span>listView1.<span style="color: #0000FF;">SelectedItems</span>, DragDropEffects.<span style="color: #0000FF;">Move</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <code>DoDragDrop</code> method begins a Drag&#038;Drop operation. The first parameter, is the element(s) you want to drag around. The second, is the type of dragging-and-dropping you want to do. Here is a list:</p>
<table>
<tr>
<td><strong>None</strong></td>
<td>The drop target does not accept the data.</td>
</tr>
<tr>
<td><strong>Copy</strong></td>
<td>The data from the drag source is copied to the drop target.</td>
</tr>
<tr>
<td><strong>Move</strong></td>
<td>The data from the drag source is moved to the drop target.</td>
</tr>
<tr>
<td><strong>Link</strong></td>
<td>The data from the drag source is linked to the drop target.</td>
</tr>
<tr>
<td><strong>Scroll</strong></td>
<td>The target can be scrolled while dragging to locate a drop position that is not currently visible in the target.</td>
</tr>
<tr>
<td><strong>All</strong></td>
<td>The combination of the Copy, Move, and Scroll effects.</td>
</tr>
</table>
<p>You can combine more than 1 DragDropEffect by bitwise ORing them:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">listView1.<span style="color: #0000FF;">DoDragDrop</span><span style="color: #000000;">&#40;</span>listView1.<span style="color: #0000FF;">SelectedItems</span>, DragDropEffects.<span style="color: #0000FF;">All</span> <span style="color: #008000;">|</span> DragDropEffects.<span style="color: #0000FF;">Link</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>In my project, I only need <code>DragDropEffects.Move</code> functionality.</p>
<p>Well. Now we only have two more things to do. First, we have to take care of the <code>DragOver</code> event. This is raised by your <strong>target</strong> control (in this case a TreeView) every time the mouse moves over the target's visible area.</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
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> treeView1_DragOver<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DragEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetDataPresent</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        e.<span style="color: #0000FF;">Effect</span> <span style="color: #008000;">=</span> DragDropEffects.<span style="color: #0000FF;">Move</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    Point position <span style="color: #008000;">=</span> treeView1.<span style="color: #0000FF;">PointToClient</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">X</span>, e.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    TreeNode tn <span style="color: #008000;">=</span> treeView1.<span style="color: #0000FF;">GetNodeAt</span><span style="color: #000000;">&#40;</span>position<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>tn <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>                
        treeView1.<span style="color: #0000FF;">SelectedNode</span> <span style="color: #008000;">=</span> tn<span style="color: #008000;">;</span>                
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>tn.<span style="color: #0000FF;">IsExpanded</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            tn.<span style="color: #0000FF;">Expand</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>                
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>There are some interesting bits of code in there:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetDataPresent</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    e.<span style="color: #0000FF;">Effect</span> <span style="color: #008000;">=</span> DragDropEffects.<span style="color: #0000FF;">Move</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Our data (the one we are dragging around) is stored in the <code>Data </code>property of the event. The <code>GetDataPresent</code> method determines whether this data can be converted to the specified format.</p>
<p>In this case, our format is <code>ListView.SelectedListViewItemCollection</code>. Why? you may ask. Well, because this is the returning type of <code>listView1.SelectedItems</code> (which is the object we are dragging around, remember?).</p>
<p>We could put this particular piece of code inside the target's (<code>TreeView</code>) <code>DragEnter </code>event. This way, it only has to be executed once.</p>
<p>This is also important:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Point position <span style="color: #008000;">=</span> treeView1.<span style="color: #0000FF;">PointToClient</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">X</span>, e.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
TreeNode tn <span style="color: #008000;">=</span> treeView1.<span style="color: #0000FF;">GetNodeAt</span><span style="color: #000000;">&#40;</span>position<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The DragEventArgs object holds some information about the event. In this case we are using <code>e.X</code> and <code>e.Y</code> to know the location of the mouse at any given time. But the thing is that the mouse location is relative to the screen, so we have to convert it to client coordinates. That's exactly what <code>PointToClient</code> does.</p>
<p>Now that we have the position relative to the client, we can get the <code>TreeNode</code> under that position. If there is no <code>TreeNode</code> under that position (maybe the mouse is moving over whitespace) it returns null.</p>
<p>The rest of the code is trivial, it expands a <code>TreeNode</code> if its not expanded already.</p>
<p>Lastly, we have the <code>DragDrop</code> event, in which we release the mouse button over our target <code>TreeNode</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
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> treeView1_DragDrop<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DragEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Point position <span style="color: #008000;">=</span> treeView1.<span style="color: #0000FF;">PointToClient</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">X</span>, e.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetDataPresent</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        TreeNode tn <span style="color: #008000;">=</span> treeView1.<span style="color: #0000FF;">GetNodeAt</span><span style="color: #000000;">&#40;</span>position<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        var li <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetData</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>ListViewItem item <span style="color: #0600FF;">in</span> li<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span>tn.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; = &quot;</span> <span style="color: #008000;">+</span> item.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                 
        <span style="color: #000000;">&#125;</span>                
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The only interesting or new line in here is this one:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var li <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">GetData</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ListView.<span style="color: #0000FF;">SelectedListViewItemCollection</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>this method retrieves the data associated with the specified data format (at least, that's what MSDN says) but you still have to cast it accordingly.</p>
<p>Once you have your data, you can do anything you want with it (i'm just displaying which TreeNode received the Items and the Items' text)</p>
<p>Happy hacking.</p>
<p><strong>UPDATE</strong></p>
<p>If you want to see which TreeNode you're selecting while dragging, just add this to your code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">treeView1.<span style="color: #0000FF;">HideSelection</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=120</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Books</title>
		<link>http://www.mexicode.com.mx/?p=114</link>
		<comments>http://www.mexicode.com.mx/?p=114#comments</comments>
		<pubDate>Wed, 03 Mar 2010 04:55:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=114</guid>
		<description><![CDATA[It's been kinda quiet lately. I've been busy reading. Yup, that's right. Reading. I got a book shipment from amazon.com last week and I have been reading since then. These are the books I got: Head First Design Patterns Design Patterns Refactoring Mythical Man Month Programming Pearls Coders at Work So, as you can see, [...]]]></description>
			<content:encoded><![CDATA[<p>It's been kinda quiet lately. I've been busy reading.</p>
<p>Yup, that's right. Reading.</p>
<p>I got a book shipment from amazon.com last week and I have been reading since then. These are the books I got:</p>
<ul>
<li>Head First Design Patterns</li>
<li>Design Patterns</li>
<li>Refactoring</li>
<li>Mythical Man Month</li>
<li>Programming Pearls</li>
<li>Coders at Work</li>
</ul>
<p>So, as you can see, I have a *LOT* to read. The good thing about my job, is that it allows me some spare time to educate myself.</p>
<p>I haven't done any programming in the last week, but I promise I'll write a post on blackberry development in the next few days, just let me finish my book first <img src='http://www.mexicode.com.mx/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=114</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse DPT JDBC Drivers</title>
		<link>http://www.mexicode.com.mx/?p=104</link>
		<comments>http://www.mexicode.com.mx/?p=104#comments</comments>
		<pubDate>Mon, 22 Feb 2010 11:14:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=104</guid>
		<description><![CDATA[I just installed eclipse-dpt for my database access (works great, btw). But I needed some JDBC "drivers" for my SQL Engines (namely MySQL and MS SQL). So, to save you the burden of looking for the files all over the internet, here it is, in a single zip file JDBC Drivers for MySQL and MSSQ [...]]]></description>
			<content:encoded><![CDATA[<p>I just installed eclipse-dpt for my database access (works great, btw).</p>
<p>But I needed some JDBC "drivers" for my SQL Engines (namely MySQL and MS SQL). So, to save you the burden of looking for the files all over the internet, here it is, in a single zip file</p>
<p><a href='http://www.mexicode.com.mx/wp-content/uploads/2010/02/JDBC1.zip'>JDBC Drivers for MySQL and MSSQ</a></p>
<p>The zip contains 3 jar files:</p>
<ul>
<li>mysql-connector-java-5.1.12-bin.jar - For MySQL v5.1 or lower</li>
<li>sqljdbc.jar - MS SQL versions 2005 and 2000</li>
<li>sqljdbc4.jar - This works only for MS SQL 2008</li>
</ul>
<p>Just uncompress the file into some folder, and add the appropiate drivers from eclipse dpt and you're done!</p>
<p><strong>Update:</strong> <a href="http://www.oxygenxml.com/doc/ug-oxygen/download-database-drivers.html">This listing</a> includes links to JDBC drivers for all major database engines. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=104</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu Quirks (ongoing&#8230;)</title>
		<link>http://www.mexicode.com.mx/?p=101</link>
		<comments>http://www.mexicode.com.mx/?p=101#comments</comments>
		<pubDate>Mon, 22 Feb 2010 00:58:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=101</guid>
		<description><![CDATA[Windows Key not detected If your "Windows Key" (Super_L) is not detected, you will have to run this command: xmodmap -e "remove mod4 = Super_L" It seems to work even after rebooting the machine Can't install Eclipse plugins In order to install eclipse plugins, after installing eclipse-platform, you *must* install the eclipse-pde package (which comes [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows Key not detected</h2>
<p>If your "Windows Key" (Super_L)  is not detected, you will have to run this command:</p>
<p><code>xmodmap -e "remove mod4 = Super_L"</code></p>
<p>It seems to work even after rebooting the machine</p>
<h2>Can't install Eclipse plugins</h2>
<p>In order to install eclipse plugins, after installing <code>eclipse-platform</code>, you *must* install the <code>eclipse-pde</code> package (which comes with the <code>eclipse-jdt</code> as a dependency, oh well...)</p>
<hr />
<p>This is an ongoing effort to write the odd things I have to do to get my OS to behave as I want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=101</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Read IMAP Emails with PHP</title>
		<link>http://www.mexicode.com.mx/?p=86</link>
		<comments>http://www.mexicode.com.mx/?p=86#comments</comments>
		<pubDate>Sat, 20 Feb 2010 09:29:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=86</guid>
		<description><![CDATA[Well, at work we are all about google app for your domain, we use it for virtually anything. So, we started a new project, in which we had to read emails from our web application, and I remembered reading something about php_imap somewhere, so I decided to check it out. Lucky as I always am, [...]]]></description>
			<content:encoded><![CDATA[<p>Well, at work we are all about google app for your domain, we use it for virtually anything. So, we started a new project, in which we had to read emails from our web application, and I remembered reading something about php_imap somewhere, so I decided to check it out.</p>
<p>Lucky as I always am, our hosting provider already had this module installed and working, so I didn´t have to go thru any extra steps, just right on programming.</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Open pop mailbox</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$mbox</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_open</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{imap.gmail.com:993/ssl/novalidate-cert}&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;mail@googledomain.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot connect/check pop mail! Exiting'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hdr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_check</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$msgCount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hdr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Nmsgs</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failed to get mail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Read $msgCount from INBOX</span>
<span style="color: #000088;">$MN</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$msgCount</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$emails</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_fetch_overview</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;1:<span style="color: #006699; font-weight: bold;">$MN</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//print email information and delete each email</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$emails</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pre&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;TO : <span style="color: #006699; font-weight: bold;">{$email-&gt;to}</span>&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> extract_attachments<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">msgno</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/pre&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">imap_delete</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">msgno</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//delete emails marked for deletion and close connection</span>
<span style="color: #990000;">imap_expunge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imap_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Well, thats shows how to connect to a google domain. I'll talk about the "extract_attachments" function in another post, I'm pretty tired right now.</p>
<p>You should really check the <a href="http://www.php.net/manual/en/ref.imap.php">PHP imap function list</a>. There is some really cool stuff going on in there.</p>
<p><strong>NOTE TO SELF</strong> the <code>novalidate-cert</code> bit on the connection string to the imap inbox, saves you from quite a few headaches</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=86</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL search engine (MATCH &#8230; AGAINST)</title>
		<link>http://www.mexicode.com.mx/?p=68</link>
		<comments>http://www.mexicode.com.mx/?p=68#comments</comments>
		<pubDate>Sat, 20 Feb 2010 08:49:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=68</guid>
		<description><![CDATA[I was writing a full fledged tutorial on performing searches using MySQL, but I think is best if you just look directly into the documentation: Full-Text Search Functions Man, there is some serious voodoo shit going on in there.]]></description>
			<content:encoded><![CDATA[<p>I was writing a full fledged tutorial on performing searches using MySQL, but I think is best if you just look directly into the documentation:</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html">Full-Text Search Functions</a></p>
<p>Man, there is some serious voodoo shit going on in there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=68</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remote connection to SQL Server Express 2008</title>
		<link>http://www.mexicode.com.mx/?p=50</link>
		<comments>http://www.mexicode.com.mx/?p=50#comments</comments>
		<pubDate>Thu, 04 Feb 2010 17:26:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[sqlserver express]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=50</guid>
		<description><![CDATA[I don't know why SQL Server Express doesn't have remote access "out-of-the-box" but anyways... here is how to enable it. In the server: Open SQL Server Configuration Manager Under SQL Server Network Configuration, select Protocols for SQLEXPRESS and make sure TCP/IP is enabled. Otherwise, enable it Then, select SQL Server Services, and make sure SQL [...]]]></description>
			<content:encoded><![CDATA[<p>I don't know why SQL Server Express doesn't have remote access "out-of-the-box" but anyways... here is how to enable it.</p>
<p>In the server:</p>
<ol>
<li>Open SQL Server Configuration Manager</li>
<li>Under SQL <strong>Server Network Configuration</strong>, select <strong>Protocols for SQLEXPRESS</strong> and make sure <strong>TCP/IP</strong> is enabled. Otherwise, enable it</li>
<li>Then, select <strong>SQL Server Services</strong>, and make sure <strong>SQL Server Browser</strong> is on Start Mode: <strong>Automatic</strong></li>
</ol>
<p>We need to be sure, that our server accepts SQL Authentication. If you know this option is already enabled in your server, skip the next steps. If you know they are not, or you're not sure, follow this steps:</p>
<ol>
<li>Open Management Studio (in the server) and connect to your database, using Windows Authentication Mode</li>
<li>Right click on your database, and select Properties</li>
<li>Under <strong>Security</strong>, select <strong>SQL Server and Windows Authentication mode</strong></li>
<li>Under <strong>Connections</strong>, check <strong>"Allow connections to this server"</strong></li>
</ol>
<p>I read somewhere that you should reboot the server. Just restarting the SQL Server Service doesn't work (I can confirm this).</p>
<p>Now, just remember ALWAYS to add the SQLEXPRESS part to your hostname. For instance, if your server name is win2008server, then you should connect to <strong>win2008server\sqlexpress</strong> in your applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=50</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Formatting DataGridView cell with custom DataSource</title>
		<link>http://www.mexicode.com.mx/?p=47</link>
		<comments>http://www.mexicode.com.mx/?p=47#comments</comments>
		<pubDate>Wed, 13 Jan 2010 21:51:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[datagridview]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=47</guid>
		<description><![CDATA[When you use a custom DataSource (in my case a generic list) the properties become the columns and the property names, become the column header. I needed to format a DateTime field, so I did this: 1 2 3 4 5 6 7 8 9 private void dataGridView1_CellFormatting&#40;object sender, DataGridViewCellFormattingEventArgs e&#41; &#123; if &#40;dataGridView1.Columns&#91;e.ColumnIndex&#93;.DataPropertyName == [...]]]></description>
			<content:encoded><![CDATA[<p>When you use a custom DataSource (in my case a generic list) the properties become the columns and the property names, become the column header.</p>
<p>I needed to format a DateTime field, so I did this:</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="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> dataGridView1_CellFormatting<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DataGridViewCellFormattingEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>dataGridView1.<span style="color: #0000FF;">Columns</span><span style="color: #000000;">&#91;</span>e.<span style="color: #0000FF;">ColumnIndex</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">DataPropertyName</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Date&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>	
        DateTime value <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>DateTime<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
        e.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> value.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;G&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        e.<span style="color: #0000FF;">FormattingApplied</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>In this case, "Date" is the property name of a DateTime field.</p>
<p>In case you are curious, the DataSource assignment is like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span>GoodReceipts<span style="color: #008000;">&gt;</span> grrs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>GoodReceipts<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
grrs.<span style="color: #0000FF;">AddRange</span><span style="color: #000000;">&#40;</span>logic.<span style="color: #0000FF;">GetGRRData</span><span style="color: #000000;">&#40;</span>consumptions, validSince, validTo<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>     
dataGridView1.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> grrs<span style="color: #008000;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connect PHP and Sql Server (ntwdblib.dll)</title>
		<link>http://www.mexicode.com.mx/?p=45</link>
		<comments>http://www.mexicode.com.mx/?p=45#comments</comments>
		<pubDate>Tue, 12 Jan 2010 23:53:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.mexicode.com.mx/?p=45</guid>
		<description><![CDATA[If you need to connect PHP with SQL Server (in a Windows installation), go to your PHP install folder, and replace the file ntwdblib.dll with this one. Apparently, PHP is not allowed to include this Dll without getting sued or something.]]></description>
			<content:encoded><![CDATA[<p>If you need to connect PHP with SQL Server (in a Windows installation), go to your PHP install folder, and replace the file ntwdblib.dll with <a href='http://www.mexicode.com.mx/wp-content/uploads/2010/01/ntwdblib.zip'>this one.</a></p>
<p>Apparently, PHP is not allowed to include this Dll without getting sued or something.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mexicode.com.mx/?feed=rss2&amp;p=45</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
