CIS407AWk2iLab/Default.aspx
Greetings and Salutations. I will master ASP.NET in this course.
CIS407AWk2iLab/Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
CIS407AWk2iLab/frmMain.aspx
Academy of Computing and Information Technology
Annual Salary Calculator
Personnel
CIS407AWk2iLab/frmMain.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class frmMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
CIS407AWk2iLab/frmPersonnel.aspx
Academy of Computing and Information Technology
CIS407AWk2iLab/frmPersonnel.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class frmPersonnel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
CIS407AWk2iLab/frmPersonnelVerified.aspx
Academy of Computing and Information Technology
CIS407AWk2iLab/frmPersonnelVerified.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class frmPersonnelVerified : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtVerifiedInfo.Text = Request["txtFirstName"] +
"\n" + Request["txtLastName"] +
"\n" + Request["txtPayRate"] +
"\n" + Request["txtStartDate"] +
"\n" + Request["txtEndDate"];
}
}
CIS407AWk2iLab/frmSalaryCalculator.aspx
Academy of Computing and Information Technology
CIS407AWk2iLab/frmSalaryCalculator.aspx.cs
using System;
using Syste ...
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
1. CIS407AWk2iLab/Default.aspx
Greetings and Salutations. I will master ASP.NET in this
course.
CIS407AWk2iLab/Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
2. CIS407AWk2iLab/frmMain.aspx
Academy of Computing and Information Technology
Annual Salary Calculator
Personnel
CIS407AWk2iLab/frmMain.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
3. using System.Web.UI;
using System.Web.UI.WebControls;
public partial class frmMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
CIS407AWk2iLab/frmPersonnel.aspx
Academy of Computing and Information Technology
6. Academy of Computing and Information Technology
CIS407AWk2iLab/frmPersonnelVerified.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class frmPersonnelVerified : System.Web.UI.Page
{
7. protected void Page_Load(object sender, EventArgs e)
{
txtVerifiedInfo.Text = Request["txtFirstName"] +
"n" + Request["txtLastName"] +
"n" + Request["txtPayRate"] +
"n" + Request["txtStartDate"] +
"n" + Request["txtEndDate"];
}
}
CIS407AWk2iLab/frmSalaryCalculator.aspx
Academy of Computing and Information Technology
11. Explorer click Website, Add Existing Item, then navigate to the
PayrollSystem_DB.accdb file you downloaded, and click the
Add button.
Make sure you select file types, which include *.accdb, *.accdb,
etc. Otherwise, you will not be able to see the database file to
select.
4. Now we need to create a new connection to the
PayrollSystem_DB.accdb. To begin, click View Server
Explorer.
5. When the Server Explorer toolbox appears, click the Connect
to Database button.
6. When the Add Connection dialog appears, click the Change
button. In the Change Data Source dialog, select MS Access
Database File; Uncheck Always use this Selection; then click
OK.
Press Continue to get the following screen.
12. 7. Click the Browse button to navigate to the
PayrollSystem_DB.accdb file in your website folder, then click
Open. (NOTE: Be sure you select the PayrollSystem_DB.accdb
file in your PayrollSystem website folder, not the one you
originally downloaded from Doc Sharing!) Click Test
Connection. You should receive a message that the test
connection succeeded. Click OK to acknowledge the message,
then click OK again to close the Add Connection dialog.
8. The PayrollSystemDB.accdb should be added to the Server
Explorer. Expand the database, then expand the Tables entry
under the database until you see tblUserActivity. Leave the
Server Explorer window open for now as you will be returning
to it in a moment.
9. Create a new dataset by selecting Website-> Add New Item.
Under Templates, select the Dataset item. Enter
dsUserActivity.xsd for the name. Click Add.
10. If the following message appears, select Yes. You want to
make this dataset available to your entire website.
11. If the TableAdapter Configuration Wizard dialog appears,
click Cancel. (We will be configuring a Data Adapter for this
dataset later in C# code, so we do not need to run this wizard.)
13. 12. Drag-and-drop the tblUserActivity table from the Server
Explorer window into the dsUserActivity dataset in the editor
window.
NOTE: If you see a message that says your connection uses a
local data file that is not in the current project, that indicates
you did not select the correct PayrollSystem_DB.accdb file
when you created your data connection. To fix this problem,
click No, then right-click on PayrollSystemDB.accdb in the
Server Explorer window and choose Modify Connection. Click
the Browse button, navigate to the PayrollSystemDB.accdb file
that is in your PayrollSystem website folder, and click Open.
Test the connection, then click OK.
Click the Save icon on the toolbar to save the
dsUserActivity.xsd dataset.
(You can now close the Server Explorer window if you wish.)
13. Create a new class to contain the C# code that will access
this dataset. To do so, click Website, Add New Item. In the Add
New Item dialog, select the Class template, and enter
clsDataLayer for the name. Make sure the Language is set to
Visual C#. Click Add.
14. If the following message appears, select Yes. You want to
make this class available to everything in your solution.
14. 15. Add the following to the top of your class, below any other
using statements created for you by Visual Studio.
Add to top of class
// Add your comments here
using System.Data.OleDb;
using System.Net;
using System.Data;
16. Add the following three functions inside the squiggly braces
for the public class clsDataLayer class, above the beginning of
the public clsDataLayer() constructor and save the class.
Class
// This function gets the user activity from the tblUserActivity
public static dsUserActivity GetUserActivity(string Database)
{
// Add your comments here
dsUserActivity DS;
OleDbConnection sqlConn;
OleDbDataAdapter sqlDA;
// Add your comments here
sqlConn = new
OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=" + Database);
// Add your comments here
sqlDA = new OleDbDataAdapter("select * from
tblUserActivity", sqlConn);
15. // Add your comments here
DS = new dsUserActivity();
// Add your comments here
sqlDA.Fill(DS.tblUserActivity);
// Add your comments here
return DS;
}
// This function saves the user activity
public static void SaveUserActivity(string Database, string
FormAccessed)
{
// Add your comments here
OleDbConnection conn = new
OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;"
+
"Data Source=" + Database);
conn.Open();
OleDbCommand command = conn.CreateCommand();
string strSQL;
strSQL = "Insert into tblUserActivity (UserIP, FormAccessed)
values ('" +
GetIP4Address() + "', '" + FormAccessed + "')";
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
command.ExecuteNonQuery();
16. conn.Close();
}
// This function gets the IP Address
public static string GetIP4Address()
{
string IP4Address = string.Empty ;
foreach (IPAddress IPA in
Dns.GetHostAddresses(HttpContext.Current.Request.UserHostA
ddress)) {
if (IPA.AddressFamily.ToString() == "InterNetwork") {
IP4Address = IPA.ToString();
break;
}
}
if (IP4Address != string.Empty) {
return IP4Address;
}
foreach (IPAddress IPA in
Dns.GetHostAddresses(Dns.GetHostName())) {
if (IPA.AddressFamily.ToString() == "InterNetwork") {
IP4Address = IPA.ToString();
break;
}
}
return IP4Address;
17. }
STEP 2: frmUserActivity, frmPersonnel, frmMain
17. Create a new web form called frmUserActivity. Switch to
Design Mode and add the ACIT logo to the page as an
ImageButton and link it back to frmMain. Below the image
button add a panel. To the panel, add a Label and GridView
(found under the Toolbox, Data tab) having the following
properties.
Property
Value
Label – Text
User Activity
GridView – (ID)
grdUserActivity
18. Go to the Page_Load method by double clicking an empty
space on the page and add the following code.
Page_Load method for frmUserActivity.aspx
if (!Page.IsPostBack) {
// Declares the DataSet
dsUserActivity myDataSet = new dsUserActivity();
// Fill the dataset with what is returned from the function
myDataSet =
clsDataLayer.GetUserActivity(Server.MapPath("PayrollSystem_
DB.accdb"));
18. // Sets the DataGrid to the DataSource based on the table
grdUserActivity.DataSource =
myDataSet.Tables["tblUserActivity"];
// Binds the DataGrid
grdUserActivity.DataBind();
}
19. Open the frmMain form, add a new link button and image
button to point to the new frmUserActivity. Find an image to
use for the image button and add the new option as View User
Activity.
20. Go to the frmMain Page_Load and add the following code.
frmMain.aspx Page_Load code
// Add your comments here
clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem
_DB.accdb"), "frmPersonnel");
21. In the