unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, StdCtrls, Buttons,
ExtCtrls,Forms, ComCtrls,DateUtils, Grids, Controls, Wwdbigrd,
Wwdbgrid, DBTables, DB, wwcheckbox;
type
TFormMain = class(TForm)
Panel1: TPanel;
tbApplysub: TTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
Database1: TDatabase;
wwExpandButton1: TwwExpandButton;
qryApply: TQuery;
Label1: TLabel;
GroupBox1: TGroupBox;
edBillno: TEdit;
Label2: TLabel;
Label3: TLabel;
dtpApplytime: TDateTimePicker;
Label4: TLabel;
cmbMan: TComboBox;
qrySearch: TQuery;
StatusBar1: TStatusBar;
btnVoid: TButton;
btnDelete: TButton;
Button4: TButton;
wwDBGrid1: TwwDBGrid;
wwDBGrid2: TwwDBGrid;
wwDBGrid2IButton: TwwIButton;
Label6: TLabel;
cbifdraw: TCheckBox;
cbifvoid: TCheckBox;
btnSeek: TButton;
Label5: TLabel;
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure cmbManCloseUp(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure rbwlClick(Sender: TObject);
procedure btnSeekClick(Sender: TObject);
procedure edBillnoKeyPress(Sender: TObject;
var Key: Char);
procedure qryApplyAfterScroll(DataSet: TDataSet);
procedure btnVoidClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure cbifdrawClick(Sender: TObject);
private
procedure SeekBill;
{ Private declarations }
public
{ Public declarations }
end;
var
FormMain: TFormMain;
procedure lib_apply(Hnd:THandle);export;
implementation
{$R *.dfm}
procedure lib_apply(Hnd:THandle);export;
begin
try
Application.Handle:=Hnd;
FormMain:=TFormMain.Create(Application);
FormMain.ShowModal;
finally
FormMain.Free
end;
//
end;
procedure TFormMain.Button4Click(Sender: TObject);
begin
Close;
end;
procedure TFormMain.FormCreate(Sender: TObject);
begin
DataBase1.Connected:=true;
qryApply.DatabaseName:=Database1.DatabaseName;
qrySearch.DatabaseName:=Database1.DatabaseName;
tbApplysub.DatabaseName:=Database1.DatabaseName;
qrySearch.Close;
qrySearch.SQL.Clear;
qrySearch.SQL.Add('select EmployeeNo,EmployeeName from pbemployee order by EmployeeNo');
qrySearch.Open;
cmbMan.Items.Clear;
cmbMan.Items.Add('(全部)');
while not qrySearch.Eof do
begin
cmbMan.Items.Add(qrySearch.fieldbyname('EmployeeNo').AsString+'-'+qrySearch.fieldbyname('EmployeeName').AsString);
qrySearch.Next;
end;
cmbMan.ItemIndex:=0;
dtpApplyTime.DateTime:=IncYear(dtpApplyTime.DateTime,-1);
end;
procedure TFormMain.cmbManCloseUp(Sender: TObject);
begin
Caption:=Copy(cmbMan.Text,1,pos('-',cmbMan.Text)-1);
end;
procedure TFormMain.SeekBill;
begin
qryApply.Close;
qryApply.SQL.Clear;
qryApply.SQL.Add('select (select ''buttons'') a,billno,p1.employeename applier,applytime,');
qryApply.SQL.Add('p2.employeename passer,p3.employeename cwpasser,ifpass,ifdraw,ifcwpass,ifvoid,memo from wlapplymaster a ');
qryApply.SQL.Add(' left join pbemployee p1 on p1.employeeno=a.applier ');
qryApply.SQL.Add(' left join pbemployee p2 on p2.employeeno=a.passer ');
qryApply.SQL.Add(' left join pbemployee p3 on p3.employeeno=a.cwpasser ');
qryApply.SQL.Add(' where a.ifcar=0 ');
if cbifdraw.Checked then
qryApply.SQL.Add(' and a.ifdraw=0 ');
if cbifvoid.Checked then
qryApply.SQL.Add(' and a.ifvoid=0 ');
if cmbMan.ItemIndex>0 then
qryApply.SQL.Add(' and a.applier='''+Copy(cmbMan.Text,1,pos('-',cmbMan.Text)-1)+'''');
qryApply.SQL.Add(' and a.billno like :billno and a.applytime>:applytime ');
qryApply.SQL.Add(' order by a.billno ');
qryApply.ParamByName('billno').AsString:='%'+ edbillno.Text+'%';
qryApply.ParamByName('applytime').AsDateTime:=dtpapplytime.DateTime;
qryApply.Open;
tbApplysub.Open;
end;
procedure TFormMain.FormShow(Sender: TObject);
begin
SeekBill;
end;
procedure TFormMain.rbwlClick(Sender: TObject);
begin
SeekBill;
end;
procedure TFormMain.btnSeekClick(Sender: TObject);
begin
SeekBill;
end;
procedure TFormMain.edBillnoKeyPress(Sender: TObject;
var Key: Char);
begin
IF Key=#13 then
begin
btnSeek.SetFocus;
btnSeek.Click;
end;
end;
procedure TFormMain.qryApplyAfterScroll(DataSet: TDataSet);
begin
// 1:=not ((1 xor 1) or (0 or 0)) //没有审核或全部通过审核 //而且没有领用也没有作废
btnVoid.Enabled:=not ((qryApply.FieldByName('ifpass').AsBoolean xor qryApply.FieldByName('ifcwpass').AsBoolean) or (qryApply.FieldByName('ifdraw').AsBoolean or qryApply.FieldByName('ifvoid').AsBoolean));
// 1:=not ((1 xor 1) or 0)
btnDelete.Enabled:=not ((qryApply.FieldByName('ifpass').AsBoolean xor qryApply.FieldByName('ifcwpass').AsBoolean) or qryApply.FieldByName('ifdraw').AsBoolean );
end;
procedure TFormMain.btnVoidClick(Sender: TObject);
begin
if Messagebox(Handle,'是否要作废这条物料申请单?','',MB_YESNO+MB_ICONQUESTION)=IDYES then
begin
qrySearch.Close;
qrySearch.SQL.Clear;
qrySearch.SQL.Add('update wlapplymaster set ifvoid=1 where billno='''+qryApply.FieldByName('billno').AsString+'''');
qrySearch.ExecSQL;
Messagebox(Handle,'作废成功!','',MB_OK+MB_ICONINFORMATION);
btnSeek.SetFocus;
btnSeek.Click;
end;
end;
procedure TFormMain.btnDeleteClick(Sender: TObject);
begin
if Messagebox(Handle,'是否要删除这条物料申请单?','',MB_YESNO+MB_ICONQUESTION)=IDYES then
begin
qrySearch.Close;
qrySearch.SQL.Clear;
qrySearch.SQL.Add('begin
TRANSACTION ');
qrySearch.SQL.Add('delete from wlapplydetail where billno='''+qryApply.FieldByName('billno').AsString+'''');
qrySearch.SQL.Add('delete from wlapplymaster where billno='''+qryApply.FieldByName('billno').AsString+'''');
qrySearch.SQL.Add('commit ');
qrySearch.ExecSQL;
Messagebox(Handle,'删除成功!','',MB_OK+MB_ICONINFORMATION);
btnSeek.SetFocus;
btnSeek.Click;
end;
end;
procedure TFormMain.cbifdrawClick(Sender: TObject);
begin
btnSeek.Click;
end;
end
上面是我以前写的一个物料申请单作废的外挂DLL,代码粗糙情见凉,不过你可以看看写dll的要点