Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitAddHomework;
- 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
- TfrmAddHomework = class(TForm)
- lblAddHomework: TLabel;
- ledtHomeworkName: TLabeledEdit;
- btnAddHomework: TButton;
- btnClose: TButton;
- cboAHSelectGroup: TComboBox;
- Label1: TLabel;
- procedure btnCloseClick(Sender: TObject);
- procedure btnAddHomeworkClick(Sender: TObject);
- procedure ledtHomeworkNameKeyPress(Sender: TObject; var Key: Char);
- procedure FormShow(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmAddHomework: TfrmAddHomework;
- implementation
- uses UnitGroupProfiles, 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 TfrmAddHomework.btnAddHomeworkClick(Sender: TObject);
- var
- ErrorMessagePram : string;
- begin
- { ---------- Validation ---------- }
- { ---------- Assessment Name ---------- }
- { ---------- Length Check ---------- }
- if Length(ledtHomeworkName.Text) > 50 then // Check to see if input length is greater than 50
- begin
- ErrorMessagePram := '';
- ErrorMessagePram := 'ERROR: Homework name must be 50 characters or less';
- ErrorOutput(ErrorMessagePram, ledtHomeworkName);
- end // End of else if statement
- { ---------- Presence Check ---------- }
- else if ledtHomeworkName.Text = '' then // if the assessment title is empty
- begin
- ErrorMessagePram := '';
- ErrorMessagePram := 'ERROR: Please enter a homework name';
- ErrorOutput(ErrorMessagePram, ledtHomeworkName);
- end // end else if
- { ---------- Group Name ---------- }
- { ---------- Presence Check ---------- }
- else if cboAHSelectGroup.Text = '' then // Check to see if input is empty
- begin
- ErrorMessagePram := '';
- ErrorMessagePram := 'ERROR: Please enter a Group Name';
- ErrorOutput(ErrorMessagePram, ledtAHGroupName);
- end // End of else if statement
- else
- begin
- { ---------- Add a column as an Homework ---------- }
- with dmDatabaseComponents.adoUnitAddHomework do
- begin
- SQL.Clear; // Initialize the SQL
- // Set SQL
- SQL.Text:='ALTER TABLE [HOMEWORK'+cboAHSelectGroup.Items[cboAHSelectGroup.ItemIndex]+'] ADD ['+ledtHomeworkName.Text+'] varchar(50)';
- ExecSQL; // Execute SQL
- end; // End of with statement
- Showmessage('Homework has successfully been added'); // Produce a confirmation message
- { ---------- ---------- }
- // Once homework is saved clear inputs
- ledtHomeworkName.Text := '';
- cboAHSelectGroup.Text := '';
- end;
- end;
- procedure TfrmAddHomework.btnCloseClick(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmAddHomework.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;
- cboAHSelectGroup.Clear; // Clear all contents of the combo box
- First; // Start at the first record
- while not Eof do
- begin
- // Add the group name to the current contents of the combo box
- cboAHSelectGroup.Items.Add(FieldByName('GroupName').AsString);
- Next; // Move to the next record
- end; // End of while loop
- end; // end of with statement
- end;
- procedure TfrmAddHomework.ledtHomeworkNameKeyPress(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