-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteRec.asp
97 lines (77 loc) · 2.56 KB
/
DeleteRec.asp
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
<%
Session("STimeoutError")=""
if Session("STxtUserEmail")="" then
Session("STimeoutError")="Your Session has been Timed Out! Please Login to continue"
response.Redirect("Login.asp")
end if
%>
<!--#include file="ValidateLogin.asp"-->
<%
Dim TableName
Dim TransID
Dim TransDate
Dim Catg
Dim Person
Dim Description
Dim CrAmount
Dim DbAmount
'Dim ErrorFound
TableName = request.Form("AccTableName")
TransID = Request.Form("TransID")
'TransDate = request.Form("TrDate")
'Catg = request.Form("SelectCategory")
'Person = request.Form("SelectPerson")
'Description = request.Form("TrDesc")
'CrAmount = request.Form("CreditAmount")
'DbAmount = request.Form("DebitAmount")
'Req Validations
'TableName <> null
'TableName not found
'Transid <> null
'id not found
'Dim Conn
'Dim CS
Dim RSTransaction
Set Conn = Server.CreateObject("ADODB.Connection")
Set RSTransaction = Server.CreateObject("ADODB.RecordSet")
CS = "Driver={SQL Server};Server=NABEELS-WORK;Database=HomeExpenseTracker;User Id=homeexpense;Password=Nabeel30;"
Conn.Open CS
'Dim QryStr
QryStr = "DELETE FROM " & TableName & " WHERE(ID = " & TransID & ")"
'response.Write(qrystr)
Conn.Execute QryStr
QryStr = "SELECT Top (1) Balance FROM " & TableName & " WHERE(ID < " & TransID & ") ORDER BY ID DESC"
'response.Write("<br>" & qrystr)
'response.End
If RSTransaction.State = 1 Then
RSTransaction.close
End If
RStransaction.Open QryStr,Conn
Dim BalAmount
If RStransaction.BOF Or RStransaction.EOF Then
BalAmount = 0
Else
BalAmount = RStransaction("Balance")
End If
'Calculating Balance for rest of the Records
QryStr = "SELECT ID,Credit,Debit FROM " & TableName & " WHERE (ID > " & TransID & ") ORDER BY ID ASC"
'response.Write("<br>" & qrystr)
If RSTransaction.State = 1 Then
RSTransaction.close
End If
RStransaction.Open QryStr,Conn
Dim CreditAmount
Dim DebitAmount
Dim TrID
Do While RStransaction.EOF = False
TrID = RStransaction("ID")
CreditAmount = RStransaction("Credit")
DebitAmount = RStransaction("Debit")
BalAmount = (BalAmount - CreditAmount) + DebitAmount
qrystr = "Update " & TableName & " SET Balance = " & BalAmount & " WHERE (ID = " & TrID & ")"
'response.Write("<br>" & qrystr)
Conn.Execute QryStr
RStransaction.MoveNext
Loop
Response.Redirect("ViewTransaction.asp?AccTableName=" & TableName)
%>