Friday, August 28, 2009

Asp .Net Mvc Resources

A list of Asp .Net Mvc Resources which I found very userful.

http://weblogs.asp.net/shijuvarghese/

ASP.NET MVC Tutorials

http://code-inside.de/blog-in/2008/11/25/howto-basics-of-aspnet-mvc-or-why-mvc/

ASP.NET MVC View Overview (C#)

DevConnections - The ASP.NET MVC Framework - Scott Hanselman

ASP.NET MVC using Visual Basic XML Literals

http://www.asp.net/learn/

ASP.NET MVC Preview 4 - Using Ajax and Ajax.Form

Free ASP.NET MVC eBook Tutorial

http://en.wikipedia.org/wiki/Model_View_Controller

http://en.wikipedia.org/wiki/Front_Controller_pattern

http://martinfowler.com/eaaCatalog/pageController.html

http://www.codeasp.net/articles/asp.net/30/aspnet-mvc-framework-tutorial

http://msdn.microsoft.com/en-us/magazine/cc337884.aspx (Old version)

Friday, August 21, 2009

WPF Windows Application, WPF Browser Application and Silverlight Clarified

WPF is Microsoft's presentation technology which is based on XAML.
WPF Windows Application in long run will act as a replacement for Windows Forms.
It runs in fuly trusted environment.


Output













WPF Browser Application
WPF Browser Application or XBAP as name suggest is browser based application. But the drawback is the that it required .net runtime present in the running machine.
It runs in partially trusted environment with limited access to system resources.














Silverlight
Silverlight is Microsoft's alternative to Flash like applications. It is based on plug in model.

Thursday, August 13, 2009

Sql Server 200 Generating Script

An Sql Script is a text file containing the database objects like like table, views, stored procedures etc.

Sql Server 2000 Enterprise Manager or Sql Server 2005/2008 Management Studio can be used for generating Sql Script.







Here is the generated script

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__Trans__ExpenseId__7C8480AE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)ALTER TABLE [dbo].[Trans] DROP CONSTRAINT FK__Trans__ExpenseId__7C8480AEGO


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__Expense__GroupId__79A81403]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)ALTER TABLE [dbo].[Expense] DROP CONSTRAINT FK__Expense__GroupId__79A81403GO


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spAllExpense]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[spAllExpense]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Expense]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[Expense]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ExpenseGroup]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[ExpenseGroup]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Trans]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[Trans]
GO

CREATE TABLE [dbo].[Expense] ( [ExpenseId] [int] IDENTITY (1, 1) NOT NULL , [GroupId] [int] NULL , [ExpenseName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Description] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY]
GO

CREATE TABLE [dbo].[ExpenseGroup] ( [GroupId] [int] IDENTITY (1, 1) NOT NULL , [GroupName] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Description] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Trans] ( [TranId] [int] IDENTITY (1, 1) NOT NULL , [ExpenseId] [int] NULL , [Date] [datetime] NULL , [Amount] [numeric](8, 2) NULL , [Description] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY]GO
SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON
GO

create procedure spAllExpense asselect * from Expense
GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON
GO

DataGridView - Extracting the Contents of Currently Selected Row

One of the common requirement is CRUD operation is extracting the contents of the currently selected row in a Grid to be updated in TextBoxes or other controls.

SqlConnection cnn;
SqlDataAdapter da;
DataSet ds = new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
cnn = new SqlConnection("Integrated Security=sspi;Initial catalog=Northwind");
cnn.Open();
da = new SqlDataAdapter("select CategoryId, CategoryName, Description from Categories", cnn);
da.Fill(ds, "Cat");
dataGridView1.DataSource = ds.Tables["Cat"];
}



private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
listBox1.Items.Clear();
for (int colindex = 0; colindex < dataGridView1.Columns.Count ; colindex++)
{
listBox1.Items.Add(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[colindex].Value.ToString());
}
}




















DataGridView ComboBox Placing and Child Table Insertion



SqlConnection cnn;
SqlDataAdapter da;
DataSet ds = new DataSet();

SqlCommand cmd;
SqlDataReader dre;

DataGridViewTextBoxColumn newCol;
DataGridViewComboBoxColumn cboCol;

private void Form1_Load(object sender, EventArgs e)
{
cnn = new SqlConnection("Integrated security=sspi;INitial Catalog=ContactManagement;Data Source=.\\shalvin");
cnn.Open();

da = new SqlDataAdapter("select * from ContactGroups", cnn);
da.Fill(ds, "Grp");

CreateGridViewColumns();
}

private void CreateGridViewColumns()
{
cboCol = new DataGridViewComboBoxColumn();
cboCol.DataSource = ds.Tables["Grp"];
cboCol.DisplayMember = "GroupName";
dataGridView1.Columns.Add(cboCol);

newCol = new DataGridViewTextBoxColumn();
dataGridView1.Columns.Add(newCol);

}



private void btnSave_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
string strGroupId = "";
DataGridViewRow row = dataGridView1.Rows[i];

string strSql;
strSql = "select GroupId from ContactGroups where GroupName= '"
+ row.Cells[0].Value.ToString() + "'";

cmd = new SqlCommand(strSql, cnn);
dre = cmd.ExecuteReader();
while(dre.Read())
strGroupId = dre["GroupId"].ToString();
dre.Close();


cmd = new SqlCommand("Insert into Contacts (GroupId, ContactName) values ('" + strGroupId + "', '" + row.Cells[1].Value.ToString() + "')", cnn);
cmd.ExecuteNonQuery();
}

MessageBox.Show("Record saved");
}




Related Blog
Windows Forms ListView
Filling Windows Forms ListView with DataTable

Tuesday, August 11, 2009

Seminar on Windows 7, Windows Server 2008 R2 and Microsoft Exchange 2010

Yesterday (August 11 th) there was a seminar on Seminar on Windows 7, Windows Server 2008 R2 and Microsoft Exchange 2010 at The Gateway Hotel, Marine Drive Kochi.
The seminar was highly informative though there was lack of proper promotion for the event. So I missed technology enthsiasts like Praseed Pai, Mathew K J and Biju Alapatt. Thanks to Plaito Williams for informing me about the event.
All the participants received the Windows 7 DVD which expires on June 2010.