Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.43 KB | None | 0 0
  1. unit UnitAddAssessment;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, MmSystem;
  8.  
  9. type
  10.   TfrmAddAssessment = class(TForm)
  11.     Label1: TLabel;
  12.     ledtAssessmentName: TLabeledEdit;
  13.     btnAddAssessment: TButton;
  14.     btnCloseAddAssessment: TButton;
  15.     Label2: TLabel;
  16.     cboAASelectGroup: TComboBox;
  17.     procedure btnCloseAddAssessmentClick(Sender: TObject);
  18.     procedure btnAddAssessmentClick(Sender: TObject);
  19.     procedure ledtAssessmentNameKeyPress(Sender: TObject; var Key: Char);
  20.     procedure FormShow(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   frmAddAssessment: TfrmAddAssessment;
  29.  
  30. implementation
  31.  
  32. uses  UnitMainMenu, UnitdmDatabaseComponents;
  33.  
  34. {$R *.dfm}
  35.  
  36. procedure ErrorOutput(ErrorMessage : string; Ledt : TLabeledEdit);
  37. begin
  38.   {  ----------  Highlight the input with an error  ----------  }
  39.   Ledt.Color := clRed;  // Turn the input into a red color
  40.   ledt.Font.Color := clWhite;  // Turn the text into the input to white
  41.   PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  42.   Showmessage(ErrorMessage);  //  Output an error message
  43.   {  ----------  Remove the highlight  ----------}
  44.   Ledt.Color := clWhite;  // Make the input white again
  45.   ledt.Font.Color := clBlack;  //  Make the font black again
  46. end;
  47.  
  48. procedure TfrmAddAssessment.btnAddAssessmentClick(Sender: TObject);
  49. var
  50.   ErrorMessagePram : string;
  51. begin
  52.   { ----------  Validation  ----------- }
  53.   { ----------  Assessment Title  ---------- }
  54.   { ----------  Length Check ---------- }
  55.   if Length(ledtAssessmentName.Text) > 50 then
  56.   begin
  57.     ErrorMessagePram := '';
  58.     ErrorMessagePram := 'ERROR: Assessment name must be 50 characters or less';
  59.     ErrorOutput(ErrorMessagePram, ledtAssessmentName);
  60.   end    //  End of if statement
  61.   { ----------  Presence Check  ---------- }
  62.   else if ledtAssessmentName.Text = '' then  // If assessment title is empty
  63.   begin
  64.     ErrorMessagePram := '';
  65.     ErrorMessagePram := 'ERROR: Please input an assessment title';
  66.     ErrorOutput(ErrorMessagePram, ledtAssessmentName);
  67.   end  // end else if
  68.  
  69.   {  ----------  Group Name Validation  ---------  }
  70.   {  ----------  Length Check ---------- }
  71.   else if cboAASelectGroup.Text = '' then  // If assessment title is empty
  72.   begin
  73.     ErrorMessagePram := '';
  74.     ErrorMessagePram := 'ERROR: Please input a group name title';
  75.     ErrorOutput(ErrorMessagePram, ledtAAGroupName);
  76.   end  // end else if
  77.  
  78.   else
  79.   begin
  80.     { ---------  Add a column as an Assessment  ----------}
  81.     with dmDatabaseComponents.adoUnitAddAssessment do
  82.     begin
  83.       SQL.Clear;  //  Initialize the SQL
  84.       // Set SQL
  85.       SQL.Text:='ALTER TABLE [ASSESSMENT'+cboAASelectGroup.Items[cboAASelectGroup.ItemIndex]+'] ADD ['+ledtAssessmentName.Text+'] varchar(50)';
  86.       ExecSQL;  // Execute SQL
  87.     end;  //  End of with statment
  88.  
  89.    Showmessage('Assessment has successfully been added');  //  Produce an error message
  90.  
  91.    {  ----------    ----------  }
  92.    // Once homework is saved clear inputs
  93.    ledtAssessmentName.Text := '';
  94.    cboAASelectGroup.Text := '';
  95.   end;  //  End of else statement
  96. end;
  97.  
  98. procedure TfrmAddAssessment.btnCloseAddAssessmentClick(Sender: TObject);
  99. begin
  100.   close;
  101. end;
  102.  
  103. procedure TfrmAddAssessment.FormShow(Sender: TObject);
  104. begin
  105.   with dmDatabaseComponents.adoASDisplayGroup do
  106.   begin
  107.     Close;
  108.     SQL.Clear;  //  Initialize the SQL
  109.     //  Set the SQL
  110.     SQL.Text := 'SELECT GroupName FROM GroupDetails';
  111.     ExecSQL;  //  Execute the SQL
  112.     Open;
  113.  
  114.     cboAASelectGroup.Clear; // Clear all contents of the combo box
  115.     First;  //  Start at the first record
  116.     while not Eof do
  117.     begin
  118.       cboAASelectGroup.Items.Add(FieldByName('GroupName').AsString);
  119.       Next;  //  Move on to the next record
  120.     end;  //  End of while loop
  121.   end;  //  End of with statement
  122. end;
  123.  
  124. procedure TfrmAddAssessment.ledtAssessmentNameKeyPress(Sender: TObject;
  125.   var Key: Char);
  126. begin
  127.   if (not (Key in ['A'..'Z','a'..'z','-','/','0'..'9', #32])) then // If a letter key is not pressed
  128.   begin
  129.     PlaySound('SYSTEMEXCLAMATION', 0, SND_ASYNC);  //  Play error sound
  130.     Showmessage('ERROR: Invalid key entered for group name');  //  Produce an error message
  131.     Key := #0; // Remove the last character
  132.   end; // end if
  133. end;
  134.  
  135. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement