<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<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/"
	>

<channel>
	<title>Just another .Net Voyegar</title>
	<link>http://motaherashermin.com/blog</link>
	<description>dotnetfreak</description>
	<pubDate>Mon, 15 Jun 2009 08:47:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>Excel 2007, openXml helper</title>
		<link>http://motaherashermin.com/blog/?p=31</link>
		<comments>http://motaherashermin.com/blog/?p=31#comments</comments>
		<pubDate>Mon, 15 Jun 2009 08:47:29 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<category><![CDATA[excel column name]]></category>

		<category><![CDATA[excel column number]]></category>

		<category><![CDATA[excel datetime]]></category>

		<category><![CDATA[excel2007]]></category>

		<category><![CDATA[openxml]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=31</guid>
		<description><![CDATA[public class ExcelMapperHelper
{
public DateTime ConvertExcelDateToDateTime(string date)
{
DateTime excelBaseDate = new DateTime(1899, 12, 30);
DateTime excelDate = DateTime.MinValue;
int integerExcelDays;
integerExcelDays = Convert.ToInt32(System.Math.Floor(Convert.ToDouble(date)));
excelDate = excelBaseDate + new TimeSpan(integerExcelDays, 0, 0, 0);
return excelDate;
}
public string GetColumnLetters(string columnName)
{
return Regex.Replace(columnName, @&#8221;(\d+\.?\d*&#124;\.\d+)&#8221;, string.Empty);
}
public string NamespacePrefix
{
get
{
return &#8220;xlsx&#8221;;
}
}
public XmlNamespaceManager GetNamespaceManager(XmlDocument xDoc, string namespacePrefix)
{
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xDoc.NameTable);
namespaceManager.AddNamespace(namespacePrefix, @&#8221;http://schemas.openxmlformats.org/spreadsheetml/2006/main&#8221;);
return namespaceManager;
}
public void GetExcelRows(XmlDocument xDoc, out string namespacePrefix, out XmlNamespaceManager [...]]]></description>
			<content:encoded><![CDATA[<p>public class ExcelMapperHelper<br />
{</p>
<p>public DateTime ConvertExcelDateToDateTime(string date)<br />
{<br />
DateTime excelBaseDate = new DateTime(1899, 12, 30);<br />
DateTime excelDate = DateTime.MinValue;<br />
int integerExcelDays;</p>
<p>integerExcelDays = Convert.ToInt32(System.Math.Floor(Convert.ToDouble(date)));<br />
excelDate = excelBaseDate + new TimeSpan(integerExcelDays, 0, 0, 0);</p>
<p>return excelDate;<br />
}</p>
<p>public string GetColumnLetters(string columnName)<br />
{<br />
return Regex.Replace(columnName, @&#8221;(\d+\.?\d*|\.\d+)&#8221;, string.Empty);<br />
}</p>
<p>public string NamespacePrefix<br />
{<br />
get<br />
{<br />
return &#8220;xlsx&#8221;;<br />
}<br />
}</p>
<p>public XmlNamespaceManager GetNamespaceManager(XmlDocument xDoc, string namespacePrefix)<br />
{<br />
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xDoc.NameTable);<br />
namespaceManager.AddNamespace(namespacePrefix, @&#8221;http://schemas.openxmlformats.org/spreadsheetml/2006/main&#8221;);<br />
return namespaceManager;<br />
}</p>
<p>public void GetExcelRows(XmlDocument xDoc, out string namespacePrefix, out XmlNamespaceManager namespaceManager, out XmlNodeList rowList)<br />
{<br />
namespacePrefix = NamespacePrefix;<br />
namespaceManager = GetNamespaceManager(xDoc, namespacePrefix);<br />
string workSheetXPath = string.Format(&#8221;{0}:worksheet/{0}:sheetData/{0}:row&#8221;, namespacePrefix);<br />
rowList = xDoc.SelectNodes(workSheetXPath, namespaceManager);<br />
}</p>
<p>public List&lt;string&gt; ReadStringTable(Stream input)<br />
{<br />
List&lt;string&gt; stringTable = new List&lt;string&gt;();</p>
<p>using (XmlTextReader reader = new XmlTextReader(input))<br />
{<br />
for (reader.MoveToContent(); reader.Read(); )<br />
if (reader.NodeType == XmlNodeType.Element &amp;&amp; reader.Name == &#8220;t&#8221;)<br />
stringTable.Add(reader.ReadElementString());<br />
}</p>
<p>return stringTable;<br />
}</p>
<p>public int GetColumnNumber(string columnName)<br />
{<br />
string letters = GetColumnLetters(columnName);<br />
double columnNumber = 0;<br />
int counter = letters.Length - 1;<br />
foreach (char c in letters)<br />
{<br />
if (Char.IsLetter(c))<br />
{<br />
int charSequence = (int)(c) - (int)(&#8217;A') + 1;<br />
columnNumber += Math.Pow(26, counter) * charSequence;<br />
counter&#8211;;<br />
}<br />
}</p>
<p>return Convert.ToInt32(columnNumber);<br />
}</p>
<p>public int GetNextColumnNumber(string columnName, int nextCount)<br />
{<br />
int number = GetColumnNumber(columnName) + nextCount;<br />
return number;<br />
}</p>
<p>public string GetColumnName(int columnNo)<br />
{<br />
int dividend = columnNo;<br />
string columnName = String.Empty;<br />
int modulo;</p>
<p>while (dividend &gt; 0)<br />
{<br />
modulo = (dividend - 1) % 26;<br />
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;<br />
dividend = (int)((dividend - modulo) / 26);<br />
}</p>
<p>return columnName;</p>
<p>}</p>
<p>}</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=31</wfw:commentRss>
		</item>
		<item>
		<title>Silly CSS pains</title>
		<link>http://motaherashermin.com/blog/?p=28</link>
		<comments>http://motaherashermin.com/blog/?p=28#comments</comments>
		<pubDate>Fri, 05 Dec 2008 19:42:18 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=28</guid>
		<description><![CDATA[TD Height :
====================================================================
&#60;tr&#62;&#60;td  style=&#8221;height:5px;&#8221;&#62;&#60;SPACER TYPE=&#8221;block&#8221; HEIGHT=&#8221;1&#8243; WIDTH=&#8221;1&#8243;&#62;&#60;/td&#62; &#60;/tr&#62;
StopEvent:
=====================================================================
function stopEvent(e) {
if (!e) e = window.event;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
]]></description>
			<content:encoded><![CDATA[<p>TD Height :<br />
====================================================================<br />
&lt;tr&gt;&lt;td  style=&#8221;height:5px;&#8221;&gt;&lt;SPACER TYPE=&#8221;block&#8221; HEIGHT=&#8221;1&#8243; WIDTH=&#8221;1&#8243;&gt;&lt;/td&gt; &lt;/tr&gt;</p>
<p>StopEvent:<br />
=====================================================================<br />
function stopEvent(e) {<br />
if (!e) e = window.event;<br />
if (e.stopPropagation) {<br />
e.stopPropagation();<br />
} else {<br />
e.cancelBubble = true;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=28</wfw:commentRss>
		</item>
		<item>
		<title>Executing a JS func for each user control inside a aspx page</title>
		<link>http://motaherashermin.com/blog/?p=27</link>
		<comments>http://motaherashermin.com/blog/?p=27#comments</comments>
		<pubDate>Fri, 21 Nov 2008 09:41:43 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<category><![CDATA["Dynamic JS Function Call"]]></category>

		<category><![CDATA[GUI]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=27</guid>
		<description><![CDATA[The scenario is, 1 aspx page needs to lead a usercontrol repetitively, and these user control needs to excute a JS method on load. The Method filters a JS array and rerenders a dropdown inside the usercontrol, so it has the reference of the server controls for respective usercontrols. thus the array is in the [...]]]></description>
			<content:encoded><![CDATA[<p>The scenario is, 1 aspx page needs to lead a usercontrol repetitively, and these user control needs to excute a JS method on load. The Method filters a JS array and rerenders a dropdown inside the usercontrol, so it has the reference of the server controls for respective usercontrols. thus the array is in the aspx page while the method is dynamic for each usercontrol. Now how to execute dynamic number of dynamically named functions for each usercontrol? the solution is below-</p>
<p><strong>In aspx page</strong><br />
================================</p>
<p>&lt;head runat=&#8221;server&#8221;&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var functionList = new Array();<br />
&lt;/script&gt;</p>
<p>&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8211;</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var lenght = functionList.length;<br />
var newfunction = functionList.pop();<br />
while(typeof newfunction != &#8220;undefined&#8221;)<br />
{<br />
newfunction();<br />
newfunction = functionList.pop();<br />
}<br />
&lt;/script&gt;<br />
&lt;/body&gt;</p>
<p><strong>In ascx page</strong>(at the end of the page)<br />
===================</p>
<p>&lt;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221;&gt;<br />
functionList.push(MethodName&lt;%=ServerControl.ClientID %&gt;);<br />
&lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=27</wfw:commentRss>
		</item>
		<item>
		<title>Set focus @end of textbox</title>
		<link>http://motaherashermin.com/blog/?p=26</link>
		<comments>http://motaherashermin.com/blog/?p=26#comments</comments>
		<pubDate>Tue, 28 Oct 2008 07:10:07 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=26</guid>
		<description><![CDATA[function SetEnd (controlObj)
{
if (controlObj.createTextRange)
{
var FieldRange = controlObj.createTextRange();
FieldRange.moveStart(&#8217;character&#8217;, controlObj.value.length);
FieldRange.collapse();
FieldRange.select();
}
}
]]></description>
			<content:encoded><![CDATA[<p>function SetEnd (controlObj)<br />
{<br />
if (controlObj.createTextRange)<br />
{<br />
var FieldRange = controlObj.createTextRange();<br />
FieldRange.moveStart(&#8217;character&#8217;, controlObj.value.length);<br />
FieldRange.collapse();<br />
FieldRange.select();<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=26</wfw:commentRss>
		</item>
		<item>
		<title>Regular expressions</title>
		<link>http://motaherashermin.com/blog/?p=22</link>
		<comments>http://motaherashermin.com/blog/?p=22#comments</comments>
		<pubDate>Wed, 09 Jul 2008 06:55:48 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=22</guid>
		<description><![CDATA[Exclude some file types from a list
================================
function Filter()
    {
        var arr = new Array(9);

//Dummy

        arr[0] = "something.aspx";
        arr[1] = "something.ascx";
        arr[2] = "something.gif";
        arr[3] = "something.asrx";
        arr[4] = "something.jp";
        arr[5] = "something.cab";
        arr[6] = "something.bat";
        arr[7] = "something.arr";
        arr[8] = "something.ashx";
        var rgex = [...]]]></description>
			<content:encoded><![CDATA[<p>Exclude some file types from a list<br />
================================</p>
<pre>function Filter()
    {
        var arr = new Array(9);</pre>
<blockquote>
<pre>//Dummy</pre>
</blockquote>
<pre>        arr[0] = "something.aspx";
        arr[1] = "something.ascx";
        arr[2] = "something.gif";
        arr[3] = "something.asrx";
        arr[4] = "something.jp";
        arr[5] = "something.cab";
        arr[6] = "something.bat";
        arr[7] = "something.arr";
        arr[8] = "something.ashx";
        var rgex = /.*[.](?!(aspx|ascx|gif)$).*$/;
        var filtered = new Array(8);

        for(var i=0;i&lt;arr.length;i++)
        {
            if(rgex.test(arr[i]))
                filtered[i] = arr[i];
            else
                filtered[i] = "ok";

        }

    }</pre>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=22</wfw:commentRss>
		</item>
		<item>
		<title>Event bubble up in asp.net user controls</title>
		<link>http://motaherashermin.com/blog/?p=20</link>
		<comments>http://motaherashermin.com/blog/?p=20#comments</comments>
		<pubDate>Sun, 06 Apr 2008 09:48:08 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<category><![CDATA[Journal]]></category>

		<category><![CDATA[asp.net mvp userControl]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=20</guid>
		<description><![CDATA[As I was new in MVP and NMock, I was given a small assignment to code. The goal was to be able to add user controls dynamically in an aspx file by clicking an &#8220;Add control&#8221;. Then each control will have a delete button in them, which upon click will remove the control from the [...]]]></description>
			<content:encoded><![CDATA[<p>As I was new in MVP and NMock, I was given a small assignment to code. The goal was to be able to add user controls dynamically in an aspx file by clicking an &#8220;Add control&#8221;. Then each control will have a delete button in them, which upon click will remove the control from the page. There was also one more thing, upon changes in the user control, each change will appear in a panel in the Default page.</p>
<p>Now it sounded pretty easy in the beginning. But to implement things in the MVP architecture created the first barrier. It was hard to put the mindset first on MVP. To take the control away from the web project made the event handling a bit tricky for me. There are actually 2 type of event which needed communication between the dynamically created user controls and the parent aspx page -</p>
<ul>
<li>Upon deletion let the aspx page know which control was deleted, and update the view state. And do this by the Presenter.</li>
<li>Upon change in content of a control, let the aspx file know to update the change log.</li>
</ul>
<p>The first event was handled in the following way-<br />
( Code in the ascx.cs file ( the View)  )</p>
<blockquote><p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">public delegate void DeleteControlDelegate(string id);<br />
public event DeleteControlDelegate DeleteControl;<o:p></o:p></span></p>
<p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">protected void btnDelete_Click(object sender, EventArgs e)<br />
{<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">if (DeleteControl != null)<br />
{<o:p></o:p></span></p>
<p style="margin-left: 80px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">DeleteControl(this.ID);<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">}<br />
this.Parent.Controls.Remove(this);<o:p></o:p></span></p>
<p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">}</span><em><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'"><o:p></o:p></span></em></p></blockquote>
<p>Now the Presenter for the Parent aspx page has a method  with the same signature of the DeleteControl(id), UpdateViewState.</p>
<blockquote><p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">public void UpdateViewState(string id)<br />
{<br />
</span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">home.ControlList = _home.ControlList.Replace(id,String.Empty);</span><br />
<span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'"> if(_home.ControlList.Contains(&#8221;||&#8221;))<o:p></o:p></span></p>
<p style="margin-left: 80px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">_home.ControlList = _home.ControlList.Replace(&#8221;||&#8221;, &#8220;|&#8221;);<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">_home.ActionList.Add(String.Format(&#8221;Control #{0} been removed&#8221;, id.Substring(0, 5)));<br />
_home.UpdateViewState(id.Substring(0,5));<o:p></o:p></span></p>
<p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">}<o:p></o:p></span></p></blockquote>
<p>Now who to hook up the two? Thats actually the easy part. See, when I added the control dynamically in the aspx page I hooked it up as follows -</p>
<blockquote><p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">public string AddControl(string type, string id, bool isNew)<br />
{<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">lblMsg.Text = String.Empty;<br />
DemoModule uc = (DemoModule)Page.LoadControl(Constants.PATH);<br />
uc.Type = type;<br />
<strong>uc.DeleteControl += new DemoModule.DeleteControlDelegate(_homePresenter.UpdateViewState);</strong><br />
uc.PropagateAction = <strong>this.Show_Activity</strong>;<br />
if (isNew)<o:p></o:p></span></p>
<p style="text-indent: 0.5in; margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">uc.ID = System.Guid.NewGuid().ToString();<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">else<o:p></o:p></span></p>
<p style="text-indent: 0.5in; margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">uc.ID = id;pnlControl.Controls.Add(uc);<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">this.ActionList.Add(String.Format(&#8221;Control #{0} has been added.&#8221;, uc.ID.Substring(0,5)));<br />
if(isNew)<o:p></o:p></span></p>
<p style="text-indent: 0.5in; margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">this.RenderChangeLabels();<o:p></o:p></span></p>
<p style="margin-left: 40px"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">return uc.ID;<o:p></o:p></span></p>
<p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">}<o:p></o:p></span></p></blockquote>
<p>The second event was rather easy. As I didnt have to bubble up dynamic information from the user control, just the action was bubbling up, I used the systems event handler delegate to work for me ( <strong>this.Show_Activity </strong>).</p>
<blockquote><p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">protected void Show_Activity(object sender, EventArgs e)<br />
{<o:p></o:p></span></p>
<p style="margin-left: 0.5in"><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">Control ctl = (Control)sender;<br />
string controlName = ctl.GetType().Name;<br />
string text = _homePresenter.FormatMessage(controlName,&#8221;change&#8221;);<br />
this.ViewState[Constants.CHANGELOG] = this.ViewState[Constants.CHANGELOG] + &#8220;|&#8221; + text;<br />
this.RenderChangeLabels();<o:p></o:p></span></p>
<p><span style="font-size: 8pt; font-family: 'Tahoma','sans-serif'">}<o:p></o:p></span></p></blockquote>
<p>Its the simplest solution. But its not complete, if we want to bubble up what was changed, the specific information, we would use the first custom delegate. Even still the code is messy, there is too much code and decisions in the code behind file. To clear it up, I could  create an object that will emulate the asp.net user control. Presenter will update the object and view will just show it. But that looks like too much work for something so small. But as I now know, its quite easy if needed :).</p>
<p>the sample solution is <a href="http://motaherashermin.com/blog/wp-content/uploads/2008/03/Demo0.zip" title="source">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=20</wfw:commentRss>
		</item>
		<item>
		<title>My MVP Wireframe/Walkthrough</title>
		<link>http://motaherashermin.com/blog/?p=18</link>
		<comments>http://motaherashermin.com/blog/?p=18#comments</comments>
		<pubDate>Thu, 13 Mar 2008 16:26:47 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Architechture]]></category>

		<category><![CDATA[Codebook]]></category>

		<category><![CDATA[StudyMaterials]]></category>

		<category><![CDATA[MVP walkthough ASP.NET]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=18</guid>
		<description><![CDATA[My friend Iftekhar was asking for a simple wireframe/walkthrough of MVP pattern. So here it is for him (and anybody else if they need  ).
First I created a website. It has one page &#8216;Default.aspx&#8217; with two labels, one textbox, one dropdown and one button. Then I created 2 class library projects for presenter and [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">My friend <a href="http://blog.iftekharul.com">Iftekhar</a> was asking for a simple wireframe/walkthrough of MVP pattern. So here it is for him (and anybody else if they need <img src='http://motaherashermin.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">First I created a website. It has one page &#8216;Default.aspx&#8217; with two labels, one textbox, one dropdown and one button. Then I created 2 class library projects for presenter and Viewfactory (interfaces for each webpage). I created one <em>IDefault</em> interfce and implemented it in the code behind of &#8216;Default.aspx&#8217;.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">IDefault interface:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 9pt; font-family: 'Courier New'"> <span style="color: blue">interface</span> <span style="color: #2b91af">IDefault<br />
</span>{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'; color: blue">string</span><span style="font-size: 9pt; font-family: 'Courier New'"> username { <span style="color: blue">get</span>;<span style="color: blue">set</span>;}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'; color: blue">string</span><span style="font-size: 9pt; font-family: 'Courier New'"> role { <span style="color: blue">get</span>;<span style="color: blue">set</span>;}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'; color: blue">void</span><span style="font-size: 9pt; font-family: 'Courier New'"> DisablePanel();</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'; color: blue">void</span><span style="font-size: 9pt; font-family: 'Courier New'"> ShowMessage(<span style="color: blue">string</span> msg);</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'; color: blue">void</span><span style="font-size: 9pt; font-family: 'Courier New'"> ShowHistory(<span style="color: blue">string</span> msg);</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 9pt; font-family: 'Courier New'">}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">Now I also created a presenter class for the default page. It has a private IDefault property. Now the codebehind will instantiate the presenter by passing itself to it. The presenter will initialize its private IDefault with the view instance.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">The Default.aspx.cs file:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">partial</span> <span style="color: blue">class</span> <span style="color: #2b91af">_Default</span> : System.Web.UI.<span style="color: #2b91af">Page</span>, <span style="color: #2b91af">IDefault<br />
</span>{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: #2b91af">DefaultPresenter</span><span style="font-size: 8pt; font-family: 'Courier New'"> _presenter; </span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">protected</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">void</span> Page_Init(<span style="color: blue">object</span> sender, <span style="color: #2b91af">EventArgs</span> e)<br />
{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">_presenter = <span style="color: blue">new</span> <span style="color: #2b91af">DefaultPresenter</span>(<span style="color: blue">this</span>);</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">protected</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">void</span> Page_Load(<span style="color: blue">object</span> sender, <span style="color: #2b91af">EventArgs</span> e)<br />
{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 1in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">username = TextBox1.Text.ToString();</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 1in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">role = drpList1.SelectedValue.ToString();</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 1in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">_presenter.OnViewLoaded(); </span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">On the other hand the presenter class is as follows –<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">class</span> <span style="color: #2b91af">DefaultPresenter<br />
</span>{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: #2b91af">Private IDefault</span><span style="font-size: 8pt; font-family: 'Courier New'"> _default; </span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 8pt; font-family: 'Courier New'"> DefaultPresenter(<span style="color: #2b91af">IDefault</span> def)<br />
{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">_default = def; </span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 0.5in; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">}………</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">Now every business logic Default.aspx.cs needs to perform to update the GUI, the presenter will have it done with the interface. This is the basic beauty in it. The view became pluggable and more testable. It’s like instead of going and look for the business logic classes and call it to view, view itself goes to the logic and let that do its work in its own place. Once presenter is done with all its hocus pocus it just calls methods of the interface ( actually the view) to update the UI components accordingly.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">Now to test the Model, I am keeping track of the value enter in textbox and selected value of the drop down. As its not directly connected to manipulating the UI components, I put it in the model. Presenter just ask the model to log the event and if it wants to show it to view, model returns something. Here also I have a IHistory for more testability and cleanliness.<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 10pt; font-family: 'verdana'">The History and IHistory:<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">interface</span> IHistory<br />
{<br />
<span style="color: blue">string</span> Createhistory(<span style="color: blue">string</span> username, <span style="color: blue">string</span> role);<br />
}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">class</span> <span style="color: #2b91af">History</span>:<span style="color: #2b91af">IHistory<br />
</span>{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">#region</span><span style="font-size: 8pt; font-family: 'Courier New'"> IHistory Members</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">public</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: blue">string</span> Createhistory(<span style="color: blue">string</span> username, <span style="color: blue">string</span> role)<br />
{</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">if</span><span style="font-size: 8pt; font-family: 'Courier New'">(<span style="color: #2b91af">String</span>.IsNullOrEmpty(username))</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">return</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: #a31515">&#8220;No open session&#8221;</span>;</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">else</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 0.5in; margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'; color: blue">return</span><span style="font-size: 8pt; font-family: 'Courier New'"> <span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&#8220;{0} logged in at {1} as {2}&#8221;</span>, username, <span style="color: #2b91af">DateTime</span>.Now, role);</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">}</span><span style="font-size: 10pt; font-family: 'verdana'"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal"><span style="font-size: 8pt; font-family: 'Courier New'">#endregion<br />
}</span></p>
<p><span style="font-size: 10pt; font-family: 'verdana'"><br />
In a nutshell -<br />
</span></p>
<ul>
<li><span style="font-size: 10pt; font-family: 'verdana'"> First design your view interfaces,<br />
</span></li>
<li><span style="font-size: 10pt; font-family: 'verdana'">create web pages implementing them ( or you can design the aspx/ascx with the designer first then write interfaces. I donno what the wise and learned people will say, I just didn&#8217;t get any difference, though most of the time it depends on what are you doing).<br />
</span></li>
<li><span style="font-size: 10pt; font-family: 'verdana'">Then create  presenter classes who will work with the interface to service the view. Write methods to calculate everything for the desired behavior of view in the presenter and at the end just call the interface methods so that view gets updated.<br />
</span></li>
<li><span style="font-size: 10pt; font-family: 'verdana'">And if you need some more things you want to code about, do it in model. </span></li>
</ul>
<p><span style="font-size: 10pt; font-family: 'verdana'">Viola, just 3/4 projects and you are done.</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: 'verdana'">The full solution file is <a href="http://motaherashermin.com/blog/wp-content/uploads/2008/03/mvpdemo.zip" title="MVP Wireframe"><span style="color: blue">here.</span></a></span></p>
<p style="font-size: 10pt; font-family: 'verdana'">I am a humble learner. So if I made some mistakes or you would like some other angles to look at it, do say.</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=18</wfw:commentRss>
		</item>
		<item>
		<title>Some more reading on Dependency Injection and MVP</title>
		<link>http://motaherashermin.com/blog/?p=14</link>
		<comments>http://motaherashermin.com/blog/?p=14#comments</comments>
		<pubDate>Wed, 12 Mar 2008 20:00:29 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Architechture]]></category>

		<category><![CDATA[Journal]]></category>

		<category><![CDATA[Dependency Injection]]></category>

		<category><![CDATA[MVP]]></category>

		<category><![CDATA[NMock]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=14</guid>
		<description><![CDATA[In my new office I was studying the following articles.

 http://www.codeproject.com/KB/architecture/DependencyInjection.aspx
http://www.martinfowler.com/articles/injection.html
http://codebetter.com/blogs/jeremy.miller/archive/2005/10/06/132825.aspx
http://msdn2.microsoft.com/en-us/magazine/cc163739.aspx

I came to read these when I started to study about Unit Testing on ASP.NET projects. And here all use MVP. Its all new experience for me.
I have always been  a fan of NTiers applications pattern. But now I am required to work on [...]]]></description>
			<content:encoded><![CDATA[<p>In my new office I was studying the following articles.</p>
<ul>
<li> http://www.codeproject.com/KB/architecture/DependencyInjection.aspx</li>
<li>http://www.martinfowler.com/articles/injection.html</li>
<li>http://codebetter.com/blogs/jeremy.miller/archive/2005/10/06/132825.aspx</li>
<li>http://msdn2.microsoft.com/en-us/magazine/cc163739.aspx</li>
</ul>
<p>I came to read these when I started to study about Unit Testing on ASP.NET projects. And here all use MVP. Its all new experience for me.<br />
I have always been  a fan of NTiers applications pattern. But now I am required to work on MVP with asp.net. Feels little out of my normal brainwave, but its stimulating. Stepping out of my comfort zone, thinking architectures in a sort of reverse way, or top-down and bottom up in parallel. Currently the architectures I have managed to put up of Dependency Injection is through constructor injection. I am loving how pluggable and traceable the solution is becoming using MVP.</p>
<p>I am trying to explain or map MVP from a NTierian&#8217;s point of view. Lets say a solution have 4 projects (DAL, BLL, Facade and website). In NTiers Website will communicate with Facade. Facade will communication with BLL and website. BLL will communicate with DAL and facade. In NTier BLL handles the business logic with Data layer. Website&#8217;s ASPX pages handles the UI related business logic themselves in their code-behind files.</p>
<p>Now say if I am to translate the design in MVP. There is no 101 relation there. See the website will be called the &#8216;<em><strong>VIEW</strong></em>&#8216; but it will not handle the business logic related to the population of the GUI, a &#8216;<strong><em>PRESENTER</em></strong>&#8216; will do it with the help of the interfaces for each view ( Factory method). Now &#8216;<strong><em>MODEL</em></strong>&#8216; will act as the facade here who will handle all sorts of other logics, both <strong><em>Presenter</em></strong> and <strong><em>DAL</em></strong> have communication with it. Good to know that the DAL will always be DAL, no matter what framework it is in.</p>
<p>The work flow of MVP and MVC from <a href="http://blog.vuscode.com/malovicn/archive/2007/12/18/model-view-presenter-mvp-vs-model-view-controller-mvc.aspx"> Nikola Malovic</a><br />
<img src="http://blog.vuscode.com/blogs/blogs/malovicn/WindowsLiveWriter/ModelViewPresenterMVPVSModelViewControll_1327B/image_15.png" alt="workflow" height="386" width="411" /></p>
<p>Actually I don&#8217;t know if I am right or wrong. Its just 3 to 4 days I am playing with MVP and this is what I felt. I am a complete beginner in t, so if anyone is reading do leave your view on it, and correct me if you find me wrong. It will be highly appreciated. My MVP readings will be found at <a href="http://del.icio.us/mshermin/mvp">Delicious.</a></p>
<p>I am working on a sample project where I am using MVP. I will write about it once i am done :).</p>
<p>For shortnote there are 3 types of dependency injection - Constructor Injection(I use it for NMock Unit testing my presenters), Setter Injection(Spring.NET framework), and Interface Injection(Avalon). I am still not wise enough to shade some lights on those. I will do that someday.</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=14</wfw:commentRss>
		</item>
		<item>
		<title>For my reference</title>
		<link>http://motaherashermin.com/blog/?p=12</link>
		<comments>http://motaherashermin.com/blog/?p=12#comments</comments>
		<pubDate>Wed, 12 Mar 2008 18:35:16 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[Codebook]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=12</guid>
		<description><![CDATA[I had 3 tables. bookmark, tags and a bookmark-tag relations table. both bookmark and tag table were independent and the only link was the @ModuleID. the relation table(bookmarkID,tagID) had the mapping for which bookmark had which tags. now I need a query to get all the bookmarks, with all the the tagnames respect with tagIDs [...]]]></description>
			<content:encoded><![CDATA[<p>I had 3 tables. bookmark, tags and a bookmark-tag relations table. both bookmark and tag table were independent and the only link was the @ModuleID. the relation table(bookmarkID,tagID) had the mapping for which bookmark had which tags. now I need a query to get all the bookmarks, with all the the tagnames respect with tagIDs for each bookmark from the relation table in CSV in one projection. the following query gave me a perfect result.</p>
<p>CREATE procedure [dbo].[Module_Bookmark_GetAllBookmark]<br />
(<br />
@ModuleID int<br />
)<br />
as<br />
begin<br />
SELECT</p>
<p>FBK.ID,FBK.ModuleID,FBK.title, FBK.URL,FBK.Description,</p>
<p>STUFF(( SELECT &#8216;,&#8217;+ FBT.[Name]+&#8217;:'+STR(FBT.[ID])</p>
<p>FROM [Module_BookmarkTags] FBT</p>
<p>INNER JOIN [Module_BookmarkTagsMapping] FBM</p>
<p>ON FBT.ID = FBM.TagId</p>
<p>WHERE FBM.[BookMarkID] = FBK.[ID]</p>
<p>FOR XML PATH(&#8221;)),1,1,&#8221;) as Tags</p>
<p>FROM [Module_Bookmark] FBK where FBK.ModuleID = @ModuleID</p>
<p>GROUP BY FBK.title,FBK.ModuleID, FBK.ID, FBK.URL,FBK.Description</p>
<p>ORDER BY title</p>
<p>END</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=12</wfw:commentRss>
		</item>
		<item>
		<title>Some reading</title>
		<link>http://motaherashermin.com/blog/?p=11</link>
		<comments>http://motaherashermin.com/blog/?p=11#comments</comments>
		<pubDate>Tue, 04 Mar 2008 15:13:56 +0000</pubDate>
		<dc:creator>Motahera</dc:creator>
		
		<category><![CDATA[StudyMaterials]]></category>

		<category><![CDATA[reading]]></category>

		<category><![CDATA[SQLSERVER]]></category>

		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://motaherashermin.com/blog/?p=11</guid>
		<description><![CDATA[http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2006/09/13/
8875.aspx
http://weblogs.asp.net/dwahlin/archive/2007/02/03/
video-creating-a-service-with-windows-communication-service-wcf.aspx
http://www.deitel.com/ResourceCenters/Programming/WindowsCommunicationFoundation/
WindowsCommunicationFoundationVideos/tabid/2832/Default.aspx
SQL server 
http://www.sqlteam.com/article/using-cross-apply-in-sql-server-2005
]]></description>
			<content:encoded><![CDATA[<p>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2006/09/13/<br />
8875.aspx</p>
<p>http://weblogs.asp.net/dwahlin/archive/2007/02/03/<br />
video-creating-a-service-with-windows-communication-service-wcf.aspx</p>
<p>http://www.deitel.com/ResourceCenters/Programming/WindowsCommunicationFoundation/<br />
WindowsCommunicationFoundationVideos/tabid/2832/Default.aspx</p>
<p><strong>SQL server </strong></p>
<p>http://www.sqlteam.com/article/using-cross-apply-in-sql-server-2005</p>
]]></content:encoded>
			<wfw:commentRss>http://motaherashermin.com/blog/?feed=rss2&amp;p=11</wfw:commentRss>
		</item>
	</channel>
</rss>

