Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitAddAssessment;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, MmSystem;
- type
- TfrmAddAssessment = class(TForm)
- Label1: TLabel;
- ledtAssessmentName: TLabeledEdit;
- btnAddAssessment: TButton;
- btnCloseAddAssessment: TButton;
- Label2: TLabel;
- cboAASelectGroup: TComboBox;
- procedure btnCloseAddAssessmentClick(Sender: TObject);
- procedure btnAddAssessmentClick(Sender: TObject);
- procedure ledtAssessmentNameKeyPress(Sender: TObject; var Key: Char);
- procedure FormShow(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmAddAssessment: TfrmAddAssessment;
- implementation
- uses UnitMainMenu, UnitdmDatabaseComponents;
- {$R *.dfm}
- procedure ErrorOutput(ErrorMessage : string; Ledt : TLabeledEdit);
- begin
- { ---------- Highlight the input with an error ---------- }
- Ledt.Color := clRed; // Turn the input into a red color
- ledt.Font.Color := clWhite; // Turn the text into the input to white
- PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC); // Play error sound
- Showmessage(ErrorMessage); // Output an error message
- { ---------- Remove the highlight ----------}
- Ledt.Color := clWhite; // Make the input white again
- ledt.Font.Color := clBlack; // Make the font black again
- end;
- procedure TfrmAddAssessment.btnAddAssessmentClick(Sender: TObject);
- var
- ErrorMessagePram : string;
- begin
- { ---------- Validation ----------- }
- { ---------- Assessment Title ---------- }
- { ---------- Length Check ---------- }
- if Length(ledtAssessmentName.Text) > 50 then
- begin
- ErrorMessagePram := '';
- ErrorMessagePram := 'ERROR: Assessment name must be 50 characters or less';
- ErrorOutput(ErrorMessagePram, ledtAssessmentName);
- end // End of if statement
- { ---------- Presence Check ---------- }
- else if ledtAssessmentName.Text = '' then // If assessment title is empty
- begin
- ErrorMessagePram := '';
- ErrorMessagePram := 'ERROR: Please input an assessment title';
- ErrorOutput(ErrorMessagePram, ledtAssessmentName);
- end // end else if
- { ---------- Group Name Validation --------- }
- { ---------- Length Check ---------- }
- else if cboAASelectGroup.Text = '' then // If assessment title is empty
- begin
- ErrorMessagePram := '';
- ErrorMessagePram := 'ERROR: Please input a group name title';
- ErrorOutput(ErrorMessagePram, ledtAAGroupName);
- end // end else if
- else
- begin
- { --------- Add a column as an Assessment ----------}
- with dmDatabaseComponents.adoUnitAddAssessment do
- begin
- SQL.Clear; // Initialize the SQL
- // Set SQL
- SQL.Text:='ALTER TABLE [ASSESSMENT'+cboAASelectGroup.Items[cboAASelectGroup.ItemIndex]+'] ADD ['+ledtAssessmentName.Text+'] varchar(50)';
- ExecSQL; // Execute SQL
- end; // End of with statment
- Showmessage('Assessment has successfully been added'); // Produce an error message
- { ---------- ---------- }
- // Once homework is saved clear inputs
- ledtAssessmentName.Text := '';
- cboAASelectGroup.Text := '';
- end; // End of else statement
- end;
- procedure TfrmAddAssessment.btnCloseAddAssessmentClick(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmAddAssessment.FormShow(Sender: TObject);
- begin
- with dmDatabaseComponents.adoASDisplayGroup do
- begin
- Close;
- SQL.Clear; // Initialize the SQL
- // Set the SQL
- SQL.Text := 'SELECT GroupName FROM GroupDetails';
- ExecSQL; // Execute the SQL
- Open;
- cboAASelectGroup.Clear; // Clear all contents of the combo box
- First; // Start at the first record
- while not Eof do
- begin
- cboAASelectGroup.Items.Add(FieldByName('GroupName').AsString);
- Next; // Move on to the next record
- end; // End of while loop
- end; // End of with statement
- end;
- procedure TfrmAddAssessment.ledtAssessmentNameKeyPress(Sender: TObject;
- var Key: Char);
- begin
- if (not (Key in ['A'..'Z','a'..'z','-','/','0'..'9', #32])) then // If a letter key is not pressed
- begin
- PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC); // Play error sound
- Showmessage('ERROR: Invalid key entered for group name'); // Produce an error message
- Key := #0; // Remove the last character
- end; // end if
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement