Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit_DeleteUser;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
- type
- TfrmDeleteUser = class(TForm)
- lbledtAccount: TLabeledEdit;
- MemoAccount: TMemo;
- btnEnter: TButton;
- btnExit: TButton;
- btnDelete: TButton;
- CoBoxAccount: TComboBox;
- procedure btnExitClick(Sender: TObject);
- procedure btnEnterClick(Sender: TObject);
- procedure CoBoxAccountChange(Sender: TObject);
- procedure btnDeleteClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmDeleteUser: TfrmDeleteUser;
- implementation
- uses
- Unit_Login;
- {$R *.dfm}
- var
- TeacherID, StudentID : Boolean;
- Count,StudentMatch: Integer; //Variables used for students
- StudentExists,TeacherExists: Boolean;
- StudentUser, StudentPassword : TStrings;
- TeacherUser, TeacherPassword : Tstrings;
- TeacherMatch : Integer;
- procedure TfrmDeleteUser.btnDeleteClick(Sender: TObject);
- Var
- N,Counter: Integer;
- begin
- if CoboxAccount.Text = 'Student Account' then
- begin
- //Uses the variables from the login form
- StudentUser.Delete(StudentMatch); //String list for StudentNumbers
- StudentPassword.Delete(StudentMatch);//String list for Student's passwords
- AssignFile(frmLogin.StudentNumberFile, 'StudentNumber.Dat');
- ReWrite(frmLogin.StudentNumberFile);
- AssignFile(frmLogin.PasswordFile, 'Password.Dat');
- ReWrite(frmLogin.PasswordFile);
- {The count is reduced to ensure the stringlists do not go out of bounds}
- for N := 0 to Count - 2 do
- begin
- //The following two lines copy the cotent of the stringlist into the main array
- frmLogin.Student_Number[N].StudentNumber := StudentUser[N];
- frmLogin.Student_Password[N].StudentPassword := StudentPassword[N];
- //This writes back all the accounts into the array which now does not include the deleted one
- Write(frmLogin.StudentNumberFile,frmLogin.Student_Number[N]);
- Write(frmLogin.PasswordFile,frmLogin.Student_Password[N]);
- end;
- CloseFile(frmLogin.StudentNumberFile);
- CloseFile(frmLogin.PasswordFile);
- Showmessage('Student account has been deleted');
- end;
- if CoboxAccount.Text = 'Teacher Account' then
- begin
- TeacherUser.Delete(TeacherMatch);
- TeacherPassword.Delete(TeacherMatch);
- AssignFile(frmLogin.TeacherUsernameFile, 'TeacherUser.Dat');
- ReWrite(frmLogin.TeacherUsernameFile);
- AssignFile(frmLogin.TeacherPasswordFile, 'TeacherPassword.Dat');
- ReWrite(frmLogin.TeacherPasswordFile);
- for N := 0 to Count - 2 do
- begin
- frmLogin.Teacher_Username[N].TeacherUsername := TeacherUser[N];
- frmLogin.Teacher_Password[N].TeacherPassword := TeacherPassword[N];
- Write(frmLogin.TeacherUsernameFile, frmLogin.Teacher_Username[N]);
- Write(frmLogin.TeacherPasswordFile, frmLogin.Teacher_Password[N]);
- end;
- Showmessage('Teacher account has been deleted');
- end;
- end;
- procedure TfrmDeleteUser.btnEnterClick(Sender: TObject);
- begin
- if CoboxAccount.Text = 'Student Account' then
- begin
- //Uses the public variables from the login form
- AssignFile(frmLogin.StudentNumberFile, 'StudentNumber.Dat');
- Reset(frmLogin.StudentNumberFile);
- AssignFile(frmLogin.PasswordFile, 'Password.Dat');
- Reset(frmLogin.PasswordFile);
- Count := 0;
- {StudentUser and StudentPassword are Stringlist}
- StudentUser := TStringList.Create;
- StudentPassword := TStringList.Create;
- StudentExists := False;
- //Reads all the studentnumber and passwords in the file
- while not eof (frmLogin.StudentNumberFile) and not eof (frmLogin.PasswordFile) do
- begin
- Read(frmLogin.StudentNumberFile,frmLogin.Student_Number[Count]);
- Read(frmLogin.PasswordFile,frmLogin.Student_Password[Count]);
- //The contents of the array are coppied into both stringlists
- StudentUser.Add(frmLogin.Student_Number[Count].StudentNumber);
- StudentPassword.Add(frmLogin.Student_Password[Count].StudentPassword);
- //The if statement checks if the student numbers matches any in the array
- if frmLogin.Student_Number[Count].StudentNumber = lbledtAccount.Text then
- begin
- StudentMatch := Count;
- //Clears the memo of any text
- MemoAccount.Clear;
- //Adds the account credentials of the account searched for
- MemoAccount.Lines.Add('Student Number : '+ frmLogin.Student_Number[Count].StudentNumber +
- ' Password : '+frmLogin.Student_Password[Count].StudentPassword);
- StudentExists := True;
- end;
- Count := Count + 1;
- end;
- CloseFile(frmLogin.StudentNumberFile);
- CloseFile(FrmLogin.PasswordFile);
- if StudentExists = False then
- begin
- Showmessage('Student Account does not exists');
- end;
- end;
- if CoboxAccount.Text = 'Teacher Account' then
- begin
- AssignFile(frmLogin.TeacherUsernameFile, 'TeacherUser.Dat');
- Reset(frmLogin.TeacherUsernameFile);
- AssignFile(frmLogin.TeacherPasswordFile, 'TeacherPassword.Dat');
- Reset(frmLogin.TeacherPasswordFile);
- Count := 0;
- TeacherUser := TStringList.Create;
- TeacherPassword := TStringList.Create;
- TeacherExists := False;
- while not eof (frmLogin.TeacherUsernameFile) and not eof (frmLogin.TeacherPasswordFile) do
- begin
- Read(frmLogin.TeacherUsernameFile,frmLogin.Teacher_Username[Count]);
- Read(frmLogin.TeacherPasswordFile,frmLogin.Teacher_Password[Count]);
- TeacherUser.Add(frmLogin.Teacher_Username[Count].TeacherUsername);
- TeacherPassword.Add(frmLogin.Teacher_Password[Count].TeacherPassword);
- if frmLogin.Teacher_Username[Count].TeacherUsername = lbledtAccount.Text then
- begin
- TeacherMatch := Count;
- MemoAccount.Clear;
- MemoAccount.Lines.Add('Username : '+frmLogin.Teacher_Username[Count].TeacherUsername
- +' Password: ' + frmLogin.Teacher_Password[Count].TeacherPassword);
- TeacherExists := True;
- end;
- Count := Count + 1;
- end;
- if TeacherExists = False then
- begin
- Showmessage('This Teacher account does not exist');
- end;
- end;
- end;
- procedure TfrmDeleteUser.btnExitClick(Sender: TObject);
- begin
- Close;
- end;
- procedure TfrmDeleteUser.CoBoxAccountChange(Sender: TObject);
- begin
- //If the User selects the teader acount in the combobox the edit label will change to teacher ID
- if CoboxAccount.Text = 'Teacher Account' then
- begin
- //if teacher account is selected the label will change to teacher ID
- lbledtAccount.EditLabel.Caption := 'Teacher ID';
- //The two following boolean variables tells the system which acconts needs to be deleted.
- TeacherID := True;
- StudentID := False;
- end;
- //If the User selects the Student acount in the combobox the edit label will change to student ID
- if CoboxAccount.Text = 'Student Account' then
- begin
- //if the student account is selected the label will change to student ID
- lbledtAccount.EditLabel.Caption := 'Student ID';
- //The two following boolean variables tells the system which acconts needs to be deleted.
- TeacherID := False;
- StudentID := True;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement