<%@ LCID = 5129 %> <% Response.expires = 0 Response.expiresabsolute = Now() - 1 Response.addHeader "pragma", "no-cache" Response.addHeader "cache-control", "private" Response.CacheControl = "no-cache" %> <% ewCurSec = 0 ' Initialise ' User levels Const ewAllowAdd = 1 Const ewAllowDelete = 2 Const ewAllowEdit = 4 Const ewAllowView = 8 Const ewAllowList = 8 Const ewAllowReport = 8 Const ewAllowSearch = 8 Const ewAllowAdmin = 16 %> <% ' Initialize common variables x_csn = Null x_type = Null x_status = Null x_issue = Null x_card_size = Null x_expiry_date = Null x_issued_date = Null x_issued_at = Null x_issuer = Null x_reissued = Null x_hot = Null x_id = Null %> <% Response.Buffer = True ' Get action sAction = Request.Form("a_add") If (sAction = "" Or IsNull(sAction)) Then sKey = Request.Querystring("key") If sKey <> "" Then sAction = "C" ' Copy record Else sAction = "I" ' Display blank record End If Else ' Get fields from form x_csn = Request.Form("x_csn") x_type = Request.Form("x_type") x_status = Request.Form("x_status") x_issue = Request.Form("x_issue") x_card_size = Request.Form("x_card_size") x_expiry_date = Request.Form("x_expiry_date") x_issued_date = Request.Form("x_issued_date") x_issued_at = Request.Form("x_issued_at") x_issuer = Request.Form("x_issuer") x_reissued = Request.Form("x_reissued") x_hot = Request.Form("x_hot") x_id = Request.Form("x_id") End If ' Open connection to the database Set conn = Server.CreateObject("ADODB.Connection") conn.Open xDb_Conn_Str Select Case sAction Case "C": ' Get a record to display If Not LoadData(sKey) Then ' Load Record based on key Session("ewmsg") = "No Record Found for Key = " & sKey conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "card_datalist.asp" End If Case "A": ' Add If AddData() Then ' Add New Record Session("ewmsg") = "Add New Record Successful" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "card_datalist.asp" End If End Select %>

Add to TABLE: card data

Back to List

csn ">
type <% If IsNull(x_type) or x_type = "" Then x_type = 0 ' Set default value %> ">
status ">
issue <% If IsNull(x_issue) or x_issue = "" Then x_issue = 0 ' Set default value %> ">
card size ">
expiry date
issued date
issued at ">
issuer ">
reissued checked<% End If %> value="Yes"> <%= "Yes" %> checked<% End If %> value="No"> <%= "No" %>
hot checked<% End If %> value="Yes"> <%= "Yes" %> checked<% End If %> value="No"> <%= "No" %>
id <% If IsNull(x_id) or x_id = "" Then x_id = 0 ' Set default value %> ">

<% conn.Close ' Close Connection Set conn = Nothing %> <% '------------------------------------------------------------------------------- ' Function LoadData ' - Load Data based on Key Value sKey ' - Variables setup: field variables Function LoadData(sKey) Dim sKeyWrk, sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy sKeyWrk = "'" & AdjustSql(sKey) & "'" sSql = "SELECT * FROM [card_data]" sSql = sSql & " WHERE [csn] = " & sKeyWrk sGroupBy = "" sHaving = "" sOrderBy = "" If sGroupBy <> "" Then sSql = sSql & " GROUP BY " & sGroupBy End If If sHaving <> "" Then sSql = sSql & " HAVING " & sHaving End If If sOrderBy <> "" Then sSql = sSql & " ORDER BY " & sOrderBy End If Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadData = False Else LoadData = True rs.MoveFirst ' Get the field contents x_csn = rs("csn") x_type = rs("type") x_status = rs("status") x_issue = rs("issue") x_card_size = rs("card_size") x_expiry_date = rs("expiry_date") x_issued_date = rs("issued_date") x_issued_at = rs("issued_at") x_issuer = rs("issuer") x_reissued = rs("reissued") x_hot = rs("hot") x_id = rs("id") End If rs.Close Set rs = Nothing End Function %> <% '------------------------------------------------------------------------------- ' Function AddData ' - Add Data ' - Variables used: field variables Function AddData() Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy ' Add New Record sSql = "SELECT * FROM [card_data]" sSql = sSql & " WHERE 0 = 1" sGroupBy = "" sHaving = "" sOrderBy = "" If sGroupBy <> "" Then sSql = sSql & " GROUP BY " & sGroupBy End If If sHaving <> "" Then sSql = sSql & " HAVING " & sHaving End If If sOrderBy <> "" Then sSql = sSql & " ORDER BY " & sOrderBy End If Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = 3 rs.Open sSql, conn, 1, 2 rs.AddNew ' Field csn sTmp = Trim(x_csn) If Trim(sTmp) = "" Then sTmp = Null sSqlChk = "SELECT * FROM [card_data] WHERE [csn] = '" & AdjustSql(sTmp) & "'" Set rsChk = conn.Execute(sSqlChk) If Not rsChk.Eof Then Response.Write "Duplicate value for index or primary key -- csn, value = " & sTmp & "
" Response.Write "Press [Previous Page] key to continue!" Response.End End If rsChk.Close Set rsChk = Nothing rs("csn") = sTmp ' Field type sTmp = x_type If Not IsNumeric(sTmp) Then sTmp = Null Else sTmp = CLng(sTmp) End If rs("type") = sTmp ' Field status sTmp = Trim(x_status) If Trim(sTmp) = "" Then sTmp = Null rs("status") = sTmp ' Field issue sTmp = x_issue If Not IsNumeric(sTmp) Then sTmp = Null Else sTmp = CLng(sTmp) End If rs("issue") = sTmp ' Field card_size sTmp = Trim(x_card_size) If Trim(sTmp) = "" Then sTmp = Null rs("card_size") = sTmp ' Field expiry_date sTmp = EW_UnFormatDateTime(x_expiry_date,7) If IsDate(sTmp) Then rs("expiry_date") = CDate(sTmp) Else rs("expiry_date") = Null End If ' Field issued_date sTmp = EW_UnFormatDateTime(x_issued_date,7) If IsDate(sTmp) Then rs("issued_date") = CDate(sTmp) Else rs("issued_date") = Null End If ' Field issued_at sTmp = Trim(x_issued_at) If Trim(sTmp) = "" Then sTmp = Null rs("issued_at") = sTmp ' Field issuer sTmp = Trim(x_issuer) If Trim(sTmp) = "" Then sTmp = Null rs("issuer") = sTmp ' Field reissued sTmp = x_reissued If sTmp = "Yes" Then rs("reissued") = True Else rs("reissued") = False End If ' Field hot sTmp = x_hot If sTmp = "Yes" Then rs("hot") = True Else rs("hot") = False End If ' Field id sTmp = x_id If Not IsNumeric(sTmp) Then sTmp = Null Else sTmp = CLng(sTmp) End If rs("id") = sTmp rs.Update rs.Close Set rs = Nothing AddData = True End Function %>