Разработка распределенного программного обеспечения для контроля знаний студентов

Сетевая система контроля знаний студентов на основе объектно-ориентированного подхода. Выбор программно-технических средств для реализации проекта. Алгоритмическое и программное обеспечение, интерфейс пользователя. Разработка элементов базы данных.

Рубрика Программирование, компьютеры и кибернетика
Вид дипломная работа
Язык русский
Дата добавления 04.02.2013
Размер файла 1,3 M

Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже

Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.

ZDataset, Dialogs, ZAbstractTable, XPMan, ExtDlgs, ActnList, Menus, ActnPopup,

XPStyleActnCtrls, ActnMan, ComCtrls, ZSqlMonitor, sSkinProvider, sSkinManager,

ImgList, Controls, RpRenderText, RpRenderRTF, RpRenderHTML, RpRender,

RpRenderPDF, RpCon, RpConDS, RpRave, RpDefine, RpBase, RpSystem, ExtCtrls;

type

TUser = record //Данные о пользователе

id: integer;

user: string;

pas: string;

access: string;

name: string;

sname: string;

patronymic: string;

end;

TFSetting = record//Настройки соединения

Host: String[100];

Port: String[100];

Database: String[100];

User: String[100];

Password: String[100];

end;

TSelection = record//Последние выбранные элементы

id_subject: integer;

id_theme: integer;

id_question: integer;

end;

Tdm = class(TDataModule)

ZConnection_spkvtk: TZConnection;

Query_login: TZQuery;

Query_data_test: TZQuery;

Table_Subject_test: TZTable;

Source_Subject: TDataSource;

Query_Subject: TZQuery;

Query_Create: TZQuery;

XP: TXPManifest;

Query_Answer: TZQuery;

Query_Question: TZQuery;

Source_Answer: TDataSource;

Source_Question: TDataSource;

OPD: TOpenPictureDialog;

Query_Illustration: TZQuery;

Source_Illustration: TDataSource;

Query_Delete: TZQuery;

Monitor: TZSQLMonitor;

Query_Theme: TZQuery;

Source_Theme: TDataSource;

Query_User: TZQuery;

Source_User: TDataSource;

SkinManager: TsSkinManager;

Query_Student: TZQuery;

Source_Student: TDataSource;

Query_Skin: TZQuery;

Source_Skin: TDataSource;

OD: TOpenDialog;

Query_Betta: TZQuery;

Source_Betta: TDataSource;

Query_Mark: TZQuery;

Source_Mark: TDataSource;

Query_Group: TZQuery;

RvSystem: TRvSystem;

RvProject: TRvProject;

RvConnectionMark: TRvDataSetConnection;

RvPDF: TRvRenderPDF;

RvHTML: TRvRenderHTML;

RvRTF: TRvRenderRTF;

RvText: TRvRenderText;

ImageList: TImageList;

procedure DataModuleCreate(Sender: TObject);//Создание модуля

procedure ReadSetting(FName: String; Var

Host,

Port,

Database,

User,

Password: String);//Чтение настроек из файла для доступа к БД

procedure ConnectSPKVTK();//Подключение к базе данных СПКВТК

private

{ Private declarations }

public

{ Public declarations }

StrUser: TUser ;//Данные о пользователе

Last_Selected: TSelection;//Последние выбранные элементы

order_str: string;

function log_in(nik: String;

password: String): Boolean ;// Проверка логина и пароля

function Query_Subject_Set(): Boolean;//Получение списка предметов

function Query_Theme_Set(): Boolean;//Получение списка тем по предмету

function Create_Subject_New(Subject_Name: String): Boolean;//Создание нового предмета

function Create_Theme_New(id_subject: integer; Theme_Name: String): Boolean;//Создание нового

function Create_Question_New(id_theme: integer): Boolean;//Создание вопроса

function Create_Answer_New(id_question: integer): Boolean;//Создание ответа

function Load_Answer(): Boolean;//Получение списка ответов по предмету

function Load_Question(): Boolean;//Получение списка вопросов

function Create_Illustration_New(id_question: integer): Boolean;//Создание иллюстрации к вопросу

function Load_Illustration(): Boolean;//Загрузка картинок к вопросу

function Load_User(): Boolean;//Загрузка списка пользователей

function Load_Student(): Boolean;//Загрузка списка пользователей

procedure Load_Query_Skin(); //Загрузка таблицы скиеов

procedure SetAllSkinPriority(priority: string);//Задать приоритет всем скинам

procedure SetSkinPriority(priority: string; id_skin: integer);//Задать приоритет одному скину

function SaveSkin(Path: String): String;//Сохранение скина на диск

procedure ApplySkin(FileName: String);//Применяет скин

procedure LoadSkinOutBD();//Загрузка скина ииз бд

