Handling errors in a system is very important and necessary. In the assignment, throwing exceptions is the way I used to catch the error or check the business rules.
I defined four exceptions by myself: DateException which is used to catch Datetime formation error, CarException and BankExcetpion for business rules' control.
In the realistic coding, I tried to catch those errors in the business logic layer and throw exceptions to the UI tier where those errors will be handled.
For example:
in business logic tier
try{}
catch(DateException){throw new DateException}
in UI tier
try{}
catch(DateException ex){dateLabel.text = ex.message}
Monday, April 20, 2009
Master Page
MasterPage is a good interface for the whole website in .net webpage design. In the assignment, I added a masterpage which connects to all the other pages. In order to refrain from adding same functions on different pages, I put the logout function, show joblist function and a breadcrumb navigation on the masterpage.
It's code of breadcrumb navigation below:
It's code of breadcrumb navigation below:
Tuesday, April 7, 2009
Login page test
I tried to establish a login page using Asp.net. It seems pretty easy to complement this function. I added two textboxes and a submit button in the web page. After inputting the username and password and clicking the login button, system will send the data to the database. Those data will check the login table in the database and then reply the match rows' number which is used to determine the authorization. The codes are below:
protected void loginButton_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source= C:\\Documents and Settings\\Administrator\\桌面\\study temp\\dataset\\dataset\\testdb.mdb;";
string select = "select count(*) from loginTable where username = '" + username.Text + "' and password = '" + password.Text + "'";
OleDbCommand command = new OleDbCommand(select);
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
command.Connection = conn;
string count = command.ExecuteScalar().ToString();
conn.Close();
if (count == "1")
{
Response.Redirect("Default.aspx");
}
else
{
verification.Text = "invalid username or password";
}
}
Although the function is realized, I think it's better to create a new event which includes a cancelEventArgs to cancel the event when the username or password is invalided. I will try to improve the code in recent days.
protected void loginButton_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source= C:\\Documents and Settings\\Administrator\\桌面\\study temp\\dataset\\dataset\\testdb.mdb;";
string select = "select count(*) from loginTable where username = '" + username.Text + "' and password = '" + password.Text + "'";
OleDbCommand command = new OleDbCommand(select);
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
command.Connection = conn;
string count = command.ExecuteScalar().ToString();
conn.Close();
if (count == "1")
{
Response.Redirect("Default.aspx");
}
else
{
verification.Text = "invalid username or password";
}
}
Although the function is realized, I think it's better to create a new event which includes a cancelEventArgs to cancel the event when the username or password is invalided. I will try to improve the code in recent days.
DataSet and DataGridView
After designing the ZR system, I began to code. It's really tough for me to program the website using c#.net & asp.net as a novice learning . net platform. First day, I got clear about two problems.
event in First was how to connect to the access database and fill the database in a dataset then bind it with the datagridview. The second problem cost me much time which was using the rowdeletingdatagridview to complement the function of deleting a row. That's the code below.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source= C:\\Documents and Settings\\Administrator\\桌面\\study temp\\dataset\\dataset\\testdb.mdb;";
string select = "SELECT * FROM customer";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(select, conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataSet ds = new DataSet();
adapter.Fill(ds);
int index = e.RowIndex;
ds.Tables[0].Rows[index].Delete();
adapter.Update(ds);
conn.Close();
}
Actually, those codes cannot reflect our design which hope to using four tiers structure to realize the functions. And one problem still need to be solved: how to bind the List with the datagridview.
event in First was how to connect to the access database and fill the database in a dataset then bind it with the datagridview. The second problem cost me much time which was using the rowdeletingdatagridview to complement the function of deleting a row. That's the code below.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source= C:\\Documents and Settings\\Administrator\\桌面\\study temp\\dataset\\dataset\\testdb.mdb;";
string select = "SELECT * FROM customer";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(select, conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataSet ds = new DataSet();
adapter.Fill(ds);
int index = e.RowIndex;
ds.Tables[0].Rows[index].Delete();
adapter.Update(ds);
conn.Close();
}
Actually, those codes cannot reflect our design which hope to using four tiers structure to realize the functions. And one problem still need to be solved: how to bind the List
Subscribe to:
Posts (Atom)
