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:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
|
asp page---
' create and open ADODB objects
dim objConn, objRS, objCmd
set objConn = server.CreateObject("ADODB.Connection")
set objRS = server.CreateObject("ADODB.Recordset")
set objCmd = server.CreateObject("ADODB.Command")
objConn.ConnectionString = application("DSN")
objConn.Open
objRS.ActiveConnection = objConn
objCmd.ActiveConnection = objConn
' update the record if submitted by form
if Request.Form("employee") <> "" then
strEmployee_Key = Request.Form("employee")
strCompany_Key = Request.Form("company")
if Request.Form("delete") <> "Delete" then
objCmd.CommandText = "sp_AddEmployee"
objCmd.CommandType = adCmdStoredProc
objCmd.Parameters.Refresh
objCmd.Parameters("@Company_Key").Value = strCompany_Key
objCmd.Parameters("@Employee_Key").Value = strEmployee_Key
objCmd.Parameters("@FirstName").Value = ucase(Request.Form("firstname"))
objCmd.Parameters("@LastName").Value = ucase(Request.Form("lastname"))
objCmd.Parameters("@Title").Value = ucase(Request.Form("title"))
objCmd.Parameters("@Phone").Value = ucase(Request.Form("phone"))
objCmd.Parameters("@Fax").Value = ucase(Request.Form("fax"))
objCmd.Parameters("@Email").Value = ucase(Request.Form("email"))
objCmd.Parameters("@TID").Value = Request.Form("tcode")
'objCmd.Parameters("@OID").Value = Request.Form("ocode")
'objCmd.Parameters("@ZID").Value = Request.Form("zcode")
'objCmd.Parameters("@QID").Value = Request.Form("qcode")
'objCmd.Parameters("@AddCode").Value = ucase(Request.Form("addcode"))
objCmd.Parameters("@User_Key").Value = session("User_Key")
set objReturn = objCmd.Execute
strEmployee_Key = objReturn(0)
strMessage = "Employee Record Updated"
else
if strEmployee_Key <> "00000000-0000-0000-0000-000000000000" then
' delete the record
objCmd.CommandText = "exec sp_DeleteEmployee '" & strEmployee_Key & "', '" & session("User_Key") & "'"
objCmd.Execute
strMessage = "Employee Record Deleted"
strEmployee_Key = "00000000-0000-0000-0000-000000000000"
else
strMessage = "Nothing to Delete!"
end if
end if
end if
stored procedure--
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_AddEmployee]
@Employee_Key uniqueidentifier,
@Company_Key UniqueIdentifier,
@FirstName varchar(50),
@LastName varchar(50),
@Title varchar(50),
@Phone varchar(50),
@Fax varchar(50),
@Email varchar(255),
@TID int,
--@OID int,
--@ZID int,
--@QID int,
--@AddCode varchar(60),
@User_Key UniqueIdentifier
AS
begin
set nocount on
if @Employee_Key = '00000000-0000-0000-0000-000000000000' or @Employee_Key is null
begin
select @Employee_Key=Newid()
-- new employee, so create a new record first
insert into tblEmployee (Employee_Key,Company_Key) values (@Employee_Key,@Company_Key)
-- Add log
insert into tblEventLog (User_Key, Event_Key, Description) values (@User_Key, '6658b02c-9a9c-43cf-b63b-3afaad76168d',cast(@Employee_Key as varchar(40)))
end
-- update the rest of the record
update tblEmployee set FirstName = @FirstName,
LastName = @LastName,
Title = @Title,
Phone = @Phone,
Fax = @Fax,
Email = @Email,
TID = @TID
-- OID = @OID,
-- ZID = @ZID,
-- QID = @QID,
-- AddCode = @AddCode
where Employee_Key = @Employee_Key
-- Add log
insert into tblEventLog (User_Key, Event_Key, Description) values (@User_Key, '188143f4-e805-401e-a3c1-c102c74dd6cd', cast(@Employee_Key as varchar(40)))
-- Return Employee_Key to calling application
select @Employee_Key as Employee_Key
end
|