Tuesday, January 25, 2011
Thoughts on n-Tiered Programming
One of the problems that I had when first learning Object Oriented Programming was that the examples shown to illustrate concepts were so basic that they made no sense.
Why add piles of seemingly needless complexity when there were much easier and more straightforward ways to program solutions?
Why code interfaces that didn’t seem to add anything but more programming work and confusion?
Why create multiple Layers when all I was doing was passing unchanged values down the chain?
A lot of it started to make sense when I started doing things that were more complicated.
If the data does not change as it is passed from one layer to the next, having multiple layers doesn’t seem to make sense.
However, imagine a more usual scenario where the way your data is stored in the database does not match what is displayed in the UI.
Then it starts to get interesting.
I find it helps to think of n-tiered programming this way: The BusinessLayer translates between the data in the database and the data in the UI.
I usually have a more or less one to one correspondence between the data in the database and the objects which are created in the DataLayer and passed back and forth to the BusinessLayer.
I usually have a more or less one to one one correspondence between the data in the BusinessLayer and the data in the UI.
The BusinessLayer is where the translation happens. This is whether retrieving data from the database to display in the UI, or collecting data entered in the UI and storing it in the database.
(My other layer is an EntitiesLayer. I contains classes with properties to store the data for passing around.)
Why add piles of seemingly needless complexity when there were much easier and more straightforward ways to program solutions?
Why code interfaces that didn’t seem to add anything but more programming work and confusion?
Why create multiple Layers when all I was doing was passing unchanged values down the chain?
A lot of it started to make sense when I started doing things that were more complicated.
If the data does not change as it is passed from one layer to the next, having multiple layers doesn’t seem to make sense.
However, imagine a more usual scenario where the way your data is stored in the database does not match what is displayed in the UI.
Then it starts to get interesting.
I find it helps to think of n-tiered programming this way: The BusinessLayer translates between the data in the database and the data in the UI.
I usually have a more or less one to one correspondence between the data in the database and the objects which are created in the DataLayer and passed back and forth to the BusinessLayer.
I usually have a more or less one to one one correspondence between the data in the BusinessLayer and the data in the UI.
The BusinessLayer is where the translation happens. This is whether retrieving data from the database to display in the UI, or collecting data entered in the UI and storing it in the database.
(My other layer is an EntitiesLayer. I contains classes with properties to store the data for passing around.)
Thursday, January 6, 2011
Outlook 2007 Cannot start Microsoft Outlook. Cannot open the Outlook window
Outlook starts to open, but then gets the error in the title of this post.
Fixed by running outlook.exe /resetnavpane in the All Programs textbox:
Fixed by running outlook.exe /resetnavpane in the All Programs textbox:
Monday, January 3, 2011
Disable Windows7 Automatic Resize to Max
Windows 7 has a feature where, when you drag a midsize window to the edge of the screen, Windows 7 maximizes it.
I found this really annoying because I frequently have several partial windows open and I drag some over to the side so they don't block each other.
To turn this feature off:
Control Panel -> Ease of Access Center
select Make the Mouse Easier to Use
check Prevent windows from being automatically arranged...
ok to save setting
I found this really annoying because I frequently have several partial windows open and I drag some over to the side so they don't block each other.
To turn this feature off:
Control Panel -> Ease of Access Center
select Make the Mouse Easier to Use
check Prevent windows from being automatically arranged...
ok to save setting
Friday, October 29, 2010
Which Templated Checkboxes in an Infragistics Webdatagrid Column are Checked
This is the codebehind I use to see which templated checkboxes in an infragistics webdatagrid column are checked.
This is the column being checked.
In this case the checkbox is not databound, but it could be.
I have not found a way to use the CRUD feature of the datasource that the WebDataGrid uses to update the db value of a boolean represented by a databound checkbox.
private void TakeActionOnSelectedCustomers ()
{
if (igWdgCustomers.Rows.Count != 0)
{
foreach (GridRecord row in igWdgCustomers.Rows)
{
CheckBox theCB = (CheckBox)row.Items[0].FindControl("cbSelect");
if ( theCB!= null && theCB.Checked)
// check for null because footer row doesn’t have cb
{
// take action
}
}
}
}
This is the column being checked.
<ig:TemplateDataField Key="cbSelect" width="30px">
<Header Text=" " />
<ItemTemplate>
<asp:CheckBox ID="cbSelect" runat="server" />
</ItemTemplate>
</ig:TemplateDataField>
In this case the checkbox is not databound, but it could be.
I have not found a way to use the CRUD feature of the datasource that the WebDataGrid uses to update the db value of a boolean represented by a databound checkbox.
Friday, August 27, 2010
DateTime.ParseExact
So after never having had CultureInfo.CurrentCulture on my radar, I ended up using it twice this week.
For the first use, see my previous post on ToUpperInvariant().
Today, I ran into a problem where I tried DateTime.Parse on a string which I had generated in a gridview using:
I ended up having to decode it using the following:
For the first use, see my previous post on ToUpperInvariant().
Today, I ran into a problem where I tried DateTime.Parse on a string which I had generated in a gridview using:
The compiler couldn't parse it.
<asp:BoundField DataField="DateStarted"   DataFormatString="{0:ddd MMM d hh:mmtt}" />
I ended up having to decode it using the following:
DateTime dateCreated =DateTime.ParseExact(sdateCreated,   "ddd MMM d hh:mmtt", CultureInfo.InvariantCulture);
ToUpperInvariant()
Whoa! Jon Skeet answered a question of mine on StackOverflow this week! I am honored.
The question was:
In C# what is the difference between ToUpper() and ToUpperInvariant()?
And the answer was, in a nutshell, "Unless you are programming in Turkish, no difference."
What brought me to ask that question started with a need to always reformat user input for first and last name with Initial Letter Case: first letter capitalized, rest lower case. (I know, I know, this is not all last names follow this convention, but hey, I didn't define the user requirements.) (In word I use Shift-F3 all the time.)
So I went looking in intellisense for a string method called InitialLetterCase(). After all, there are string methods ToUpper() and ToLower().
There was no InitialLetterCase() method, but I found ToUpperInvariant(). What did that do? I did a google search but the first few hits didn't seem to answer the question.
So thank you, Jon Skeet and StackOverflow, for the answer.
FYI, the solution to my request is a simple
tbFirstName.Text =
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tbFirstName.Text); :
The question was:
In C# what is the difference between ToUpper() and ToUpperInvariant()?
And the answer was, in a nutshell, "Unless you are programming in Turkish, no difference."
What brought me to ask that question started with a need to always reformat user input for first and last name with Initial Letter Case: first letter capitalized, rest lower case. (I know, I know, this is not all last names follow this convention, but hey, I didn't define the user requirements.) (In word I use Shift-F3 all the time.)
So I went looking in intellisense for a string method called InitialLetterCase(). After all, there are string methods ToUpper() and ToLower().
There was no InitialLetterCase() method, but I found ToUpperInvariant(). What did that do? I did a google search but the first few hits didn't seem to answer the question.
So thank you, Jon Skeet and StackOverflow, for the answer.
FYI, the solution to my request is a simple
tbFirstName.Text =
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tbFirstName.Text); :
Wednesday, July 7, 2010
RegisterStartupScript vs Response.Write
Even though putting windows popup alerts into your UI can be bad design, annoying to your users, etc, sometimes it's just what you need to get the job done. I feel it's ok to use an occasional windows alert, as long as you don't abuse them.
If you are also using Ajax, you have a choice of 2 ways to program that alert from the code behind: Response.Write or ScriptManager.RegisterStartupScript.
The difference is that Response.Write will popup an alert box before the page loads, ie on a white background, and ScriptManager.RegisterStartupScript will pop it up after the page has loaded, so the page is visible behind the popup.
I prefer using ScriptManager.RegisterStartupScript, but maybe I just haven't come across an application where Response.Write would be better.
In any case, the following is the code to use for each case:
I have also popped up an alert on pageload by using the following in the html < body> tag of the page:
If you are also using Ajax, you have a choice of 2 ways to program that alert from the code behind: Response.Write or ScriptManager.RegisterStartupScript.
The difference is that Response.Write will popup an alert box before the page loads, ie on a white background, and ScriptManager.RegisterStartupScript will pop it up after the page has loaded, so the page is visible behind the popup.
I prefer using ScriptManager.RegisterStartupScript, but maybe I just haven't come across an application where Response.Write would be better.
In any case, the following is the code to use for each case:
Response.Write("<script language='javascript'>       alert('This pops up on a blank page      (ie before the page loads) using response.write');</SCRIPT> ");
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID,   "alert('This pops up after the page loads,      using ScriptManager.RegisterStartupScript');", true);
I have also popped up an alert on pageload by using the following in the html < body> tag of the page:
The \r\n causes a line break.
<body onLoad="alert('Update. \r\n \r\n Thank you for your interest, \r\n however, \r\n we are not taking any new orders at this time.')" >
Subscribe to:
Posts (Atom)