Смекни!
smekni.com

Процесс информирования родителей об успеваемости учеников (стр. 6 из 6)

then

begin

ADOTable1.Edit;

for y:=2 to High(Matrix[x]) do

if (ADOTable1.FieldByName(Matrix[0,y]).Value<>Matrix[x,y])

and(Matrix[x,y]<>'')

then

ADOTable1.FieldByName(Matrix[0,y]).Value:=Matrix[x,y]+#14;

ADOTable1.Post;

end

else

begin

ADOTable1.Append;

ADOTable1.FieldByName('Предмет').Value:=WS.Name;

for y:=2 to High(Matrix[x]) do

if Matrix[x,y]<>''

then

ADOTable1.FieldByName(Matrix[0,y]).Value:=Matrix[x,y]+#14;

ADOTable1.Post;

end;

ADOTable1.Close;

//---

end;

//конец Цикл3

Progress.AddProgress(Round(100/(Length(FileList)*WB.Sheets.Count)));

end;

//конец Цикл2

WB.Close;

ADOConnection1.CommitTrans;

ADOConnection1.Close;

end;

//конец Цикл1

//Изменение размера окна

Progress.AddProgress(100);

Progress.Destroy;

Label1_.Destroy;

Label2_.Destroy;

StaticText.Destroy;

ClientHeight:=ClientHeight-111;

Constraints.MaxHeight:=200;

CreateMessages; //Создание сообщений

MessageDlg('Данные успешно внесены',mtInformation,[mbOK],0);

end;

{-------Отправка сообщений--------}

procedure TMainForm.SendBtnClick(Sender: TObject);

var

S1,S2:string;

S:WideString;

start,n,i:integer;

begin

MainForm.nrComm1.Active:=true;

ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetCurrentDir+'&bsol;DataBases&bsol;MainDB.mdb;Persist Security Info=False';

ADOConnection1.Open;

ADOConnection1.BeginTrans;

//Открытие таблицы "Сообщения" в MainDB.mdb

ADOTable1.TableName:='Сообщения';

ADOTable1.Open;

ADOTable1.First;

start:=0;

//Цикл1

While not ADOTable1.Eof do

begin

//Сообщение отправлено?

if not ADOTable1.FieldByName('Статус отправки').AsBoolean

then

begin

if (ADOTable1.FieldByName('Номер абонента').Value<>'')or(ADOTable1.FieldByName('Номер абонента').Value<>null)

then

begin

S1:=ADOTable1.FieldByName('Номер абонента').Value;

S:=ADOTable1.FieldByName('Текст сообщения').Value;

n:=1;

if Length(S)>69

then

n:=(Length(S) div 69)+1;

if ((Length(S)+n*4)div 69)>(n-1)

then

Inc(n);

if n>1

then

for i:=1 to n do

begin

S:=IntToStr(i)+'/'+IntToStr(n)+#10+S;

S2:=copy(S,1,69);

S:=copy(S,70,Length(S)-69);

//Отправка сообщения абоненту

nrGsm1.SmsSend(S1,S2,false);

//Ожидание 15 секунд для отправки сообщения

Delay(15000);

end

else

begin

//Отправка сообщения абоненту

nrGsm1.SmsSend(S1,S,false);

//Ожидание 15 секунд для отправки сообщения

Delay(15000);

end;

ADOTable1.Edit;

ADOTable1.FieldValues['Статус отправки']:=true;

ADOTable1.FieldByName('Дата отправки').Value:=DateToStr(Today);

ADOTable1.UpdateRecord;

ADOTable1.Post;

end;

Inc(Start);

end;

ADOTable1.Next;

end;

//конец Цикл1

ADOTable1.Close;

ADOConnection1.CommitTrans;

ADOConnection1.Close;

//N сообщений отправлено

MessageDlg('Отправлено сообщений:'+IntToStr(start)+'.',mtInformation,[mbOK],0);

end;

procedure TMainForm.FormShow(Sender: TObject);

begin

Form1.ShowModal;

OpenHideBtn.Caption:=#134;

end;

procedure TMainForm.OpenHideBtnClick(Sender: TObject);

var

i:integer;

begin

i:=Width;

if OpenHideBtn.Left=320 then

begin

Constraints.MaxWidth:=474;

Width:=i+100;

OpenHideBtn.Left:=420;

OpenHideBtn.Layout:=blGlyphRight;

OpenHideBtn.Caption:=#133;

PupilsBtn.Visible:=true;

MsgBtn.Visible:=true;

end

else

begin

Constraints.MaxWidth:=374;

OpenHideBtn.Left:=320;

OpenHideBtn.Top:=0;

Width:=i-100;

OpenHideBtn.Layout:=blGlyphLeft;

OpenHideBtn.Caption:=#134;

PupilsBtn.Visible:=false;

MsgBtn.Visible:=false;

end;

end;

procedure TMainForm.PupilsBtnClick(Sender: TObject);

var

i,j:integer;

Exist:boolean;

begin

DBForm.Caption:='База данных Ученики';

DBForm.HeaderLbl.Caption:='Введите необходимую информацию';

DBForm.HeaderLbl.Visible:=true;

DBForm.YearEdit.Visible:=true;

DBForm.YearLbl.Visible:=true;

DBForm.TermEdit.Visible:=true;

DBForm.TermLbl.Visible:=true;

DBForm.SchoolCBox.Visible:=true;

DBForm.SchoolLbl.Visible:=true;

DBForm.FormCBox.Visible:=true;

DBForm.FormLbl.Visible:=true;

DBForm.PupilCBox.Visible:=true;

DBForm.PupilLbl.Visible:=true;

DBForm.TermEdit.Enabled:=false;

DBForm.SchoolCBox.Enabled:=false;

DBForm.FormCBox.Enabled:=false;

DBForm.PupilCBox.Enabled:=false;

DBForm.YearEdit.Text:='';

DBForm.TermEdit.Text:='';

DBForm.SchoolCBox.Clear;

DBForm.FormCBox.Clear;

DBForm.PupilCBox.Clear;

DBForm.Width:=672;

DBForm.Constraints.MaxWidth:=672;

DBForm.TextMsg.Visible:=false;

ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetCurrentDir+'&bsol;DataBases&bsol;MainDB.mdb;Persist Security Info=False';

ADOTable1.TableName:='Школы';

SetLength(SchoolList,0);

SetLength(FormList,0,0);

ADOTable1.Open;

ADOTable1.First;

While not ADOTable1.Eof do

begin

SetLength(SchoolList,Length(SchoolList)+1);

SetLength(FormList,Length(FormList)+1);

SchoolList[High(SchoolList)]:=ADOTable1.FieldByName('Школа').AsString;

While (ADOTable1.FieldByName('Школа').AsString=SchoolList[High(SchoolList)])and(not ADOTable1.Eof) do

begin SetLength(FormList[High(FormList)],Length(FormList[High(FormList)])+1); FormList[High(FormList),High(FormList[High(FormList)])]:=ADOTable1.FieldByName('Класс').AsString;

ADOTable1.Next;

end;

end;

ADOTable1.Close;

DBForm.SchoolCBox.Clear;

for i:=0 to High(SchoolList)do

DBForm.SchoolCBox.Items.Add(SchoolList[i]);

DBForm.DBGrid1.ReadOnly:=true;

DBForm.DBGrid1.OnDrawDataCell:=DBForm.DBGrid1DrawDataCell1;

DBForm.ShowModal;

end;

procedure TMainForm.MsgBtnClick(Sender: TObject);

begin

DBForm.Caption:='База данных Сообщения';

DBForm.HeaderLbl.Caption:='Нажмите сообщение, текст которого хотите посмотреть';

DBForm.YearEdit.Visible:=false;

DBForm.YearLbl.Visible:=false;

DBForm.TermEdit.Visible:=false;

DBForm.TermLbl.Visible:=false;

DBForm.SchoolCBox.Visible:=false;

DBForm.SchoolLbl.Visible:=false;

DBForm.FormCBox.Visible:=false;

DBForm.FormLbl.Visible:=false;

DBForm.PupilCBox.Visible:=false;

DBForm.PupilLbl.Visible:=false;

DBForm.Width:=672;

DBForm.Constraints.MaxWidth:=672;

DBForm.TextMsg.Visible:=false;

ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetCurrentDir+'&bsol;DataBases&bsol;MainDB.mdb;Persist Security Info=False';

ADOTable1.TableName:='Сообщения';

ADOTable1.Active:=true;

DBForm.DBGrid1.ReadOnly:=false;

DBForm.DBGrid1.OnDrawDataCell:=DBForm.DBGrid1DrawDataCell;

DBForm.ShowModal;

end;

end.

ОкноотображенияБД (листинг)

unit DBWindow;

interface

uses

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

Dialogs, MainWindow, Grids, DBGrids, DB, DBTables, StdCtrls;

type

TDBForm = class(TForm)

DBGrid1: TDBGrid;

DataSource1: TDataSource;

YearEdit: TEdit;

TermEdit: TEdit;

SchoolCBox: TComboBox;

FormCBox: TComboBox;

PupilCBox: TComboBox;

TextMsg: TMemo;

YearLbl: TLabel;

TermLbl: TLabel;

SchoolLbl: TLabel;

FormLbl: TLabel;

PupilLbl: TLabel;

HeaderLbl: TLabel;

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

procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

Field: TField; State: TGridDrawState);

procedure DBGrid1DrawDataCell1(Sender: TObject; const Rect: TRect;

Field: TField; State: TGridDrawState);

procedure SchoolCBoxChange(Sender: TObject);

procedure FormCBoxChange(Sender: TObject);

procedure PupilCBoxChange(Sender: TObject);

procedure YearEditChange(Sender: TObject);

procedure TermEditChange(Sender: TObject);

procedure DBGrid1CellClick(Column: TColumn);

procedure FormCreate(Sender: TObject);

procedure DBGrid1KeyUp(Sender: TObject; var Key: Word;

Shift: TShiftState);

private

{ Private declarations }

public

{ Public declarations }

end;

var

DBForm: TDBForm;

implementation

{$R *.dfm}

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

begin

MainForm.ADOTable1.Active:=false;

MainForm.ADOConnection1.Close;

FormCBox.Enabled:=false;

PupilCBox.Enabled:=false;

//MainForm.ADOTable1.Close;

end;

procedure TDBForm.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;

Field: TField; State: TGridDrawState);

var

S: string;

begin

if Field is TMemoField then

with (Sender as TDBGrid).Canvas do

begin

S := MainForm.ADOTable1.FieldValues['Текстсообщения'];

{ remove carriage returns & line feeds }