procedure Load_Betta();//Загрузка заметок Бетта

procedure Load_Mark_Subject(id_subject: integer); //Загрузка оценок по предмету

procedure Load_Mark_Theme(id_theme: integer); //Загрузка оценок по теие

procedure Load_Mark_Group(id_theme: integer; n_group: String);//Загрузка оценок по теие

procedure Load_Marks_Al();//Загрузка всех оценок

procedure Load_Group();//Загруска списка груп

end;

var

dm: Tdm;

implementation

uses

unit_edit_test, unit_start, unit_authentication;

{$R *.dfm}

procedure Tdm.ApplySkin(FileName: String);

var

Fname: String;

I: Integer;

Name: String;

Path: String;

begin

Fname := dm.OD.FileName;

if FileExists( FileName ) then

begin

Path := ExtractFilePath(FileName);

Name := ExtractFileName(FileName);

Delete( Name, LastDelimiter( '.', Name ), Length( Name ) );

end

else

Name := '';

dm.SkinManager.SkinDirectory := Path;

dm.SkinManager.SkinName := Name;

dm.SkinManager.Active := true;

end;

procedure Tdm.ConnectSPKVTK;

// Подключение к базе данных СПКВТК

var

Host: String;

Port: String;

Database: String;

User: String;

Password: String;

begin

try

ReadSetting(ExtractFilePath(ParamStr(0))+'mysql.stg', Host, Port, Database, User, Password);

ZConnection_spkvtk.HostName := Host;

ZConnection_spkvtk.Port := StrToInt(Port);

ZConnection_spkvtk.Database := Database;

ZConnection_spkvtk.User := User;

ZConnection_spkvtk.Password := Password;

Zconnection_spkvtk.Connected := true;

except

ShowMessage('Ошибка подключения к ' + Host + ':' + Port);

authentication.Close;

end;

end;

function Tdm.Create_Answer_New(id_question: integer): Boolean;

//Создание нового ответа

begin

Create_Answer_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO answer(id_question, propstr, correct) VALUE(' + IntToStr(id_question) + ', true, false)') ;

Active := true;

Last_Selected.id_question := FieldByName('id_answer').AsInteger;

end;

except

;

end;

end;

function Tdm.Create_Illustration_New(id_question: integer): Boolean;

//Создание иллюстрации для вопроса

begin

Create_Illustration_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO q_illustration(id_question) VALUE(' + IntToStr(id_question) + ')') ;

Active := true;

end;

except

;

end;

end;

function Tdm.Create_Question_New(id_theme: integer): Boolean;

//Создание нового вопроса

begin

Create_Question_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO question(id_theme, only_one, mix_answer) VALUE(' + IntToStr(id_theme) + ', true, true)') ;

Active := true;

Last_Selected.id_question := FieldByName('id_question').AsInteger;

end;

except

;

end;

end;

function Tdm.Create_Subject_New(Subject_Name: String): Boolean;

//Создание нового предмета

begin

Create_Subject_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO subject(subject) VALUE("' + Subject_Name + '")') ;

Active := true;

end;

except

;

end;

end;

function Tdm.Create_Theme_New(id_subject: integer; Theme_Name: String): Boolean;

//Создание нового

begin

Create_Theme_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO theme(id_subject, theme) VALUE(' + IntToStr(id_subject) + ', "' + Theme_Name + '")') ;

Active := true;

Last_Selected.id_theme := FieldByName('id_theme').AsInteger;

end;

except

;

end;

end;

procedure Tdm.DataModuleCreate(Sender: TObject);

//Создание модуля

begin

;

end;

procedure Tdm.LoadSkinOutBD;

var

path: string;

begin

try

With Query_Skin do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM skin') ;

SQL.Add('WHERE priority in (Select max(priority) FROM skin)' );

Active := true;

Path := ExtractFilePath(ParamStr(0)) + 'temp\';

if Eof then exit;

ApplySkin(SaveSkin(Path));

end;

except

;

end;

end;

function Tdm.Load_Answer: Boolean;

//Загрузка ответа на вопрос

begin

Load_Answer := true;

try

With Query_Answer do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM Answer') ;

SQL.Add('WHERE id_question=' + IntToStr(Query_Question.FieldByName('id_question').AsInteger));

Active := true;

end;

except

;

Load_Answer := false;

end;

end;

procedure Tdm.Load_Betta;

begin

try

With Query_Betta do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT *') ;

SQL.Add('FROM betta') ;

Active := true;

end;

except

;

end;

end;

procedure Tdm.Load_Group;

begin

try

With Query_Group do

begin

Active := false ;

SQL.Clear;

SQL.Add('SELECT DISTINCT n_group');

SQL.Add('FROM student');

Active := true;

end;

except

;

end;

end;

