Advertisement
UHaroon

Untitled

Apr 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 24.27 KB | None | 0 0
  1. unit UnitAddStudent;
  2.  
  3. interface
  4.  
  5.  
  6. uses
  7.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  8.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  9.   Data.Win.ADODB, MmSystem;
  10.  
  11.  
  12.  
  13. type
  14.   TfrmAddStudent = class(TForm)
  15.     lblAddStudent: TLabel;
  16.     ledtStudentNumber: TLabeledEdit;
  17.     ledtFirstName: TLabeledEdit;
  18.     ledtLastName: TLabeledEdit;
  19.     ledtCandidateNumber: TLabeledEdit;
  20.     rgStudentDetails: TRadioGroup;
  21.     rgAcademicYear: TRadioGroup;
  22.     ledtTeacherName: TLabeledEdit;
  23.     ledtStudentEmail: TLabeledEdit;
  24.     ledtParentGuardianEmail: TLabeledEdit;
  25.     btnBackToGroupProfiles: TButton;
  26.     btnCreateStudent: TButton;
  27.     rbNoASQaulfication: TRadioButton;
  28.     rgAcademicInformation: TRadioGroup;
  29.     cboTargetGradeInput: TComboBox;
  30.     cboPastASQualification: TComboBox;
  31.     lblPastASQualification: TLabel;
  32.     lblTargetGrade: TLabel;
  33.     cboASSelectGroup: TComboBox;
  34.     btnGCSESubjects: TButton;
  35.     cboGCSEGrade1: TComboBox;
  36.     cboGCSEGrade2: TComboBox;
  37.     lblGCSESubject1: TLabel;
  38.     lblGCSESubject2: TLabel;
  39.     lblGPGroupName: TLabel;
  40.     procedure btnBackToGroupProfilesClick(Sender: TObject);
  41.     procedure btnCreateStudentClick(Sender: TObject);
  42.     procedure ledtStudentNumberKeyPress(Sender: TObject; var Key: Char);
  43.     procedure ledtCandidateNumberKeyPress(Sender: TObject; var Key: Char);
  44.     procedure ledtFirstNameKeyPress(Sender: TObject; var Key: Char);
  45.     procedure ledtLastNameKeyPress(Sender: TObject; var Key: Char);
  46.     procedure ledtTeacherNameKeyPress(Sender: TObject; var Key: Char);
  47.     procedure rgAcademicYearClick(Sender: TObject);
  48.     procedure ledtGroupNameKeyPress(Sender: TObject; var Key: Char);
  49.     procedure FormShow(Sender: TObject);
  50.     procedure btnGCSESubjectsClick(Sender: TObject);
  51.   private
  52.     { Private declarations }
  53.   public
  54.     { Public declarations }
  55.   end;
  56.  
  57. var
  58.   frmAddStudent: TfrmAddStudent;
  59.  
  60.  
  61. implementation
  62.  
  63. uses UnitGroupProfiles, UnitdmDatabaseComponents, UnitGCSESubjects;
  64.  
  65. {$R *.dfm}
  66.  
  67. procedure ExistanceCheck(SQLText, FieldName, Fine: string; Ledt : TLabeledEdit; DataExists : boolean);
  68. begin
  69.   with dmDatabaseComponents.adoExistanceCheck do
  70.   begin
  71.     Close;
  72.     SQL.Clear;
  73.     SQL.Text := SQLText;
  74.     ExecSQL;
  75.     Open;
  76.  
  77.     {  ----------  Traverse through the table  ----------  }
  78.     First;  //  Start at the first record
  79.     while not EoF do
  80.     begin
  81.       if Ledt.Text = FieldByName(FieldName).AsString then
  82.       begin
  83.         DataExists := True;
  84.         Break;  //  Once item stop the loop
  85.         Fine := 'Fine'
  86.       end
  87.       else
  88.       begin
  89.         Next;  //  If the student number does not match move to the next record
  90.       end;
  91.     end;
  92.   end;
  93. end;
  94.  
  95. procedure ErrorOutputComboBox(ErrorMessage : string; Cbo : TComboBox);
  96. begin
  97.   {  ----------  Highlight the input with an error  ----------  }
  98.   Cbo.Color := clRed;  // Turn the input into a red color
  99.   Cbo.Font.Color := clWhite;  // Turn the text into the input to white
  100.   PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  101.   Showmessage(ErrorMessage);  //  Output an error message
  102.   {  ----------  Remove the highlight  ----------}
  103.   Cbo.Color := clWhite;  // Make the input white again
  104.   Cbo.Font.Color := clBlack;  //  Make the font black again
  105. end;
  106.  
  107. procedure ErrorOutputLabeledEdit(ErrorMessage : string; Ledt : TLabeledEdit);
  108. begin
  109.   {  ----------  Highlight the input with an error  ----------  }
  110.   Ledt.Color := clRed;  // Turn the input into a red color
  111.   ledt.Font.Color := clWhite;  // Turn the text into the input to white
  112.   PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  113.   Showmessage(ErrorMessage);  //  Output an error message
  114.   {  ----------  Remove the highlight  ----------}
  115.   Ledt.Color := clWhite;  // Make the input white again
  116.   ledt.Font.Color := clBlack;  //  Make the font black again
  117. end;
  118.  
  119. procedure CorrectKeyPressedName(KeyIn : Char; Field : string);
  120. begin
  121.   if (not (KeyIn in ['A'..'Z','a'..'z', #8])) then // If a letter key is not pressed
  122.   begin
  123.     PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  124.     Showmessage('ERROR: '+Field+' must be a letters only');  //  Produce an error message
  125.     KeyIn := #0; // Remove the last character
  126.   end; // end if
  127. end;
  128.  
  129. procedure CorrectKeyPressedNumerical(KeyIn : Char; Field : string);
  130. begin
  131.    if not (KeyIn in ['0'..'9', #8]) then // If a letter pressed is pressed
  132.    begin
  133.       PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  134.       Showmessage('ERROR: '+Field+' must only be numerical');  // Produce an error message
  135.       KeyIn := #0; // Remove the last character
  136.    end; // end if
  137. end;
  138.  
  139. procedure TfrmAddStudent.btnBackToGroupProfilesClick(Sender: TObject);
  140. begin
  141.   frmAddStudent.Hide;
  142.   frmGroupProfile.Show;
  143. end;
  144.  
  145. function IsEmailValid(Email : string): Boolean;
  146.  
  147.   function CheckAllowed(EmailAdress : string): Boolean;
  148.   var
  149.     i : integer;
  150.   begin
  151.     Result := False;
  152.     // Loop through the entire string
  153.     for i := 1 to Length(EmailAdress) do
  154.       //  If the string does not contain these charaters
  155.       if not (EmailAdress[i] in ['A'..'Z','a'..'z','0'..'9','_','-','.']) then
  156.       begin
  157.         //  Make the email address invalid
  158.         Result := False
  159.       end  //  End of if statement
  160.       else
  161.       begin
  162.         //  Make the email address invalid
  163.         Result := True;
  164.       end;  //  End of the else statement
  165.   end;  // End of checked allowed
  166.  
  167. var
  168.   i : integer;
  169.   //  Email variables
  170.   NamePart, ServerPart : string;
  171. begin
  172.   Result := False;
  173.   //  Find the intial position of the at value
  174.   i := Pos('@', Email);
  175.   //  If it has not been included...
  176.   if i = 0 then
  177.   begin
  178.     //  Returen that the email is not valid
  179.     Result := False;
  180.   end  //  End of the if statement
  181.   //  Otherwise...
  182.  
  183.   else
  184.   begin
  185.     //  ...Find the name part of the email
  186.     NamePart:= Copy(Email, 1, i-1);
  187.     //  ...Find the server part
  188.     ServerPart:= Copy(Email, i+1, Length(Email));
  189.     // If the name was not included or server is less than 5 characters
  190.     if (Length(NamePart)=0) or (Length(ServerPart)<5) then
  191.     begin
  192.       //  Returen that the email is not valid
  193.       Result := False;
  194.     end  //  end of the if statement statement
  195.     // Otherwise...
  196.     else
  197.     begin
  198.  
  199.       //  Find the position of the . in the server
  200.       i := Pos('.', ServerPart);
  201.       //  If the . was not included
  202.       if (i = 0) or (i > (Length(ServerPart)-2)) then
  203.       begin
  204.         //  Returen that the email is not valid
  205.         Result := False
  206.       end  //  End of the if statement
  207.  
  208.  
  209.       // Otherwise
  210.       else
  211.       begin
  212.         {
  213.           Check to see if the name part and the server part
  214.           contain valid characters
  215.         }
  216.         //
  217.         Result := CheckAllowed(NamePart) and CheckAllowed(ServerPart);
  218.       end;  //  End of the else statement
  219.     end;  //  End of the else statement
  220.   end;  //  End of the else statement
  221. end;
  222.  
  223. procedure TfrmAddStudent.btnCreateStudentClick(Sender: TObject);
  224. var
  225.   // Existance Check variables
  226.   StudentNumberExists, StudentEmailExists, ParentGuardianEmailExists : Boolean;
  227.   ExistanceCheckSQL, ExistanceCheckFieldName : string;
  228.  
  229.   // Email format check variables
  230.   x : integer;
  231.   ValidEmailFormat : Boolean;
  232.  
  233.   ErrorMessagePram, Fine : string;
  234. begin
  235.   {  ----------  Carry out the format check for...  ----------  }
  236.   //  ...For the student email
  237.   IsEmailValid(ledtStudentEmail.Text);
  238.   //  ...For the parent guardian email
  239.   IsEmailValid(ledtParentGuardianEmail.Text);
  240.   {  ----------  Carry out any existance checks  ----------  }
  241.   with dmDatabaseComponents.adoExistanceCheck do
  242.   begin
  243.     Close;
  244.     SQL.Text;  //  Initialise the SQL
  245.     //  Set the SQL
  246.     SQL.Text :='SELECT * FROM [StudentDetails]';
  247.     ExecSQL;  //  Execute the SQL
  248.     Open;
  249.  
  250.     First;  //  Start at the first record
  251.     //  Traverse through the table
  252.     while not Eof do
  253.     begin
  254.       // if the student number matchs the student number at a particular record
  255.       if ledtStudentNumber.Text = FieldByName('StudentNumber').AsString then
  256.       begin
  257.         //  The student exists
  258.         StudentNumberExists := True;
  259.         Break;
  260.       end  //  End of if statement
  261.       else
  262.         Next;  //  Move on to the next record
  263.     end;  //  End of while loop
  264.   end;  //  End of with
  265.  
  266.   //
  267.   {  ----------  Carry out any existance checks  ----------  }
  268.   with dmDatabaseComponents.adoExistanceCheck do
  269.   begin
  270.     Close;
  271.     SQL.Text :='SELECT * FROM [StudentDetails]';
  272.     ExecSQL;
  273.     Open;
  274.  
  275.     First;
  276.     while not Eof do
  277.     begin
  278.       if ledtStudentEmail.Text = FieldByName('StudentEmail').AsString then
  279.       begin
  280.         StudentEmailExists := True;
  281.         Break;
  282.       end
  283.       else
  284.         Next;
  285.     end;
  286.   end;
  287.  
  288.   //
  289.   {  ----------  Carry out any existance checks  ----------  }
  290.   with dmDatabaseComponents.adoExistanceCheck do
  291.   begin
  292.     Close;
  293.     SQL.Text :='SELECT * FROM [StudentDetails]';
  294.     ExecSQL;
  295.     Open;
  296.  
  297.     First;
  298.     while not Eof do
  299.     begin
  300.       if ledtParentGuardianEmail.Text = FieldByName('ParentGuardianEmail').AsString then
  301.       begin
  302.         ParentGuardianEmailExists := True;
  303.         Break;
  304.       end
  305.       else
  306.         Next;
  307.     end;
  308.   end;
  309.   { ----------  Create A Student Profile  ---------- }
  310.  
  311.   if (lblGCSESubject1.Caption = '') OR (lblGCSESubject2.Caption = '') then
  312.   begin
  313.     Showmessage('Please add a GCSE Subjects');
  314.   end
  315.  
  316.   { ----------  Student Number Validation  ---------- }
  317.   { ----------  Presence Check  -----------  }
  318.   else if ledtStudentNumber.Text =  ''  then  // Checks if entry is empty
  319.   begin
  320.     ErrorMessagePram := '';
  321.     ErrorMessagePram := 'ERROR: Student Number is of an invalid type';
  322.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentNumber);
  323.   end // end if
  324.   { ----------  Range Check  ---------- }
  325.   else if (StrToInt(ledtStudentNumber.Text) < 150000) OR (StrToInt(ledtStudentNumber.Text) > 169999) then
  326.   begin
  327.     ErrorMessagePram := '';
  328.     ErrorMessagePram := 'ERROR: Student Number is of an invalid type';
  329.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentNumber);
  330.   end
  331.  
  332.   {  ----------  Existance Check  ----------  }
  333.   else if StudentNumberExists = True then
  334.   begin
  335.     ErrorMessagePram := '';
  336.     ErrorMessagePram := 'ERROR: Student Number already exists';
  337.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentNumber);
  338.   end
  339.  
  340.  
  341.   { ----------  First Name Validation  ---------- }
  342.   { ----------  Length Check  ---------- }
  343.   else if Length(ledtFirstName.Text) > 15  then  // Checks if first name is greater than 15 characters
  344.   begin
  345.     ErrorMessagePram := '';
  346.     ErrorMessagePram := 'ERROR: First name must be under 15 characters';
  347.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtFirstName);
  348.   end //  end if
  349.   { ----------  Presence Check  ---------- }
  350.   else if ledtFirstName.Text = '' then  // Check to see if the input is empty
  351.   begin
  352.     ErrorMessagePram := '';
  353.     ErrorMessagePram := 'ERROR: Please enter first name';
  354.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtFirstName);
  355.   end  // end if
  356.  
  357.   { ----------  Last Name Validation  ----------  }
  358.   { ----------  Length Check  ---------- }
  359.   else if Length(ledtLastName.Text) > 15 then  // Checks if last name is greater than 15 characters
  360.   begin
  361.     ErrorMessagePram := '';
  362.     ErrorMessagePram := 'ERROR: Last name must be 15 charaters or less';
  363.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtLastName);
  364.   end
  365.   { ----------  Presence Check  ---------- }
  366.   else if ledtLastName.Text = '' then
  367.   begin
  368.     ErrorMessagePram := '';
  369.     ErrorMessagePram := 'ERROR: Please enter last name';
  370.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtLastName);
  371.   end
  372.  
  373.   { ----------  Candidate Number Validation  ----------  }
  374.   { ----------  Presence Check  ---------- }
  375.   else if ledtCandidateNumber.Text = '' then
  376.   begin
  377.     ErrorMessagePram := '';
  378.     ErrorMessagePram := 'ERROR: Please enter candidate number';
  379.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtCandidateNumber);
  380.   end
  381.   { ----------  Length Check  ---------- }
  382.   else if (StrToInt(ledtCandidateNumber.Text) < 1000) AND (StrToInt(ledtCandidateNumber.Text) > 9999) then  // Checks if Candidae Number is in required range
  383.   begin
  384.     ErrorMessagePram := '';
  385.     ErrorMessagePram := 'ERROR: Candidate number is of an invalid type';
  386.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtCandidateNumber);
  387.   end //  end if
  388.  
  389.   { ----------  Teacher Name Validation  ---------- }
  390.   { ----------  Length Check  ---------- }
  391.   else if Length(ledtTeacherName.Text) > 25 then   //  Check if Teacher name is greater than 25
  392.   begin
  393.     ErrorMessagePram := '';
  394.     ErrorMessagePram := 'ERROR: Teacher name must be 25 characters or less';
  395.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtCandidateNumber);
  396.   end  // end if
  397.   { ----------  Presence Check  ---------- }
  398.   else if ledtTeacherName.Text = '' then
  399.   begin
  400.     ErrorMessagePram := '';
  401.     ErrorMessagePram := 'ERROR: Please enter a teacher name';
  402.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtTeacherName);
  403.   end
  404.  
  405.   { ----------  Group Name Validation  ---------- }
  406.   { ----------  Length Check  ---------- }
  407.   { ----------  Presence Check  ---------- }
  408.   else if cboASSelectGroup.Text = '' then
  409.   begin
  410.     ErrorMessagePram := '';
  411.     ErrorMessagePram := 'ERROR: Please enter a group name';
  412.     ErrorOutputComboBox(ErrorMessagePram, cboASSelectGroup);
  413.   end
  414.  
  415.   { ----------  Student Email Validation  ---------- }
  416.   {  ----------  Format Check  ----------  }
  417.   else if IsEmailValid(ledtStudentEmail.Text) = False then
  418.   begin
  419.     ErrorMessagePram := '';
  420.     ErrorMessagePram := 'ERROR: Student email is in the wrong format';
  421.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentEmail);
  422.   end
  423.   { ----------  Lentgh Check  ---------- }
  424.   else if Length(ledtStudentEmail.Text) > 30 then   //  Check if Student Email is greater than 30
  425.   begin
  426.     ErrorMessagePram := '';
  427.     ErrorMessagePram := 'ERROR: Student Email must be 30 characters or less';
  428.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentEmail);
  429.   end  // end if
  430.   { ----------  Presence Check  ----------}
  431.   else if ledtStudentEmail.Text = '' then
  432.   begin
  433.     ErrorMessagePram := '';
  434.     ErrorMessagePram := 'ERROR: Please enter a student email';
  435.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentEmail);
  436.   end
  437.   {  ----------  Existance Check  ----------  }
  438.   else if StudentEmailExists = True then
  439.   begin
  440.     ErrorMessagePram := '';
  441.     ErrorMessagePram := 'ERROR: Student email already exists';
  442.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtStudentEmail);
  443.   end
  444.   { ----------  Parent/Guardian Email Validation  ---------- }
  445.   {  ----------  Presence Check  ----------  }
  446.   else if ledtParentGuardianEmail.Text = '' then
  447.   begin
  448.     ErrorMessagePram := '';
  449.     ErrorMessagePram := 'ERROR: Please enter an email for Parent/Guardian';
  450.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtParentGuardianEmail);
  451.   end
  452.   { ----------  Length Check  ---------- }
  453.   else if Length(ledtParentGuardianEmail.Text) > 30 then   //  Check if Parent/Guardian Email is greater than 30
  454.   begin
  455.     ErrorMessagePram := '';
  456.     ErrorMessagePram := 'ERROR: Parent/Guardian email must be 30 characters or less';
  457.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtParentGuardianEmail);
  458.   end  // end if
  459.   {  ----------  Existance Check  ----------  }
  460.   else if ParentGuardianEmailExists = True then
  461.   begin
  462.     ErrorMessagePram := '';
  463.     ErrorMessagePram := 'ERROR: Parent/guardian email already exists';
  464.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtParentGuardianEmail);
  465.   end
  466.   {  ----------  Format Check  ----------  }
  467.   else if IsEmailValid(ledtParentGuardianEmail.Text) = False then
  468.   begin
  469.     ErrorMessagePram := '';
  470.     ErrorMessagePram := 'ERROR: Parent/Guardian email is in the wrong format';
  471.     ErrorOutputLabeledEdit(ErrorMessagePram, ledtParentGuardianEmail);
  472.   end
  473.   {  ----------  GCSE Subject 1 Presence Check  ----------  }
  474.   else if cboGCSEGrade1.Text = '' then
  475.   begin
  476.     ErrorMessagePram := '';
  477.     ErrorMessagePram := 'ERROR: Please enter a GCSE grade';
  478.     ErrorOutputComboBox(ErrorMessagePram, cboGCSEGrade1);
  479.   end
  480.   {  ----------  GCSE Subject 2 Presence Check  ----------  }
  481.   else if cboGCSEGrade2.Text = '' then
  482.   begin
  483.     ErrorMessagePram := '';
  484.     ErrorMessagePram := 'ERROR: Please enter a GCSE grade';
  485.     ErrorOutputComboBox(ErrorMessagePram, cboGCSEGrade1);
  486.   end
  487.   {  ----------  Target Grade Presence Check  ----------  }
  488.   else if cboTargetGradeInput.Text = '' then
  489.   begin
  490.     ErrorMessagePram := '';
  491.     ErrorMessagePram := 'ERROR: Please enter a target grade';
  492.     ErrorOutputComboBox(ErrorMessagePram, cboTargetGradeInput);
  493.   end
  494.   else
  495.   {  ----------  Begin process of a dding a new student  ----------  }
  496.   begin
  497.  
  498.     { ----------  Add Student To StudentDetails Table ----------  }
  499.     with dmDatabaseComponents.adoUnitAddStudent do
  500.     begin
  501.       SQL.Clear;  // Initialize the SQL
  502.       // The query to INSERT
  503.       SQL.Text:='INSERT INTO StudentDetails (StudentNumber, FirstName, LastName, CandidateNumber, TeacherName, GroupName, StudentEmail, ParentGuardianEmail) values (:SNo,:FN,:LN,:CN,:TN,:GN,:SE,:PGE)';
  504.       // Set parameters to their inputs
  505.       Parameters.ParamByName('SNo').Value:=StrToInt(ledtStudentNumber.Text);
  506.       Parameters.ParamByName('FN').Value:=ledtFirstName.Text;
  507.       Parameters.ParamByName('LN').Value:=ledtLastName.Text;
  508.       Parameters.ParamByName('CN').Value:=StrToInt(ledtCandidateNumber.Text);
  509.       Parameters.ParamByName('TN').Value:=ledtTeacherName.Text;
  510.       Parameters.ParamByName('GN').Value:=cboASSelectGroup.Items[cboASSelectGroup.ItemIndex];
  511.       Parameters.ParamByName('SE').Value:=ledtStudentEmail.Text;
  512.       Parameters.ParamByName('PGE').Value:=ledtParentGuardianEmail.Text;
  513.       ExecSQL;  //  Execute the SQL
  514.  
  515.       SQL.Clear;  // Initialize the SQL
  516.       // The query to INSERT
  517.       SQL.Text:='UPDATE [StudentDetails] SET TargetGrade = :TG, PastASQualification = :PASQ, GCSESubject1 = :GCSE1, GCSESubject2 = :GCSE2, AcademicYear = :AY WHERE StudentNumber = '+ledtStudentNumber.Text;
  518.       // Set parameters to their inputs
  519.       Parameters.ParamByName('TG').Value:=cboTargetGradeInput.Items[cboTargetGradeInput.ItemIndex];
  520.       // If the user selected No past AS Qualification
  521.       if rbNoASQaulfication.Checked = True then
  522.       begin
  523.         // Make the parameter 'None'
  524.         Parameters.ParamByName('PASQ').Value:='None'
  525.       end
  526.       else
  527.       begin
  528.         // Make the parameter the qaulification selected
  529.         Parameters.ParamByName('PASQ').Value:=cboPastASQualification.Items[cboPastASQualification.ItemIndex];
  530.       end;
  531.       Parameters.ParamByName('GCSE1').Value:=cboGCSEGrade1.Items[cboGCSEGrade1.ItemIndex];
  532.       Parameters.ParamByName('GCSE2').Value:=cboGCSEGrade2.Items[cboGCSEGrade2.ItemIndex];
  533.       Parameters.ParamByName('AY').Value:=rgAcademicYear.Items[rgAcademicYear.ItemIndex];
  534.       ExecSQL; // Execute the SQL
  535.     end;
  536.  
  537.     { ----------  Add Student Into Correct Homework Table  ----------  }
  538.     with dmDatabaseComponents.adoUnitAddStudent do
  539.     begin
  540.       Close;
  541.       SQL.Clear; // Initialize the SQL
  542.       SQL.Text:='INSERT INTO [HOMEWORK'+cboASSelectGroup.Items[cboASSelectGroup.ItemIndex]+'] (StudentID, StudentName) values (:SNo,:SN)';  // Set SQL Query
  543.       //  Set parameters to correct inputs
  544.       Parameters.ParamByName('SNo').Value:=StrToInt(ledtStudentNumber.Text);
  545.       Parameters.ParamByName('SN').Value:=ledtFirstName.Text+' '+ledtLastName.Text;
  546.       ExecSQL;  // Execute the SQL
  547.     end;  // End with
  548.  
  549.  
  550.     { ----------  Add Student Into Correct Assessment Table  ----------  }
  551.     with dmDatabaseComponents.adoUnitAddStudent do
  552.     begin
  553.       Close;
  554.       SQL.Clear;  // Initialize the SQL
  555.       SQL.Text:='INSERT INTO [ASSESSMENT'+cboASSelectGroup.Items[cboASSelectGroup.ItemIndex]+'] (StudentID, StudentName) values (:SNo,:SN)';   // Set SQL Query
  556.       // Set parameter values
  557.       Parameters.ParamByName('SNo').Value:=StrToInt(ledtStudentNumber.Text);
  558.       Parameters.ParamByName('SN').Value:=ledtFirstName.Text+' '+ledtLastName.Text;
  559.       ExecSQL;  // Execute the SQL
  560.     end;  // End with
  561.  
  562.    Showmessage('Student has successfully been added'); //  Confirmation Message
  563.  
  564.    {  ----------  Reset the inputs  ----------  }
  565.    // Once the student is saved clear inputs
  566.    ledtStudentNumber.Text := '';  //  Clear the student number field
  567.    ledtFirstName.Text  := '';  //  Clear the first name field
  568.    ledtLastName.Text  := '';  //  Clear the last field
  569.    ledtCandidateNumber.Text  := '';  //  Clear the candidate number field
  570.    ledtTeacherName.Text := '';  //  Clear the teacher name field
  571.    cboASSelectGroup.Text := '';  //  Clear the group name field
  572.    ledtStudentEmail.Text := '';  //  Clear the student email field
  573.    ledtParentGuardianEmail.Text := '';  //  Clear the parent/guardian email field
  574.    cboGCSEGrade1.Text := '';  //  Clear the GCSE grade 1 field
  575.    cboGCSEGrade2.Text := '';  //  Clear the GCSE grade 2 field
  576.    rbNoASQaulfication.Checked := False;  // Uncheck the no past AS qualificatioin
  577.    cboTargetGradeInput.Text := '';  //  Clear the target grade field
  578.    cboPastASQualification.Text := '';  //  Clear the past AS qualification field
  579.  
  580.   end;  //  End of else
  581.  
  582. end;
  583.  
  584. procedure TfrmAddStudent.btnGCSESubjectsClick(Sender: TObject);
  585. begin
  586.   frmGCSESubjects.Show;
  587. end;
  588.  
  589. procedure TfrmAddStudent.FormShow(Sender: TObject);
  590. begin
  591.   cboASSelectGroup.Clear;
  592.   with dmDatabaseComponents.adoASDisplayGroup do
  593.   begin
  594.     First;  //  Start from the fist record
  595.     while not Eof do
  596.     begin
  597.         //  Add the group
  598.        cboASSelectGroup.Items.Add(FieldByName('GroupName').AsString);  // Read the GroupNames record only
  599.        Next;  // Next Record
  600.     end;
  601.   end;
  602.  
  603.   GCSESubjectsFileRead := '';
  604.  
  605.   AssignFile(GCSESubjectsFile, 'GCSESubjects.txt');
  606.   //  Open the file for reading access
  607.   Reset(GCSESubjectsFile);
  608.   //  Read the first line
  609.   Readln(GCSESubjectsFile, GCSESubjectsFileRead);
  610.   lblGCSESubject1.Caption := GCSESubjectsFileRead;
  611.   //  Read the second line
  612.   Readln(GCSESubjectsFile, GCSESubjectsFileRead);
  613.   lblGCSESubject2.Caption := GCSESubjectsFileRead;
  614.   //  Close the file
  615.   CloseFile(GCSESubjectsFile);
  616. end;
  617.  
  618. procedure TfrmAddStudent.ledtCandidateNumberKeyPress(Sender: TObject;
  619.   var Key: Char);
  620. begin
  621.   CorrectKeyPressedNumerical(Key, 'Candidate Number');
  622. end;
  623.  
  624. procedure TfrmAddStudent.ledtFirstNameKeyPress(Sender: TObject; var Key: Char);
  625. begin
  626.   CorrectKeyPressedName(Key, 'First Name')
  627. end;
  628.  
  629. procedure TfrmAddStudent.ledtGroupNameKeyPress(Sender: TObject; var Key: Char);
  630. begin
  631.   if (not (Key in ['A'..'Z','a'..'z','-','/','0'..'9'])) then // If a letter key is not pressed
  632.   begin
  633.     PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  634.     Showmessage('ERROR: Invalid key entered for group name');  //  Produce an error message
  635.     Key := #0; // Remove the last character
  636.   end; // end if
  637. end;
  638.  
  639. procedure TfrmAddStudent.ledtLastNameKeyPress(Sender: TObject; var Key: Char);
  640. begin
  641.   CorrectKeyPressedName(Key, 'Last Name');
  642. end;
  643.  
  644. procedure TfrmAddStudent.ledtStudentNumberKeyPress(Sender: TObject;
  645.   var Key: Char);
  646. begin
  647.   CorrectKeyPressedNumerical(Key, 'Student Number');
  648. end;
  649.  
  650. procedure TfrmAddStudent.ledtTeacherNameKeyPress(Sender: TObject;
  651.   var Key: Char);
  652. begin
  653.     if (not (Key in ['A'..'Z','a'..'z', #32])) then // If a letter key is not pressed
  654.   begin
  655.     PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  656.     Showmessage('ERROR: Teacher name must be a letters only');  //  Produce an error message
  657.     Key := #0; // Remove the last character
  658.   end; // end if
  659. end;
  660.  
  661. procedure TfrmAddStudent.rgAcademicYearClick(Sender: TObject);
  662. begin
  663.   { ----------  Disable Past AS Qaulification if AS student  -----------  }
  664.   if rgAcademicYear.Items[rgAcademicYear.ItemIndex] = 'AS' then  // If the user is creating an AS student profile
  665.   begin
  666.     cboPastASQualification.Enabled:=False;  //  Allow input for Past AS qualification
  667.   end // end if
  668.   else if rgAcademicYear.Items[rgAcademicYear.ItemIndex] = 'A2' then  // If the user is creating an A2 student profile
  669.   begin
  670.     cboPastASQualification.Enabled:=True;  //  Allow input for an A2 qualification
  671.   end; // end else
  672.  
  673. end;
  674.  
  675. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement