Смекни!
smekni.com

Разработка базы данных (стр. 17 из 20)

TBUpdate: TToolButton;

TBFirst: TToolButton;

TBPrev: TToolButton;

TBNext: TToolButton;

TBLast: TToolButton;

ActionList1: TActionList;

DataSetFirst: TDataSetFirst;

DataSetPrior: TDataSetPrior;

DataSetNext: TDataSetNext;

TBRefrash: TToolButton;

DataSetLast: TDataSetLast;

DataSetInsert: TAction;

DataSetDelete: TAction;

DataSetUpdate: TAction;

DataSetRefrash: TAction;

ApplicationEvents1: TApplicationEvents;

FileExit: TFileExit;

MainMenu1: TMainMenu;

HelpAbout: TAction;

mmTable: TMenuItem;

mmFile: TMenuItem;

mmSort: TMenuItem;

mmExit: TMenuItem;

mmFirst: TMenuItem;

mmPrior: TMenuItem;

mmNext: TMenuItem;

mmLast: TMenuItem;

N5: TMenuItem;

mmInsert: TMenuItem;

mmDelete: TMenuItem;

mmUpdate: TMenuItem;

mmRefrash: TMenuItem;

mmHelp: TMenuItem;

SortByNum: TAction;

SortByAut: TAction;

SortByTit: TAction;

SortByLan: TAction;

SortByNo: TAction;

SortDirInc: TAction;

SortDirDec: TAction;

TBOpen: TToolButton;

DataSetOpen: TAction;

mmOpen: TMenuItem;

mmSortByNum: TMenuItem;

mmSortByAut: TMenuItem;

mmSortByTit: TMenuItem;

mmSortByLan: TMenuItem;

mmSortByNo: TMenuItem;

N12: TMenuItem;

mmSortDirInc: TMenuItem;

mmSortDirDec: TMenuItem;

mmAbout: TMenuItem;

DataSetFind: TAction;

DataSetFilter: TAction;

N14: TMenuItem;

mmFind: TMenuItem;

TBFind: TToolButton;

TBSapce2: TToolButton;

DataSetFindNext: TAction;

TBSpace1: TToolButton;

TBFindNext: TToolButton;

mmFindNext: TMenuItem;

TBFilter: TToolButton;

mmFilter: TMenuItem;

DataSetAll: TAction;

TBAll: TToolButton;

mmAll: TMenuItem;

FileUser: TAction;

N18: TMenuItem;

mmUser: TMenuItem;

mmOptions: TMenuItem;

OptColor: TAction;

OptFont: TAction;

FileDataBasePath: TAction;

mmDataBasePath: TMenuItem;

ColorDialog1: TColorDialog;

FontDialog1: TFontDialog;

mmColor: TMenuItem;

mmFont: TMenuItem;

PanelMain: TPanel;

PanelMemo: TPanel;

DBMemo1: TDBMemo;

Panel1: TPanel;

PanelGrid: TPanel;

Panel2: TPanel;

DBGrid1: TDBGrid;

Splitter1: TSplitter;

StatusBar1: TStatusBar;

Edit1: TEdit;

OptConfDel: TAction;

mmOptConfDel: TMenuItem;

N19: TMenuItem;

procedure FormCreate(Sender: TObject);

procedure FormActivate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure SaveIniFiles;

procedure RestoreIniFiles;

procedure ApplicationEvents1Hint(Sender: TObject);

procedure RadioGroup1Click(Sender: TObject);

procedure RadioGroup2Click(Sender: TObject);

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

DataCol: Integer; Column: TColumn; State: TGridDrawState);

procedure DBGrid1ColExit(Sender: TObject);

procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);

procedure Edit1Exit(Sender: TObject);

procedure DataSetInsertExecute(Sender: TObject);

procedure DataSetDeleteExecute(Sender: TObject);

procedure DataSetUpdateExecute(Sender: TObject);

procedure DataSetRefrashExecute(Sender: TObject);

procedure DataSetOpenExecute(Sender: TObject);

procedure DataSetFindExecute(Sender: TObject);

procedure DataSetFindNextExecute(Sender: TObject);

procedure DataSetFilterExecute(Sender: TObject);

procedure DataSetAllExecute(Sender: TObject);

procedure FileDataBasePathExecute(Sender: TObject);

procedure FileUserExecute(Sender: TObject);

procedure OptColorExecute(Sender: TObject);

procedure OptFontExecute(Sender: TObject);

procedure OptConfDelExecute(Sender: TObject);

procedure HelpAboutExecute(Sender: TObject);

private

EditField : Integer;

OpenCounter: Integer;

public

{ Public declarations }

end;

var

MainForm: TMainForm;

implementation

uses DB, ShellAPI, IniFiles, DBUnit,

Edit, About, Files, Delete, Data, Find,

Filter, User, Path;

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);

begin

Root:=ExtractFilePath(Application.ExeName);

if not DirectoryExists(TmpDir) then

MkDir(TmpDir)

else

DeleteFiles(MainForm.Handle,Concat(Root,TmpDir,'*.*'));

MkDir(BrowseDir);

OpenCounter:=0;

end;

procedure TMainForm.FormActivate(Sender: TObject);

begin

RestoreIniFiles;

if not DataModule1.InitDBParams then Close;

DataModule1.SetAccess;

DataSetInsert.Enabled:=DataModule1.fWriter;

DataSetDelete.Enabled:=DataModule1.fWriter;

DataSetUpdate.Enabled:=DataModule1.fWriter;

DataSetRefrashExecute(Sender);

end;

procedure TMainForm.FormDestroy(Sender: TObject);

begin

DeleteFiles(MainForm.Handle,Concat(Root,TmpDir,'*.*'));

ChDir(Root);

RmDir(TmpDir);

SaveIniFiles;

end;

procedure TMainForm.SaveIniFiles;

var

F : TIniFile;

FN: ANSIString;

begin

FN:=Concat(Root,IniFile);

F:=TIniFile.Create(FN);

with F do

begin

WriteString('DataBase','Server',DataModule1.fServer);

WriteString('DataBase','File',DataModule1.fFile);

WriteString('DataBase','DefaultUser',DBDefaultUser);

WriteString('DataBase','DefaultPassword',DBDefaultPass);

WriteInteger('Window','State',Ord(WindowState));

WriteInteger('Window','Top',BoundsRect.Top);

WriteInteger('Window','Left',BoundsRect.Left);

WriteInteger('Window','Bottom',BoundsRect.Bottom);

WriteInteger('Window','Right',BoundsRect.Right);

WriteInteger('Window','Spliter',PanelMemo.Height);

WriteInteger('Memo','Top',PanelMemo.BoundsRect.Top);

WriteInteger('Memo','Bottom',PanelMemo.BoundsRect.Bottom);

WriteInteger('Grid','Author',DBGrid1.Columns.Items[0].Width);

WriteInteger('Grid','Title',DBGrid1.Columns.Items[1].Width);

WriteInteger('Grid','Language',DBGrid1.Columns.Items[2].Width);

WriteInteger('Grid','Archive',DBGrid1.Columns.Items[3].Width);

WriteInteger('Grid','File',DBGrid1.Columns.Items[4].Width);

WriteInteger('Options','Color',DBMemo1.Color);

WriteBool('Options','ConfDel',ConfirmDelete);

WriteInteger('Font','Charset',DBMemo1.Font.Charset);

WriteInteger('Font','Color',DBMemo1.Font.Color);

WriteInteger('Font','Height',DBMemo1.Font.Height);

WriteString('Font','Name',DBMemo1.Font.Name);

WriteInteger('Font','Pitch',Ord(DBMemo1.Font.Pitch));

WriteInteger('Font','Size',DBMemo1.Font.Size);

WriteBool('Font','Bold',fsBold in DBMemo1.Font.Style);

WriteBool('Font','Italic',fsItalic in DBMemo1.Font.Style);

WriteBool('Font','Underline',fsUnderline in DBMemo1.Font.Style);

WriteBool('Font','StrikeOut',fsStrikeOut in DBMemo1.Font.Style);

Free;

end;

end;

procedure TMainForm.RestoreIniFiles;

var

F : TIniFile;

FN : ANSIString;

WinSt: Byte;

WinTop: Integer;

WinLeft: Integer;

WinBottom: Integer;

WinRight: Integer;

X : LongInt;

S : ShortString;

begin

FN:=Concat(Root,IniFile);

if FileExists(FN) then

begin

F:=TIniFile.Create(FN);

with DataModule1 do

begin

fServer:=F.ReadString('DataBase','Server',DBDefaultServer);

fFile:=F.ReadString('DataBase','File',DBDefaultFile);

end;

DBDefaultUser:=F.ReadString('DataBase','DefaultUser',DBDefaultUser);

DBDefaultPass:=F.ReadString('DataBase',' Default Password',DBD efault Pass);

WinSt:=F.ReadInteger('Window','State',DefaultWinState);

case WinSt of

0: WindowState:=wsNormal;

1: WindowState:=wsMinimized;

2: WindowState:=wsMaximized;

end;

WinTop:=F.ReadInteger('Window','Top',DefaultWinTop);

WinLeft:=F.ReadInteger('Window','Left',DefaultWinLeft);

WinBottom:=F.ReadInteger('Window','Bottom',DefaultWinBottom);

WinRight:=F.ReadInteger('Window','Right',DefaultWinRight);

SetBounds(WinLeft,WinTop,WinRight-WinLeft,WinBottom-WinTop);

PanelMemo.Height:=F.ReadInteger('Window','Spliter',30);

with DBGrid1.Columns do

begin

Items[0].Width:=F.ReadInteger('Grid','Author',DefaultGrid1);

Items[1].Width:=F.ReadInteger('Grid','Title',DefaultGrid2);

Items[2].Width:=F.ReadInteger('Grid','Language',DefaultGrid3);

Items[3].Width:=F.ReadInteger('Grid','Archive',DefaultGrid4);

Items[4].Width:=F.ReadInteger('Grid','File',DefaultGrid5);

end;

X:=F.ReadInteger('Options','Color',DefaultColor);

DBGrid1.Color:=X;

DBMemo1.Color:=X;

Edit1.Color:=X;

ConfirmDelete:=F.ReadBool('Options','ConfDel',ConfirmDelete);

X:=F.ReadInteger('Font','Charset',DefaultFontCharset);

DBGrid1.Font.Charset:=X;

DBMemo1.Font.Charset:=X;

Edit1.Font.Charset:=X;

X:=F.ReadInteger('Font','Color',DefaultFontColor);

DBGrid1.Font.Color:=X;

DBMemo1.Font.Color:=X;

Edit1.Font.Color:=X;

X:=F.ReadInteger('Font','Height',DefaultFontHeight);

DBGrid1.Font.Height:=X;

DBMemo1.Font.Height:=X;

Edit1.Font.Height:=X;

S:=F.ReadString('Font','Name',DefaultFontName);

DBGrid1.Font.Name:=S;

DBMemo1.Font.Name:=S;

Edit1.Font.Name:=S;

X:=F.ReadInteger('Font','Pitch',DefaultFontPitch);

case X of

0:

begin

DBGrid1.Font.Pitch:=fpDefault;

DBMemo1.Font.Pitch:=fpDefault;

Edit1.Font.Pitch:=fpDefault;

end;

1:

begin

DBGrid1.Font.Pitch:=fpFixed;

DBMemo1.Font.Pitch:=fpFixed;

Edit1.Font.Pitch:=fpFixed;

end;

2:

begin

DBGrid1.Font.Pitch:=fpVariable;

DBMemo1.Font.Pitch:=fpVariable;

Edit1.Font.Pitch:=fpVariable;

end;

end;

X:=F.ReadInteger('Font','Size',DefaultFontSize);

DBGrid1.Font.Size:=X;

DBMemo1.Font.Size:=X;

Edit1.Font.Size:=X;

if F.ReadBool('Font','Bold',DefaultFontBold) then

begin

DBGrid1.Font.Style:=DBGrid1.Font.Style+[fsBold];

DBMemo1.Font.Style:=DBMemo1.Font.Style+[fsBold];

Edit1.Font.Style:=Edit1.Font.Style+[fsBold];

end;

if F.ReadBool('Font','Italic',DefaultFontItalic) then

begin

DBGrid1.Font.Style:=DBGrid1.Font.Style+[fsItalic];

DBMemo1.Font.Style:=DBMemo1.Font.Style+[fsItalic];

Edit1.Font.Style:=Edit1.Font.Style+[fsItalic];

end;

if F.ReadBool('Font','Underline',DefaultFontUnderline) then

begin

DBGrid1.Font.Style:=DBGrid1.Font.Style+[fsUnderline];

DBMemo1.Font.Style:=DBMemo1.Font.Style+[fsUnderline];

Edit1.Font.Style:=Edit1.Font.Style+[fsUnderline];

end;

if F.ReadBool('Font','StrikeOut',DefaultFontStrikeOut) then

begin

DBGrid1.Font.Style:=DBGrid1.Font.Style+[fsStrikeOut];

DBMemo1.Font.Style:=DBMemo1.Font.Style+[fsStrikeOut];

Edit1.Font.Style:=Edit1.Font.Style+[fsStrikeOut];

end;

F.Free;

end;

end;

procedure TMainForm.ApplicationEvents1Hint(Sender: TObject);

begin

StatusBar1.SimpleText:=Application.Hint;

end;

procedure TMainForm.RadioGroup1Click(Sender: TObject);

begin

DataSetRefrashExecute(Sender);

end;

procedure TMainForm.RadioGroup2Click(Sender: TObject);

begin

DataSetRefrashExecute(Sender);

end;

procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;

const Rect: TRect; DataCol: Integer; Column: TColumn;

State: TGridDrawState);

begin

if (DataModule1.fWriter) and (gdFocused in State) then

if (Column.Field.FieldName = 'Author') or

(Column.Field.FieldName = 'Title') or

(Column.Field.FieldName = 'Language') then

begin

EditField:=Column.Field.FieldNo-1;

Edit1.Text:=Column.Field.AsString;

with Edit1 do

begin

Left := Rect.Left + DBGrid1.Left;

Top := Rect.Top + DBGrid1.Top+PanelGrid.Top+PanelMain.Top;

Width := Rect.Right - Rect.Left + 2;

Visible := True;

end;

end;

end;

procedure TMainForm.DBGrid1ColExit(Sender: TObject);

var

FldName : ShortString;

begin

if DataModule1.fWriter then

begin

FldName:=DBGrid1.SelectedField.FieldName;

if (FldName = 'Author') or

(FldName = 'Title') or

(FldName = 'Language') then

begin

Edit1.Visible := False;

end;

end;

end;

procedure TMainForm.DBGrid1KeyPress(Sender: TObject; var Key: Char);

var

FldName : ShortString;

begin

if DataModule1.fWriter then

begin

FldName:=DBGrid1.SelectedField.FieldName;

if (FldName = 'Author') or

(FldName = 'Title') or

(FldName = 'Language') then

if (Key <> Chr(9)) then

begin

Edit1.SetFocus;

SendMessage(Edit1.Handle, WM_CHAR, Word(Key), 0);

end;

end;

end;

procedure TMainForm.Edit1Exit(Sender: TObject);

const

NamePre='Update';

ParPre ='ip';

Par: array [1..5] of ShortString=('Aut', 'Tit', 'Lan', 'Typ' ,'Ext');

begin

with DataModule1, DataModule1.IBStoredProc1 do

if IBDataSet1.Fields.Fields[EditField].AsString<>Edit1.Text then

begin

StoredProcName:=NamePre+IBDataSet1.FieldList.Strings[EditField];

ParamByName(ParPre+Par[EditField]).Value:=Edit1.Text;

ParamByName('ipNum').Value:=IBDataSet1.Fields.Fields[0].AsInteger;

Prepare;

ExecProc;

DataSetRefrashExecute(Sender);

end;

end;

procedure TMainForm.DataSetInsertExecute(Sender: TObject);

var

N : Integer;

ArcName: ANSIString;

Stream : TMemoryStream;

Res : Boolean;

begin

if not Assigned (EditForm) then

EditForm:= TEditForm.Create (Application);

with EditForm do

begin

Caption:=InsertWinName;

ShowModal;

if ModalResult=mrOK then

begin

case RadioGroupSource.ItemIndex of

0:

begin

if Trim(EditNewArc.Text)<>'' then

ArcName:=GetNewArcName(EditNewArc.Text+ArcExt)

else

begin

ArcName:=ExtractFileLastDir(EditDir.Text);

ArcName:=GetNewArcName(LibDir+ArcName+ArcExt);

end;

Res:=PackFiles(ArcName,EditDir.Text+'&bsol;*.*');

end;

1:

begin

if (Trim(EditNewArc.Text)<>'') then

begin

ArcName:=GetNewArcName(EditNewArc.Text+ArcExt);

Res:=(CopyFiles(Application.Handle,EditArc.Text,ArcName)=0);

end

else

begin

ArcName:=EditArc.Text;

Res:=True;

end;

end;

2:

begin

if Trim(EditNewArc.Text)<>'' then

ArcName:=GetNewArcName(EditNewArc.Text+ArcExt)

else

begin

ArcName:=ExtractFileName(EditFile.Text);

DeleteFileExt(ArcName);

ArcName:=GetNewArcName(LibDir+ArcName+ArcExt);

end;

Res:=PackFiles(ArcName,EditFile.Text);

end;

end;

if Res then

begin

Stream:=TMemoryStream.Create;

Memo1.Lines.SaveToStream(Stream);

DataModule1.CallInsertBook(ComboBoxAut.Text,

ComboBoxTit.Text,

ComboBoxLan.Text,

Stream,

ArcName,

ExtractFileName(EditFile.Text),N);

Stream.Free;

MainForm.DataSetRefrashExecute(Sender);

DataModule1.IBDataSet1.Locate('Number',N,[loPartialKey]);

end;

end;

end;

end;

procedure TMainForm.DataSetDeleteExecute(Sender: TObject);

begin

if ConfirmDelete then

begin

if not Assigned (DeleteForm) then

DeleteForm:= TDeleteForm.Create (Application);

with DeleteForm do

begin

Caption:=DeleteWinName;

ShowModal;

end;

if (DeleteForm.ModalResult = mrYes) then

DataModule1.CallDeleteBook;

end

else

DataModule1.CallDeleteBook;

DataSetRefrashExecute(Sender);

end;

procedure TMainForm.DataSetUpdateExecute(Sender: TObject);

var

N : Integer;

ArcName: ANSIString;

Str : ANSIString;

Stream : TStream;

MStream: TMemoryStream;

Res : Boolean;