function Tdm.Load_Illustration: Boolean;

// загрузка иллюстраций к вопросу

begin

Load_Illustration := true;

try

With Query_illustration do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM q_illustration ') ;

SQL.Add('WHERE id_question=' + IntToStr(Query_Question.FieldByName('id_question').AsInteger));

Active := true;

end;

except

;

Load_illustration := false;

end;

end;

procedure Tdm.Load_Mark_Subject(id_subject: integer);

begin

//try

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'su.id_subject = ' + IntToStr(id_subject));

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Mark_Theme(id_theme: integer);

begin

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'th.id_theme = ' + IntToStr(id_theme));

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Marks_Al;

begin

//try

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'te.id_subject = su.id_subject');

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Mark_Group(id_theme: Integer; n_group: String);

begin

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'th.id_theme = ' + IntToStr(id_theme) + ' AND ');

SQL.Add( 'st.n_group = ' + n_group);

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Query_Skin;

begin

try

With Query_Skin do

begin

Active := false ;

SQL.Clear;

SQL.Add('SELECT *');

SQL.Add('FROM skin');

Active := true;

end;

except

;

end;

end;

function Tdm.Load_Question: Boolean;

//чтение вопросов по предмету

begin

Load_Question := true;

try

With Query_Question do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM Question') ;

SQL.Add('WHERE id_theme=' + IntToStr(Last_Selected.id_theme));

Active := true;

end;

except

Load_Question := false;

end;

end;

function Tdm.Load_Student: Boolean;

//Загрузка списка пользователей

begin

Load_Student := true;

try

With Query_Student do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM student') ;

Active := true;

end;

except

Load_Student := false;

end;

end;

function Tdm.Load_User: Boolean;

//Загрузка списка пользователей

begin

Load_User := true;

try

With Query_User do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM user') ;

Active := true;

end;

except

Load_User := false;

end;

end;

procedure Tdm.ReadSetting(FName: String; var Host, Port, Database, User, Password: String);

//Чтение настроек из файла

var

FSetting: File of TFSetting;

Setting: TFSetting;

begin

AssignFile(FSetting, FName);

Reset(FSetting);

Read(FSetting, Setting);

Host := Setting.Host;

port := Setting.Port;

user := Setting.User;

password := Setting.Password;

database := Setting.Database;

CloseFile(FSetting);

end;

function Tdm.SaveSkin(Path: String): String;

var

FileName: String;

begin

FileName := Path + dm.Query_Skin.FieldByName('name').AsString + '.asz';

(dm.Query_Skin.FieldByName('skin') as TBlobField).SaveToFile(FileName);

SaveSkin := FileName;

end;

procedure Tdm.SetAllSkinPriority(priority: String);

begin

try

With Query_Skin do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE skin set priority =' + priority) ;

Active := true;

end;

except

;

end;

end;

procedure Tdm.SetSkinPriority(priority: String; id_skin: integer);

begin

try

With Query_Skin do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE skin set priority = ' + priority) ;

SQL.Add('WHERE id_skin = ' + IntToStr(id_skin));

Active := true;

end;

except

;

end

end;

function Tdm.log_in(nik: String;

password: String): boolean;

//Проверка имени пользователя и пароля

begin

try

With Query_login do

begin

Active := false ;

SQL.Clear;

SQL.Add('select * from user where ');

SQL.Add('user = "' + nik + '" and ');

SQL.Add('password = "' + password + '"');

Active := true;

StrUser.id := FieldByName('id_user').AsInteger;

if not Query_login.IsEmpty then

begin

StrUser.user := FieldByName('user').AsString;

StrUser.pas := FieldByName('password').AsString;

StrUser.access := FieldByName('access').AsString;

StrUser.name := FieldByName('name').AsString;

StrUser.sname := FieldByName('sname').AsString;

StrUser.patronymic := FieldByName('patronymic').AsString;

log_in := true;

end

else

log_in := false;

end;

except

;

end;

end;

function Tdm.Query_Subject_Set: boolean;

//Получение списка предметов

begin

Query_Subject_Set := true;

try

With Query_Subject do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * FROM Subject ') ;

Active := true;

end;

except

ShowMessage('Ошибка получения списка предметов');

Query_Subject_Set := false;

end;

end;

function Tdm.Query_Theme_Set: Boolean;

//Получение списка тем по даному предмету

var

id_subject: Integer;

begin

Query_Theme_Set := true;

try

id_subject := Query_Subject.FieldByName('id_subject').AsInteger;

With Query_Theme do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * FROM theme WHERE id_subject = ' + IntToStr(id_subject));

Active := true;

end;

except

ShowMessage('Ошибка получения списка тем по данному предмету');

Query_Theme_Set := false;

end;

end;

end.

Приложение Б

