Dearest experts,
I am a first timer here and I ask for your patience and heavenly assistance.
I have one serious issue.
The history:
I have 12 attorneys. This number doesn't change.
Each attorney is assigned a case, no more than one case a time.
The cases are assigned randomly.
First, a case is created, then each attorney is selected from the dropdown and assigned a case.
The dropdown is also known as a wheel.
Once a attorney is assigned a case, the attorney disappears from the dropdown (wheel).
Next time a case is created, it is assigned to another attorney.
This process goes on until all attorneys in the dropdown or wheel is assigned a case.
Once each attorney has been assigned a case, and no attorney is left on the dropdown, any attempt to assign another case to a attorney results to the following message I created:
"No attorneys available to handle case " & caseid (whatever the case number is)"
This is simply because ALL attorneys on the dropdown has been assigned a wheel.
These scenarios work great so far.
The problem I have now is that once all attorneys have each been assigned a case, and a new case is created, rather than this code below:
we would like to reload the dropdown with SAME attorneys and start assigning new cases to each attorney all over again.
I tried this:
But it isn't working.
I am really stumped as to how to handle this.
I would really, really appreciate your assistance with handling this portion ofthe problem.
3 tables are involved so far:
Attorney table (lookup table)
AttorneyCode nvarchar(50),
AttorneyName nvarchar(50)
Clients table (lookup table)
ClientID int pk identity key,
ClientName nvarchar(50)
Cases table
caseId int pk identity key,
attorneyCode nvarchar(50),
ClientId int,
CaseName nvarchar(50),
CaseType nvarchar(50
Do I need to make any changes to these tables to help solve this problem?
Please let me know.
Below is the entire working code.
Many thanks in advance for your assistance.
I am a first timer here and I ask for your patience and heavenly assistance.
I have one serious issue.
The history:
I have 12 attorneys. This number doesn't change.
Each attorney is assigned a case, no more than one case a time.
The cases are assigned randomly.
First, a case is created, then each attorney is selected from the dropdown and assigned a case.
The dropdown is also known as a wheel.
Once a attorney is assigned a case, the attorney disappears from the dropdown (wheel).
Next time a case is created, it is assigned to another attorney.
This process goes on until all attorneys in the dropdown or wheel is assigned a case.
Once each attorney has been assigned a case, and no attorney is left on the dropdown, any attempt to assign another case to a attorney results to the following message I created:
"No attorneys available to handle case " & caseid (whatever the case number is)"
This is simply because ALL attorneys on the dropdown has been assigned a wheel.
These scenarios work great so far.
The problem I have now is that once all attorneys have each been assigned a case, and a new case is created, rather than this code below:
Code:
If RS.EOF Then
Response.Write "FATAL ERROR: No attorneys available to handle case " & caseid
RS.Close
Conn.Close
Response.End
End If
I tried this:
Code:
If RS.EOF Then
Response.Write "Reloading attorneys wheel"
SQL = "SELECT j.AttorneyCode, j.AttorneyName " & _
"FROM Attorneys j " & _
"LEFT JOIN Cases c ON c.AttorneyCode = j.AttorneyCode " & _
"WHERE c.AttorneyCode IS NULL " & _
"ORDER BY j.AttorneyName"
RS.Close
Conn.Close
Response.End
End If
I am really stumped as to how to handle this.
I would really, really appreciate your assistance with handling this portion ofthe problem.
3 tables are involved so far:
Attorney table (lookup table)
AttorneyCode nvarchar(50),
AttorneyName nvarchar(50)
Clients table (lookup table)
ClientID int pk identity key,
ClientName nvarchar(50)
Cases table
caseId int pk identity key,
attorneyCode nvarchar(50),
ClientId int,
CaseName nvarchar(50),
CaseType nvarchar(50
Do I need to make any changes to these tables to help solve this problem?
Please let me know.
Below is the entire working code.
Many thanks in advance for your assistance.
Code:
<html>
<head>
<script>
function clearText(thefield){
if (thefield.defaultValue==thefield.value) {
thefield.value = "";
}
}
function restoreText(thefield){
if (thefield.value=="") {
thefield.value = thefield.defaultValue;
}
}
</script>
</head>
<body background="images/fcweb_bg.jpg">
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Driver={SQL Server};" & _
"Server=wgc;" & _
"Address=wgc,1433;" & _
"Network=DBMSSOCN;" & _
"Database=ATTORNEYS" & _
"Uid=***;" & _
"Pwd=***"
If Request("POSTBACK") = "NEWCASE" Then
' new case requested
client = Trim(Request("clientid"))
casename = Trim(Request("casename"))
casetype = Trim(Request("casetype"))
If client <= 0 Then
' only generate a new client id if we *NEED* to!!!!!
SQL = "Set Nocount on; " _
& " Insert INTO Clients (ClientName) VALUES ('" & Replace(Request("newclientid"),"'","''") & "');" _
& " Select @@identity; " _
& " set nocount off"
'response.write SQL
'response.end
Set RS = Conn.Execute(SQL)
client = RS(0)
RS.close
End If
SQL = "INSERT INTO Cases (clientid,casename,casetype) " _
& " VALUES(" & client & ",'" & casename & "','" & casetype & "')"
' response.write SQL & "<br>"
' response.end
conn.Execute SQL
SQL = "SELECT @@IDENTITY"
Set RS = conn.Execute(SQL)
caseid = RS(0)
' response.write caseid& "<br>"
' response.end
RS.Close
End If
If Request("POSTBACK") = "ASSIGNCASE" Then
caseid = Trim(Request("caseid"))
AttorneyCode = Trim(Request("Attorney"))
SQL = "UPDATE Cases SET AttorneyCode = '" & AttorneyCode & "' WHERE caseid = " & caseid
conn.Execute( SQL )
End If
' see if there are any cases pending that need a Attorney assigned to them:
SQL = "SELECT TOP 1 CaseID, ClientID, casename, casetype FROM Cases WHERE Coalesce(AttorneyCode,'0') = '0' ORDER BY CaseID "
'Response.write sql & "<br>"
'Response.end
Set RS = conn.Execute(SQL)
If Not RS.EOF Then
' aha! have a case that needs assignment
caseid = RS("caseID")
clientid = RS("clientID")
casename = RS("casename")
casetype = RS("casetype")
' now, does this client have any cases assigned to any Attorney?
SQL = "SELECT TOP 1 AttorneyCode FROM Cases WHERE clientID = " & clientid & " AND Coalesce(AttorneyCode,'0') <> '0' "
'Response.write sql & "<br>"
'Response.end
Set RS = conn.Execute(SQL)
If Not RS.EOF Then
lcode = RS(0) ' yes! already has this code assigned
SQL = "UPDATE Cases SET AttorneyCode = '" & lcode & "' WHERE caseid = " & caseid
conn.Execute SQL
Response.Write "<h3>Assigned " & lcode & " to case " & caseid & " for client " & clientid & "</h3>" _
& "<br/>Case name: " & casename & "<br/>Case type: " & casetype _
& "<br/>(same client as a prior case)</br></hr>" & vbNewLine
Else
' if here, this is first case for this client...so find an available attorney:
' SQL = "SELECT AttorneyCode, AttorneyName FROM Attorneys " _
' & " WHERE AttorneyCode NOT IN (SELECT AttorneyCode FROM Cases) " _
' & " ORDER BY AttorneyName "
'Response.write sql & "<br>"
'Response.end
' SQL = "SELECT Attorneys.AttorneyCode, AttorneyName " & _
' "FROM Attorneys " & _
' "LEFT JOIN Cases ON Cases.AttorneyCode = Attorneys.AttorneyCode " & _
' "WHERE Cases.CaseId IS NULL " & _
' "ORDER BY AttorneyName "
SQL = "SELECT j.AttorneyCode, j.AttorneyName " & _
"FROM Attorneys j " & _
"LEFT JOIN Cases c ON c.AttorneyCode = j.AttorneyCode " & _
"WHERE c.AttorneyCode IS NULL " & _
"ORDER BY j.AttorneyName"
Set RS = Conn.Execute( SQL )
If RS.EOF Then
Response.Write "FATAL ERROR: No attorneys available to handle case " & caseid
RS.Close
Conn.Close
Response.End
End If
' so let the clerk choose a attorney:
%>
<hr>
<br/>
<h2>Choose Attorney for Case</h2>
<br/>
Case id: <%=caseid%><br/>
Client id: <%=clientid%><br/>
Case Name: <%=casename%><br/>
Case Type: <%=casetype%><br/>
<form name="attorneyForm">
<input type="hidden" name="POSTBACK" value="ASSIGNCASE" />
<input type="hidden" name="caseid" value="<%=caseid%>" />
Choose an available attorney:
<select name="attorney">
<%
Do Until RS.EOF
%>
<option value="<%=RS("AttorneyCode")%>"><%=RS("AttorneyCode")%></option>
<%
RS.MoveNext
Loop
RS.Close
%>
</select>
<br/>
<input type="submit" value="Assign Attorney"/>
</form>
</body></html>
<%
conn.Close
Response.End ' don't display more...must choose a attorney
End If
End If
%>
<img src="images/casewheel.gif">
<h2>Create a new Case</h2>
<table width="74%" style="border:1 solid #F3EFE0;" cellspacing=0>
<tr style="background: #F3EFE0;color:#003;vertical-align:top;margin-top:0;height: 25px;">
<td>
<form name="caseForm">
<input type="hidden" name="POSTBACK" value="NEWCASE" />
<select name="clientid">
<option value="0">Choose client</option>
<%
Set RS = Conn.Execute("SELECT ClientID, ClientName FROM Clients ORDER BY ClientName")
Do Until RS.EOF %>
<option value="<%=rs(0)%>"><%=rs(1)%></option>
<%
RS.MoveNext
Loop
RS.Close
%>
</select>
<INPUT Name="newclientid" size="32" onFocus="this.form.clientid.selectedIndex=0;"> <--Type in client name if not in the dropdown list<br>
<br/>
<input name="casename" onfocus="clearText(this)" onblur="restoreText(this)" size="50" value="Enter case name" />
<br/><br>
<input name="casetype" onfocus="clearText(this)" onblur="restoreText(this)" size="50" value="Enter case type" />
<input style="font-size: x-small; font-weight: bold; color: #003;" type=submit value="Create Case" name=case>
</form>
</td>
</tr>
</table>
</body>
</html>