ylzjcx.~pas

来自「应对服装行业的生产成本控制系统」· ~PAS 代码 · 共 463 行

~PAS
463
字号
unit ylzjcx;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ComCtrls, Grids, DBGrids, ExtCtrls, DBCtrls,
  DB, ADODB, DBClient;

type
  TFrmylzjcx = class(TForm)
    Pz: TPanel;
    help: TLabel;
    Label7: TLabel;
    Pd: TPanel;
    pq: TPanel;
    cddh: TCheckBox;
    qddh: TEdit;
    cxh: TCheckBox;
    qxh: TEdit;
    cje: TCheckBox;
    qje: TEdit;
    cllr: TCheckBox;
    qllr: TEdit;
    cflr: TCheckBox;
    qflr: TEdit;
    Cqq: TCheckBox;
    Czq: TCheckBox;
    zq: TDateTimePicker;
    qq: TDateTimePicker;
    GroupBox1: TGroupBox;
    DBGrid5: TDBGrid;
    bprint: TBitBtn;
    breturn: TBitBtn;
    Bquery: TBitBtn;
    bprintc: TBitBtn;
    Bddhz: TBitBtn;
    OpenDialog1: TOpenDialog;
    procedure bprintClick(Sender: TObject);
    procedure breturnClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BqueryClick(Sender: TObject);
    procedure DBGrid5TitleClick(Column: TColumn);
    procedure bprintcClick(Sender: TObject);
    procedure BddhzClick(Sender: TObject);
    procedure DBGrid5KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
      rzczy,rzsj,rzjsj,rzcsj:string;
      errzt: integer;
      errcode:boolean;
  commandstring,commandstringq: string;
  function hz():boolean;
  public
    { Public declarations }

  end;

var
  Frmylzjcx: TFrmylzjcx;

implementation

uses unit28, Unit1, Unit16, func;

{$R *.dfm}

procedure TFrmylzjcx.bprintClick(Sender: TObject);
begin
help.Caption:='   暂不提供打印功能!';
end;

procedure TFrmylzjcx.breturnClick(Sender: TObject);
begin
try
rzcsj:=datetimetostr(now);
form16.WriteTorz(rzczy,rzsj,rzjsj,rzcsj);
DataModule1.ClientDataSet27.IndexFieldNames:='';
if DataModule1.clientdataset27.Active then  DataModule1.ClientDataSet27.Active:=false;
except
showmessage('数据库没有打开!');
end;
close;
end;

procedure TFrmylzjcx.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:='';
help.Caption:='  请您点击< 查询>按钮开始查询余料追加记录!';
end;

procedure TFrmylzjcx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
DataModule1.ClientDataSet27.IndexFieldNames:='';
if DataModule1.clientdataset27.Active then  DataModule1.ClientDataSet27.Active:=false;
if rzcsj<>'' then exit;
rzcsj:=datetimetostr(now);
form16.WriteTorz(rzczy,rzsj,rzjsj,rzcsj);
except
showmessage('数据库没有打开!');
end;
close;
end;

procedure TFrmylzjcx.BqueryClick(Sender: TObject);
var
commandtring1,relation,cx:string;
begin
 relation:=' like ''';
    cx:='%';
commandstring:='select * from dbo.ylzj';
commandtring1:='select * from dbo.ylzj';
  try
if (trim(qddh.Text)<>'') and (cddh.Checked) then
   begin
 relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end;
end
else
begin
qddh.Text:='';
end;
if (trim(qxh.Text)<>'') and (cxh.Checked) then
   begin
 relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.xh'+relation+cx+trim(qxh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.xh'+relation+cx+trim(qxh.Text)+cx+''')';
end;
end
else
begin
qxh.Text:='';
end;
if cqq.Checked then
 begin
if commandstring=commandtring1 then
begin
relation:=' >= ''';
    cx:='';
commandstring:=commandstring+' where (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
end
else
begin
relation:=' >= ''';
    cx:='';
commandstring:=commandstring+' and (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
end;
end;
if czq.Checked then
 begin
if commandstring=commandtring1 then
begin
relation:=' < ''';
    cx:='';
commandstring:=commandstring+' where (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
end
else
begin
relation:=' < ''';
    cx:='';
commandstring:=commandstring+' and (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
end;
end;