Модуль тестирования

unit unit_dm;

interface

uses

SysUtils, Classes, ZConnection, DB, ZAbstractRODataset, ZAbstractDataset,

ZDataset, Dialogs, ZAbstractTable, XPMan, ExtDlgs, ActnList, Menus, ActnPopup,

XPStyleActnCtrls, ActnMan, ComCtrls, ZSqlMonitor, sSkinProvider, sSkinManager,

ImgList, Controls, RpRenderText, RpRenderRTF, RpRenderHTML, RpRender,

RpRenderPDF, RpCon, RpConDS, RpRave, RpDefine, RpBase, RpSystem, ExtCtrls;

type

TUser = record //Данные о пользователе

id: integer;

user: string;

pas: string;

access: string;

name: string;

sname: string;

patronymic: string;

end;

TFSetting = record//Настройки соединения

Host: String[100];

Port: String[100];

Database: String[100];

User: String[100];

Password: String[100];

end;

TSelection = record//Последние выбранные элементы

id_subject: integer;

id_theme: integer;

id_question: integer;

end;

Tdm = class(TDataModule)

ZConnection_spkvtk: TZConnection;

Query_login: TZQuery;

Query_data_test: TZQuery;

Table_Subject_test: TZTable;

Source_Subject: TDataSource;

Query_Subject: TZQuery;

Query_Create: TZQuery;

XP: TXPManifest;

Query_Answer: TZQuery;

Query_Question: TZQuery;

Source_Answer: TDataSource;

Source_Question: TDataSource;

OPD: TOpenPictureDialog;

Query_Illustration: TZQuery;

Source_Illustration: TDataSource;

Query_Delete: TZQuery;

Monitor: TZSQLMonitor;

Query_Theme: TZQuery;

Source_Theme: TDataSource;

Query_User: TZQuery;

Source_User: TDataSource;

SkinManager: TsSkinManager;

Query_Student: TZQuery;

Source_Student: TDataSource;

Query_Skin: TZQuery;

Source_Skin: TDataSource;

OD: TOpenDialog;

Query_Betta: TZQuery;

Source_Betta: TDataSource;

Query_Mark: TZQuery;

Source_Mark: TDataSource;

Query_Group: TZQuery;

RvSystem: TRvSystem;

RvProject: TRvProject;

RvConnectionMark: TRvDataSetConnection;

RvPDF: TRvRenderPDF;

RvHTML: TRvRenderHTML;

RvRTF: TRvRenderRTF;

RvText: TRvRenderText;

ImageList: TImageList;

procedure DataModuleCreate(Sender: TObject);//Создание модуля

procedure ReadSetting(FName: String; Var

Host,

Port,

Database,

User,

Password: String);//Чтение настроек из файла для доступа к БД

procedure ConnectSPKVTK();//Подключение к базе данных СПКВТК

private

{ Private declarations }

public

{ Public declarations }

StrUser: TUser ;//Данные о пользователе

Last_Selected: TSelection;//Последние выбранные элементы

order_str: string;

function log_in(nik: String;

password: String): Boolean ;// Проверка логина и пароля

function Query_Subject_Set(): Boolean;//Получение списка предметов

function Query_Theme_Set(): Boolean;//Получение списка тем по предмету

function Create_Subject_New(Subject_Name: String): Boolean;//Создание нового предмета

function Create_Theme_New(id_subject: integer; Theme_Name: String): Boolean;//Создание нового

function Create_Question_New(id_theme: integer): Boolean;//Создание вопроса

function Create_Answer_New(id_question: integer): Boolean;//Создание ответа

function Load_Answer(): Boolean;//Получение списка ответов по предмету

function Load_Question(): Boolean;//Получение списка вопросов

function Create_Illustration_New(id_question: integer): Boolean;//Создание иллюстрации к вопросу

function Load_Illustration(): Boolean;//Загрузка картинок к вопросу

function Load_User(): Boolean;//Загрузка списка пользователей

function Load_Student(): Boolean;//Загрузка списка пользователей

procedure Load_Query_Skin(); //Загрузка таблицы скиеов

procedure SetAllSkinPriority(priority: string);//Задать приоритет всем скинам

procedure SetSkinPriority(priority: string; id_skin: integer);//Задать приоритет одному скину

function SaveSkin(Path: String): String;//Сохранение скина на диск

procedure ApplySkin(FileName: String);//Применяет скин

procedure LoadSkinOutBD();//Загрузка скина ииз бд

procedure Load_Betta();//Загрузка заметок Бетта

procedure Load_Mark_Subject(id_subject: integer); //Загрузка оценок по предмету

procedure Load_Mark_Theme(id_theme: integer); //Загрузка оценок по теие

procedure Load_Mark_Group(id_theme: integer; n_group: String);//Загрузка оценок по теие

