gxgx.pas
来自「应对服装行业的生产成本控制系统」· PAS 代码 · 共 401 行
PAS
401 行
unit gxgx;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, Grids, DBGrids, ExtCtrls, DBCtrls,
DB, ADODB, DBClient;
type
TFrmgxgx = class(TForm)
Pz: TPanel;
Label25: TLabel;
Label28: TLabel;
Label41: TLabel;
help: TLabel;
tgxmc: TEdit;
tddh: TEdit;
tdj: TEdit;
Label7: TLabel;
tdj1: TEdit;
Pd: TPanel;
GroupBox1: TGroupBox;
DBGrid5: TDBGrid;
bgxgx: TBitBtn;
breturn: TBitBtn;
Bquery: TBitBtn;
Panel1: TPanel;
Cddh: TCheckBox;
qddh: TEdit;
Cgxmc: TCheckBox;
qgxmc: TEdit;
Cdj: TCheckBox;
qdj: TEdit;
Cxs: TCheckBox;
qxs: TEdit;
Cbz: TCheckBox;
qbz: TEdit;
Cczy: TCheckBox;
qczy: TEdit;
Label8: TLabel;
qq: TDateTimePicker;
Label1: TLabel;
zq: TDateTimePicker;
Label2: TLabel;
bclgx: TBitBtn;
procedure tdjKeyPress(Sender: TObject; var Key: Char);
procedure tddhKeyPress(Sender: TObject; var Key: Char);
procedure breturnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BqueryClick(Sender: TObject);
procedure tgxmcKeyPress(Sender: TObject; var Key: Char);
procedure tdj1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid5TitleClick(Column: TColumn);
procedure DBGrid1TitleClick(Column: TColumn);
procedure bgxgxClick(Sender: TObject);
procedure bclgxClick(Sender: TObject);
procedure DBGrid5DblClick(Sender: TObject);
private
{ Private declarations }
rzczy,rzsj,rzjsj,rzcsj:string;
errzt: integer;
errcode:boolean;
commandstring,commandstringq: string;
public
{ Public declarations }
end;
var
Frmgxgx: TFrmgxgx;
implementation
uses unit28, Unit1, Unit16, xtfz;
{$R *.dfm}
procedure TFrmgxgx.tdjKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8,#13,'.']) then
begin
key:=#0;
help.caption:=' 请输入数字!';
end;
if key=#13 then tdj1.SetFocus;
end;
procedure TFrmgxgx.tddhKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then tgxmc.SetFocus;
end;
procedure TFrmgxgx.breturnClick(Sender: TObject);
begin
try
rzcsj:=datetimetostr(now);
form16.WriteTorz(rzczy,rzsj,rzjsj,rzcsj);
DataModule1.ClientDataSet23.IndexFieldNames:='';
if DataModule1.clientdataset23.Active then DataModule1.ClientDataSet23.Active:=false;
except
showmessage('数据库没有打开!');
end;
close;
end;
procedure TFrmgxgx.FormActivate(Sender: TObject);
var
commandstring,relation,cx,str:string;
begin
rzjsj:=datetimetostr(now);
rzczy:=form1.StatusBar1.Panels[4].Text;
rzsj:='工序单价更新';
qq.DateTime:=date-30;
zq.DateTime:=date;
help.Caption:=' 请您点击< 查询>按钮开始查询工序记录!';
end;
procedure TFrmgxgx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
DataModule1.ClientDataSet23.IndexFieldNames:='';
if DataModule1.clientdataset23.Active then DataModule1.ClientDataSet23.Active:=false;
if rzcsj<>'' then exit;
rzcsj:=datetimetostr(now);
form16.WriteTorz(rzczy,rzsj,rzjsj,rzcsj);
except
showmessage('数据库没有打开!');
end;
close;
end;
procedure TFrmgxgx.BqueryClick(Sender: TObject);
var
commandtring1,relation,cx:string;
begin
relation:=' like ''';
cx:='%';
commandstring:='select * from dbo.gxb';
commandtring1:='select * from dbo.gxb';
try
if (trim(qddh.Text)<>'') and (cddh.Checked) then
begin
relation:=' like ''';
cx:='%';
if commandstring=commandtring1 then
begin
commandstring:=commandstring+' where (dbo.gxb.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.gxb.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end;
end
else
begin
qddh.Text:='';
end;
if (trim(qgxmc.Text)<>'') and (cgxmc.Checked) then
begin
relation:=' like ''';
cx:='%';
if commandstring=commandtring1 then
begin
commandstring:=commandstring+' where (dbo.gxb.gxmc'+relation+cx+trim(qgxmc.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.gxb.gxmc'+relation+cx+trim(qgxmc.Text)+cx+''')';
end;
end
else
begin
qgxmc.Text:='';
end;
if (trim(qdj.Text)<>'') and (cdj.Checked) then
begin
relation:=' like ''';
cx:='%';
if commandstring=commandtring1 then
BEGIN
commandstring:=commandstring+' where (dbo.gxb.dj'+relation+cx+TRIM(qdj.Text)+cx+''')'
END
else
BEGIN
commandstring:=commandstring+' and (dbo.gxb.dj'+relation+cx+TRIM(qdj.Text)+cx+''')'
end;
end
else
begin
qdj.Text:='';
end;
if (trim(qxs.Text)<>'') and (cxs.Checked) then
begin
relation:=' like ''';
cx:='%';
if commandstring=commandtring1 then
BEGIN
commandstring:=commandstring+' where (dbo.gxb.xs'+relation+cx+TRIM(qxs.Text)+cx+''')'
END
else
BEGIN
commandstring:=commandstring+' and (dbo.gxb.xs'+relation+cx+TRIM(qxs.Text)+cx+''')'
end;
end
else
begin
qxs.Text:='';
end;
if (trim(qbz.Text)<>'') and (cbz.Checked) then
begin
relation:=' like ''';
cx:='%';
if commandstring=commandtring1 then
BEGIN
commandstring:=commandstring+' where (dbo.gxb.bz'+relation+cx+TRIM(qbz.Text)+cx+''')'
END
else
BEGIN
commandstring:=commandstring+' and (dbo.gxb.bz'+relation+cx+TRIM(qbz.Text)+cx+''')'
end;
end
else
begin
qbz.Text:='';
end;
if (trim(qczy.Text)<>'') and (cczy.Checked) then
begin
relation:=' like ''';
cx:='%';
if commandstring=commandtring1 then
BEGIN
commandstring:=commandstring+' where (dbo.gxb.czy'+relation+cx+TRIM(qczy.Text)+cx+''')'
END
else
BEGIN
commandstring:=commandstring+' and (dbo.gxb.czy'+relation+cx+TRIM(qczy.Text)+cx+''')'
end;
end
else
begin
qczy.Text:='';
end;
commandstring:=commandstring+' order by ddh,gxmc';
commandstringq:=commandstring;
DataModule1.ClientDataSet23.DisableControls;
DataModule1.ClientDataSet23.Close;
DataModule1.ClientDataSet23.CommandText:=commandstring;
DataModule1.ClientDataSet23.Open;
DataModule1.ClientDataSet23.EnableControls;
help.Caption:=' 查询完毕,请用鼠标双击工序记录所在的行!';
except
DataModule1.clientdataset23.EnableControls;
showmessage('数据库没有打开!');
end;
end;
procedure TFrmgxgx.tgxmcKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then tdj.SetFocus;
end;
procedure TFrmgxgx.tdj1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8,#13,'.']) then
begin
key:=#0;
help.caption:=' 请输入数字!';
end;
if key=#13 then qq.SetFocus;
end;
procedure TFrmgxgx.DBGrid5TitleClick(Column: TColumn);
var i : integer;
begin
for i:= 1 to DBGrid5.Columns.Count do
begin
//恢复所有标题字体为默认
DBGrid5.Columns[i-1].Title.Font.Color := clBlue;
DBGrid5.Columns[i-1].Title.Font.Style := [];
end;
if DataModule1.ClientDataSet23.IndexFieldNames<>(Column.FieldName) then //判断原排序方式
begin
DataModule1.ClientDataSet23.IndexFieldNames:= Column.FieldName;
Column.Title.Font.Color := clRed; //改变标题行字体为红色,表示当前的排序方式为升序
Column.Title.Font.Style := [fsBold];
end;
end;
procedure TFrmgxgx.DBGrid1TitleClick(Column: TColumn);
var i : integer;
begin
end;
procedure TFrmgxgx.bgxgxClick(Sender: TObject);
var
relation,cx,dx,sqlstr:string;
begin
if not DataModule1.ClientDataSet23.Active then exit;
if DataModule1.ClientDataSet23.RecordCount<1 then exit;
relation:=' = ''';
cx:='';
dx:= ' ''';
if (trim(tddh.Text)='') or (trim(tgxmc.Text)='') or (trim(tdj.Text)='') or (trim(tdj1.Text)='') then exit;
bgxgx.Enabled:=false;
sqlstr:='update dbo.gxb set dj'+relation+trim(tdj1.Text)+dx;
sqlstr:=sqlstr+' where (ddh' +relation+cx+trim(tddh.Text)+cx+''')';
sqlstr:=sqlstr+' and (gxmc' +relation+cx+trim(tgxmc.Text)+cx+''')';
sqlstr:=sqlstr+' and (dj' +relation+cx+trim(tdj.Text)+cx+''')';
try
DataModule1.ClientDataSet23.CommandText:=sqlstr;
DataModule1.ClientDataSet23.Execute;
DataModule1.ClientDataSet23.ApplyUpdates(-1);
DataModule1.ClientDataSet23.DisableControls;
DataModule1.ClientDataSet23.Close;
DataModule1.ClientDataSet23.CommandText:=commandstringq;
DataModule1.ClientDataSet23.Open;
DataModule1.ClientDataSet23.EnableControls;
bgxgx.Enabled:=true;
help.Caption:= ' 工序单价更新成功!';
except
DataModule1.clientdataset23.EnableControls;
help.Caption:= ' 工序单价更新失败!';
end;
end;
procedure TFrmgxgx.bclgxClick(Sender: TObject);
var
datestr,relation,cx,dx,sqlstr,commandstringp:string;
begin
if qq.Date>zq.Date then
begin
help.Caption:=' 更新日期错误,更新失败!';
exit;
end;
datestr:=frmxtfz.checkfzrq(formatdatetime('yyyy-mm-dd',qq.date));
if datestr<>'' then
begin
help.Caption:=' 封账日期为'+datestr+'您不能修改封账日期前的数据';
exit;
end;
if not DataModule1.ClientDataSet23.Active then exit;
if DataModule1.ClientDataSet23.RecordCount<1 then exit;
relation:=' = ''';
cx:='';
dx:= ' ''';
if (trim(tddh.Text)='') or (trim(tgxmc.Text)='') or (trim(tdj.Text)='') or (trim(tdj1.Text)='') then exit;
bclgx.Enabled:=false;
sqlstr:='select * from dbo.cllrb';
sqlstr:=sqlstr+' where (ddh' +relation+cx+trim(tddh.Text)+cx+''')';
sqlstr:=sqlstr+' and (gxmc' +relation+cx+trim(tgxmc.Text)+cx+''')';
sqlstr:=sqlstr+' and (dj' +relation+cx+trim(tdj.Text)+cx+''')';
relation:=' >= ''';
sqlstr:=sqlstr+' and (rq' +relation+cx+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
relation:=' < ''';
sqlstr:=sqlstr+' and (rq' +relation+cx+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
try
DataModule1.ClientDataSet25.Close;
DataModule1.ClientDataSet25.CommandText:=sqlstr;
DataModule1.ClientDataSet25.Open;
commandstringp:=sqlstr;
relation:=' = ''';
cx:='';
dx:= ' ''';
sqlstr:='update dbo.cllrb set dj'+relation+trim(tdj1.Text)+dx;
sqlstr:=sqlstr+' where (ddh' +relation+cx+trim(tddh.Text)+cx+''')';
sqlstr:=sqlstr+' and (gxmc' +relation+cx+trim(tgxmc.Text)+cx+''')';
sqlstr:=sqlstr+' and (dj' +relation+cx+trim(tdj.Text)+cx+''')';
relation:=' >= ''';
sqlstr:=sqlstr+' and (rq' +relation+cx+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
relation:=' < ''';
sqlstr:=sqlstr+' and (rq' +relation+cx+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
DataModule1.ClientDataSet25.CommandText:=sqlstr;
DataModule1.ClientDataSet25.Execute;
DataModule1.ClientDataSet25.ApplyUpdates(-1);
sqlstr:='UPDATE a SET a.cz = b.sl * b.dj * b.xs FROM cllrb a, cllrb b WHERE a.clh = b.clh';
DataModule1.ClientDataSet25.CommandText:=sqlstr;
DataModule1.ClientDataSet25.Execute;
DataModule1.ClientDataSet25.ApplyUpdates(-1);
DataModule1.ClientDataSet25.Active:=false;
bclgx.Enabled:=true;
help.Caption:= ' 产量单价更新成功!';
except
DataModule1.clientdataset25.EnableControls;
help.Caption:= ' 产量单价更新失败!';
end;
end;
procedure TFrmgxgx.DBGrid5DblClick(Sender: TObject);
begin
if not DataModule1.ClientDataSet23.Active then exit;
if DataModule1.ClientDataSet23.RecordCount<1 then exit;
tddh.Text:=DataModule1.ClientDataSet23.fieldbyname('ddh').AsString;
tgxmc.Text:=DataModule1.ClientDataSet23.fieldbyname('gxmc').AsString;
tdj.Text:=DataModule1.ClientDataSet23.fieldbyname('dj').AsString;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?