ASP.NET代写:COMP4012 RBTN

使用ASP.NET完成对数据的增删改查操作,数据库使用MSSQL.

MSSQL

DATABASE TABLE: Sites

1
2
3
4
5
6
7
ID INT IDENTITY(1,1) PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
NFCCode VARCHAR(16) NOT NULL,
IsArmorySite BIT NOT NULL,
ArmoryID INT NOT NULL,
CompanyID INT NOT NULL FOREIGN KEY REFERENCES Company(UID),
Status VARCHAR(20) NOT NULL

Question 1

Based on above MSSQL database table, using ASP.NET C# to insert one record into database.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
protected void rbtnAddSubmit_Click(object sender, EventArgs e)
{

if (ValidateInput("ADD"))
{
/* VARIABLE */
string name = rtxtAddName.Text.Trim();
string nfcCode = rtxtAddNfcCode.Text.Trim();
bool isArmorySite = Convert.ToBoolean(rcbbAddArmorySite.SelectedValue);
string armoryId = rtxtAddArmoryID.Text.Trim();
int companyId = user.CompanyUid;
string status = "Active";

SqlConnection connection = Utility.GetConnection();
SqlCommand command = new SqlCommand();
try
{
connection.Open();
command.Connection = connection;

/* INSERT YOUR CODE HERE */

RadGrid1.Rebind();
plhAddItem.Visible = false;
plhMain.Visible = true;

AlertMessage("Success! New site has been added!");
}
catch (Exception ex)
{
AlertMessage("Error! Please contact company helpdesk!");
}
finally
{
try { connection.Close(); }
catch { }
connection.Dispose();
}
}
}

Question 2

Based on above MSSQL database table, using ASP.NET C# to update one record by given record ID and other information.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
protected void rbtnEditSubmit_Click(object sender, EventArgs e)
{

if (ValidateInput("EDIT"))
{
/* VARIABLE */
string id = hdfRecordId.Value.Trim();
string name = rtxtEditName.Text.Trim();
string nfcCode = rtxtEditNfcCode.Text.Trim();
bool isArmorySite = Convert.ToBoolean(rcbbEditArmorySite.SelectedValue);
string armoryId = rtxtEditArmoryID.Text.Trim();
int companyId = user.CompanyUid;
string status = "Active";

SqlConnection connection = Utility.GetConnection();
SqlCommand command = new SqlCommand();
try
{
connection.Open();
command.Connection = connection;

/* INSERT YOUR CODE HERE */

RadGrid1.Rebind();
plhEditItem.Visible = false;
plhMain.Visible = true;
AlertMessage("Success! Site has been updated!");
}
catch (Exception ex)
{
AlertMessage("Error! Please contact company helpdesk!");
}
finally
{
try { connection.Close(); }
catch { }

connection.Dispose();
}
}
}

Question 3

Based on above MSSQL database table, using ASP.NET C# to delete one record by given record ID.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
protected void rbtnDeleteSubmit_Click(object sender, EventArgs e)
{

if (ValidateInput("Delete"))
{
/* VARIABLE */
string id = hdfRecordId.Value.Trim();
SqlConnection connection = Utility.GetConnection();
SqlCommand command = new SqlCommand();
try
{
connection.Open();
command.Connection = connection;

/* INSERT YOUR CODE HERE */

RadGrid1.Rebind();
AlertMessage("Success! Site has been removed!");
}
catch (Exception ex)
{
AlertMessage("Error! Please contact company helpdesk!");
}
finally
{
try { connection.Close(); }
catch { }

connection.Dispose();
}
}
}