procedure Load_Marks_Al();//Загрузка всех оценок

procedure Load_Group();//Загруска списка груп

end;

var

dm: Tdm;

implementation

uses

unit_edit_test, unit_start, unit_authentication;

{$R *.dfm}

procedure Tdm.ApplySkin(FileName: String);

var

Fname: String;

I: Integer;

Name: String;

Path: String;

begin

Fname := dm.OD.FileName;

if FileExists( FileName ) then

begin

Path := ExtractFilePath(FileName);

Name := ExtractFileName(FileName);

Delete( Name, LastDelimiter( '.', Name ), Length( Name ) );

end

else

Name := '';

dm.SkinManager.SkinDirectory := Path;

dm.SkinManager.SkinName := Name;

dm.SkinManager.Active := true;

end;

procedure Tdm.ConnectSPKVTK;

// Подключение к базе данных СПКВТК

var

Host: String;

Port: String;

Database: String;

User: String;

Password: String;

begin

try

ReadSetting(ExtractFilePath(ParamStr(0))+'mysql.stg', Host, Port, Database, User, Password);

ZConnection_spkvtk.HostName := Host;

ZConnection_spkvtk.Port := StrToInt(Port);

ZConnection_spkvtk.Database := Database;

ZConnection_spkvtk.User := User;

ZConnection_spkvtk.Password := Password;

Zconnection_spkvtk.Connected := true;

except

ShowMessage('Ошибка подключения к ' + Host + ':' + Port);

authentication.Close;

end;

end;

function Tdm.Create_Answer_New(id_question: integer): Boolean;

//Создание нового ответа

begin

Create_Answer_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO answer(id_question, propstr, correct) VALUE(' + IntToStr(id_question) + ', true, false)') ;

Active := true;

Last_Selected.id_question := FieldByName('id_answer').AsInteger;

end;

except

;

end;

end;

function Tdm.Create_Illustration_New(id_question: integer): Boolean;

//Создание иллюстрации для вопроса

begin

Create_Illustration_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO q_illustration(id_question) VALUE(' + IntToStr(id_question) + ')') ;

Active := true;

end;

except

;

end;

end;

function Tdm.Create_Question_New(id_theme: integer): Boolean;

//Создание нового вопроса

begin

Create_Question_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO question(id_theme, only_one, mix_answer) VALUE(' + IntToStr(id_theme) + ', true, true)') ;

Active := true;

Last_Selected.id_question := FieldByName('id_question').AsInteger;

end;

except

;

end;

end;

function Tdm.Create_Subject_New(Subject_Name: String): Boolean;

//Создание нового предмета

begin

Create_Subject_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO subject(subject) VALUE("' + Subject_Name + '")') ;

Active := true;

end;

except

;

end;

end;

function Tdm.Create_Theme_New(id_subject: integer; Theme_Name: String): Boolean;

//Создание нового

begin

Create_Theme_New := true;

try

With Query_Create do

begin

Active := false;

SQL.Clear;

SQL.Add('INSERT INTO theme(id_subject, theme) VALUE(' + IntToStr(id_subject) + ', "' + Theme_Name + '")') ;

Active := true;

Last_Selected.id_theme := FieldByName('id_theme').AsInteger;

end;

except

;

end;

end;

procedure Tdm.DataModuleCreate(Sender: TObject);

//Создание модуля

begin

;

end;

procedure Tdm.LoadSkinOutBD;

var

path: string;

begin

try

With Query_Skin do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM skin') ;

SQL.Add('WHERE priority in (Select max(priority) FROM skin)' );

Active := true;

Path := ExtractFilePath(ParamStr(0)) + 'temp\';

if Eof then exit;

ApplySkin(SaveSkin(Path));

end;

except

;

end;

end;

function Tdm.Load_Answer: Boolean;

//Загрузка ответа на вопрос

begin

Load_Answer := true;

try

With Query_Answer do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM Answer') ;

SQL.Add('WHERE id_question=' + IntToStr(Query_Question.FieldByName('id_question').AsInteger));

Active := true;

end;

except

Load_Answer := false;

end;

end;

procedure Tdm.Load_Betta;

begin

try

With Query_Betta do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT *') ;

SQL.Add('FROM betta') ;

Active := true;

end;

except

;

end;

end;

procedure Tdm.Load_Group;

begin

try

With Query_Group do

begin

Active := false ;

SQL.Clear;

SQL.Add('SELECT DISTINCT n_group');

SQL.Add('FROM student');

Active := true;

end;

except

;

end;

end;

function Tdm.Load_Illustration: Boolean;

// загрузка иллюстраций к вопросу

begin

Load_Illustration := true;

try

With Query_illustration do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM q_illustration ') ;

