Файл: Проектирование реализации операций бизнес-процесса «Управление товарными потоками».pdf
Добавлен: 21.05.2023
Просмотров: 170
Скачиваний: 3
Приложение
Enter.pas
unit Enter;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, acPNG, acImage;
type
TF_Login = class(TForm)
BitBtn2: TBitBtn;
DBGrid1: TDBGrid;
Login: TEdit;
Pass: TEdit;
Button1: TButton;
Label3: TLabel;
Label4: TLabel;
BitBtn1: TBitBtn;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure PassKeyPress(Sender: TObject; var Key: Char);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
F_Login: TF_Login;
BDS:string;
implementation
uses DataModule, Liza_Gazprom;
{$R *.dfm}
function GoLogs(str:string):boolean;
var
f:TextFile;
FileDir:String;
today:TDateTime;
begin
today:=Now;
FileDir:='logs.log';
AssignFile(f,FileDir);
if not FileExists(FileDir) then
begin
Rewrite(f);
CloseFile(f);
end;
Append(f);
Writeln(f,DateToStr(today)+' '+TimeToStr(today)+' '+str);
Flush(f);
CloseFile(f);
end;
procedure TF_Login.FormCreate(Sender: TObject);
begin
BDS:='Database.mdb';
ShowModal;
end;
procedure TF_Login.BitBtn2Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TF_Login.Button1Click(Sender: TObject);
begin
if (Login.Text = 'Administrator') Then Begin GoLogs('Пользователь '+Login.Text+' вошел в систему'); Makynin.Select_DB(BDS,Login.Text,Pass.Text); Close; end else
Begin
Makynin.Select_DB(BDS,'User','');
if (DBGrid1.DataSource.DataSet.Locate('Familiya;Nom_pas', VarArrayOf([Login.Text,Pass.Text]), [])) Then
Begin
GoLogs('Пользователь '+Login.Text+' вошел в систему');
Makynin.N15.Enabled:=false;
Makynin.N3.Enabled:=false;
Makynin.N11.Enabled:=false;
Makynin.MainMenu1.Tag:=DM.ManagersId_manager.AsInteger;
Close;
End
else Begin GoLogs('Попытка входа под пользователем - '+Login.Text); showmessage('Ошибка входа не верный логин или пароль'); end;
End;
end;
procedure TF_Login.PassKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 Then Button1Click(Sender);
end;
procedure TF_Login.BitBtn1Click(Sender: TObject);
begin
DM.Connection.Connected:=false;
if OpenDialog1.execute Then
if CopyFile(Pchar(OpenDialog1.FileName), Pchar(ExtractFilePath(Application.ExeName)+'Data\Database.mdb'), false) then
ShowMessage('База успешно восстановлена.')
else
ShowMessage('Ошибка: база не восстановлена.');
end;
end.
Tovar.pas
unit Tovar;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, Buttons, ExtCtrls;
type
TF_Tovar = class(TForm)
Naimenovanie: TEdit;
Label2: TLabel;
Firma_proizvod: TEdit;
Label3: TLabel;
Strana_proizvod: TEdit;
Label4: TLabel;
Label5: TLabel;
Id_tip_technic: TDBLookupComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Price: TEdit;
Label9: TLabel;
Label11: TLabel;
Id_postavshika: TDBLookupComboBox;
ComboBox1: TComboBox;
procedure FormActivate(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure PriceKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
F_Tovar: TF_Tovar;
implementation
uses DataModule, DB, ADODB;
{$R *.dfm}
procedure TF_Tovar.FormActivate(Sender: TObject);
begin
Naimenovanie.SetFocus;
end;
procedure TF_Tovar.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TF_Tovar.BitBtn1Click(Sender: TObject);
begin
Strana_proizvod.Text:=Combobox1.Text;
if Naimenovanie.Text='' then begin
Application.MessageBox('ƒл¤ добавлени¤ товара необходимо указать наименование','',MB_OK+MB_ICONWARNING);
Abort;
end
else if Id_tip_technic.KeyValue=-1 then begin
Application.MessageBox('ƒл¤ добавлени¤ товара необходимо указать тип товара','',MB_OK+MB_ICONWARNING);
Abort;
end
else if Id_postavshika.KeyValue=-1 then begin
Application.MessageBox('ƒл¤ добавлени¤ товара необходимо указать поставщика','',MB_OK+MB_ICONWARNING);
Abort;
end;
if Tag=1 then begin
with DM.For_AE do begin
SQL.Clear;
SQL.Add('INSERT INTO Tovar(Naimenovanie,Firma,Strana,Id_tip_tovara,Cena,Ostalos,Ojidaetsya,Id_postavshika)');
SQL.Add('VALUES(:Naimenovanie,:Firma,:Strana,:Id_tip_tovara,:Cena,:Ostalos,:Ojidaetsya,:Id_postavshika)');
end;
end
else begin
with DM.For_AE do begin
SQL.Clear;
SQL.Add('UPDATE Tovar SET Naimenovanie=:Naimenovanie,Firma=:Firma,Strana=:Strana,Id_tip_tovara=:Id_tip_tovara,');
SQL.Add('Cena=:Cena,Ostalos=:Ostalos,Ojidaetsya=:Ojidaetsya,Id_postavshika=:Id_postavshika WHERE Id_tovara=:Id_tovara');
end;
end;
with DM.For_AE do begin
Parameters.ParamByName('Naimenovanie').Value:=Naimenovanie.Text;
Parameters.ParamByName('Firma').Value:=Firma_proizvod.Text;
Parameters.ParamByName('Strana').Value:=Strana_proizvod.Text;
Parameters.ParamByName('Id_tip_tovara').Value:=Id_tip_technic.KeyValue;
Parameters.ParamByName('Cena').Value:=Price.Text;
if F_Tovar.Tag=1 then begin
Parameters.ParamByName('Ostalos').Value:=0;
Parameters.ParamByName('Ojidaetsya').Value:=0;
end;
Parameters.ParamByName('Id_postavshika').Value:=Id_postavshika.KeyValue;
if F_Tovar.Tag=0 then Parameters.ParamByName('Id_tovara').Value:=DM.TovarId_tovara.AsInteger;
ExecSQL;
end;
DM.Tovar.Close;
DM.Tovar.Open;
if Tag=1 then DM.Tovar.Last;
Close;
end;
procedure TF_Tovar.PriceKeyPress(Sender: TObject; var Key: Char);
begin
if Not (Key in ['0'..'9']) and (Ord(Key)<>8) and (Key<>',') then Key:=#0;
end;
end.
Prodagi.pas
unit Prodazi;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, DBGrids, StdCtrls, Buttons, ComObj;
type
TF_Prodazi = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
DBGrid1: TDBGrid;
Panel4: TPanel;
Label1: TLabel;
DBGrid2: TDBGrid;
Panel5: TPanel;
Label2: TLabel;
BitBtn1: TBitBtn;
Edit1: TEdit;
BitBtn2: TBitBtn;
Label3: TLabel;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
Bevel2: TBevel;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
Bevel1: TBevel;
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
F_Prodazi: TF_Prodazi;
Itog:double;
implementation
uses DataModule, ADODB, Liza_Gazprom, DB;
{$R *.dfm}
procedure TF_Prodazi.BitBtn4Click(Sender: TObject);
begin
if Not DM.Tovar.Eof then begin
DBGrid1.Tag:=1;
Edit1.Enabled:=True;
BitBtn1.Enabled:=True;
BitBtn2.Enabled:=True;
BitBtn4.Enabled:=False;
BitBtn5.Enabled:=False;
BitBtn6.Enabled:=False;
end;
end;
procedure TF_Prodazi.BitBtn1Click(Sender: TObject);
begin
DM.For_AE.SQL.Clear;
if (Edit1.Text='') then begin
Application.MessageBox('Количество покупки должно быть больше 0','',MB_OK);
Abort;
end;
if (StrToInt(Edit1.Text)<1) then begin
Application.MessageBox('Количество покупки должно быть больше 0','',MB_OK);
Abort;
end;
if (DBGrid1.Tag=1) then DM.For_AE.SQL.Add('INSERT INTO Prodazi(Data_prodazi,Id_tovara,Kol,Id_manager) VALUES(:Data_prodazi,:Id_tovara,:Kol,:Id_manager)')
else DM.For_AE.SQL.Add('UPDATE Prodazi SET Data_prodazi=:Data_prodazi,Id_tovara=:Id_tovara,Kol=:Kol,Id_manager=:Id_manager WHERE Id_prodazi=:Id_prodazi');
with DM.For_AE.Parameters do begin
ParamByName('Data_prodazi').Value:=FormatDateTime('dd/mm/yy',Now);
if DBGrid1.Tag=1 then ParamByName('Id_tovara').Value:=DM.TovarId_tovara.AsInteger
else ParamByName('Id_tovara').Value:=DM.For_ProdaziTId_tovara.AsInteger;
ParamByName('Kol').Value:=StrToInt(Edit1.Text);
ParamByName('Id_manager').Value:=Makynin.MainMenu1.Tag;
if DBGrid1.Tag=0 then ParamByName('Id_prodazi').Value:=DM.For_ProdaziId_prodazi.AsInteger;
end;
if DBGrid1.Tag=1 then Itog:=Itog+(DM.TovarCena.AsFloat*StrToInt(Edit1.Text))
else Itog:=Itog-(DM.For_ProdaziCena.AsFloat*(DM.For_ProdaziKol.AsInteger-StrToFloat(Edit1.Text)));
DM.For_AE.ExecSQL;
DM.For_AE.SQL.Clear;
DM.For_AE.SQL.Add('UPDATE Tovar SET Ostalos=:Kolichestvo WHERE Id_tovara=:Id_tovara');
DM.For_AE.Parameters.ParamByName('Id_tovara').Value:=DM.TovarId_tovara.AsInteger;
if DBGrid1.Tag=1 then
DM.For_AE.Parameters.ParamByName('Kolichestvo').Value:=DM.TovarOstalos.AsInteger-StrToInt(Edit1.Text)
else
DM.For_AE.Parameters.ParamByName('Kolichestvo').Value:=DM.TovarOstalos.AsInteger-DM.For_ProdaziKol.AsInteger-StrToInt(Edit1.Text);
DM.For_AE.ExecSQL;
DM.Tovar.Close;
DM.Tovar.Open;
Edit1.Clear;
Edit1.Enabled:=False;
BitBtn1.Enabled:=False;
BitBtn2.Enabled:=False;
BitBtn4.Enabled:=True;
BitBtn5.Enabled:=True;
BitBtn6.Enabled:=True;
BitBtn3.SetFocus;
DM.Prodazi.Close;
DM.Prodazi.Open;
DM.For_Prodazi.Close;
DM.For_Prodazi.Open;
end;
procedure TF_Prodazi.BitBtn5Click(Sender: TObject);
begin
if Not DM.For_Prodazi.Eof then begin
DBGrid1.Tag:=0;
Edit1.Enabled:=True;
BitBtn1.Enabled:=True;
BitBtn2.Enabled:=True;
BitBtn4.Enabled:=False;
BitBtn5.Enabled:=False;
BitBtn6.Enabled:=False;
end;
end;
procedure TF_Prodazi.BitBtn2Click(Sender: TObject);
begin
Edit1.Clear;
Edit1.Enabled:=False;
BitBtn1.Enabled:=False;
BitBtn2.Enabled:=False;
BitBtn4.Enabled:=True;
BitBtn5.Enabled:=True;
BitBtn6.Enabled:=True;
end;
procedure TF_Prodazi.BitBtn6Click(Sender: TObject);
begin
if Not DM.For_Prodazi.Eof then begin
DM.For_AE.SQL.Clear;
DM.For_AE.SQL.Add('DELETE * FROM Prodazi WHERE Id_prodazi=:Id_prodazi');
DM.For_AE.Parameters.ParamByName('Id_prodazi').Value:=DM.For_ProdaziId_prodazi.AsInteger;
DM.For_AE.ExecSQL;
DM.For_AE.SQL.Clear;
DM.For_AE.SQL.Add('UPDATE Tovar SET Ostalos=:Kolichestvo WHERE Id_tovar=:Id_tovar');
DM.For_AE.Parameters.ParamByName('Id_tovar').Value:=DM.TovarId_tovara.AsInteger;
DM.For_AE.Parameters.ParamByName('Kolichestvo').Value:=DM.TovarOstalos.AsInteger+DM.For_ProdaziKol.AsInteger;
DM.For_AE.ExecSQL;
DM.Tovar.Close;
DM.Tovar.Open;
DM.Prodazi.Close;
DM.Prodazi.Open;
DM.For_Prodazi.Close;
DM.For_Prodazi.Open;
end;
end;
procedure TF_Prodazi.BitBtn3Click(Sender: TObject);
Var XLApp,Sheet,Colum:Variant;
index,i:integer;
begin
if DM.For_Prodazi.RecordCount>0 then begin
XLApp:=CreateOleObject('Excel.Application');
XLApp.Visible:=False;
XLApp.Workbooks.Add(-4167);
XLApp.Workbooks[1].WorkSheets[1].Name:='Товарная накладная';
Colum:=XLApp.Workbooks[1].WorkSheets['Товарная накладная'].Columns;
Colum.Columns[1].ColumnWidth:=15;//Дата продажи
Colum.Columns[2].ColumnWidth:=50;//Наименование
Colum.Columns[3].ColumnWidth:=15;//Продавец
Colum.Columns[4].ColumnWidth:=10;//Количество
Colum.Columns[5].ColumnWidth:=10;//Артикул
Colum.Columns[6].ColumnWidth:=15;//Фирма
Colum.Columns[7].ColumnWidth:=10;//Кол. в упак.
Colum.Columns[8].ColumnWidth:=10;//Цена
Colum:=XLApp.Workbooks[1].WorkSheets['Товарная накладная'].Rows;
XLApp.Range['A1:G1'].Select;
XLApp.Selection.MergeCells:=True;
XLApp.Selection.HorizontalAlignment:=3;
Colum.Rows[1].Font.Bold:=true;
Colum.Rows[2].Font.Bold:=true;
Colum.Rows[1].Font.Color:=clRed;
Colum.Font.Size:=12;
Sheet:=XLApp.Workbooks[1].WorkSheets['Товарная накладная'];
Sheet.Cells[1,1]:='Мобильные телефоны';
Sheet.Cells[2,1]:='Дата продажи';
Sheet.Cells[2,2]:='Наименование';
Sheet.Cells[2,3]:='Фирма';
Sheet.Cells[2,4]:='Страна производитель';
Sheet.Cells[2,5]:='Количество';
Sheet.Cells[2,6]:='Цена';
index:=3;
DM.For_Prodazi.First;
for i:=0 to DM.For_Prodazi.RecordCount-1 do begin
Sheet.Cells[index,1]:=FormatDateTime('dd/mm/yy',DM.For_Prodazi.Fields[1].AsDateTime);
Sheet.Cells[index,2]:=DM.For_Prodazi.Fields[6].AsString;
Sheet.Cells[index,3]:=DM.For_Prodazi.Fields[7].AsString;
Sheet.Cells[index,4]:=DM.For_Prodazi.Fields[8].AsString;
Sheet.Cells[index,5]:=DM.For_Prodazi.Fields[3].AsString;
Sheet.Cells[index,6]:=DM.For_Prodazi.Fields[11].AsString;
Inc(index);
DM.For_Prodazi.Next;
end;
Sheet.Cells[index+1,1]:='Ртого: '+FloatToStr(Itog)+' СЂСѓР±.';
Sheet.Cells[index+2,1]:='Продавец: '+DM.For_ProdaziFamiliya.AsString+' / _________ /';
if Application.MessageBox('Респечатать?','',MB_OKCANCEL)=ID_OK then
XLApp.ActiveSheet.PrintOut;
try
XLApp.Workbooks[1].SaveAs(ExtractFilePath(Application.ExeName)+'Otcheti\'+FormatDateTime('dd/mm/yy',Now)+'_'+DM.For_ProdaziId_prodazi.AsString+'.xls');
except
Abort;
end;
XLApp.Visible:=True;
end;
Close;
end;
procedure TF_Prodazi.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Not (Key in ['0'..'9']) and (Ord(Key)<>8) then Key:=#0;
end;
end.
Managers.pas
unit Managers;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, Buttons, ExtCtrls, ComCtrls;
type
TF_Manager = class(TForm)
Label2: TLabel;
Familiya: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Label1: TLabel;
Adres: TEdit;
Label5: TLabel;
Telephon: TMaskEdit;
CheckBox1: TCheckBox;
Imya: TEdit;
Otchestvo: TEdit;
Label3: TLabel;
Label4: TLabel;
Data_r: TDateTimePicker;
Label6: TLabel;
Ser_pas: TEdit;
Label8: TLabel;
Nom_pas: TEdit;
Label9: TLabel;
procedure CheckBox1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Ser_pasKeyPress(Sender: TObject; var Key: Char);
procedure Nom_pasKeyPress(Sender: TObject; var Key: Char);
procedure FamiliyaKeyPress(Sender: TObject; var Key: Char);