ddchcx.pas

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

PAS
461
字号
unit ddchcx;

interface

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

type
  TFrmddchcx = class(TForm)
    Pz: TPanel;
    help: TLabel;
    Label7: TLabel;
    Pd: TPanel;
    pq: TPanel;
    cddh: TCheckBox;
    qddh: TEdit;
    cxh: TCheckBox;
    qxh: TEdit;
    ccl: TCheckBox;
    qcl: TEdit;
    ccz: TCheckBox;
    qcz: TEdit;
    cbz: TCheckBox;
    qbz: TEdit;
    Cqq: TCheckBox;
    Czq: TCheckBox;
    zq: TDateTimePicker;
    qq: TDateTimePicker;
    GroupBox1: TGroupBox;
    DBGrid5: TDBGrid;
    bprint: TBitBtn;
    breturn: TBitBtn;
    Bquery: TBitBtn;
    bprintc: TBitBtn;
    OpenDialog1: TOpenDialog;
    Bddhz: TBitBtn;
    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
  Frmddchcx: TFrmddchcx;

implementation

uses unit28, Unit1, Unit16, func;

{$R *.dfm}

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

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

procedure TFrmddchcx.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 TFrmddchcx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
DataModule1.ClientDataSet19.IndexFieldNames:='';
if DataModule1.clientdataset19.Active then  DataModule1.ClientDataSet19.Active:=false;
if rzcsj<>'' then exit;
rzcsj:=datetimetostr(now);
form16.WriteTorz(rzczy,rzsj,rzjsj,rzcsj);
except
showmessage('数据库没有打开!');
end;
close;
end;

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

if (trim(qcl.Text)<>'') and (ccl.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.sl'+relation+cx+trim(qcl.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.sl'+relation+cx+trim(qcl.Text)+cx+''')';
end;
end
else
begin
qcl.Text:='';
end;
if (trim(qcz.Text)<>'') and (ccz.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.czl'+relation+cx+trim(qcz.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.czl'+relation+cx+trim(qcz.Text)+cx+''')';
end;
end
else
begin
qcz.Text:='';
end;
if (trim(qbz.Text)<>'') and (cbz.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.bz'+relation+cx+trim(qbz.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.bz'+relation+cx+trim(qbz.Text)+cx+''')';
end;
end
else
begin
qbz.Text:='';
end;
commandstring:=commandstring+' order by ddh,xh';
commandstringq:=commandstring;
DataModule1.ClientDataSet19.DisableControls;
DataModule1.ClientDataSet19.Close;
DataModule1.ClientDataSet19.CommandText:=commandstring;
DataModule1.ClientDataSet19.Open;
hz;
DataModule1.ClientDataSet19.EnableControls;
except
DataModule1.clientdataset19.EnableControls;
showmessage('数据库没有打开!');
end;
end;

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

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

procedure TFrmddchcx.BddhzClick(Sender: TObject);
var
commandtring1,relation,cx:string;
begin
 relation:=' like ''';
    cx:='%';
commandstring:='select ddh,sum(sl) as sl from dbo.ddchb';
commandtring1:=commandstring;
  try
if (trim(qddh.Text)<>'') and (cddh.Checked) then
   begin
 relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.ddh'+relation+cx+trim(qddh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.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.ddchb.xh'+relation+cx+trim(qxh.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.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.ddchb.rq'+ relation+FormatDateTime('yyyy-mm-dd',qq.Date)+cx+''')';
end
else
begin
relation:=' >= ''';
    cx:='';
commandstring:=commandstring+' and (dbo.ddchb.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.ddchb.rq'+ relation+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
end
else
begin
relation:=' < ''';
    cx:='';
commandstring:=commandstring+' and (dbo.ddchb.rq'+ relation+FormatDateTime('yyyy-mm-dd',zq.Date+1)+cx+''')';
end;
end;

if (trim(qcl.Text)<>'') and (ccl.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.sl'+relation+cx+trim(qcl.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.sl'+relation+cx+trim(qcl.Text)+cx+''')';
end;
end
else
begin
qcl.Text:='';
end;
if (trim(qcz.Text)<>'') and (ccz.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.czl'+relation+cx+trim(qcz.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.czl'+relation+cx+trim(qcz.Text)+cx+''')';
end;
end
else
begin
qcz.Text:='';
end;
if (trim(qbz.Text)<>'') and (cbz.Checked) then
   begin
    relation:=' like ''';
    cx:='%';
  if  commandstring=commandtring1 then
  begin
commandstring:=commandstring+' where (dbo.ddchb.bz'+relation+cx+trim(qbz.Text)+cx+''')';
end
else
begin
commandstring:=commandstring+' and (dbo.ddchb.bz'+relation+cx+trim(qbz.Text)+cx+''')';
end;
end
else
begin
qbz.Text:='';
end;
commandstring:=commandstring+' group by ddh';
commandstring:=commandstring+' order by ddh';
commandstringq:=commandstring;
DataModule1.ClientDataSet19.DisableControls;
DataModule1.ClientDataSet19.Close;
DataModule1.ClientDataSet19.CommandText:=commandstring;
DataModule1.ClientDataSet19.Open;
hz;
DataModule1.ClientDataSet19.EnableControls;
except
DataModule1.clientdataset19.EnableControls;
showmessage('数据库没有打开!');
end;
end;
function TFrmddchcx.hz:boolean;
var
  sl: String;
  i: integer;
begin
sl:='0';
if not DataModule1.ClientDataSet19.RecordCount>0 then exit;
   DataModule1.ClientDataSet19.First;
   for i := 1 to DataModule1.ClientDataSet19.RecordCount do
  begin
 if DataModule1.ClientDataSet19.FieldByName('sl').AsString<>'' then sl:= formatfloat('0',strtofloat(sl)+DataModule1.ClientDataSet19.FieldByName('sl').AsFloat);
 DataModule1.ClientDataSet19.Next;
  end;
DataModule1.ClientDataSet19.First;
help.Caption:='  合计数量为'+sl;
end;

procedure TFrmddchcx.DBGrid5KeyPress(Sender: TObject; var Key: Char);
var
  sl: String;
  i: integer;
begin
sl:='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('sl').AsString<>'' then sl:= formatfloat('0',strtofloat(sl)+DBGrid5.DataSource.DataSet.FieldByName('sl').AsFloat);
  end;
help.Caption:='  合计数量为'+sl;
end;
end;

end.

⌨️ 快捷键说明

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