SQL.Add('WHERE id_question=' + IntToStr(Query_Question.FieldByName('id_question').AsInteger));

Active := true;

end;

except

Load_illustration := false;

end;

end;

procedure Tdm.Load_Mark_Subject(id_subject: integer);

begin

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'su.id_subject = ' + IntToStr(id_subject));

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Mark_Theme(id_theme: integer);

begin

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'th.id_theme = ' + IntToStr(id_theme));

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Marks_Al;

begin

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'te.id_subject = su.id_subject');

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Mark_Group(id_theme: Integer; n_group: String);

begin

With Query_Mark do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT n_group, sname, name, subject, theme, mark, date_begin, time_begin, time_end, mark_5, mark_100 ');

SQL.Add('FROM test te, student st, subject su, theme th') ;

SQL.Add('WHERE te.id_subject = su.id_subject AND');

SQL.Add( 'te.id_theme = th.id_theme AND');

SQL.Add( 'te.id_student = st.id_student AND');

SQL.Add( 'th.id_theme = ' + IntToStr(id_theme) + ' AND ');

SQL.Add( 'st.n_group = ' + n_group);

if dm.order_str <> '' then

SQL.Add( 'ORDER BY ' + dm.order_str);

Active := true;

end;

end;

procedure Tdm.Load_Query_Skin;

begin

try

With Query_Skin do

begin

Active := false ;

SQL.Clear;

SQL.Add('SELECT *');

SQL.Add('FROM skin');

Active := true;

end;

except

;

end;

end;

function Tdm.Load_Question: Boolean;

//чтение вопросов по предмету

begin

Load_Question := true;

try

With Query_Question do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM Question') ;

SQL.Add('WHERE id_theme=' + IntToStr(Last_Selected.id_theme));

Active := true;

end;

except

Load_Question := false;

end;

end;

function Tdm.Load_Student: Boolean;

//Загрузка списка пользователей

begin

Load_Student := true;

try

With Query_Student do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM student') ;

Active := true;

end;

except

Load_Student := false;

end;

end;

function Tdm.Load_User: Boolean;

//Загрузка списка пользователей

begin

Load_User := true;

try

With Query_User do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * ') ;

SQL.Add('FROM user') ;

Active := true;

end;

except

Load_User := false;

end;

end;

procedure Tdm.ReadSetting(FName: String; var Host, Port, Database, User, Password: String);

//Чтение настроек из файла

var

FSetting: File of TFSetting;

Setting: TFSetting;

begin

AssignFile(FSetting, FName);

Reset(FSetting);

Read(FSetting, Setting);

Host := Setting.Host;

port := Setting.Port;

user := Setting.User;

password := Setting.Password;

database := Setting.Database;

CloseFile(FSetting);

end;

function Tdm.SaveSkin(Path: String): String;

var

FileName: String;

begin

FileName := Path + dm.Query_Skin.FieldByName('name').AsString + '.asz';

(dm.Query_Skin.FieldByName('skin') as TBlobField).SaveToFile(FileName);

SaveSkin := FileName;

end;

procedure Tdm.SetAllSkinPriority(priority: String);

begin

try

With Query_Skin do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE skin set priority =' + priority) ;

Active := true;

end;

except

;

end;

end;

procedure Tdm.SetSkinPriority(priority: String; id_skin: integer);

begin

try

With Query_Skin do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE skin set priority = ' + priority) ;

SQL.Add('WHERE id_skin = ' + IntToStr(id_skin));

Active := true;

end;

except

;

end

end;

function Tdm.log_in(nik: String;

password: String): boolean;

//Проверка имени пользователя и пароля

begin

try

With Query_login do

begin

Active := false ;

SQL.Clear;

SQL.Add('select * from user where ');

SQL.Add('user = "' + nik + '" and ');

SQL.Add('password = "' + password + '"');

Active := true;

StrUser.id := FieldByName('id_user').AsInteger;

if not Query_login.IsEmpty then

begin

StrUser.user := FieldByName('user').AsString;

StrUser.pas := FieldByName('password').AsString;

StrUser.access := FieldByName('access').AsString;

StrUser.name := FieldByName('name').AsString;

StrUser.sname := FieldByName('sname').AsString;

StrUser.patronymic := FieldByName('patronymic').AsString;

log_in := true;

end

else

log_in := false;

end;

except

;

end;

end;

function Tdm.Query_Subject_Set: boolean;

//Получение списка предметов

begin

Query_Subject_Set := true;

try

With Query_Subject do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * FROM Subject ') ;

Active := true;

end;

except

ShowMessage('Ошибка получения списка предметов');

Query_Subject_Set := false;

end;

end;

function Tdm.Query_Theme_Set: Boolean;

//Получение списка тем по даному предмету

var

id_subject: Integer;

begin

Query_Theme_Set := true;

try

id_subject := Query_Subject.FieldByName('id_subject').AsInteger;

With Query_Theme do

begin

Active := false;

SQL.Clear;

SQL.Add('SELECT * FROM theme WHERE id_subject = ' + IntToStr(id_subject));

Active := true;

end;

except

ShowMessage('Ошибка получения списка тем по данному предмету');

Query_Theme_Set := false;

end;

end;

end.

unit unit_inquirer;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Mask, DBCtrls, unit_dm, ExtCtrls, jpeg, Buttons, ComCtrls,

Grids, DBGrids, JRCheckBox, JRDBCheckBoxMySQL, DB, DBTables, Menus, ActnPopup,

ActnList, XPStyleActnCtrls, ActnMan, sEdit, sBitBtn, sDBRichEdit, sRichEdit,

sSplitter, sRadioButton, sCheckBox, sPanel, sScrollBox, sGroupBox, ToolWin,

sToolBar;

type

TForm_Inquirer = class(TForm)

MenuAnswer: TPopupMenu;

delete: TMenuItem;

PanelAnswer: TsPanel;

mix_answer: TJRDBCheckBoxMySQL;

only_one: TJRDBCheckBoxMySQL;

propstr: TJRDBCheckBoxMySQL;

mix_question: TJRDBCheckBoxMySQL;

QuestionText: TsDBRichEdit;

sToolBar1: TsToolBar;

BoxIllustration: TsGroupBox;

Questionillustration: TImage;

DBIllustrationText: TsDBRichEdit;

BoxIllustrationBtn: TsGroupBox;

dbILast: TsBitBtn;

dbINext: TsBitBtn;

dbIPrior: TsBitBtn;

dbIFirst: TsBitBtn;

dbIGoToN: TsBitBtn;

N_Illustration: TEdit;

sSplitter1: TsSplitter;

BoxAnswerBtn: TsGroupBox;

dbQLasst: TsBitBtn;

dbQNext: TsBitBtn;

dbQPrior: TsBitBtn;

dbQFirst: TsBitBtn;

dbQGoToN: TsBitBtn;

N_Question: TsEdit;

PaneMainlAnswer: TsPanel;

BoxAnswer: TsScrollBox;

BtnRendering: TsBitBtn;

procedure deleteClick(Sender: TObject);

procedure dbQCancelClick(Sender: TObject);

procedure dbIGoToNClick(Sender: TObject);

procedure dbILastClick(Sender: TObject);

procedure dbINextClick(Sender: TObject);

procedure dbIPriorClick(Sender: TObject);

procedure dbIFirstClick(Sender: TObject);

procedure dbQPostClick(Sender: TObject);

procedure dbQGoToNClick(Sender: TObject);

procedure dbQLasstClick(Sender: TObject);

procedure dbQNextClick(Sender: TObject);

procedure dbQPriorClick(Sender: TObject);

procedure dbQFirstClick(Sender: TObject);

