我将主程序及DATAMODE表单内容贴上,请帮我分析分析!
主程序:
unit MainPas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
DBTables, Dialogs, Menus, ComCtrls, ExtCtrls, ToolWin, StdCtrls;
type
TA00Form = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N22: TMenuItem;
procedure InputClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
A00Form: TA00Form;
implementation
uses DataMode, MInput;
{$R *.dfm}
procedure TA00Form.InputClick(Sender: TObject);
begin
if MDIChildCount > 0 then MDIChildren[0].Close;
Application.CreateForm(TForm1, Form1);
end;
procedure TA00Form.FormCreate(Sender: TObject);
begin
SetMenu(Handle, MainMenu1.Handle);
Application.CreateForm(TDM, DM);
end;
end.
DATAMODE表单内容:
Unit DataMode;
interface
uses
Windows, Forms, BDE, SysUtils, Classes, DB, DBTables, Dialogs, Variants;
type
TDM = class(TDataModule)
Money: TTable;
Custom: TTable;
MIndex: TTable;
SendIn: TTable;
QSendIn: TQuery;
QSendOut: TQuery;
QMIndex: TQuery;
MoneyS: TDataSource;
CustomS: TDataSource;
MIndexS: TDataSource;
SendInS: TDataSource;
QSendInS: TDataSource;
QSendOutS: TDataSource;
QMIndexS: TDataSource;
SendOut: TTable;
SendOutS: TDataSource;
Save01: TTable;
Save01S: TDataSource;
QSave01: TQuery;
QSave01S: TDataSource;
QArrive: TQuery;
QArriveS: TDataSource;
CSendIn: TQuery;
CSendOut: TQuery;
CArrive: TQuery;
CSendInS: TDataSource;
CSendOutS: TDataSource;
CArriveS: TDataSource;
CMoney: TQuery;
CMoneyS: TDataSource;
Query1: TQuery;
DataSource4: TDataSource;
procedure IncSave01(DataSet: TDataSet);
procedure DecSave01(DataSet: TDataSet);
procedure SendInAfterEdit(DataSet: TDataSet);
procedure SendOutAfterEdit(DataSet: TDataSet);
procedure SendInBeforeCancel(DataSet: TDataSet);
procedure SendInBeforeDelete(DataSet: TDataSet);
procedure SendInBeforePost(DataSet: TDataSet);
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure PackTable(Table: TTable);
Const
IDField: String = '编号';
var
DM: TDM;
implementation
{$R *.dfm}
procedure PackTable;
//DbiPackTable(Table1.DBHandle, Table1.Handle, nil, szdBASE, True);
var
Props: CURProps;
hDb: hDBIDb;
TableDesc: CRTblDesc;
begin
Table.Exclusive := True;
Try
Table.Open;
HDb := Table.Database.Handle;
DbiGetCursorProps(Table.Handle, Props);
Table.Close;
if (Props.szTableType = szPARADOX) then begin
FillChar(TableDesc, sizeof(TableDesc), 0);
StrPCopy(TableDesc.szTblName, Table.TableName);
StrPCopy(TableDesc.szTblType, Props.szTableType);
TableDesc.bPack := True;
DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, False);
End;
Except
Showmessage('因故无法整理数据库:' + Table.TableName);
End;
end;
procedure TDM.IncSave01(DataSet: TDataSet);
begin
if Save01.Locate(IDField,DataSet[IDField],[]) Then Save01.Edit Else
Begin
Save01.Append;
Save01[IDField] := DataSet[IDField];
Save01['数量'] := 0;
Showmessage('新入药品');
End;
Save01['数量'] := Save01['数量'] + DataSet['数量'];
Save01.Post;
end;
procedure TDM.DecSave01(DataSet: TDataSet);
begin
if not Save01.Locate(IDField,DataSet[IDField],[]) then
Begin
Showmessage('该产品没有库存,无法出货');
Abort;
Exit;
End;
Save01.Edit;
Save01['数量'] := Save01['数量'] - DataSet['数量'];
Save01.Post;
end;
procedure TDM.SendInAfterEdit(DataSet: TDataSet);
begin
Save01.Locate(IDField,DataSet[IDField],[]);
Save01.Edit;
if Dataset = SendIn Then
Save01['数量'] := Save01['数量'] - DataSet['数量']
else
Save01['数量'] := Save01['数量'] + DataSet['数量'];
Save01.Post;
end;
procedure TDM.SendOutAfterEdit(DataSet: TDataSet);
begin
Save01.Locate(IDField,DataSet[IDField],[]);
Save01.Edit;
Save01['数量'] := Save01['数量'] + DataSet['数量'];
Save01.Post;
end;
procedure TDM.SendInBeforeCancel(DataSet: TDataSet);
begin
if Dataset.State = dsInsert Then Exit;
IncSave01(DataSet);
end;
procedure TDM.SendInBeforeDelete(DataSet: TDataSet);
begin
if DataSet[IDField] = null then Exit;
if not Save01.Locate(IDField,DataSet[IDField],[]) then Begin
if IDNo = MessageBox(Application.Handle,'无法删除库存部分数据,继续吗?',
'系统提示', MB_YESNO) then Abort;
Exit;
End;
Save01.Edit;
if Dataset = SendIn Then
Save01['数量'] := Save01['数量'] - DataSet['数量']
else
Save01['数量'] := Save01['数量'] + DataSet['数量'];
Save01.Post;
end;
procedure TDM.SendInBeforePost(DataSet: TDataSet);
begin
if DataSet[IDField] = null then Abort;
end;
end.