unit rkFormU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB,
QRCtrls, QuickRpt;
type
TrkForm = class(TForm)
Panel1: TPanel;
StatusBar1: TStatusBar;
Panel2: TPanel;
Label1: TLabel;
rkdhEdit: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
spbhCB: TComboBox;
spmcEdit: TEdit;
dwEdit: TEdit;
slEdit: TEdit;
kgCB: TComboBox;
shCB: TComboBox;
bzMemo: TMemo;
DBGrid1: TDBGrid;
GroupBox1: TGroupBox;
DBGrid2: TDBGrid;
jhdQuery: TADOQuery;
tmpQuery: TADOQuery;
rkQuery: TADOQuery;
DataSource1: TDataSource;
DataSource2: TDataSource;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Label9: TLabel;
rkdhCXEdit: TEdit;
Label10: TLabel;
spbhCXEdit: TEdit;
Label11: TLabel;
sjCXEdit: TEdit;
Button10: TButton;
Button11: TButton;
QR: TQuickRep;
ColumnHeaderBand1: TQRBand;
DetailBand1: TQRBand;
PageFooterBand1: TQRBand;
PageHeaderBand1: TQRBand;
QRLabel1: TQRLabel;
QRLabel2: TQRLabel;
QRLabel3: TQRLabel;
QRLabel4: TQRLabel;
QRLabel5: TQRLabel;
QRLabel6: TQRLabel;
QRLabel7: TQRLabel;
QRLabel8: TQRLabel;
QRLabel9: TQRLabel;
QRDBText1: TQRDBText;
QRDBText2: TQRDBText;
QRDBText3: TQRDBText;
QRDBText4: TQRDBText;
QRDBText5: TQRDBText;
QRDBText6: TQRDBText;
QRDBText7: TQRDBText;
QRDBText8: TQRDBText;
QRSysData1: TQRSysData;
Label12: TLabel;
cfckCB: TComboBox;
jhdQueryRKDH: TWideStringField;
jhdQueryKG: TWideStringField;
jhdQueryJSR: TWideStringField;
jhdQuerySJ: TDateTimeField;
rkQueryBH: TAutoIncField;
rkQuerySPBH: TWideStringField;
rkQuerySPMC: TWideStringField;
rkQueryRKDH: TWideStringField;
rkQueryDW: TWideStringField;
rkQuerySL: TSmallintField;
rkQueryKG: TWideStringField;
rkQueryJSR: TWideStringField;
rkQuerySJ: TDateTimeField;
rkQueryCK: TWideStringField;
rkQueryBZ: TWideStringField;
Label13: TLabel;
rqCB: TDateTimePicker;
procedure FormDestroy(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure spbhCBSelect(Sender: TObject);
procedure DBGrid2CellClick(Column: TColumn);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
procedure showData;
procedure getData;
function CheckQX(QX:String):Boolean;
procedure btnModel(zt:String);
procedure editModel(zt:String);
procedure getSPBHs;
procedure getYGMCs;
procedure getCKs;
procedure clearEdit;
public
{ Public declarations }
end;
var
rkForm: TrkForm;
implementation
uses mainForm;
var
rzt:String;
{$R *.dfm}
procedure TrkForm.getSPBHs;
begin
tmpQuery.Close;
tmpQuery.SQL.Clear;
tmpQuery.SQL.Add('Select * From SP');
tmpQuery.Open;
while not tmpQuery.Eof do
begin
spbhCB.Items.Add(tmpQuery.FieldByName('SPBH').AsString);
tmpQuery.Next;
end;
end;
procedure TrkForm.getYGMCs;
begin
tmpQuery.Close;
tmpQuery.SQL.Clear;
tmpQuery.SQL.Add('Select * From YGDA');
tmpQuery.Open;
while not tmpQuery.Eof do
begin
kgCB.Items.Add(tmpQuery.FieldByName('YGXM').AsString);
shCB.Items.Add(tmpQuery.FieldByName('YGXM').AsString);
tmpQuery.Next;
end;
end;
procedure TrkForm.getCKs;
begin
tmpQuery.Close;
tmpQuery.SQL.Clear;
tmpQuery.SQL.Add('Select * From CK');
tmpQuery.Open;
while not tmpQuery.Eof do
begin
cfckCB.Items.Add(tmpQuery.FieldByName('CKMC').AsString);
tmpQuery.Next;
end;
end;
procedure TrkForm.FormDestroy(Sender: TObject);
begin
rkForm:=nil;
end;
function TrkForm.CheckQX(QX:String):Boolean;
begin
Result:=False;
tmpQuery.Close;
tmpQuery.SQL.Clear;
tmpQuery.SQL.Add('Select * From QXB Where YGBH="'+userID+'" and QX="'+QX+'" and BG="RK"');
tmpQuery.Open;
if tmpQuery.RecordCount>0 then begin
Result:=True;
end;
end;
procedure TrkForm.showData;
begin
rkdhEdit.Text:=rkQuery.FieldByName('RKDH').AsString;
spbhCB.Text:=rkQuery.FieldByName('SPBH').AsString;
spmcEdit.Text:=rkQuery.FieldByName('SPMC').AsString;
dwEdit.Text:=rkQuery.FieldByName('DW').AsString;
slEdit.Text:=rkQuery.FieldByName('SL').AsString;
kgCB.Text:=rkQuery.FieldByName('KG').AsString;
shCB.Text:=rkQuery.FieldByName('JSR').AsString;
rqCB.Date:=StrToDate(rkQuery.FieldByName('SJ').AsString);
cfckCB.Text:=rkQuery.FieldByName('CK').AsString;
bzMemo.Text:=rkQuery.FieldByName('BZ').AsString;
end;
procedure TrkForm.getData;
begin
rkQuery.FieldByName('RKDH').AsString:=rkdhEdit.Text;
rkQuery.FieldByName('SPBH').AsString:=spbhCB.Text;
rkQuery.FieldByName('SPMC').AsString:=spmcEdit.Text;
rkQuery.FieldByName('DW').AsString:=dwEdit.Text;
rkQuery.FieldByName('SL').AsString:=slEdit.Text;
rkQuery.FieldByName('KG').AsString:=kgCB.Text;
rkQuery.FieldByName('JSR').AsString:=shCB.Text;
rkQuery.FieldByName('SJ').AsString:=DateToStr(rqCB.Date);
rkQuery.FieldByName('CK').AsString:=cfckCB.Text;
rkQuery.FieldByName('BZ').AsString:=bzMemo.Text;
end;
procedure TrkForm.editModel(zt:String);
begin
if zt='NOR' then begin
rkdhEdit.ReadOnly:=true;
spmcEdit.ReadOnly:=true;
dwEdit.ReadOnly:=true;
slEdit.ReadOnly:=true;
bzMemo.ReadOnly:=true;
end;
if (zt='INS') or (zt='UPD') then begin
rkdhEdit.ReadOnly:=false;
spmcEdit.ReadOnly:=false;
dwEdit.ReadOnly:=false;
slEdit.ReadOnly:=false;
bzMemo.ReadOnly:=false;
end;
end;
procedure TrkForm.clearEdit;
begin
rkdhEdit.Clear;
spmcEdit.Clear;
dwEdit.Clear;
slEdit.Clear;
bzMemo.Clear;
end;
procedure TrkForm.btnModel(zt:String);
begin
if zt='NOR' then begin
Button1.Enabled:=True;
Button2.Enabled:=True;
Button3.Enabled:=True;
Button5.Enabled:=False;
Button6.Enabled:=False;
end;
if (zt='INS') or (zt='UPD') then begin
Button1.Enabled:=False;
Button2.Enabled:=False;
Button3.Enabled:=False;
Button5.Enabled:=True;
Button6.Enabled:=True;
end;
end;
procedure TrkForm.Button9Click(Sender: TObject);
begin
close;
end;
procedure TrkForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose:=True;
if (rzt='INS') or (rzt='UPD') then begin
MessageDlg('请先结束输入模式后再离开!',mtConfirmation,[mbOK],0);
CanClose:=False;
end;
end;
procedure TrkForm.FormCreate(Sender: TObject);
begin
rzt:='NOR';
btnModel(rzt);
editModel(rzt);
if CheckQX('OPE') then begin
getSPBHs;
getYGMCs;
getCKs;
jhdQuery.Active:=True;
rkQuery.Active:=True;
if rkQuery.RecordCount>0 then
showData;
end;
end;
procedure TrkForm.spbhCBSelect(Sender: TObject);
begin
tmpQuery.Close;
tmpQuery.SQL.Clear;
tmpQuery.SQL.Add('Select * From SP Where SPBH="'+spbhCB.Text+'"');
tmpQuery.Open;
spmcEdit.Text:=tmpQuery.FieldByName('SPMC').AsString;
dwEdit.Text:=tmpQuery.FieldByName('SPDW').AsString;
end;
procedure TrkForm.DBGrid2CellClick(Column: TColumn);
begin
showData;
end;
procedure TrkForm.Button2Click(Sender: TObject);
begin
if checkQX('DEL') then begin
if MessageDlg('您确定要删除这条记录吗?',mtInformation,[mbYes,mbNo],0)=6 then
rkQuery.Delete;
showData;
jhdQuery.Active:=False;
jhdQuery.Active:=True;
end;
end;
procedure TrkForm.Button1Click(Sender: TObject);
begin
if CheckQX('INS') then begin
rzt:='INS';
btnModel(rzt);
editModel(rzt);
clearEdit;
end;
end;
procedure TrkForm.Button3Click(Sender: TObject);
begin
if CheckQX('UPD') then begin
rzt:='UPD';
btnModel(rzt);
editModel(rzt);
jhdQuery.Active:=False;
jhdQuery.Active:=True;
end;
end;
procedure TrkForm.Button5Click(Sender: TObject);
begin
if rkdhEdit.Text='' then begin
showMessage('入库单号不得为空');
rkdhEdit.SetFocus;
exit;
end;
if spmcEdit.Text='' then begin
showMessage('商品名称不得为空!');
spmcEdit.SetFocus;
exit;
end;
if dwEdit.Text='' then begin
showMessage('单位不得为空!');
dwEdit.SetFocus;
exit;
end;
if slEdit.Text='' then begin
showMessage('数量不的为空!');
slEdit.SetFocus;
exit;
end;
try
StrToInt(slEdit.Text);
except
showmessage('数量为数值型!');
slEdit.SetFocus;
exit;
end;
if rzt='INS' then begin
rkQuery.Append;
getData;
rkQuery.Post;
rzt:='NOR';
btnModel(rzt);
editModel(rzt);
end;
if rzt='UPD' then begin
rkQuery.Edit;
getData;
rkQuery.Post;
rzt:='NOR';
btnModel(rzt);
editModel(rzt);
end;
jhdQuery.Active:=False;
jhdQuery.Active:=True;
end;
procedure TrkForm.Button6Click(Sender: TObject);
begin
rzt:='NOR';
btnModel(rzt);
editModel(rzt);
end;
procedure TrkForm.DBGrid1CellClick(Column: TColumn);
begin
rkQuery.Close;
rkQuery.SQL.Clear;
rkQuery.SQL.Add('Select * From RKJL ');
rkQuery.SQL.Add('Where RKDH="'+jhdQuery.FieldByName('RKDH').AsString+'"');
rkQuery.Open;
showData;
end;
procedure TrkForm.Button10Click(Sender: TObject);
begin
if CheckQX('QUE') then begin
if sjCXEdit.Text<>'' then begin
try
StrToDate(sjCXEdit.Text);
except
showmessage('时间格式错误,如(2002-6-1).');
sjCXEdit.SetFocus;
exit;
end;
end;
rkQuery.Close;
rkQuery.SQL.Clear;
rkQuery.SQL.Add('Select * From RKJL ');
if (rkdhCXEdit.Text<>'') or (spbhCXEdit.Text<>'') or (sjCXEdit.Text<>'') then
rkQuery.SQL.Add('Where ');
if rkdhCXEdit.Text<>'' then begin
rkQuery.SQL.Add('RKDH="'+rkdhCXEdit.Text+'" ');
if (spbhCXEdit.Text<>'') or (sjCXEdit.Text<>'') then
rkQuery.SQL.Add('And ');
end;
if spbhCXEdit.Text<>'' then begin
rkQuery.SQL.Add('SPBH="'+spbhCXEdit.Text+'" ');
if sjCXEdit.Text<>'' then
rkQuery.SQL.Add('And ');
end;
if sjCXEdit.Text<>'' then
rkQuery.SQL.Add('SJ=#'+sjCXEdit.Text+'#');
rkQuery.Open;
end;
end;
procedure TrkForm.Button11Click(Sender: TObject);
begin
rkdhCXEdit.Clear;
spbhCXEdit.Clear;
sjCXEdit.Clear;
end;
procedure TrkForm.Button7Click(Sender: TObject);
begin
if CheckQX('PRI') then
QR.Preview;
end;
procedure TrkForm.Button8Click(Sender: TObject);
begin
if CheckQX('PRI') then
QR.Print;
end;
procedure TrkForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
rkForm.Release;
end;
procedure TrkForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=112 then Button1.Click;
if key=113 then Button2.Click;
if key=114 then Button3.Click;
if key=116 then Button5.Click;
if key=117 then Button6.Click;
if key=118 then Button7.Click;
if key=119 then Button9.Click;
end;
end.