procedure FormShow(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure FormClose(Sender: TObject; var Action: TCloseAction);

procedure BtnRenderingClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

procedure InsertAnswer();

procedure CreateList();

procedure DestroyObject();

procedure LoadQuestion();

procedure LoadAnswer();

procedure FreeListAnswer();

procedure ClickIllustrationAnswer(Sender: TObject);

procedure ClickRadioAnswer(Sender: TObject);

procedure ClikCheckAnswer(Sender: TObject);

procedure ClikTextAnswer(Sender: TObject);

procedure MouseDownAnswerText(Sender: TObject;

Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

procedure SaveAnswer();

procedure Loadillustration();

procedure Createillustration();

procedure ReLoadIllustration();

procedure SaveillustrationQuestion();

procedure ClikCheckPropStr(Sender: TObject);

procedure SetSQuestion();

procedure Rendering();

procedure QFirst();

procedure QPrior();

procedure QNext();

procedure QLast();

procedure QRecNo();//Переход к вопросу номер ...

procedure QSFirst();

procedure QSPrior();

procedure QSNext();

procedure QSLast();

procedure QSRecNo();

procedure AFirst();

procedure ANext();

procedure ASFirst();

procedure ASNext();

end;

var

Form_Inquirer: TForm_Inquirer;

AnswerTop: integer;

PanelList: TList;

TextList: TList;

SplitList: TList;

ImageList: TList;

CheckList: TLIst;

CheckStretchList: TLIst;

RadioList: TList;

RadioIndex: array[0..1000] of integer;

CheckIndex: array[0..1000] of integer;

CheckStretchIndex: array[0..1000] of integer;

TextIndex: array[0..1000] of integer;

IllustrationIndex: array[0..1000] of integer;

SenderRich: TObject;

IndexQuestion: integer;//Номер вопроса

IndexAnswer: integer;//Номер ответа на вопрос

implementation

{$R *.dfm}

uses

unit_private, unit_result;

procedure TForm_Inquirer.dbINextClick(Sender: TObject);

begin

dm.Query_Illustration.Next;

ReLoadIllustration();

end;

procedure TForm_Inquirer.dbIPriorClick(Sender: TObject);

begin

dm.Query_Illustration.Prior;

ReLoadIllustration();

end;

procedure TForm_Inquirer.AFirst;

begin

IndexAnswer := 1;

dm.Query_Answer.RecNo := dm.Navigator.NavigatorQuestion[IndexQuestion].No_answer[IndexAnswer];

end;

procedure TForm_Inquirer.ANext;

begin

Inc(IndexAnswer);

dm.Query_Answer.RecNo := dm.Navigator.NavigatorQuestion[IndexQuestion].No_answer[IndexAnswer];

end;

procedure TForm_Inquirer.ASFirst;

begin

dm.Query_S_Answer.RecNo := dm.Navigator.NavigatorQuestion[IndexQuestion].No_answer[IndexAnswer];

end;

procedure TForm_Inquirer.ASNext;

begin

dm.Query_S_Answer.RecNo := dm.Navigator.NavigatorQuestion[IndexQuestion].No_answer[IndexAnswer];

end;

procedure TForm_Inquirer.ClickIllustrationAnswer;

//обработчик клика на картинке ответа

begin

;

end;

procedure TForm_Inquirer.ClickRadioAnswer(Sender: TObject);

//клик на зависемом переключателе ответа

var

ID: integer;

ID_ND: integer;

index: integer;

Checked: Char;

begin

ID_ND := RadioIndex[TsRadioButton(Sender).Tag];

index := 0;

while index < 100 do

begin

try

ID := RadioIndex[TsRadioButton(RadioList.Items[index]).Tag];

Checked := '0';

if ID = ID_ND then

begin

TsRadioButton(RadioList.Items[index]).Checked := True;

With dm.Query_S_Answer do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE s_answer ') ;

SQL.Add('SET correct = 1');

SQL.Add('WHERE id_s_answer =' + IntToStr(ID));

Active := true;

end;

end

else

begin

TsRadioButton(RadioList.Items[index]).Checked := False;

With dm.Query_S_Answer do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE s_answer ') ;

SQL.Add('SET correct = 0');

SQL.Add('WHERE id_s_answer =' + IntToStr(ID));

Active := true;

end;

end;

except

;

end;

Inc(index);

end;

end;

procedure TForm_Inquirer.ClikCheckAnswer(Sender: TObject);

//клик на независемом переключателе ответа

var

ID: integer;

ID_ND: integer;

index: integer;

Checked: Char;

begin

ID_ND := CheckIndex[TsCheckBox(Sender).Tag];

index := 0;

while index < 100 do

begin

try

ID := CheckIndex[TsCheckBox(CheckList.Items[index]).Tag];

if ID = ID_ND then

begin

if TsCheckBox(CheckList.Items[index]).Checked = True then

Checked := '1'

else

Checked := '0';

With dm.Query_S_Answer do

begin

Active := false;

SQL.Clear;

SQL.Add('UPDATE s_answer ') ;

SQL.Add('SET correct = ' + Checked);

SQL.Add('WHERE id_s_answer =' + IntToStr(ID));

Active := true;

end;

end;

except

;

end;

inc(index);

end;

end;

procedure TForm_Inquirer.ClikCheckPropStr(Sender: TObject);

begin

;

end;

procedure TForm_Inquirer.ClikTextAnswer(Sender: TObject);

//клик на поле ткста ответа

begin

SenderRich := Sender;

end;

procedure TForm_Inquirer.Createillustration;

begin

end;

procedure TForm_Inquirer.CreateList;

begin

// Создание контейнеров Tlist для нумерации компонентов

TextList := TList.Create;

PanelList := TList.Create;

SplitList := TList.Create;

ImageList := TList.Create;

CheckList := TLIst.Create;

CheckStretchList := TLIst.Create;

RadioList := TList.Create;

end;

procedure TForm_Inquirer.DestroyObject;

begin

FreeListAnswer();

end;

procedure TForm_Inquirer.dbQCancelClick(Sender: TObject);

begin

try

dm.Query_Question.Cancel;

except

;

end;

SaveAnswer();

LoadQuestion();

end;

procedure TForm_Inquirer.dbQFirstClick(Sender: TObject);

//переход на первый вопрос


Подобные документы

Работы в архивах красиво оформлены согласно требованиям ВУЗов и содержат рисунки, диаграммы, формулы и т.д.
PPT, PPTX и PDF-файлы представлены только в архивах.
Рекомендуем скачать работу.