--PAGE_BREAK--
unit MainUnit;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, Db, DBTables, PropUnit, ReportUnit, RecieveUnit, PassUnit, SaleUnit, Menus;
type TMainForm = class(TForm)
PassButton: TButton;
DataSourceTov: TDataSource;
TableTov: TTable;
DBGrid1: TDBGrid;
Label1: TLabel;
ExitButton: TButton;
SaleButton: TButton;
RecieveButton: TButton;
TableNakl: TTable;
DataSourceNakl: TDataSource;
TablePost: TTable;
DataSourcePost: TDataSource;
DBGrid3: TDBGrid;
DBGrid4: TDBGrid;
Label3: TLabel;
Label4: TLabel;
PropButton: TButton;
ReportButton: TButton;
SelectButton: TButton;
QueryTov: TQuery;
QueryNakl: TQuery;
QueryPost: TQuery;
SaveButton: TButton;
CancelSelectButton: TButton;
QueryPostPostCode: TIntegerField;
QueryPostPostName: TStringField;
QueryPostPostPhone: TIntegerField;
QueryNaklNaklNum: TIntegerField;
QueryNaklTovarCode: TSmallintField;
QueryNaklPostCode: TSmallintField;
QueryNaklDate: TDateField;
QueryNaklRecieved: TIntegerField;
QueryNaklSum: TIntegerField;
QueryTovTovarCode: TIntegerField;
QueryTovTovarName: TStringField;
QueryTovEdIzm: TStringField;
QueryTovPrice: TCurrencyField;
QueryTovCol: TIntegerField;
TableNaklNaklNum: TAutoIncField;
TableNaklTovarCode: TSmallintField;
TableNaklPostCode: TSmallintField;
TableNaklDate: TDateField;
TableNaklRecieved: TIntegerField;
TableNaklSum: TIntegerField;
TableTovTovarCode: TAutoIncField;
TableTovTovarName: TStringField;
TableTovEdIzm: TStringField;
TableTovPrice: TCurrencyField;
TableTovCol: TIntegerField;
TablePostPostCode: TAutoIncField;
TablePostPostName: TStringField;
TablePostPostPhone: TIntegerField;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
procedure PassButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SaleButtonClick(Sender: TObject);
procedure Rights;
procedure RecieveButtonClick(Sender: TObject);
procedure ReportButtonClick(Sender: TObject);
procedure PropButtonClick(Sender: TObject);
procedure SelectButtonClick(Sender: TObject);
procedure SaveButtonClick(Sender: TObject);
procedure CancelSelectButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var MainForm: TMainForm;
implementation
uses FindUnit;
{$R *.DFM}
procedure TMainForm.Rights;
var i:byte;
begin
for i:=0 to ComponentCount-1 do begin
If (Components[i] is TButton) then (Components[i] as TButton).enabled:=false;
If (Components[i] is TLabel) and ((Components[i] as TLabel).Caption'Медикаменты') then (Components[i] as TLabel).visible:=false;
If (Components[i] is TDBGrid) then
begin
If (Components[i] as TDBGrid).Name='DBGrid1' then (Components[i] as TDBGrid).ReadOnly:=true
else (Components[i] as TDBGrid).visible:=false;
end; end;
ExitButton.Enabled:=true;
SelectButton.Enabled:=true;
CancelSelectButton.Enabled:=true;
PassButton.Enabled:=true;
N3.enabled:=false;
N5.enabled:=false;
N7.enabled:=false;
N8.enabled:=false;
If Mode='Завоз' then
begin
RecieveButton.Enabled:=true;
N7.enabled:=true;
end
else If Mode='Продажа' then
begin
SaleButton.enabled:=true;
N8.enabled:=true;
end
else If Mode='Администрирование' then
begin
for i:=0 to ComponentCount-1 do begin
If (Components[i] is TButton) then (Components[i] as TButton).enabled:=true;
If (Components[i] is TMenuItem) then (Components[i] as TMenuItem).enabled:=true;
If (Components[i] is TLabel) then (Components[i] as TLabel).visible:=true;
If (Components[i] is TDBGrid) then
begin
(Components[i] as TDBGrid).ReadOnly:=false;
(Components[i] as TDBGrid).visible:=true;
end; end; end;end;
procedure TMainForm.PassButtonClick(Sender: TObject);
begin
PassForm.Edit1.text:='';
PassForm.ShowModal;
Rights;
end;
procedure TMainForm.ExitButtonClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.FormCreate(Sender: TObject);
Var curday,curmonth,curyear,
day,month,year:word;
f:textfile;
rash,doh:longint;
num:word;
Procedure GenerateReport;
begin
rash:=0;
doh:=0;
num:=0;
TableNakl.First;
while not TableNakl.Eof do begin
DecodeDate(TableNakl.FieldByName('Date').AsDateTime,Year,month,day);
if (year=curyear) and (month=curmonth-1) then begin;
inc(num);
rash:=rash+TableNakl.FieldByName('sum').AsInteger;
doh:=doh+TableNakl.FieldByName('col').AsInteger*
TableTov.FieldByName('Price').AsInteger;
end;
TableNakl.Next;
end;
assignfile(f,'report.txt');
If Fileexists('report.txt') then append(f)
else rewrite(f);
Writeln(f);
Writeln(f,'==== Отчет за ',curmonth-1,'/',curyear,'г ====');
Writeln(f);
Writeln(f,'Совершено ',num,' сделок на общую сумму ',rash,' рублей.');
Writeln(f,'Ожидаемая выручка от реализации ',doh-rash);
closefile(f);
end;
begin
If not PassForm.regexists then begin
ShowMessage('Ключи паролей не найдены и будут воссозданы');
PropForm.writereg('Продажа','1');
PropForm.writereg('Завоз','2');
PropForm.writereg('Администрирование','3');
end;
Mode:='Просмотр';
Rights;
DecodeDate(Date,curyear,curmonth,curday);
if curday=1 then GenerateReport;
end;
procedure TMainForm.SaleButtonClick(Sender: TObject);
begin
with SaleForm do begin
SpinEdit1.MaxValue:=TableTov.Fields[4].AsInteger;
SpinEdit1.Value:=TableTov.Fields[4].AsInteger;
ShowModal;
end;
end;
procedure TMainForm.RecieveButtonClick(Sender: TObject);
begin
RecieveForm.ShowModal;
end;
procedure TMainForm.ReportButtonClick(Sender: TObject);
begin
ReportForm.ShowModal;
end;
procedure TMainForm.PropButtonClick(Sender: TObject);
begin
PropForm.ShowModal;
end;
procedure TMainForm.SelectButtonClick(Sender: TObject);
begin
SelectForm.SortButton.Visible:=true;
SelectForm.SelectButton.Caption:='Выборка';
SelectForm.Caption:='Найти все';
SelectForm.Height:=260;
SelectForm.Panel1.Visible:=true;
CancelSelection:=false;
SelectForm.Show;
end;
procedure TMainForm.SaveButtonClick(Sender: TObject);
begin
If TableTov.State in [dsInsert,dsEdit] then TableTov.Post;
If TableNakl.State in [dsInsert,dsEdit] then TableNakl.Post;
If TablePost.State in [dsInsert,dsEdit] then TablePost.Post;
end;
procedure TMainForm.CancelSelectButtonClick(Sender: TObject);
begin
SelectForm.SortButton.Visible:=false;
SelectForm.Caption:='Отменить выборку';
SelectForm.SelectButton.Caption:='Отменить';
SelectForm.Height:=140;
SelectForm.Panel1.Visible:=false;
SelectForm.Show;
CancelSelection:=true;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
QueryTov.Active:=false;
QueryNakl.Active:=false;
QueryPost.Active:=false;
end;
end.
unit FindUnit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DBCtrls;
type TSelectForm = class(TForm)
RadioGroup1: TRadioGroup;
SelectButton: TButton;
ExitButton: TButton;
Panel1: TPanel;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
ComboBox2: TComboBox;
Label3: TLabel;
Edit1: TEdit;
SortButton: TButton;
procedure ExitClick(Sender: TObject);
procedure SelectButtonClick(Sender: TObject);
procedure SortClick(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var SelectForm: TSelectForm;
Selecttype:boolean;
CancelSelection:boolean;
implementation
uses MainUnit;
{$R *.dfm}
procedure TSelectForm.ExitClick(Sender: TObject);
begin
Close;
end;
procedure TSelectForm.SelectButtonClick(Sender: TObject);
begin
With MainForm do
case RadioGroup1.ItemIndex of
0: begin
QueryTov.Active:=false;
QueryTov.SQL.Clear;
If CancelSelection Then begin
QueryTov.SQL.Add('Select * From Tovar');
DataSourceTov.DataSet:=TableTov;
end
else begin
DataSourceTov.DataSet:=QueryTov;
QueryTov.SQL.Add('Select * From Tovar where '+ComboBox1.Text);
If SelectType then QueryTov.SQL.Add(ComboBox2.Text+Edit1.text)
else QueryTov.SQL.Add(' Like "'+Edit1.text+'"');
end;
QueryTov.Active:=true;
end;
1: begin
QueryNakl.Active:=false;
QueryNakl.SQL.Clear;
If CancelSelection Then begin
QueryNakl.SQL.Add('Select * From Nakladnie');
DataSourceNakl.DataSet:=TableNakl;
end
else begin
DataSourceNakl.DataSet:=QueryNakl;
QueryNakl.SQL.Add('Select * From Nakladnie where '+ComboBox1.Text);
If SelectType then
QueryNakl.SQL.Add(' '+ComboBox2.Text+' '+Edit1.text)
else QueryNakl.SQL.Add(' Like "'+Edit1.text+'"');
end;
QueryNakl.Active:=true;
end;
2: begin
QueryPost.Active:=false;
QueryPost.SQL.Clear;
If CancelSelection Then begin
QueryPost.SQL.Add('Select * From Postavschik');
DataSourcePost.DataSet:=TablePost;
end
else begin
DataSourcePost.DataSet:=QueryPost;
QueryPost.SQL.Add('Select * From Postavschik where '+ComboBox1.Text);
If SelectType then
QueryPost.SQL.Add(' '+ComboBox2.Text+' '+Edit1.text)
else QueryPost.SQL.Add(' Like "'+Edit1.text+'"');
end;
QueryPost.Active:=true;
end;
end;
Close;
end;
procedure TSelectForm.RadioGroup1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0:begin ComboBox1.Items:=MainForm.TableTov.FieldList; end;
1:begin ComboBox1.Items:=MainForm.TableNakl.FieldList; end;
2:begin ComboBox1.Items:=MainForm.TablePost.FieldList;end;
end;
end;
procedure TSelectForm.ComboBox1Change(Sender: TObject);
begin
Combobox2.Items.Clear;
If (ComboBox1.Text='Price') or
(ComboBox1.Text='Col') or
(ComboBox1.Text='Recieved') or
(ComboBox1.Text='Sum')
then begin
Combobox2.Items.Add('=');
Combobox2.Items.Add('>');
Combobox2.Items.Add('
Combobox2.Items.Add('>=');
Combobox2.Items.Add('
Combobox2.Items.Add('');
Selecttype:=true;
end
else If (ComboBox1.Text='TovarCode') or
(ComboBox1.Text='NaklNum') or
(ComboBox1.Text='PostCode')
then begin
Combobox2.Items.Add('=');
Combobox2.ItemIndex:=0;
Selecttype:=true;
end
else If (ComboBox1.Text='TovarName') or
(ComboBox1.Text='PostName')
then begin
Combobox2.Items.Add('ёютярфрхЄ');
Combobox2.ItemIndex:=0;
Selecttype:=false;
end;
end;
procedure TSelectForm.SortClick(Sender: TObject);
Var txt:string;
begin
txt:=ComboBox1.Text;
With MainForm do
case RadioGroup1.ItemIndex of
0:begin
QueryTov.Active:=false;
QueryTov.SQL.Clear;
DataSourceTov.DataSet:=QueryTov;
QueryTov.SQL.Add('Select * From Tovar where '+txt+'='+Txt+' order by '+txt);
QueryTov.Active:=true;
end;
1:begin
QueryNakl.Active:=false;
QueryNakl.SQL.Clear;
DataSourceNakl.DataSet:=QueryNakl;
QueryNakl.SQL.Add('Select * From Nakladnie where '+Txt+'='+txt+' order by '+Txt);
QueryNakl.Active:=true;
end;
2:begin
QueryPost.Active:=false;
QueryPost.SQL.Clear;
DataSourcePost.DataSet:=QueryPost;
QueryPost.SQL.Add('Select * From Postavschik where '+Txt+'='+Txt+' order by '+Txt);
QueryPost.Active:=true;
end;
end;
Close;
end;end. продолжение
--PAGE_BREAK--