I think i am going crazy...now is the worst no error message but the query just don execute.
@{
var applyLicense = Session["license"];
var applyFrom = Session["from"];
var applyTo = Session["to"];
var applyGroup = Session["group"];
var applyClass1 = Session["class1"];
var applyCategory1 = Session["category1"];
var applyClass = Session["class"];
var applyCategory = Session["category"];
Page.Title = "Medical Questionnaire";
var id = WebSecurity.GetUserId(WebSecurity.CurrentUserName);
var db = Database.Open("Test");
var username = WebSecurity.CurrentUserName;
var sql1 = "SELECT * FROM Users Where UserName = @0";
var me = db.QuerySingle(sql1, username);
var myFirstName = me.FirstName;
var myLastName = me.LastName;
var myCDSID = me.UserName; //this gives myCDSID the data type in the database
// Driving licence input variables used for preserve the inputs when server side validation fails,
// such that users do not need to re-enter those fields :)
// The input values of the checkboxes and radio buttons are preserved using the Helpers.checked function
// Without preserving the inputs, if the server side validation fails, all user inputs will be lost and
// the users have to enter them again :(
@* the page is first accessed using the defaul http "get" method *@
@* when the form is submitted using a http "post" method, the following *@
@* within if(IsPost) will be prcessed on the server side, and after *@
@* the processing, the resultant page will be return to the user/client *@
var q1 = Request["medq1"];
var q2 = Request["medq2"];
var q3 = Request["medq3"];
var q4 = Request["medq4"];
var q5 = Request["medq5"];
var q6 = Request["medq6"];
var q7 = Request["medq7"];
var q8 = Request["medq8"];
var q9 = Request["medq9"];
var q10 = Request["medq10"];
var q11 = Request["medq11"];
var q12 = Request["medq12"];
var q13 = Request["medq13"];
var q14 = Request["medq14"];
var q15 = Request["medq15"];
var q16 = Request["medq16"];
var q17 = Request["medq17"];
var q18 = Request["medq18"];
var q19 = Request["medq19"];
var q20 = Request["medq20"];
var alcohol = Request["alcohol"];
var medication = Request["medication"];
var details = Request["details"];
if(IsPost){
if(Request["medq1"].IsEmpty()){
ModelState.AddError("medq1", "Please Answer this question");
}
if(Request["medq2"].IsEmpty()){
ModelState.AddError("medq2", "Please Answer this question");
}
if(Request["medq3"].IsEmpty()){
ModelState.AddError("medq3", "Please Answer this question");
}
if(Request["medq4"].IsEmpty()){
ModelState.AddError("medq4", "Please Answer this question");
}
if(Request["medq5"].IsEmpty()){
ModelState.AddError("medq5", "Please Answer this question");
}
if(Request["medq6"].IsEmpty()){
ModelState.AddError("medq6", "Please Answer this question");
}
if(Request["medq7"].IsEmpty()){
ModelState.AddError("medq7", "Please Answer this question");
}
if(Request["medq8"].IsEmpty()){
ModelState.AddError("medq8", "Please Answer this question");
}
if(Request["medq9"].IsEmpty()){
ModelState.AddError("medq9", "Please Answer this question");
}
if(Request["medq10"].IsEmpty()){
ModelState.AddError("medq10", "Please Answer this question");
}
if(Request["medq11"].IsEmpty()){
ModelState.AddError("medq11", "Please Answer this question");
}
if(Request["medq12"].IsEmpty()){
ModelState.AddError("medq12", "Please Answer this question");
}
if(Request["medq13"].IsEmpty()){
ModelState.AddError("medq13", "Please Answer this question");
}
if(Request["medq14"].IsEmpty()){
ModelState.AddError("medq14", "Please Answer this question");
}
if(Request["medq15"].IsEmpty()){
ModelState.AddError("medq15", "Please Answer this question");
}
if(Request["medq16"].IsEmpty()){
ModelState.AddError("medq16", "Please Answer this question");
}
if(Request["medq17"].IsEmpty()){
ModelState.AddError("medq17", "Please Answer this question");
}
if(Request["medq18"].IsEmpty()){
ModelState.AddError("medq18", "Please Answer this question");
}
if(Request["medq19"].IsEmpty()){
ModelState.AddError("medq19", "Please Answer this question");
}
if(Request["medq20"].IsEmpty()){
ModelState.AddError("medq20", "Please Answer this question");
}
if(Request["alcohol"].IsEmpty()){
ModelState.AddError("alcohol", "Please Answer this question");
}
if(Request["medication"].IsEmpty()){
ModelState.AddError("medication", "Please Answer this question");
}
if(!ModelState.IsValid){
ModelState.AddFormError("Question 1-17 and questions with * are mandatory.");
} else {
//check if the user have any previous medical record.
var firstMedical = false;
var sql="SELECT * FROM Medical WHERE CDSID = @0";
var myMedical = db.QuerySingle(sql1, myCDSID);
if (myMedical ==null){
firstMedical= true;
} else {
firstMedical= false;
}
if (firstMedical){
//if all the medical data is filled in, run sql1 to store all the answer into a database.
var sql10 = "INSERT INTO Medical (Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Alcohol, Medication, Details, CDSID) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23)";
var medquestionnaire = new[]{Request["medq1"], Request["medq2"], Request["medq3"], Request["medq4"], Request["medq5"], Request["medq6"], Request["medq7"], Request["medq8"], Request["medq9"], Request["medq10"], Request["medq11"], Request["medq12"], Request["medq13"], Request["medq14"], Request["medq15"], Request["medq16"], Request["medq17"], Request["medq18"], Request["medq19"], Request["medq20"], Request["alcohol"], Request["medication"], Request["details"], myCDSID};
db.Execute(sql10, medquestionnaire);
//Next check if the application is first time or renewal.
var firstApplication = false;
var sql5 = "SELECT * FROM Permit Where CDSID = @0";
var myPermit = db.QuerySingle(sql5, myCDSID);
if (myPermit == null) {
// if no permit record exists for the person, create one (largely empty for now)
// if no exist, this means that this is the first application of the person
// he or she has no permit and driving licence information in the system (i.e. the Permit table)
// we create a record (largely empty one) for later update to complete the needed information
var sql6 = "INSERT INTO Permit (CDSID) values (@0)";
db.Execute(sql6, myCDSID);
}
var sql7 = "SELECT * FROM Permit Where CDSID = @0";
var prePermit = db.QuerySingle(sql7, myCDSID);
var preClass = prePermit.Class;
var preCategory = prePermit.Category;
var preDrivingLicenceNo =prePermit.DrivingLicenceNo;
var preLicenceStartDate = prePermit.LicenceStartDate;
var preLicenceValidUntil = prePermit.LicenceValidUntil;
var preLicenceGroup = prePermit.LicenceGroup;
if (prePermit.DrivingLicenceNo == null && prePermit.Class == null) {
firstApplication = true;
} else {
firstApplication = false;
}
if (firstApplication) {
// update the permit record for the applicant, as this is the first application of the person
// his or her permit record had not data before this update. After this only the penalty information
// is missing (there should be another separated function to update the penalty information).
var sql8 = @"UPDATE Permit SET Class = @0, Category = @1, DrivingLicenceNo = @2, LicenceGroup = @3,
LicenceStartDate = @4, LicenceValidUntil = @5, LastAccidentDate = GetDate()-GetDate(), PenaltyPoints = 0, Disqualification = 0 Where CDSID = @6";
var para = new[]{applyClass1, applyCategory1, applyLicense, applyGroup, applyFrom, applyTo, myCDSID};
db.Execute(sql8, para);
}
// if all inputs are valid, use the inputs to update the Permit record and create a PermitApp record for the person
// create a PermitApp record (application form) for managers to check and sign
var sql9 = "INSERT INTO PermitApp (CDSID, Renew, RPClass, RPCategory, AppDate) VALUES (@0, @1, @2, @3, GetDate())";
var parameters = new[]{myCDSID, Convert.ToInt32(!firstApplication), applyClass, applyCategory};
db.Execute(sql9, parameters);
}else{
var sql2 = "UPDATE Medical SET Q1=@0, Q2=@1, Q3=@2, Q4=@3, Q5=@4, Q6=@5, Q7=@6, Q8=@7, Q9=@8, Q10=@9, Q11=@10, Q12=@11, Q13=@12, Q14=@13, Q15=@14, Q16=@15, Q17=@16, Q18=@17, Q19=@18, Q20=@19, Alcohol=@20, Medication=@21, Details=@22 WHERE CDSID=@23";
var updquestionnaire = new[]{q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, alcohol, medication, details, myCDSID};
db.Execute(sql2,updquestionnaire);
@*var sql3 = "SELECT MedicalId From Medical WHERE CDSID=@0";
var medical = db.QuerySingle(sql3, myCDSID);
var myMedicalId = medical.MedicalId;
var sql4 = "UPDATE Users SET MedicalId = @0; WHERE UserName=@1";
db.Execute(sql4, myMedicalId, myCDSID);
// after the creation, run the query in apply page.
Response.Redirect("~/Applications.cshtml");*@
//Next check if the application is first time or renewal.
var firstApplication = false;
var sql5 = "SELECT * FROM Permit Where CDSID = @0";
var myPermit = db.QuerySingle(sql5, myCDSID);
if (myPermit == null) {
// if no permit record exists for the person, create one (largely empty for now)
// if no exist, this means that this is the first application of the person
// he or she has no permit and driving licence information in the system (i.e. the Permit table)
// we create a record (largely empty one) for later update to complete the needed information
var sql6 = "INSERT INTO Permit (CDSID) values (@0)";
db.Execute(sql6, myCDSID);
}
var sql7 = "SELECT * FROM Permit Where CDSID = @0";
var prePermit = db.QuerySingle(sql7, myCDSID);
var preClass = prePermit.Class;
var preCategory = prePermit.Category;
var preDrivingLicenceNo =prePermit.DrivingLicenceNo;
var preLicenceStartDate = prePermit.LicenceStartDate;
var preLicenceValidUntil = prePermit.LicenceValidUntil;
var preLicenceGroup = prePermit.LicenceGroup;
if (prePermit.DrivingLicenceNo == null && prePermit.Class == null) {
firstApplication = true;
} else {
firstApplication = false;
}
if (firstApplication) {
// update the permit record for the applicant, as this is the first application of the person
// his or her permit record had not data before this update. After this only the penalty information
// is missing (there should be another separated function to update the penalty information).
var sql8 = @"UPDATE Permit SET Class = @0, Category = @1, DrivingLicenceNo = @2, LicenceGroup = @3,
LicenceStartDate = @4, LicenceValidUntil = @5, LastAccidentDate = GetDate()-GetDate(), PenaltyPoints = 0, Disqualification = 0 Where CDSID = @6";
var para = new[]{applyClass1, applyCategory1, applyLicense, applyGroup, applyFrom, applyTo, myCDSID};
db.Execute(sql8, para);
}
// if all inputs are valid, use the inputs to update the Permit record and create a PermitApp record for the person
// create a PermitApp record (application form) for managers to check and sign
var sql9 = "INSERT INTO PermitApp (CDSID, Renew, RPClass, RPCategory, AppDate) VALUES (@0, @1, @2, @3, GetDate())";
var parameters = new[]{myCDSID, Convert.ToInt32(!firstApplication), applyClass, applyCategory};
db.Execute(sql9, parameters);
}
}
}
}
@section header{
Medical Questionnaire
}
@Html.ValidationSummary(true)
<form method="post" action="@Href("~/Questionnaire")">
<table border="1" id="questionnaire" >
<tr>
<td colspan="4">Do you currently have:</td>
</tr>
<tr>
<td width="33">1.</td>
<td width="491">Heart or circulatory problems including: high blood pressure, heart attack, angina, heart murmur, heart failure, palpitations, circulatory problemseg. whitefinger, blocked arteries, stroke aneurysm.</td>
<td width="68"><input name="medq1" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td>
<td width="78"><input name="medq1" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>2.</td>
<td>Chest problems including asthma, bronchitis, pneumothorax, shortness of breath on mild exertion eg. unable to walk at a normal pace on the flat.</td>
<td><input name="medq2" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq2" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>3.</td>
<td>Recurrent nausea/vomiting/ diarrhoea, stomach/abdominal pain, ulcers, gall bladder problems, pancreatitis, liver failure, hepatitis, other bowel problems.</td>
<td><input name="medq3" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq3" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>4.</td>
<td>Kidney failure, kidney stones, urinary tract infections or other kidney/bladder problems.</td>
<td><input name="medq4" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq4" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>5.</td>
<td>Diabetes, thyroid problems, Addison’s disease, Cushing’s syndrome, immune deficiency, blood disorders including anaemia/sickle cell disease & blood clotting disorders such as DVT, Pulmonary Embolism.</td>
<td><input name="medq5" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq5" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>6.</td>
<td>Any form of cancer?</td>
<td><input name="medq6" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq6" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>7.</td>
<td>Epilepsy, "fits or blackouts", "dizzy turns", neurological disease eg Multiple Sclerosis, Motor neurone disease, Parkinsons Disease, brain tumour, brain surgery, severe head injury.</td>
<td><input name="medq7" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq7" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>8.</td>
<td>Problems with your back, neck, other joints or muscles of sufficient severity to affect your ability to drive or control a vehicle.</td>
<td><input name="medq8" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq8" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>9.</td>
<td>Skin problems including eczema, psoriasis, severe acne.</td>
<td><input name="medq9" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq9" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>10.</td>
<td>Allergies including hay fever.</td>
<td><input name="medq10" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq10" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>11.</td>
<td>Ear nose or throat problems including discharging ears, recurrent sinusitis or difficulty hearing.</td>
<td><input name="medq11" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td>
<td><input name="medq11" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>12.</td>
<td>Mental health problems including anxiety, depression, schizophrenia, or any condition requiring referral to a psychiatrist.</td>
<td><input name="medq12" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq12" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>13.</td>
<td>Drug or alcohol abuse or dependency.</td>
<td><input name="medq13" id="yes" type="radio" value="yes"onclick="displayTextBox()" /><label for="yes"> Yes </label></td>
<td><input name="medq13" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>14.</td>
<td>Sleep disorders including sleep apnoea.</td>
<td><input name="medq14" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq14" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>15.</td>
<td>Any difficulties with shift working.</td>
<td><input name="medq15" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq15" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>16.</td>
<td>Can you read a number plate at 20 metres using glasses/contact lenses if needed.</td>
<td><input name="medq16" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq16" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td>17.</td>
<td>Are you able to see clearly to either side when looking straight ahead?</td>
<td><input name="medq17" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td>
<td><input name="medq17" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td colspan="2">Are you receiving any medical treatment or have you received any within the past five years<font color="#FF0000">*</font></td>
<td><input name="medq18" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq18" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td colspan="2">Have you any other medical problems which you believe could impact you undertaking this job<font color="#FF0000">*</font></td>
<td><input name="medq19" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq19" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td colspan="2">Do You smoke?<font color="#FF0000">*</font></td>
<td><input name="medq20" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medq20" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr>
<td colspan="2">How many units of alcohol do you drink per week? (A unit is 1/2 pt of beer, single shot of spirit, normal sized glass of wine)</td>
<td colspan="2"><input name="alcohol" id="alcohol" type="text"/></td>
</tr>
<tr>
<td colspan="2">Are you currently on any medication? Include purchased or prescribed.<font color="#FF0000">*</font></td>
<td><input name="medication" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td><input name="medication" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
</tr>
<tr >
<td id="addmed" colspan="4" style="display:none;">
<p>If you have a yes in any the questions, please type in the details here.<br/>
<textarea name="details" id="addmedtext" cols="70" rows="4" placeholder="Please give details with dates"></textarea></p>
</td>
</tr>
<tr>
<td colspan="4" style="text-align:center;"><input class="button" style="margin:0px auto;" type="submit" name="applynextbutton" value="SUBMIT" /></td>
</tr>
</table>
</form>
hubertjiang
0 Points
21 Posts
Re: Can someone tell me what is this error means?? Webmatrix is getting on my nerves.
Apr 21, 2012 11:04 PM|LINK
I think i am going crazy...now is the worst no error message but the query just don execute.
@{ var applyLicense = Session["license"]; var applyFrom = Session["from"]; var applyTo = Session["to"]; var applyGroup = Session["group"]; var applyClass1 = Session["class1"]; var applyCategory1 = Session["category1"]; var applyClass = Session["class"]; var applyCategory = Session["category"]; Page.Title = "Medical Questionnaire"; var id = WebSecurity.GetUserId(WebSecurity.CurrentUserName); var db = Database.Open("Test"); var username = WebSecurity.CurrentUserName; var sql1 = "SELECT * FROM Users Where UserName = @0"; var me = db.QuerySingle(sql1, username); var myFirstName = me.FirstName; var myLastName = me.LastName; var myCDSID = me.UserName; //this gives myCDSID the data type in the database // Driving licence input variables used for preserve the inputs when server side validation fails, // such that users do not need to re-enter those fields :) // The input values of the checkboxes and radio buttons are preserved using the Helpers.checked function // Without preserving the inputs, if the server side validation fails, all user inputs will be lost and // the users have to enter them again :( @* the page is first accessed using the defaul http "get" method *@ @* when the form is submitted using a http "post" method, the following *@ @* within if(IsPost) will be prcessed on the server side, and after *@ @* the processing, the resultant page will be return to the user/client *@ var q1 = Request["medq1"]; var q2 = Request["medq2"]; var q3 = Request["medq3"]; var q4 = Request["medq4"]; var q5 = Request["medq5"]; var q6 = Request["medq6"]; var q7 = Request["medq7"]; var q8 = Request["medq8"]; var q9 = Request["medq9"]; var q10 = Request["medq10"]; var q11 = Request["medq11"]; var q12 = Request["medq12"]; var q13 = Request["medq13"]; var q14 = Request["medq14"]; var q15 = Request["medq15"]; var q16 = Request["medq16"]; var q17 = Request["medq17"]; var q18 = Request["medq18"]; var q19 = Request["medq19"]; var q20 = Request["medq20"]; var alcohol = Request["alcohol"]; var medication = Request["medication"]; var details = Request["details"]; if(IsPost){ if(Request["medq1"].IsEmpty()){ ModelState.AddError("medq1", "Please Answer this question"); } if(Request["medq2"].IsEmpty()){ ModelState.AddError("medq2", "Please Answer this question"); } if(Request["medq3"].IsEmpty()){ ModelState.AddError("medq3", "Please Answer this question"); } if(Request["medq4"].IsEmpty()){ ModelState.AddError("medq4", "Please Answer this question"); } if(Request["medq5"].IsEmpty()){ ModelState.AddError("medq5", "Please Answer this question"); } if(Request["medq6"].IsEmpty()){ ModelState.AddError("medq6", "Please Answer this question"); } if(Request["medq7"].IsEmpty()){ ModelState.AddError("medq7", "Please Answer this question"); } if(Request["medq8"].IsEmpty()){ ModelState.AddError("medq8", "Please Answer this question"); } if(Request["medq9"].IsEmpty()){ ModelState.AddError("medq9", "Please Answer this question"); } if(Request["medq10"].IsEmpty()){ ModelState.AddError("medq10", "Please Answer this question"); } if(Request["medq11"].IsEmpty()){ ModelState.AddError("medq11", "Please Answer this question"); } if(Request["medq12"].IsEmpty()){ ModelState.AddError("medq12", "Please Answer this question"); } if(Request["medq13"].IsEmpty()){ ModelState.AddError("medq13", "Please Answer this question"); } if(Request["medq14"].IsEmpty()){ ModelState.AddError("medq14", "Please Answer this question"); } if(Request["medq15"].IsEmpty()){ ModelState.AddError("medq15", "Please Answer this question"); } if(Request["medq16"].IsEmpty()){ ModelState.AddError("medq16", "Please Answer this question"); } if(Request["medq17"].IsEmpty()){ ModelState.AddError("medq17", "Please Answer this question"); } if(Request["medq18"].IsEmpty()){ ModelState.AddError("medq18", "Please Answer this question"); } if(Request["medq19"].IsEmpty()){ ModelState.AddError("medq19", "Please Answer this question"); } if(Request["medq20"].IsEmpty()){ ModelState.AddError("medq20", "Please Answer this question"); } if(Request["alcohol"].IsEmpty()){ ModelState.AddError("alcohol", "Please Answer this question"); } if(Request["medication"].IsEmpty()){ ModelState.AddError("medication", "Please Answer this question"); } if(!ModelState.IsValid){ ModelState.AddFormError("Question 1-17 and questions with * are mandatory."); } else { //check if the user have any previous medical record. var firstMedical = false; var sql="SELECT * FROM Medical WHERE CDSID = @0"; var myMedical = db.QuerySingle(sql1, myCDSID); if (myMedical ==null){ firstMedical= true; } else { firstMedical= false; } if (firstMedical){ //if all the medical data is filled in, run sql1 to store all the answer into a database. var sql10 = "INSERT INTO Medical (Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Alcohol, Medication, Details, CDSID) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23)"; var medquestionnaire = new[]{Request["medq1"], Request["medq2"], Request["medq3"], Request["medq4"], Request["medq5"], Request["medq6"], Request["medq7"], Request["medq8"], Request["medq9"], Request["medq10"], Request["medq11"], Request["medq12"], Request["medq13"], Request["medq14"], Request["medq15"], Request["medq16"], Request["medq17"], Request["medq18"], Request["medq19"], Request["medq20"], Request["alcohol"], Request["medication"], Request["details"], myCDSID}; db.Execute(sql10, medquestionnaire); //Next check if the application is first time or renewal. var firstApplication = false; var sql5 = "SELECT * FROM Permit Where CDSID = @0"; var myPermit = db.QuerySingle(sql5, myCDSID); if (myPermit == null) { // if no permit record exists for the person, create one (largely empty for now) // if no exist, this means that this is the first application of the person // he or she has no permit and driving licence information in the system (i.e. the Permit table) // we create a record (largely empty one) for later update to complete the needed information var sql6 = "INSERT INTO Permit (CDSID) values (@0)"; db.Execute(sql6, myCDSID); } var sql7 = "SELECT * FROM Permit Where CDSID = @0"; var prePermit = db.QuerySingle(sql7, myCDSID); var preClass = prePermit.Class; var preCategory = prePermit.Category; var preDrivingLicenceNo =prePermit.DrivingLicenceNo; var preLicenceStartDate = prePermit.LicenceStartDate; var preLicenceValidUntil = prePermit.LicenceValidUntil; var preLicenceGroup = prePermit.LicenceGroup; if (prePermit.DrivingLicenceNo == null && prePermit.Class == null) { firstApplication = true; } else { firstApplication = false; } if (firstApplication) { // update the permit record for the applicant, as this is the first application of the person // his or her permit record had not data before this update. After this only the penalty information // is missing (there should be another separated function to update the penalty information). var sql8 = @"UPDATE Permit SET Class = @0, Category = @1, DrivingLicenceNo = @2, LicenceGroup = @3, LicenceStartDate = @4, LicenceValidUntil = @5, LastAccidentDate = GetDate()-GetDate(), PenaltyPoints = 0, Disqualification = 0 Where CDSID = @6"; var para = new[]{applyClass1, applyCategory1, applyLicense, applyGroup, applyFrom, applyTo, myCDSID}; db.Execute(sql8, para); } // if all inputs are valid, use the inputs to update the Permit record and create a PermitApp record for the person // create a PermitApp record (application form) for managers to check and sign var sql9 = "INSERT INTO PermitApp (CDSID, Renew, RPClass, RPCategory, AppDate) VALUES (@0, @1, @2, @3, GetDate())"; var parameters = new[]{myCDSID, Convert.ToInt32(!firstApplication), applyClass, applyCategory}; db.Execute(sql9, parameters); }else{ var sql2 = "UPDATE Medical SET Q1=@0, Q2=@1, Q3=@2, Q4=@3, Q5=@4, Q6=@5, Q7=@6, Q8=@7, Q9=@8, Q10=@9, Q11=@10, Q12=@11, Q13=@12, Q14=@13, Q15=@14, Q16=@15, Q17=@16, Q18=@17, Q19=@18, Q20=@19, Alcohol=@20, Medication=@21, Details=@22 WHERE CDSID=@23"; var updquestionnaire = new[]{q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, alcohol, medication, details, myCDSID}; db.Execute(sql2,updquestionnaire); @*var sql3 = "SELECT MedicalId From Medical WHERE CDSID=@0"; var medical = db.QuerySingle(sql3, myCDSID); var myMedicalId = medical.MedicalId; var sql4 = "UPDATE Users SET MedicalId = @0; WHERE UserName=@1"; db.Execute(sql4, myMedicalId, myCDSID); // after the creation, run the query in apply page. Response.Redirect("~/Applications.cshtml");*@ //Next check if the application is first time or renewal. var firstApplication = false; var sql5 = "SELECT * FROM Permit Where CDSID = @0"; var myPermit = db.QuerySingle(sql5, myCDSID); if (myPermit == null) { // if no permit record exists for the person, create one (largely empty for now) // if no exist, this means that this is the first application of the person // he or she has no permit and driving licence information in the system (i.e. the Permit table) // we create a record (largely empty one) for later update to complete the needed information var sql6 = "INSERT INTO Permit (CDSID) values (@0)"; db.Execute(sql6, myCDSID); } var sql7 = "SELECT * FROM Permit Where CDSID = @0"; var prePermit = db.QuerySingle(sql7, myCDSID); var preClass = prePermit.Class; var preCategory = prePermit.Category; var preDrivingLicenceNo =prePermit.DrivingLicenceNo; var preLicenceStartDate = prePermit.LicenceStartDate; var preLicenceValidUntil = prePermit.LicenceValidUntil; var preLicenceGroup = prePermit.LicenceGroup; if (prePermit.DrivingLicenceNo == null && prePermit.Class == null) { firstApplication = true; } else { firstApplication = false; } if (firstApplication) { // update the permit record for the applicant, as this is the first application of the person // his or her permit record had not data before this update. After this only the penalty information // is missing (there should be another separated function to update the penalty information). var sql8 = @"UPDATE Permit SET Class = @0, Category = @1, DrivingLicenceNo = @2, LicenceGroup = @3, LicenceStartDate = @4, LicenceValidUntil = @5, LastAccidentDate = GetDate()-GetDate(), PenaltyPoints = 0, Disqualification = 0 Where CDSID = @6"; var para = new[]{applyClass1, applyCategory1, applyLicense, applyGroup, applyFrom, applyTo, myCDSID}; db.Execute(sql8, para); } // if all inputs are valid, use the inputs to update the Permit record and create a PermitApp record for the person // create a PermitApp record (application form) for managers to check and sign var sql9 = "INSERT INTO PermitApp (CDSID, Renew, RPClass, RPCategory, AppDate) VALUES (@0, @1, @2, @3, GetDate())"; var parameters = new[]{myCDSID, Convert.ToInt32(!firstApplication), applyClass, applyCategory}; db.Execute(sql9, parameters); } } } } @section header{ Medical Questionnaire } @Html.ValidationSummary(true) <form method="post" action="@Href("~/Questionnaire")"> <table border="1" id="questionnaire" > <tr> <td colspan="4">Do you currently have:</td> </tr> <tr> <td width="33">1.</td> <td width="491">Heart or circulatory problems including: high blood pressure, heart attack, angina, heart murmur, heart failure, palpitations, circulatory problemseg. whitefinger, blocked arteries, stroke aneurysm.</td> <td width="68"><input name="medq1" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td> <td width="78"><input name="medq1" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>2.</td> <td>Chest problems including asthma, bronchitis, pneumothorax, shortness of breath on mild exertion eg. unable to walk at a normal pace on the flat.</td> <td><input name="medq2" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq2" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>3.</td> <td>Recurrent nausea/vomiting/ diarrhoea, stomach/abdominal pain, ulcers, gall bladder problems, pancreatitis, liver failure, hepatitis, other bowel problems.</td> <td><input name="medq3" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq3" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>4.</td> <td>Kidney failure, kidney stones, urinary tract infections or other kidney/bladder problems.</td> <td><input name="medq4" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq4" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>5.</td> <td>Diabetes, thyroid problems, Addison’s disease, Cushing’s syndrome, immune deficiency, blood disorders including anaemia/sickle cell disease & blood clotting disorders such as DVT, Pulmonary Embolism.</td> <td><input name="medq5" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq5" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>6.</td> <td>Any form of cancer?</td> <td><input name="medq6" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq6" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>7.</td> <td>Epilepsy, "fits or blackouts", "dizzy turns", neurological disease eg Multiple Sclerosis, Motor neurone disease, Parkinsons Disease, brain tumour, brain surgery, severe head injury.</td> <td><input name="medq7" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq7" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>8.</td> <td>Problems with your back, neck, other joints or muscles of sufficient severity to affect your ability to drive or control a vehicle.</td> <td><input name="medq8" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq8" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>9.</td> <td>Skin problems including eczema, psoriasis, severe acne.</td> <td><input name="medq9" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq9" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>10.</td> <td>Allergies including hay fever.</td> <td><input name="medq10" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq10" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>11.</td> <td>Ear nose or throat problems including discharging ears, recurrent sinusitis or difficulty hearing.</td> <td><input name="medq11" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td> <td><input name="medq11" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>12.</td> <td>Mental health problems including anxiety, depression, schizophrenia, or any condition requiring referral to a psychiatrist.</td> <td><input name="medq12" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq12" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>13.</td> <td>Drug or alcohol abuse or dependency.</td> <td><input name="medq13" id="yes" type="radio" value="yes"onclick="displayTextBox()" /><label for="yes"> Yes </label></td> <td><input name="medq13" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>14.</td> <td>Sleep disorders including sleep apnoea.</td> <td><input name="medq14" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq14" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>15.</td> <td>Any difficulties with shift working.</td> <td><input name="medq15" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq15" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>16.</td> <td>Can you read a number plate at 20 metres using glasses/contact lenses if needed.</td> <td><input name="medq16" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq16" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td>17.</td> <td>Are you able to see clearly to either side when looking straight ahead?</td> <td><input name="medq17" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td> <td><input name="medq17" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td colspan="2">Are you receiving any medical treatment or have you received any within the past five years<font color="#FF0000">*</font></td> <td><input name="medq18" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq18" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td colspan="2">Have you any other medical problems which you believe could impact you undertaking this job<font color="#FF0000">*</font></td> <td><input name="medq19" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq19" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td colspan="2">Do You smoke?<font color="#FF0000">*</font></td> <td><input name="medq20" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medq20" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr> <td colspan="2">How many units of alcohol do you drink per week? (A unit is 1/2 pt of beer, single shot of spirit, normal sized glass of wine)</td> <td colspan="2"><input name="alcohol" id="alcohol" type="text"/></td> </tr> <tr> <td colspan="2">Are you currently on any medication? Include purchased or prescribed.<font color="#FF0000">*</font></td> <td><input name="medication" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td> <td><input name="medication" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td> </tr> <tr > <td id="addmed" colspan="4" style="display:none;"> <p>If you have a yes in any the questions, please type in the details here.<br/> <textarea name="details" id="addmedtext" cols="70" rows="4" placeholder="Please give details with dates"></textarea></p> </td> </tr> <tr> <td colspan="4" style="text-align:center;"><input class="button" style="margin:0px auto;" type="submit" name="applynextbutton" value="SUBMIT" /></td> </tr> </table> </form>This query:
var sql10 = "INSERT INTO Medical (Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Alcohol, Medication, Details, CDSID) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23)"; var medquestionnaire = new[]{Request["medq1"], Request["medq2"], Request["medq3"], Request["medq4"], Request["medq5"], Request["medq6"], Request["medq7"], Request["medq8"], Request["medq9"], Request["medq10"], Request["medq11"], Request["medq12"], Request["medq13"], Request["medq14"], Request["medq15"], Request["medq16"], Request["medq17"], Request["medq18"], Request["medq19"], Request["medq20"], Request["alcohol"], Request["medication"], Request["details"], myCDSID}; db.Execute(sql10, medquestionnaire);just don't want to execute!! Damn webmatrix...How i wish i can just use dreamweaver and php!! so much simpler