while Pos(#13, S) > 0 do S[Pos(#13, S)] := ' ';

while Pos(#10, S) > 0 do S[Pos(#10, S)] := ' ';

{ clear the cell }

FillRect(Rect);

{ fill cell with memo data }

TextOut(Rect.Left, Rect.Top, S);

end;

end;

procedure TDBForm.SchoolCBoxChange(Sender: TObject);

var

i:integer;

begin

FormCBox.Enabled:=true;

PupilCBox.Enabled:=false;

FormCBox.Clear;

for i:=0 to High(FormList[SchoolCBox.ItemIndex])do

DBForm.FormCBox.Items.Add(FormList[SchoolCBox.ItemIndex,i]);

end;

procedure TDBForm.FormCBoxChange(Sender: TObject);

begin

PupilCBox.Enabled:=true;

PupilCBox.Clear;

if FileExists(GetCurrentDir+'&bsol;DataBases&bsol;'+SchoolCBox.Items.Strings[SchoolCBox.ItemIndex]+'&bsol;'+FormCBox.Items.Strings[FormCBox.ItemIndex]+'&bsol;'+'DB_'+TermEdit.Text+'_'+YearEdit.Text+'.mdb')

then

begin

MainForm.ADOConnection1.Close;

MainForm.ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetCurrentDir+'&bsol;DataBases&bsol;'+SchoolCBox.Items.Strings[SchoolCBox.ItemIndex]+'&bsol;'+FormCBox.Items.Strings[FormCBox.ItemIndex]+'&bsol;'+'DB_'+TermEdit.Text+'_'+YearEdit.Text+'.mdb;Persist Security Info=False';

MainForm.ADOTable1.TableName:='Ученики';

MainForm.ADOTable1.Open;

MainForm.ADOTable1.First;

While not MainForm.ADOTable1.Eof do

begin

PupilCBox.Items.Add(MainForm.ADOTable1.FieldValues['Фамилия']+' '+MainForm.ADOTable1.FieldValues['Имя']+' - '+MainForm.ADOTable1.FieldValues['Телефон']);

MainForm.ADOTable1.Next;

end;

MainForm.ADOTable1.Close;

end

else

begin

PupilCBox.Items.Add('НеттакойБД');

PupilCBox.ItemIndex:=0;

PupilCBox.Enabled:=false;

end;

end;

procedure TDBForm.PupilCBoxChange(Sender: TObject);

begin

MainForm.ADOConnection1.Close; MainForm.ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetCurrentDir+'&bsol;DataBases&bsol;'+SchoolCBox.Items.Strings[SchoolCBox.ItemIndex]+'&bsol;'+FormCBox.Items.Strings[FormCBox.ItemIndex]+'&bsol;'+'DB_'+TermEdit.Text+'_'+YearEdit.Text+'.mdb;Persist Security Info=False';

MainForm.ADOTable1.TableName:=PupilCBox.Items.Strings[PupilCBox.ItemIndex];

MainForm.ADOTable1.Active:=true;

end;

procedure TDBForm.YearEditChange(Sender: TObject);

begin

MainForm.ADOTable1.Active:=false;

MainForm.ADOConnection1.Close;

TermEdit.Text:='';

SchoolCBox.ItemIndex:=-1;

FormCBox.ItemIndex:=-1;

PupilCBox.ItemIndex:=-1;

TermEdit.Enabled:=true;

SchoolCBox.Enabled:=false;

FormCBox.Enabled:=false;

PupilCBox.Enabled:=false;

end;

procedure TDBForm.TermEditChange(Sender: TObject);

begin

MainForm.ADOTable1.Active:=false;

MainForm.ADOConnection1.Close;

SchoolCBox.ItemIndex:=-1;

FormCBox.ItemIndex:=-1;

PupilCBox.ItemIndex:=-1;

SchoolCBox.Enabled:=true;

FormCBox.Enabled:=false;

PupilCBox.Enabled:=false;

end;

procedure TDBForm.DBGrid1CellClick(Column: TColumn);

var

S1,S2:string;

begin

TextMsg.Clear;

if Column.FieldName='Текстсообщения'

then

begin

Constraints.MaxWidth:=856;

Width:=856;

TextMsg.Visible:=true;

S1:=DBGrid1.SelectedField.AsString;

while pos(#10,S1)>1 do

begin

S2:=copy(S1,1,pos(#10,S1)-1);

S1:=copy(S1,pos(#10,S1)+1,Length(S1)-pos(#10,S1));

TextMsg.Lines.Add(S2);

end;

end

else

begin

Width:=672;

Constraints.MaxWidth:=672;

TextMsg.Visible:=false;

end;

end;

procedure TDBForm.FormCreate(Sender: TObject);

begin

YearEdit.Text:='';

TermEdit.Text:='';

SchoolCBox.Clear;

FormCBox.Clear;

PupilCBox.Clear;

end;

procedure TDBForm.DBGrid1KeyUp(Sender: TObject; var Key: Word;

Shift: TShiftState);

begin

if (key=vk_left)or(key=vk_up)or(key=vk_right)or(key=vk_down)

then

DBGrid1CellClick(DBGrid1.Columns.Items[DBGrid1.SelectedIndex]);

end;

end.