001.
Imports
Microsoft.VisualBasic
002.
Imports
System
003.
Imports
System.Data
004.
Imports
System.Data.SqlClient
005.
Imports
System.Web.Configuration
006.
Imports
System.Web.UI.WebControls
007.
008.
Partial
Class
HRInsertEmployee
009.
Inherits
System.Web.UI.Page
010.
Dim
objConn
As
SqlConnection
011.
Dim
objCmd
As
SqlCommand
012.
Dim
dtAdapter
As
SqlDataAdapter
013.
Dim
query, query1, strSQL
As
String
014.
Dim
strSQL1, strSQL2, strSQL3, strSQL4, strSQL5
As
String
015.
Dim
dtAdapter2, dtAdapter3, dtAdapter4, dtAdapter5
As
SqlDataAdapter
016.
017.
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
018.
019.
If
Not
Page.IsPostBack()
Then
020.
Dim
dt
As
New
DataTable
021.
022.
Dim
strConnString
As
String
023.
strConnString = ConfigurationManager.ConnectionStrings.Item(
"ConnectionString"
).ConnectionString
024.
objConn =
New
SqlConnection(strConnString)
025.
objConn.Open()
026.
027.
strSQL1 =
"SELECT head_id, head_name FROM head"
028.
dtAdapter =
New
SqlDataAdapter(strSQL1, objConn)
029.
dtAdapter.Fill(dt)
030.
dtAdapter =
Nothing
031.
objConn.Close()
032.
objConn =
Nothing
033.
With
Me
.ddlHead
034.
.DataSource = dt
035.
.DataTextField =
"head_name"
036.
.DataValueField =
"head_id"
037.
.DataBind()
038.
End
With
039.
ddlHead.SelectedIndex = ddlHead.Items.IndexOf(ddlHead.Items.FindByValue(
"head_id"
))
040.
041.
End
If
042.
043.
If
Not
Page.IsPostBack()
Then
044.
Dim
dt
As
New
DataTable
045.
046.
Dim
strConnString
As
String
047.
strConnString = ConfigurationManager.ConnectionStrings.Item(
"ConnectionString"
).ConnectionString
048.
objConn =
New
SqlConnection(strConnString)
049.
objConn.Open()
050.
051.
strSQL =
"SELECT department_id, department_name FROM department"
052.
dtAdapter =
New
SqlDataAdapter(strSQL, objConn)
053.
dtAdapter.Fill(dt)
054.
dtAdapter =
Nothing
055.
objConn.Close()
056.
objConn =
Nothing
057.
With
Me
.ddldepartment
058.
.DataSource = dt
059.
.DataTextField =
"department_name"
060.
.DataValueField =
"department_id"
061.
.DataBind()
062.
End
With
063.
ddldepartment.SelectedIndex = ddldepartment.Items.IndexOf(ddldepartment.Items.FindByValue(
"department_id"
))
064.
065.
End
If
066.
067.
If
Not
Page.IsPostBack()
Then
068.
Dim
dt
As
New
DataTable
069.
070.
Dim
strConnString
As
String
071.
strConnString = ConfigurationManager.ConnectionStrings.Item(
"ConnectionString"
).ConnectionString
072.
objConn =
New
SqlConnection(strConnString)
073.
objConn.Open()
074.
075.
strSQL =
"SELECT authentication_id, authentication_name FROM authentication"
076.
dtAdapter =
New
SqlDataAdapter(strSQL, objConn)
077.
dtAdapter.Fill(dt)
078.
dtAdapter =
Nothing
079.
objConn.Close()
080.
objConn =
Nothing
081.
With
Me
.ddlauthentication
082.
.DataSource = dt
083.
.DataTextField =
"authentication_name"
084.
.DataValueField =
"authentication_id"
085.
.DataBind()
086.
End
With
087.
ddlauthentication.SelectedIndex = ddlauthentication.Items.IndexOf(ddlauthentication.Items.FindByValue(
"authentication_id"
))
088.
089.
End
If
090.
091.
If
Not
Page.IsPostBack()
Then
092.
Dim
dt
As
New
DataTable
093.
094.
Dim
strConnString
As
String
095.
strConnString = ConfigurationManager.ConnectionStrings.Item(
"ConnectionString"
).ConnectionString
096.
objConn =
New
SqlConnection(strConnString)
097.
objConn.Open()
098.
strSQL =
"SELECT role_id, role_name FROM roces_role"
099.
dtAdapter =
New
SqlDataAdapter(strSQL, objConn)
100.
dtAdapter.Fill(dt)
101.
dtAdapter =
Nothing
102.
objConn.Close()
103.
objConn =
Nothing
104.
With
Me
.ddlrole
105.
.DataSource = dt
106.
.DataTextField =
"role_name"
107.
.DataValueField =
"role_id"
108.
.DataBind()
109.
End
With
110.
ddlrole.SelectedIndex = ddlrole.Items.IndexOf(ddlrole.Items.FindByValue(
"role_id"
))
111.
112.
End
If
113.
114.
If
Not
Page.IsPostBack()
Then
115.
Dim
dt
As
New
DataTable
116.
117.
Dim
strConnString
As
String
118.
strConnString = ConfigurationManager.ConnectionStrings.Item(
"ConnectionString"
).ConnectionString
119.
objConn =
New
SqlConnection(strConnString)
120.
objConn.Open()
121.
strSQL =
"SELECT term_id, term_name FROM term"
122.
dtAdapter =
New
SqlDataAdapter(strSQL, objConn)
123.
dtAdapter.Fill(dt)
124.
dtAdapter =
Nothing
125.
objConn.Close()
126.
objConn =
Nothing
127.
With
Me
.ddlterm
128.
.DataSource = dt
129.
.DataTextField =
"term_name"
130.
.DataValueField =
"term_id"
131.
.DataBind()
132.
End
With
133.
ddlterm.SelectedIndex = ddlterm.Items.IndexOf(ddlterm.Items.FindByValue(
"term_id"
))
134.
135.
End
If
136.
137.
End
Sub
138.
139.
Protected
Sub
btnSave_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnSave.Click
140.
Dim
strConnString
As
String
141.
142.
143.
strConnString = ConfigurationManager.ConnectionStrings.Item(
"ConnectionString"
).ConnectionString
144.
strSQL =
"INSERT INTO employee(employee_id, username, password, first_name, last_name, email)"
& _
145.
" VALUES "
& _
146.
" ('"
&
Me
.txtemployee_id.Text &
"','"
&
Me
.txtusername.Text &
"','"
&
Me
.txtpassword.Text &
"', "
& _
147.
" '"
&
Me
.txtfirst_name.Text &
"','"
&
Me
.txtlast_name.Text &
"','"
&
Me
.txtemail.Text &
"')"
148.
objConn =
New
SqlConnection(strConnString)
149.
objConn.Open()
150.
151.
objCmd =
New
SqlCommand
152.
With
objCmd
153.
.Connection = objConn
154.
.CommandText = strSQL
155.
.CommandType = CommandType.Text
156.
End
With
157.
158.
strSQL1 =
"INSERT INTO head(head_id)"
& _
159.
" VALUES "
& _
160.
" ('"
&
Me
.ddlHead.SelectedItem.Value &
"')"
161.
objConn =
New
SqlConnection(strConnString)
162.
objConn.Open()
163.
164.
objCmd =
New
SqlCommand
165.
With
objCmd
166.
.Connection = objConn
167.
.CommandText = strSQL
168.
.CommandType = CommandType.Text
169.
170.
171.
172.
173.
174.
End
With
175.
176.
strSQL2 =
"INSERT INTO department(department_id, department_name)"
& _
177.
" VALUES "
& _
178.
" ('"
&
Me
.ddldepartment.Text &
"')"
179.
objConn =
New
SqlConnection(strConnString)
180.
objConn.Open()
181.
182.
objCmd =
New
SqlCommand
183.
With
objCmd
184.
.Connection = objConn
185.
.CommandText = strSQL2
186.
.CommandType = CommandType.Text
187.
188.
189.
190.
191.
192.
End
With
193.
194.
strSQL3 =
"INSERT INTO authentication(authentication_id, authentication_name)"
& _
195.
" VALUES "
& _
196.
" ('"
&
Me
.ddlauthentication.Text &
"')"
197.
objConn =
New
SqlConnection(strConnString)
198.
objConn.Open()
199.
200.
objCmd =
New
SqlCommand
201.
With
objCmd
202.
.Connection = objConn
203.
.CommandText = strSQL3
204.
.CommandType = CommandType.Text
205.
206.
207.
208.
209.
210.
End
With
211.
212.
strSQL4 =
"INSERT INTO roces_role(role_id, role_name)"
& _
213.
" VALUES "
& _
214.
" ('"
&
Me
.ddlrole.Text &
"')"
215.
objConn =
New
SqlConnection(strConnString)
216.
objConn.Open()
217.
218.
objCmd =
New
SqlCommand
219.
With
objCmd
220.
.Connection = objConn
221.
.CommandText = strSQL4
222.
.CommandType = CommandType.Text
223.
224.
225.
226.
227.
228.
End
With
229.
230.
strSQL5 =
"INSERT INTO term(term_id, term_name)"
& _
231.
" VALUES "
& _
232.
" ('"
&
Me
.ddlterm.Text &
"')"
233.
objConn =
New
SqlConnection(strConnString)
234.
objConn.Open()
235.
236.
objCmd =
New
SqlCommand
237.
With
objCmd
238.
.Connection = objConn
239.
.CommandText = strSQL5
240.
.CommandType = CommandType.Text
241.
242.
243.
244.
245.
246.
247.
End
With
248.
249.
Me
.pnlAdd.Visible =
False
250.
251.
Try
252.
objCmd.ExecuteNonQuery()
253.
Me
.lblStatus.Text =
"Record Inserted"
254.
Me
.lblStatus.Visible =
True
255.
Catch
ex
As
Exception
256.
Me
.lblStatus.Visible =
True
257.
Me
.lblStatus.Text =
"Record can not insert Error ("
& ex.Message &
")"
258.
End
Try
259.
260.
objConn.Close()
261.
objConn =
Nothing
262.
263.
Response.Redirect(
"HRManagerEmployee.aspx"
)
264.
End
Sub
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
End
Class