if (trim(qje.Text)<>'') and (cje.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.je'+relation+cx+trim(qje.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.je'+relation+cx+trim(qje.Text)+cx+''')';
end;
end
else
begin
qje.Text:='';
end;
if (trim(qllr.Text)<>'') and (cllr.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.llr'+relation+cx+trim(qllr.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.llr'+relation+cx+trim(qllr.Text)+cx+''')';
end;
end
else
begin
qllr.Text:='';
end;
if (trim(qflr.Text)<>'') and (cflr.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.flr'+relation+cx+trim(qflr.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.flr'+relation+cx+trim(qflr.Text)+cx+''')';
end;
end
else
begin
qflr.Text:='';
end;
commandstring:=commandstring+' order by ddh,xh';
commandstringq:=commandstring;
DataModule1.ClientDataSet27.DisableControls;
DataModule1.ClientDataSet27.Close;
DataModule1.ClientDataSet27.CommandText:=commandstring;
DataModule1.ClientDataSet27.Open;
hz;
DataModule1.ClientDataSet27.EnableControls;
help.Caption:='   查询完毕!';
except
DataModule1.clientdataset27.EnableControls;
showmessage('数据库没有打开!');
end;
end;

procedure TFrmylzjcx.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.ClientDataSet27.IndexFieldNames<>(Column.FieldName) then //判断原排序方式
begin
DataModule1.ClientDataSet27.IndexFieldNames:= Column.FieldName;
Column.Title.Font.Color := clRed; //改变标题行字体为红色,表示当前的排序方式为升序
Column.Title.Font.Style := [fsBold];
end;
end;

procedure TFrmylzjcx.bprintcClick(Sender: TObject);
var
excelname: string;
begin
if not DataModule1.ClientDataSet27.Active then exit;
if not form1.excel then
begin
showmessage('您还未获得管理员的授权!请您与管理员联系获取授权!');
exit;
end;
if DataModule1.ClientDataSet27.RecordCount<1 then exit;
opendialog1.Filter:='Excel 文件 (*.xls) │*.xls';
if opendialog1.Execute then excelname:=opendialog1.FileName;
if length(excelname)>0 then writetoexcel(DataModule1.ClientDataSet27,excelname,'余料追加信息报表');
exit;
end;

procedure TFrmylzjcx.BddhzClick(Sender: TObject);
var
commandtring1,relation,cx:string;
begin
 relation:=' like ''';
    cx:='%';
commandstring:='select ddh,sum(je) as je,llr from dbo.ylzj';
commandtring1:=commandstring;
  try
if (trim(qddh.Text)<>'') and (cddh.Checked) then
   begin
 relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end;
end
else
begin
qddh.Text:='';
end;
if (trim(qxh.Text)<>'') and (cxh.Checked) then
   begin
 relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.xh'+relation+cx+trim(qxh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.xh'+relation+cx+trim(qxh.Text)+cx+''')';
end;
end
else
begin
qxh.Text:='';
end;
if cqq.Checked then
 begin
if commandstring=commandtring1 then
begin
relation:=' >= ''';
    cx:='';
commandstring:=commandstring+' where (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
end
else
begin
relation:=' >= ''';
    cx:='';
commandstring:=commandstring+' and (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
end;
end;
if czq.Checked then
 begin
if commandstring=commandtring1 then
begin
relation:=' < ''';
    cx:='';
commandstring:=commandstring+' where (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
end
else
begin
relation:=' < ''';
    cx:='';
commandstring:=commandstring+' and (dbo.ylzj.rq'+ relation+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
end;
end;
if (trim(qje.Text)<>'') and (cje.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.je'+relation+cx+trim(qje.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.je'+relation+cx+trim(qje.Text)+cx+''')';
end;
end
else
begin
qje.Text:='';
end;
if (trim(qllr.Text)<>'') and (cllr.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.llr'+relation+cx+trim(qllr.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.llr'+relation+cx+trim(qllr.Text)+cx+''')';
end;
end
else
begin
qllr.Text:='';
end;
if (trim(qflr.Text)<>'') and (cflr.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ylzj.flr'+relation+cx+trim(qflr.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ylzj.flr'+relation+cx+trim(qflr.Text)+cx+''')';
end;
end
else
begin
qflr.Text:='';
end;
commandstring:=commandstring+' group by ddh,llr';
commandstring:=commandstring+' order by ddh,llr';
commandstringq:=commandstring;
DataModule1.ClientDataSet27.DisableControls;
DataModule1.ClientDataSet27.Close;
DataModule1.ClientDataSet27.CommandText:=commandstring;
DataModule1.ClientDataSet27.Open;
hz;
DataModule1.ClientDataSet27.EnableControls;
help.Caption:='   查询完毕!';
except
DataModule1.clientdataset27.EnableControls;
showmessage('数据库没有打开!');
end;
end;

function TFrmylzjcx.hz:boolean;
var
  sl,je: String;
  i: integer;
begin
je:='0';
if not DataModule1.ClientDataSet27.RecordCount>0 then exit;
   DataModule1.ClientDataSet27.First;
   for i := 1 to DataModule1.ClientDataSet27.RecordCount do
  begin
 if DataModule1.ClientDataSet27.FieldByName('je').AsString<>'' then je:= formatfloat('0.00',strtofloat(je)+DataModule1.ClientDataSet27.FieldByName('je').AsFloat);
 DataModule1.ClientDataSet27.Next;
  end;
 DataModule1.ClientDataSet27.First;
help.Caption:='  合计数量为'+sl+'  合计金额为'+je;
end;

procedure TFrmylzjcx.DBGrid5KeyPress(Sender: TObject; var Key: Char);
var
  je: String;
  i: integer;
begin
je:='0';
if key=#13 then
begin
   for i := 0 to (DBGrid5.SelectedRows.Count - 1) do
  begin
    DBGrid5.DataSource.DataSet.GotoBookmark(pointer(DBGrid5.SelectedRows.Items[i]));
 if DBGrid5.DataSource.DataSet.FieldByName('je').AsString<>'' then je:= formatfloat('0.00',strtofloat(je)+DBGrid5.DataSource.DataSet.FieldByName('je').AsFloat);
  end;
help.Caption:='  合计金额为'+je;
end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?