Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Friday, July 25, 2008

Beginning Subversion (SVN) for .NET

I've had enough of zipping my project for backup before editing it. I mean it works fine for personal development, but for team projects it is time for a versioning system. That means either using CVS (Control Versioning System) or SVN (Subversion), since VSS (Visual Source Safe) would be too expensive.

First you need the download and install subversion: http://subversion.tigris.org/

Next you need to create the repository. Suppose you've created your svn directory. Fire up the command prompt and navigate there. create the "MyProject" repository:
svnadmin create MyProject

Next, recognize the recommended standard structures:
svn/MyProject
svn/MyProject/trunk
svn/MyProject/branches
svn/MyProject/tags

Next, place the trunk directory in hte MyProject directory and the .NET actual Website directory in the trunk:
svn/MyProject/trunk/MyWebsite

Next, checkout the project:
svn checkout "file:///c:/documents and settings/user/svn/MyProject"

Next, add the trunk, branches, and tags folders to the MyProject repository:
cd MyProject
svn mkdir trunk
svn mkdir branches
svn update
svn add tags

Next, commit the updates to in effect check-in the project:
svn commit -m "initial project setup"

References:
http://www.germane-software.com/~ser/R_n_R/subversion.html
http://www.onlamp.com/pub/a/bsd/2005/08/11/FreeBSD_Basics.html?page=2
http://svnbook.red-bean.com/

Saturday, July 19, 2008

Opposite Conventions List

Here is a list of opposing actions to help maintain consistent conventions:
add/remove
increment/decrement
open/close
begin/end
insert/delete
show/hide
create/destroy
lock/unlock
source/target
first/last
min/max
start/stop
get/put
next/previous
up/down
get/set
old/new
Reference: Code Complete

Saturday, July 12, 2008

Wiki Trials and Errors

I read about Wikis in Code Complete and decided to try some out for software design. This was my first contact beyond the famous Wikipedia. Wikis are basically editable html pages for documenting facts, design, and collaborating amongst users. Here are the results:

I tried FlexWiki and read their basic documentation to add namespaces and edit pages. I set it up on my localhost and continuously ran into 404 errors after updating a page. The few fixes I read about looked incomplete, so I scrapped the FlexWiki.

Next I installed DokuWiki from a PHP application on my Kensoft server. I'll update the review when I'm done setting up a sample. But in the meantime, I'd recommend avoiding FlexWiki.

Reference: http://www.splitbrain.org/go/dokuwiki

Thursday, July 3, 2008

Using a GridView with Edit and Delete that use stored procedures

Here is how to use a GridView with Edit and Delete that use stored procedures for update and delete. First, the aspx:

<asp:GridView ID="gvEmail" runat="server" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
AllowPaging="True" OnRowDeleting="gvEmail_RowDeleting" PageSize="99" OnRowUpdating="gvEmail_OnRowUpdating">
<Columns>
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [email] FROM [vw_Email]"
DeleteCommand="sproc_DeleteEmail" DeleteCommandType="StoredProcedure"
UpdateCommand="sproc_UpdateEmail" UpdateCommandType="StoredProcedure"
>
<DeleteParameters><asp:Parameter Name="email" Type="String" /></DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="newEmail" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Now the code behind.

protected void gvEmail_RowDeleting(object sender, GridViewDeleteEventArgs e) //DELETE
{
SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("sproc_DeleteEmail", conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
conn.Open();
string email = string.Empty;
DataControlFieldCell cell = gvEmail.Rows[e.RowIndex].Cells[1] as DataControlFieldCell;
gvEmail.Columns[0].ExtractValuesFromCell(
e.Keys,
cell,
DataControlRowState.Normal,
true);
email = e.Keys[0].ToString();
if (!string.IsNullOrEmpty(email))
{
command.Parameters.AddWithValue("@email", email);
command.ExecuteNonQuery();
}
command.Parameters.Clear();
conn.Close();
}
protected void gvEmail_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("sproc_UpdateEmail", conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
conn.Open();
string newEmail = e.NewValues[0] as string;
string email = e.OldValues[0] as string;
if (!string.IsNullOrEmpty(email))
{
command.Parameters.AddWithValue("@email", email);
command.Parameters.AddWithValue("@newEmail", newEmail);
command.ExecuteNonQuery();
}
command.Parameters.Clear();
conn.Close();
}
Note: Exception handling left off for brevity.
Reference: http://www.developerfusion.co.uk/show/91/7/

Tuesday, July 1, 2008

Using XML and XPath for a GridView

This demonstrates how to use XML and XPath with a GridView to display links:

<asp:GridView ID="gvLinks" runat="server" DataSourceID="XmlDataSource1" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Link">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank" NavigateUrl='<%#XPath("href") %>'>
<%#XPath("title")%>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblrOwner" runat="server" Text=&lt;%#XPath("description")%&gt;></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Links.xml"
XPath="links/link"></asp:XmlDataSource>
Here is the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<links>
<link>
<title>Yahoo</title>
<href>http://www.yahoo.com/</href>
<owner>Yang</owner>
<description>Yahoo web portal</description>
</link>
<link>
<title>MSN</title>
<href>http://www.msn.com/</href>
<owner>Balmer</owner>
<description>Microsoft web portal</description>
</link>
<link>
<title>Delicious</title>
<href>http://del.icio.us/</href>
<owner></owner>
<description>Internet bookmark manager</description>
</link>
<link>
<title>YouTube</title>
<href>http://youtube.com/</href>
<owner></owner>
<description>Internet videos</description>
</link>
<link>
<title>SlashDot</title>
<href>http://slashdot.org/</href>
<owner></owner>
<description>News that matters</description>
</link>

</links>
Reference: http://bytes.com/forum/thread528704.html