-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssetModule.cs
96 lines (80 loc) · 3.16 KB
/
AssetModule.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MOF_ATMS
{
public partial class AssetModule : Form
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\user\Documents\dbMATMS.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand com = new SqlCommand();
SqlDataReader dr;
public AssetModule()
{
InitializeComponent();
}
public void Clear()
{
txtName.Clear();
txtAssetId.Clear();
txtAssigned.Clear();
txtStudentN.Clear();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (MessageBox.Show("Are you sure you want to save this asset?", "Saving Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
com = new SqlCommand("INSERT INTO tbAsset(assetID,name,assignedStudent,studentNum)VALUES(@assetID,@name,@assignedStudent,@studentNum)", con);
com.Parameters.AddWithValue("@assetID", txtAssetId.Text);
com.Parameters.AddWithValue("@name", txtName.Text);
com.Parameters.AddWithValue("@assignedStudent", txtAssigned.Text);
com.Parameters.AddWithValue("@studentNum", Convert.ToInt16(txtStudentN.Text));
con.Open();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Asset has been successfully saved.");
Clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
if (MessageBox.Show("Are you sure you want to update this asset?", "Saving Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
com = new SqlCommand("UPDATE tbAsset(assetID,name,assigndStudent)VALUES(@assetID,@name,@assigndStudent)", con);
com.Parameters.AddWithValue("@assetID", txtAssetId.Text);
com.Parameters.AddWithValue("@name", txtName.Text);
com.Parameters.AddWithValue("@assignedStudent", txtAssigned.Text);
com.Parameters.AddWithValue("@studentNum", Convert.ToInt16(txtStudentN.Text));
con.Open();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Asset has been successfully updated.");
Clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}