<?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>Phalanx Blogosphere</title>
	<atom:link href="http://phalanx.spartansoft.org/feed" rel="self" type="application/rss+xml" />
	<link>http://phalanx.spartansoft.org</link>
	<description>Whatever happens, SPARTAN&#039;S code must stand ... Or at least crash responsibly.</description>
	<lastBuildDate>Fri, 04 Jun 2010 09:36:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using LINQ to SQL ORM</title>
		<link>http://phalanx.spartansoft.org/2010/06/03/using-linq-to-sql-orm/</link>
		<comments>http://phalanx.spartansoft.org/2010/06/03/using-linq-to-sql-orm/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 13:45:37 +0000</pubDate>
		<dc:creator>Mentor Ibrahimi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=1101</guid>
		<description><![CDATA[One of the hardest things i encounter when i do write LINQ queris, is that i always tend to approach results as i would in T-SQL. Well, recently i read an article about LINQ and the author said that one of the major steps a developer find hard to do, is working with LINQ without [...]]]></description>
			<content:encoded><![CDATA[<p>One of the hardest things i encounter when i do write LINQ queris, is that i always tend to approach results as i would in T-SQL. Well, recently i read an article about LINQ and the author said that one of the major steps a developer find hard to do, is working with LINQ without thinking of the problem in T-SQL way. Well that&#8217;s what i run yesterday, i started writing the query, and debugging, and over analyzing without giving it a clear view of what i wanted. To demonstrate that, let&#8217;s first show the model i was working against:</p>
<p style="text-align: center;">﻿﻿﻿<a href="http://phalanx.spartansoft.org/wp-content/uploads/2010/06/Capture.jpg"><img class="size-medium wp-image-1104 aligncenter" title="LINQ to SQL ORM" src="http://phalanx.spartansoft.org/wp-content/uploads/2010/06/Capture-300x205.jpg" alt="" width="300" height="205" /></a></p>
<p>What i wanted to achieve is to get three most sold pizzas and three most active clients. Although the result is easier that i supposed, as i said, i tended to get them as i think from the T-SQL world. My first approach was like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var topPizzas <span style="color: #008000;">=</span> from pizza <span style="color: #0600FF;">in</span> dataContext.<span style="color: #0000FF;">OrderDetails</span>
&nbsp;
.<span style="color: #0000FF;">GroupBy</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p.<span style="color: #0000FF;">PizzaTypeID</span><span style="color: #000000;">&#41;</span>
&nbsp;
select <span style="color: #008000;">new</span> <span style="color: #000000;">&#123;</span>pizza.<span style="color: #0000FF;">Key</span>, Total <span style="color: #008000;">=</span> pizza.<span style="color: #0000FF;">Sum</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p.<span style="color: #0000FF;">Quantity</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
var top3Pizzas <span style="color: #008000;">=</span> topPizzas.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var topCustomers <span style="color: #008000;">=</span> from customer <span style="color: #0600FF;">in</span> dataContext.<span style="color: #0000FF;">Orders</span>
&nbsp;
.<span style="color: #0000FF;">GroupBy</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p.<span style="color: #0000FF;">CustomerID</span><span style="color: #000000;">&#41;</span>
&nbsp;
select <span style="color: #008000;">new</span> <span style="color: #000000;">&#123;</span>customer.<span style="color: #0000FF;">Key</span>, Total <span style="color: #008000;">=</span> customer.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
var top3Customers <span style="color: #008000;">=</span> topCustomers.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This way we get the right result but we get just the id of the pizza and the sum of quantity orders it was ordered. Whenever we try to project to a pizza type we will hit the wall on full speed asking our selves where is the problem, it &#8220;MUST&#8221; work this way.</p>
<p>But this time must come, &#8220;Wait a minute, what do i want?&#8221; and yeah the answer is top pizzas and customers and probably not some order&#8230; thing <img src='http://phalanx.spartansoft.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  and the following query really must work:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var topPizzas <span style="color: #008000;">=</span> from pizza <span style="color: #0600FF;">in</span> dataContext.<span style="color: #0000FF;">PizzaTypes</span>
&nbsp;
orderby pizza.<span style="color: #0000FF;">OrderDetails</span>.<span style="color: #0000FF;">Sum</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p.<span style="color: #0000FF;">Quantity</span><span style="color: #000000;">&#41;</span> descending
&nbsp;
select pizza<span style="color: #008000;">;</span>
&nbsp;
var top3Pizzas <span style="color: #008000;">=</span> topPizzas.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var topCustomers <span style="color: #008000;">=</span> from customer <span style="color: #0600FF;">in</span> dataContext.<span style="color: #0000FF;">Customers</span>
&nbsp;
orderby customer.<span style="color: #0000FF;">Orders</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> descending
&nbsp;
select customer<span style="color: #008000;">;</span>
&nbsp;
var top3Customers <span style="color: #008000;">=</span> topCustomers.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
And even a shorter version with lambda expressions looks like <span style="color: #0600FF;">this</span><span style="color: #008000;">:</span>
&nbsp;
var topPizzas <span style="color: #008000;">=</span> dataContext.<span style="color: #0000FF;">PizzaTypes</span>
&nbsp;
.<span style="color: #0000FF;">OrderByDescending</span><span style="color: #000000;">&#40;</span>pizza <span style="color: #008000;">=&gt;</span> pizza.<span style="color: #0000FF;">OrderDetails</span>.<span style="color: #0000FF;">Sum</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p.<span style="color: #0000FF;">Quantity</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var top3Pizzas <span style="color: #008000;">=</span> topPizzas.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var topCustomers <span style="color: #008000;">=</span> dataContext.<span style="color: #0000FF;">PizzaTypes</span>
&nbsp;
.<span style="color: #0000FF;">OrderByDescending</span><span style="color: #000000;">&#40;</span>pizza <span style="color: #008000;">=&gt;</span> pizza.<span style="color: #0000FF;">OrderDetails</span>.<span style="color: #0000FF;">Sum</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p.<span style="color: #0000FF;">Quantity</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var top3Customers <span style="color: #008000;">=</span> topCustomers.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This is probably just a first step to forgetting T-SQL queries (perhaps not DDL <img src='http://phalanx.spartansoft.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) and looking ahead! Don&#8217;t hesitate to ask yourself what you want, the answer is always inside your self&#8230; hahaha and no i&#8217;m not from social sciences, just joking.</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/06/03/using-linq-to-sql-orm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic text generator using Markov Chains (in C#)</title>
		<link>http://phalanx.spartansoft.org/2010/03/30/markov-chain-generator-in-c/</link>
		<comments>http://phalanx.spartansoft.org/2010/03/30/markov-chain-generator-in-c/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 22:47:10 +0000</pubDate>
		<dc:creator>Visar Shehu</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[markov chain]]></category>
		<category><![CDATA[text generator]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/2010/03/30/markov-chain-generator-in-c/</guid>
		<description><![CDATA[Prandaj, pra, n&#8217;e doni fisin,
mali, bregu edhe Malcija
prej njaj goje sod t&#8217;brohrisim:
Me gjuhë t&#8217;veten e lèn mbas dore.
Në gjuhë shqype nanat tona
qi prej djepit na kanë thânun,
se asht një Zot, qi do ta dona;
njatë, qi jetën na ka dhânun;
edhe shqyp na thanë se Zoti
për shqyptarë Shqypninë e fali,
se sa t&#8217;enden stina e nji tërmetit,
ngjashtu â&#8217; [...]]]></description>
			<content:encoded><![CDATA[<div class="quotation">Prandaj, pra, n&#8217;e doni fisin,<br />
mali, bregu edhe Malcija<br />
prej njaj goje sod t&#8217;brohrisim:<br />
Me gjuhë t&#8217;veten e lèn mbas dore.<br />
Në gjuhë shqype nanat tona<br />
qi prej djepit na kanë thânun,<br />
se asht një Zot, qi do ta dona;<br />
njatë, qi jetën na ka dhânun;<br />
edhe shqyp na thanë se Zoti<br />
për shqyptarë Shqypninë e fali,<br />
se sa t&#8217;enden stina e nji tërmetit,<br />
ngjashtu â&#8217; gjuha e jonë shqyptare.<br />
Ah! po; â&#8217; e toskë, malci e qyteta,<br />
gjuhën t&#8217;uej kurr mos ta gzojn kta djalë mbas dore.<br />
Në gjuhë hyjnore;</div>
<p>In the first glance this text might look like gibberish, however to some people it might resemble to something they have seen or read previously.</p>
<p>This one as well:</p>
<div class="quotation">praying and looking out the<br />
thigh-bones, wrapped them round in two sons of Olympus, and<br />
plunged into the silver hilt of his tent and all day Achilles called them in offering insult no man. Therefore I prayed, and now you alone of mortals. If I have<br />
ever decked your own prize, while I mean to go out<br />
with the host to plague the people, but upon<br />
the tenth day long the host. But of this she left its parent stem upon the other side. Then<br />
uprose smooth-tongued Nestor, the facile speaker of the hoar<br />
sea,</div>
<p>What we are seeing in the previous two examples is automatically generated text using <a title="Markov Chain" href="http://en.wikipedia.org/wiki/Markov_chain">Markov Chains</a>. The first one resembles the style of a famous Albanian poet: Gjergj Fishta.  The other one resembles The Illiad by Homer.</p>
<p>I needed to benchmark two databases: MySql and MongoDB. However, since I did not have any data (that would resemble human comments) I had to find a way to automatically generate them. That is why I choose to write an application that would automatically generate text.</p>
<p>One can say that automatically generating text is simple, just taking random words from the dictionary and you are done. However, this approach has one big problem: the text would not look natural at all. This is because we do not take into consideration the statistics of a language. In a language, each word is not followed randomly by another word; e.g., the word &#8220;hello&#8221; in the English language is more likely to be followed by the word &#8220;world” than by the word &#8220;hi&#8221;.</p>
<p>Markov Chain is a process of generating a finite state sequence of events (in our case words), in which you can transfer from each state to another based on some probabilistic model. E.g., suppose your current state is &#8220;hello&#8221;. From here you can jump to another state like: &#8220;world&#8221; or &#8220;home&#8221; because there is a probability that these two words proceed the word &#8220;hello&#8221;.</p>
<p>Building a Markov Model is fairly simple:</p>
<p>First you will need a text file, from which you will build the model.</p>
<p>For each word from that text file, create e k-level list of words proceeding it. k is a fixed number of words that proceed each word. The higher k is, phrases will make more sense. After you are done with all the words you will have a table, with each row representing a starting word, followed by k-other words.</p>
<p>Let’s suppose our text is the Wikipedia Article for Markov Chains (<a href="http://en.wikipedia.org/wiki/Markov_chain">http://en.wikipedia.org/wiki/Markov_chain</a>).</p>
<p>If k=2 then our table would have the following structure:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="213" valign="top">In</td>
<td width="213" valign="top">Mathematics,</td>
<td width="213" valign="top">A</td>
</tr>
<tr>
<td width="213" valign="top">Mathematics,</td>
<td width="213" valign="top">A</td>
<td width="213" valign="top">Markov</td>
</tr>
<tr>
<td width="213" valign="top">A</td>
<td width="213" valign="top">Markov</td>
<td width="213" valign="top">Chain,</td>
</tr>
<tr>
<td width="213" valign="top">Markov</td>
<td width="213" valign="top">Chain,</td>
<td width="213" valign="top">Named</td>
</tr>
<tr>
<td width="213" valign="top">….</td>
<td width="213" valign="top">…</td>
<td width="213" valign="top">…</td>
</tr>
</tbody>
</table>
<p>If k=3 then we would have the following table:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="160" valign="top">In</td>
<td width="160" valign="top">Mathematics,</td>
<td width="160" valign="top">A</td>
<td width="160" valign="top">Markov</td>
</tr>
<tr>
<td width="160" valign="top">Mathematics</td>
<td width="160" valign="top">A</td>
<td width="160" valign="top">Markov</td>
<td width="160" valign="top">Chain,</td>
</tr>
<tr>
<td width="160" valign="top">A</td>
<td width="160" valign="top">Markov</td>
<td width="160" valign="top">Chain,</td>
<td width="160" valign="top">Named</td>
</tr>
<tr>
<td width="160" valign="top">…</td>
<td width="160" valign="top">…</td>
<td width="160" valign="top">…</td>
<td width="160" valign="top">…</td>
</tr>
</tbody>
</table>
<p>One can continue with the same pattern for k=4, 5 &#8230; N.</p>
<p>Since now have our model, we can generate text from it:</p>
<p>1. Pick a random word (from our list of words). Let this word be the first word of your automatically generated text.</p>
<p>2. Randomly select one of the elements from our table that starts with the word that we picked.</p>
<p>3. Append all subsequent words from the list to the generated text.</p>
<p>4. Repeat from step 2, for the last word on your list.</p>
<p>My approach is a word level Markov Chain generator. One can change the same algorithm to generate character level chains, which also generate interesting text patterns.</p>
<p>You can download the entire solution written in C#:</p>
<p><div class="wpfilebase-attachment">
 <div class="wpfilebase-fileicon"><a href="http://phalanx.spartansoft.org/download/MarkovTextGenerator.rar" onclick="wpfilebase_dlclick(1, 'download/MarkovTextGenerator.rar')" title="Download Markov Chain Source"><img align="middle" src="http://phalanx.spartansoft.org/wp-includes/images/crystal/archive.png" alt="Markov Chain Source" /></a></div>
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://phalanx.spartansoft.org/download/MarkovTextGenerator.rar" onclick="wpfilebase_dlclick(1, 'download/MarkovTextGenerator.rar')" title="Download Markov Chain Source">Markov Chain Source</a><br />
   MarkovTextGenerator.rar<br />
   Version: 1.0<br />
   
  </div>
  <div class="wpfilebase-filedetails" id="wpfilebase-filedetails2" style="display: none;">
  <p></p>
  <table border="0">
   
   <tr><th>Author:</th><td>Visar Shehu</td></tr>
   
   
   
   
   <tr><th>Date:</th><td>September 9, 2010</td></tr>
   
  </table>
  </div>
 </div>
 <div class="wpfilebase-fileinfo">
  38.8 KiB<br />
  133 Downloads<br />
  <a href="#" onclick="return wpfilebase_filedetails(2);">Details...</a>
 </div>
 <div style="clear: both;"></div>
</div></p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/03/30/markov-chain-generator-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 &#8211; &#8220;Saving changes is not permitted&#8221;</title>
		<link>http://phalanx.spartansoft.org/2010/03/21/sql-server-2008-saving-changes-is-not-permitted/</link>
		<comments>http://phalanx.spartansoft.org/2010/03/21/sql-server-2008-saving-changes-is-not-permitted/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 22:15:51 +0000</pubDate>
		<dc:creator>Visar Shehu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=1077</guid>
		<description><![CDATA[Since I installed SQL Server 2008, I was getting an annoying error while saving changes to a given table: &#8220;Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#8217;t be re-created or enabled the option Prevent [...]]]></description>
			<content:encoded><![CDATA[<p>Since I installed SQL Server 2008, I was getting an annoying error while saving changes to a given table: &#8220;Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can&#8217;t be re-created or enabled the option Prevent saving changes that require the table to be re-created.&#8221; </p>
<p>The solution is simple (but saved a lot of time for me): </p>
<p>In SQL Server Management Studio select<br />
Tools -> Options -> Designers and uncheck &#8220;Prevent saving changes that require table re-creation&#8221; </p>
<p>Simple as that <img src='http://phalanx.spartansoft.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/03/21/sql-server-2008-saving-changes-is-not-permitted/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ORM DHE LINq &#8211; PJESA E PARE</title>
		<link>http://phalanx.spartansoft.org/2010/03/20/orm-dhe-linq-pjesa-e-pare/</link>
		<comments>http://phalanx.spartansoft.org/2010/03/20/orm-dhe-linq-pjesa-e-pare/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 11:42:35 +0000</pubDate>
		<dc:creator>Visar Shehu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/2010/03/20/orm-dhe-linq-pjesa-e-pare/</guid>
		<description><![CDATA[Gjate kesaj serie te postimeve, do te mundohem qe nepermjet te posteve te shkurtra, te shpjegoj se cfare paraqesin teknologjite ORM dhe LINQ dhe si mund te perdoren ne zgjidhjen e disa projekteve praktike.
LINQ (Language Integrated Query) paraqet nje teknologji te re te Microsoft qe perkrahet nga .NET 3.5 e siper, e cila mundohet te [...]]]></description>
			<content:encoded><![CDATA[<p>Gjate kesaj serie te postimeve, do te mundohem qe nepermjet te posteve te shkurtra, te shpjegoj se cfare paraqesin teknologjite ORM dhe LINQ dhe si mund te perdoren ne zgjidhjen e disa projekteve praktike.</p>
<p>LINQ (Language Integrated Query) paraqet nje teknologji te re te Microsoft qe perkrahet nga .NET 3.5 e siper, e cila mundohet te zgjedhe (ose lehtesoje) menyren e manipulimit me te dhena si databaza, XML ose te kolekcione rekordesh ne memorje (lista, vargje &#8230;).</p>
<h4>ORM</h4>
<p>Para se te flas per LINQ, ne dy pjeset e para te kesaj serie do paraqes nje hyrje te shkurter per Object Relational Mapping (ORM). ORM paraqet nje qasje (ose metodologji) programimi ku zhvilluesi mundohet qe te paraqese ne forme abstrakte objektet nga nje databaze (tabelat, lidhjet etj.) ne nje forme me te afert me konceptet e njohura nga modeli i orientuar ne objekte (OO Model).</p>
<p>Ekzistojne disa implementime komerciale dhe open source per ORM automatik. Ne kete post manualisht do te krijojme ORM, me specifikisht ate qe njihet Reverse Mapping (krijimi i klasave nga tabelat). Ky post nuk ka per qellim te pershkruje te gjithe specifikat e ORM, por vetem te parashtroje problemet e mundshme me te cilat do te ballafaqohej nje perdorues gjate krijimit te ORM.</p>
<p>Ne esence nje tabele ne databazen tone paraqet kolekcion reshtash dhe kolonash. Cdo resht mund te trajtohet si objekt, ndersa cdo kolone mund te trajtohet si atribut / karakteristike e atij objekti. Menjehere verehet nje ngjashmeri ndermjet tabelave dhe klasave. Cdo klase pershkruan nje objekt, objektet paraqesin instance te nje klase. Cdo objekt definohet nga karakteristikat e tij (qe implementohen me variabla) dhe sjelljeve (behaviors) te tij (qe implementohen me metoda).</p>
<p>Te marim nje shembull:</p>
<p><a href="http://phalanx.spartansoft.org/wp-content/uploads/2010/03/Table.png"><img style="display: block; float: none; margin-left: auto; margin-right: auto;" title="Tabela e perdoruesve" src="http://phalanx.spartansoft.org/wp-content/uploads/2010/03/Table.png" alt="Tabela e perdoruesve" width="210" height="162" /></a></p>
<p>Me SQL kjo tabele do krijohej ne kete menyre:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> Perdoruesit
<span style="color: #66cc66;">&#40;</span>
ID uniqueidentifier<span style="color: #66cc66;">,</span>
Emri nvarchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
Mbiemri nvarchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
EmriPerdoruesit nvarchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
Fjalekalimi nvarchar <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>ID<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Nga skema relacionale e kesaj tabele, shihet qarte se ne mund te definojme nje klase:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Perdoruesi
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">public</span> Guid ID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> Emri <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> Mbiemri <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> EmriPerdoruesit <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> Fjalekalimi <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>E qarte qe tani ne mund te krijojme instanca te kesaj klase:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Perdoruesi p <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Perdoruesi<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> Guid.<span style="color: #0000FF;">NewID</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Emri</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Visar&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Mbiemri</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Shehu&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">EmriPerdoruesit</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;vshehu&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Fjalekalimi</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;sekret&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Nga kjo mund edhe te krijojme kolekcione te tipit Perdorues:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span>Perdoruesit<span style="color: #008000;">&gt;</span> lista <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Perdoruesit<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
lista.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Pastaj dhe te manipulojme me to, psh ti listojme vetem ato perdorues Emri i te cileve fillon me shkronjen &#8220;A&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Perdoruesi tmpP <span style="color: #0600FF;">in</span> lista<span style="color: #000000;">&#41;</span>     
<span style="color: #000000;">&#123;</span>          
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>tmpP.<span style="color: #0000FF;">Emri</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;A&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>          
<span style="color: #000000;">&#123;</span>               
Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>tmpP.<span style="color: #0000FF;">Emri</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>          
<span style="color: #000000;">&#125;</span>      
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Sidoqofte, deri tani ne kemi vetem nje kopje te skemes relacionale ne memorje. Cdo objekt qe do ta krijojme do te shkaterohet automatikisht dhe me te edhe te dhenat per ate objekt ose kolekcion. Qe te kemi nje aplikacion funksional ne duhet te implementojme CRUD operacionet (Create, Read, Update, Delete). Te gjithe keto do ti implementoj si metoda ne klasen Perdorues (qasje e cila eshte diskutabile, mirepo problemet me kete qasje do ti adresoj ne postin e ardhshem).</p>
<h2>Create</h2>
<p>Ky eshte edhe operacioni i pare qe do te deshim ta implementojme per objektin tone. Ideja eshte e thjeshte: te kemi nje mundesi qe objektin e krijuar ne memorje, ta regjistrojme si rekord ne databaze. Ne esence duam qe objekti jone te kete nje sjellje (behavior) qe do te ruaje gjendjen e ketij objekti. Sjelljet ne OO terminologjine implementohen me ane te metodave. Per rastin tone do te krijojme nje metode Save() qe do te na mundesoje kete. Klasa Perdoruesi tani do te kete kete forme:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Perdoruesi
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Guid ID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> Emri <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> Mbiemri <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> EmriPerdoruesit <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">String</span> Fjalekalimi <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Save<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">String</span> sql <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;INSERT INTO Perdoruesit(ID, Emri, Mbiemri, EmriPerdoruesit, Fjalekalimi) VALUES (@ID, @Emri, @Mbiemri, @EmriPerdoruesit, @Fjalekalimi)&quot;</span><span style="color: #008000;">;</span>
            SqlConnection con <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            SqlCommand cmd <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlCommand<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cmd.<span style="color: #0000FF;">CommandText</span> <span style="color: #008000;">=</span> sql<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Shtojme parametrat e nevojshem</span>
            cmd.<span style="color: #0000FF;">Parameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@ID&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ID</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cmd.<span style="color: #0000FF;">Parameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@Emri&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Emri</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cmd.<span style="color: #0000FF;">Parameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@Mbiemri&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Mbiemri</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cmd.<span style="color: #0000FF;">Parameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@EmriPerdoruesit&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">EmriPerdoruesit</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cmd.<span style="color: #0000FF;">Parameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@Fjalekalimi&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Fjalekalimi</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//Hapet konekcioni dhe ekzekutojme komanden</span>
            con.<span style="color: #0000FF;">ConnectionString</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Definojme connection string ketu&quot;</span><span style="color: #008000;">;</span>
            con.<span style="color: #0000FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            cmd.<span style="color: #0000FF;">ExecuteNonQuery</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            con.<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>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>Shfrytezuesit e kesaj librarie do te shohin vetem kete Interface te klases tone:</p>
<p><a href="http://phalanx.spartansoft.org/wp-content/uploads/2010/03/image.png"><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="image" src="http://phalanx.spartansoft.org/wp-content/uploads/2010/03/image_thumb.png" border="0" alt="image" width="189" height="244" /></a></p>
<p>Dhe kur nje shfrytezues do ta shfrytezoje kete klase, ai do te jete i sigurt se sapo ta perdore metoden Save() ne bazen e te dhenave do te regjistrohet nje perdorues i ri:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Perdoruesi p <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Perdoruesi<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> Guid.<span style="color: #0000FF;">NewID</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Emri</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Visar&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Mbiemri</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Shehu&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">EmriPerdoruesit</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;vshehu&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Fjalekalimi</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;sekret&quot;</span><span style="color: #008000;">;</span>
p.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Ngjashem mund te implementohet edhe metoda Delete(). Ne postin e ardhshem do te flas se si mund te implementohen metodat tjera per leximin e nje ose me teper rekordeve, qe me vone te kalojme ne perdorimin e ndonje ORM te gatshem.</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/03/20/orm-dhe-linq-pjesa-e-pare/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Troubleshooting the database could not be exclusively locked to perform the operation error on SQL Server</title>
		<link>http://phalanx.spartansoft.org/2010/02/20/troubleshooting-the-database-could-not-be-exclusively-locked-to-perform-the-operation-error-on-sql-server/</link>
		<comments>http://phalanx.spartansoft.org/2010/02/20/troubleshooting-the-database-could-not-be-exclusively-locked-to-perform-the-operation-error-on-sql-server/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 19:25:20 +0000</pubDate>
		<dc:creator>Mehmetali Shaqiri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=918</guid>
		<description><![CDATA[Recently we have started to implement our own Content Management System codename  DeepThought and when testing the creation of articles and menus we realized that we cannot use the default database collation of SQL Server. The reason is that in future we might have clients that require the use of Cyrillic characters.  Therefore the collation that should be used for these cases is SQL_Latin1_General_CP1251_CS_AS.

But when trying to change the collation I came across the following error: The database could not be exclusively locked to perform the operation.]]></description>
			<content:encoded><![CDATA[<p>Recently we have started to implement our own Content Management System codename  DeepThought and when testing the creation of articles and menus we realized that we cannot use the default database collation of SQL Server. The reason is that in future we might have clients that require the use of Cyrillic characters.  Therefore the collation that should be used for these cases is <strong>SQL_Latin1_General_CP1251_CS_AS.</strong></p>
<p>But when trying to change the collation I came across the following error:</p>
<p style="text-align: center;"><strong><span style="color: #ff0000;">The database could not be exclusively locked to perform the operation.</span></strong></p>
<p style="text-align: left;"><span style="color: #000000;">Apparently you cannot change the database collation if the accessibility of the database is set to MULTI_USER (which is by default).</span></p>
<p style="text-align: left;"><span style="color: #000000;"> Therefore if you want to change the database collation, you must do the following:</span></p>
<ul>
<li>Set the restrict access of the database to  SINGLE_USER (note the you might kill all the active sessions)</li>
<li>Change the collation of database to whatever you want it, in my case SQL_Latin1_General_CP1251_CS_AS</li>
<li>And switch back the restrict access of the database to MULTI_USER</li>
</ul>
<p>You can accomplish this either by executing the following t-sql in you sql management studio:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #66cc66;">&#91;</span>database_name<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">SET</span> SINGLE_USER <span style="color: #993333; font-weight: bold;">WITH</span> ROLLBACK IMMEDIATE
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #66cc66;">&#91;</span>database_name<span style="color: #66cc66;">&#93;</span> COLLATE <span style="color: #66cc66;">&#91;</span>desired collation<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #66cc66;">&#91;</span>database_name<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">SET</span> MULTI_USER</pre></div></div>

<p>or from SQL Management Studio by choosing the database properties:</p>
<p><a href="http://phalanx.spartansoft.org/wp-content/uploads/2010/02/database-properties.jpg"><img class="aligncenter size-full wp-image-919" title="Database Properties" src="http://phalanx.spartansoft.org/wp-content/uploads/2010/02/database-properties.jpg" alt="Database Properties" width="704" height="631" /></a></p>
<p>Sometimes the simplest issues can cause you a real headache.</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/02/20/troubleshooting-the-database-could-not-be-exclusively-locked-to-perform-the-operation-error-on-sql-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>KDE SC 4.4 Release Party in Prishtina, Kosovo</title>
		<link>http://phalanx.spartansoft.org/2010/02/02/kde-sc-4-4-release-party-in-prishtina-kosovo/</link>
		<comments>http://phalanx.spartansoft.org/2010/02/02/kde-sc-4-4-release-party-in-prishtina-kosovo/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 08:55:20 +0000</pubDate>
		<dc:creator>Milot Shala</dc:creator>
				<category><![CDATA[KDE]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=893</guid>
		<description><![CDATA[
I proudly announce that we are having a KDE SC 4.4 Release Party in Prishtina, it will be held on 9th of February at 18:00 o&#8217;clock at IDI (Information Development Initiative) Academy offices, here is the map to the location and  here is the link to the KDE.org release party list, you are free [...]]]></description>
			<content:encoded><![CDATA[<p><center><a href="http://www.kde.org/"><img class="aligncenter" title="KDE Logo" src="http://www.perspektive89.com/system/files/images/170px-Kde-logo.jpg" alt="" width="170" height="170" /></a></center></p>
<p>I proudly announce that we are having a KDE SC 4.4 Release Party in Prishtina, it will be held on 9th of February at 18:00 o&#8217;clock at IDI (Information Development Initiative) Academy offices, <a href='http://www.openstreetmap.org/?lat=42.6562468707561&#038;lon=21.1707079410553&#038;zoom=18'>here</a> is the map to the location and  <a href="http://community.kde.org/Promo/ReleaseParties/4.4#Prishtina">here</a> is the link to the KDE.org release party list, you are free to join us.</p>
<p> Let&#8217;s celebrate together this KDE release.</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/02/02/kde-sc-4-4-release-party-in-prishtina-kosovo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Happy New Year 2010</title>
		<link>http://phalanx.spartansoft.org/2010/01/02/happy-new-year-2010/</link>
		<comments>http://phalanx.spartansoft.org/2010/01/02/happy-new-year-2010/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 16:44:20 +0000</pubDate>
		<dc:creator>Mehmetali Shaqiri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=884</guid>
		<description><![CDATA[I'd like to wish to all of our readers a happy new year.

Each day we grow as developers and also in 2010 we'll be here to continue to share our experience on solving complex programming problems and inspirational highlights.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to wish to all of our readers a happy new year.</p>
<p>Each day we grow as developers and also in 2010 we&#8217;ll be here to continue to share our experience on solving complex programming problems and inspirational highlights.</p>
<div class="wp-caption aligncenter" style="width: 530px"><a href="http://www.gpsmagazine.com/assets/happy_new_year_fireworks.jpg"><img title="Happy New Year 2010" src="http://www.gpsmagazine.com/assets/happy_new_year_fireworks.jpg" alt="Happy New Year 2010" width="520" height="349" /></a><p class="wp-caption-text">Happy New Year 2010</p></div>
<p>A big thank you for all your support &#8211; we could not do it without you (our readers).</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2010/01/02/happy-new-year-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nokia Certified Qt Developer</title>
		<link>http://phalanx.spartansoft.org/2009/12/29/nokia-certified-qt-developer/</link>
		<comments>http://phalanx.spartansoft.org/2009/12/29/nokia-certified-qt-developer/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 13:30:16 +0000</pubDate>
		<dc:creator>Milot Shala</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=873</guid>
		<description><![CDATA[
I am a proud Qt Developer now. Yesterday I earned the title Nokia Certified Qt Developer.
]]></description>
			<content:encoded><![CDATA[<p><center><a href="http://phalanx.spartansoft.org/wp-content/uploads/2009/12/Nokia_Certified_Qt_Developer_Logo.jpg"><img class="aligncenter size-full wp-image-874" title="Nokia Certified Qt Developer" src="http://phalanx.spartansoft.org/wp-content/uploads/2009/12/Nokia_Certified_Qt_Developer_Logo.jpg" alt="" width="360" height="93" /></a></center></p>
<p>I am a proud Qt Developer now. Yesterday I earned the title Nokia Certified Qt Developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2009/12/29/nokia-certified-qt-developer/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Implementing Strategy Pattern in C#</title>
		<link>http://phalanx.spartansoft.org/2009/11/06/implementing-strategy-design-pattern-in-cshar/</link>
		<comments>http://phalanx.spartansoft.org/2009/11/06/implementing-strategy-design-pattern-in-cshar/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:39:03 +0000</pubDate>
		<dc:creator>Mehmetali Shaqiri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=780</guid>
		<description><![CDATA[As a software developer, my primary goal is making my code correct, elegant, extensible and efficient. Although simplistic, every programming decision I make is largely based on maintainability. Back at my studies (Computer Sciences in SEE-University) I had the chance to read C# 3.0 Design Patterns by Judith Bishop, a great book which covers the full set of 23 patterns that were originally proposed in Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides’s Design Patterns: Elements of Reusable Object-Oriented Software in 1994.  By reading this book, I’ve acquired skills in: programming design patterns, basic UML modeling notation, ability to select appropriate patterns for given scenarios and advanced language features of C# 3.0. I highly recommend this book.]]></description>
			<content:encoded><![CDATA[<p>As a software developer, my primary goal is making my code correct, elegant, extensible and efficient. Although simplistic, every programming decision I make is largely based on maintainability. I&#8217;m very loyal to Don’t Repeat Yourself (DRY) principle.</p>
<p><a href="http://oreilly.com/catalog/9780596527730" target="_blank"><img class="alignleft" title="C# 3.0 Design Patterns" src="http://covers.oreilly.com/images/9780596527730/cat.gif" alt="C# 3.0 Design Patterns" height="150" /></a>Back at my studies (Computer Sciences in SEE-University) I had the chance to read C# 3.0 Design Patterns by Judith Bishop, a great book which covers the full set of 23 patterns that were originally proposed in Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides’s Design Patterns: Elements of Reusable Object-Oriented Software in 1994.  By reading this book, I’ve acquired skills in: programming design patterns, basic UML modeling notation, ability to select appropriate patterns for given scenarios and advanced language features of C# 3.0. I highly recommend this book.</p>
<div style="margin-left:0px;">
<h1><a>why strategy pattern?</a></h1>
<p>There are cases that for a given problem you could apply various algorithms. If  you keep all your algorithms in single class as a result you’ll have a very messy code with lots of conditional statements. It may work but it’s very hard to maintain, you may not recognize it after a while, it’s not the right way of doing it and it can be your worst nightmare. The ultimate tool in making your code maintainable is to keep it as simple as possible.</p></div>
<p>The strategy pattern enables a client to choose which algorithm to use from a range of supported algorithms and gives it a simple way to access it for ex. you have an News syndication service and you want to give you users the ability to grab those news in RSS or ATOM. In this case the scenario was to choose whether to process xml or text files.</p>
<h1><a>Design</a></h1>
<p>The key players for strategy patterns are as follows:</p>
<ol>
<li> <strong>Context </strong>- <em>Contains an IStrategy object’s algorithm in which we’re working on</em></li>
<li> <strong>IStrategy </strong>- <em>Defines an interface common to all the strategies</em></li>
<li> <strong>TextFileImporter</strong>, <strong>XmlFileImporter </strong>- <em>Classes that include algorithms that implement the IStrategy interface</em></li>
</ol>
<p>Below you have the UML diagram:</p>
<div id="attachment_784" class="wp-caption aligncenter" style="width: 514px"><img class="size-full wp-image-784" title="Strategy Pattern UML Diagram" src="http://phalanx.spartansoft.org/wp-content/uploads/2009/11/strategy_pattern_uml.JPG" alt="Strategy Pattern UML Diagram" width="504" height="228" /><p class="wp-caption-text">Strategy Pattern UML Diagram</p></div>
<h1><a>Implementation</a></h1>
<p>The <strong>IStrategy</strong> interface is used to define a contract that is shared between <strong>TextFileImporter</strong> and <strong>XmlFileImporter</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> FileImporter.<span style="color: #0000FF;">BusinessLogic</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// A common interface to all supported file types</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IStrategy
    <span style="color: #000000;">&#123;</span>
        XDocument ImportOrders<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></pre></div></div>

<p>Both <strong>TextFileImporter</strong> and <strong>XmlFileImporter</strong> classes implement <strong>IStrategy</strong> interface and they have a constructor which takes the file path as parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> FileImporter.<span style="color: #0000FF;">BusinessLogic</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> TextFileImporter<span style="color: #008000;">:</span>IStrategy
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _path<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> TextFileImporter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> path<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>._path <span style="color: #008000;">=</span> path<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region IStrategy Members</span>
&nbsp;
        <span style="color: #0600FF;">public</span> XDocument ImportOrders<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            XDocument doc <span style="color: #008000;">=</span> XDocument.<span style="color: #0000FF;">Load</span><span style="color: #000000;">&#40;</span>_path<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> doc<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>        
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> XmlFileImporter<span style="color: #008000;">:</span>IStrategy
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _path<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> XmlFileImporter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> path<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>._path <span style="color: #008000;">=</span> path<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region IStrategy Members</span>
&nbsp;
        <span style="color: #0600FF;">public</span>  XDocument ImportOrders<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            XDocument doc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            doc <span style="color: #008000;">=</span> XDocument.<span style="color: #0000FF;">Load</span><span style="color: #000000;">&#40;</span>_path<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> doc<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>        
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Here the context <strong>FileImporter</strong> points to a strategy and delegates to it. If a TextFileImporter is passed to the constructor than the TextFileImporter algorithm will take place and vise versa.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> FileImporter.<span style="color: #0000FF;">BusinessLogic</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FileImporter
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> IStrategy _strategy<span style="color: #008000;">;</span>              
&nbsp;
        <span style="color: #0600FF;">public</span> FileImporter<span style="color: #000000;">&#40;</span>IStrategy strategy<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _strategy <span style="color: #008000;">=</span> strategy<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> ImportOrders<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            XDocument xmlDoc <span style="color: #008000;">=</span> _strategy.<span style="color: #0000FF;">ImportOrders</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            SqlHelper.<span style="color: #0000FF;">InsertOrders</span><span style="color: #000000;">&#40;</span>xmlDoc<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></div></div>

<p>And here is where the decision making process takes place. Here the client can choose whether to use the <strong>XmlFileImporter</strong> or <strong>TextFileImporter</strong>. This is a code snippet from a windows service (more on this on later posts) which monitors a given directory and whenever a new file is created, it checks what type of file is (.xml or .txt) and based on the file extension if uses an appropriate strategy.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> watcher_Created<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span>.<span style="color: #0000FF;">FileSystemEventArgs</span> 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>File.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">FullPath</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
        FileImporter.<span style="color: #0000FF;">BusinessLogic</span>.<span style="color: #0000FF;">FileImporter</span> importer <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        <span style="color: #FF0000;">string</span> ext <span style="color: #008000;">=</span> e.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Substring</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">IndexOf</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'.'</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>ext<span style="color: #000000;">&#41;</span>
       <span style="color: #000000;">&#123;</span>
             <span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;.xml&quot;</span><span style="color: #008000;">:</span>
                   importer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileImporter.<span style="color: #0000FF;">BusinessLogic</span>.<span style="color: #0000FF;">FileImporter</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> XmlFileImporter<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">FullPath</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                   break<span style="color: #008000;">;</span>
             <span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;.txt&quot;</span><span style="color: #008000;">:</span>
                   importer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileImporter.<span style="color: #0000FF;">BusinessLogic</span>.<span style="color: #0000FF;">FileImporter</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> TextFileImporter<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">FullPath</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                   break<span style="color: #008000;">;</span>
             <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
                   break<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>importer <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
              Thread thr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> ThreadStart<span style="color: #000000;">&#40;</span>importer.<span style="color: #0000FF;">ImportOrders</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
              thr.<span style="color: #0000FF;">Start</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></div></div>

<p>Hope this helps <img src='http://phalanx.spartansoft.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2009/11/06/implementing-strategy-design-pattern-in-cshar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Answer To Life, The Universe and Everything</title>
		<link>http://phalanx.spartansoft.org/2009/10/21/the-answer-to-life-the-universe-and-everything-2/</link>
		<comments>http://phalanx.spartansoft.org/2009/10/21/the-answer-to-life-the-universe-and-everything-2/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 10:23:54 +0000</pubDate>
		<dc:creator>Mehmetali Shaqiri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://phalanx.spartansoft.org/?p=759</guid>
		<description><![CDATA[One quiet morning, while going through the motions of my daily routine - drinking coffee with my fellow programmers, I got a call from a client who said: I just checked our vacancies page and it sucks, we don't have an online form where users would submit their information but instead they have to fill the form locally and then send it to us by mail or fax. We have to improve this fast. I need this for tomorrow!]]></description>
			<content:encoded><![CDATA[<p>One quiet morning, while going through the motions of my daily routine &#8211; drinking coffee with my fellow programmers, I got a call from a client who said:</p>
<div class="quotation">I just checked our vacancies page and it sucks, we don&#8217;t have an online form where users would submit their information but instead they have to fill the form locally and then send it to us by mail or fax. We have to improve this fast. I need this for tomorrow!</div>
<p>So I drank my coffee and started brainstorming on how I could accomplish this task the best way I could, always keeping in mind that I  would have to finish it during the day. The task was peace of cake, I could do it in two hours, but the challenge was on UI. How to make it more dynamic (allowing users to enter multiple previous job positions, multiple phone numbers, multiple addresses etc.) and give users a greater experience on using the app. I wanted to accomplish this with no postbacks at all.</p>
<p>So in this case, <strong><a href="http://en.wikipedia.org/wiki/The_Answer_to_Life,_the_Universe,_and_Everything" target="_blank">the answer to life, the universe, and everything</a></strong> for me it was jQuery.</p>
<p>You&#8217;ve probably heard about <strong><a href="http://jquery.com" target="_blank">jQuery</a></strong>, The Write Less, Do More JavaScript Framework. For those who didn&#8217;t have the chance to get their hands into jQuery, let me summarize it for you:</p>
<ul>
<li>It&#8217;s a lightweight JavaScript framework (less than 20 KB)</li>
<li>Access DOM element using CSS selectors.</li>
<li>Needless to check for null objects</li>
<li>Uses chains of actions</li>
<li>MVC JavaScript Architecture</li>
<li>Simple and very clean &#8230; the SPARTAN WAY</li>
<li>CSS 3.0 compliant</li>
<li>Cross-Browser</li>
<li>Extensible (support for plugins)</li>
<li>And a great community support</li>
</ul>
<p>And without further ado, let&#8217;s do that voodoo that we do do so well.</p>
<p>Below you have a screenshot of the above scenario.</p>
<div>
<dl id="attachment_738" style="width: 691px;">
<dt><img title="jQuery Life Saviour" src="http://phalanx.spartansoft.org/wp-content/uploads/2009/10/jQueryLifeSaviour.png" alt="jQuery Life Saviour" width="681" height="347" /></dt>
<dd>jQuery Life Saviour</dd>
</dl>
</div>
<p>As you can see, the job position and company name are added based on user desire and are appended dynamically to the DOM. Initially I&#8217;ve defined only the FamilyName and the FirstName of the applicant. Then I&#8217;ve defined the container <strong>workContainer</strong> in which after the DOM is ready, are initialized the first controls<br />
<span style="color:red;font-weight:bold;">[ updated ]</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;% using <span style="color: #66cc66;">&#40;</span>Html.BeginForm<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Result&quot;</span>, <span style="color: #ff0000;">&quot;Home&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></span>
<span style="color: #009900;">       <span style="color: #66cc66;">&#123;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;legend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Your Information<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/legend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;right&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        Family Name:
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;">&lt;%=Html.TextBox<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;FamilyName&quot;</span>, <span style="color: #ff0000;">&quot;&quot;</span>, new <span style="color: #66cc66;">&#123;</span> @class = <span style="color: #ff0000;">&quot;txt&quot;</span>, style = <span style="color: #ff0000;">&quot;width: 200px&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;right&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        First Name:
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;">&lt;%=Html.TextBox<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;FirstName&quot;</span>, <span style="color: #ff0000;">&quot;&quot;</span>, new <span style="color: #66cc66;">&#123;</span> @class = <span style="color: #ff0000;">&quot;txt&quot;</span>, style = <span style="color: #ff0000;">&quot;width: 200px&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;right&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        ...
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        ...
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;right&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        ...
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        ...
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;right&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        Work Experience?
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td</span> <span style="color: #000066;">align</span>=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span>=<span style="color: #ff0000;">&quot;top&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;workContainer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;">&lt;%= Html.AntiForgeryToken<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Apply For this Job&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;">&lt;%<span style="color: #66cc66;">&#125;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>            
	<span style="color: #006600; font-style: italic;">//wait until DOM is ready</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//prepare initial controls</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;table id=&quot;tblWork&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Position&lt;/th&gt;&lt;th&gt;Company&lt;/th&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;position&quot; /&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;company&quot; /&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;#&quot; id=&quot;addAnother&quot; class=&quot;add&quot;&gt;Add Another&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">prependTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#workContainer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                    
&nbsp;
		<span style="color: #006600; font-style: italic;">//atach an event handler to the addAnother link</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#addAnother&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			  <span style="color: #006600; font-style: italic;">//get the whole table                                           </span>
			  <span style="color: #003366; font-weight: bold;">var</span> $tblWork <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table#tblWork&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                      
&nbsp;
			  <span style="color: #006600; font-style: italic;">//add row at the end of the table</span>
			  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table#tblWork tr:last&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;position&quot; /&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;company&quot; /&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;#&quot; class=&quot;delete&quot;&gt;Remove&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			  <span style="color: #006600; font-style: italic;">//find all links with &quot;delete&quot; class and atach the handler</span>
			  $tblWork.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.delete'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>              
				<span style="color: #006600; font-style: italic;">//remove the current table row                                      </span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                      
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
&nbsp;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The classes defined in this project are Applicant and WorkExperience.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> jQueryLifeSaviour.<span style="color: #0000FF;">Entities</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WorkExperience
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Position <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Company <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> jQueryLifeSaviour.<span style="color: #0000FF;">Entities</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Applicant
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> FamilyName <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> FirstName <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>WorkExperience<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> Experience <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And here is the action which occurs after you click on <strong>Apply for this job</strong> button.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// Get user input posted by view.</span>
<span style="color: #008080; font-style: italic;">/// Accepts only POST HTTP Methods,</span>
<span style="color: #008080; font-style: italic;">/// although in this case the GET would be just fine since we are not dealing with sensitive data</span>
<span style="color: #008080; font-style: italic;">///The collection of posted form elements</span>
<span style="color: #008080; font-style: italic;">/// The current view (in this case Result)</span>
<span style="color: #000000;">&#91;</span>AcceptVerbs<span style="color: #000000;">&#40;</span>HttpVerbs.<span style="color: #0000FF;">Post</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> ActionResult Result<span style="color: #000000;">&#40;</span>FormCollection form<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
     <span style="color: #008080; font-style: italic;">//create a new intance of Applicant class</span>
     Applicant obj <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Applicant
     <span style="color: #000000;">&#123;</span>
          FamilyName <span style="color: #008000;">=</span> form<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;FamilyName&quot;</span><span style="color: #000000;">&#93;</span>,
          FirstName <span style="color: #008000;">=</span> form<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;FirstName&quot;</span><span style="color: #000000;">&#93;</span>,
          Experience <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>WorkExperience<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">//hold all input fields regarding company info</span>
     <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> companies <span style="color: #008000;">=</span> form.<span style="color: #0000FF;">GetValues</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;company&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">//hold all input fields regarding job position</span>
     <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> positions <span style="color: #008000;">=</span> form.<span style="color: #0000FF;">GetValues</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;position&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">//iterate through posted work experience and fill the WorkExperience list</span>
     <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> positions.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
     <span style="color: #000000;">&#123;</span>
          obj.<span style="color: #0000FF;">Experience</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> WorkExperience
          <span style="color: #000000;">&#123;</span>
               Position <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>positions<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>,
               Company <span style="color: #008000;">=</span> companies<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>
          <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
      ViewData<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Applicant&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> obj<span style="color: #008000;">;</span>
      <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I&#8217;ve been using jQuery for a while and it made me realize that life is so much easier when using jQuery. With jQuery, JavaScript is no more &#8220;the necessary evil&#8221;, it&#8217;s even fun to code with.</p>
<p>You can download the full project <a href="http://phalanx.spartansoft.org/wp-content/uploads/2009/10/jQueryLifeSaviour.rar">here</a>. This demo is developed on ASP.NET MVC 1.0 Framework, so you must install it in prior, otherwise you want be able to open it.</p>
]]></content:encoded>
			<wfw:commentRss>http://phalanx.spartansoft.org/2009/10/21/the-answer-to-life-the-universe-and-everything-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
