jfgs.pas

来自「一个仓库管理中的子系统--采购子系统」· PAS 代码 · 共 277 行

PAS
277
字号
unit jfgs;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, StdCtrls, ExtCtrls, Grids, ComCtrls;

const
  grid_headcolor=$00ACEEFF;
  grid_highcolor=$00F7FFFF;
  grid_lowcolor=$00CAFFFF;
  grid_selectedcolor=$00ACEEFF;   
type
  TjfgsForm = class(TForm)
    Label1: TLabel;
    StringGrid1: TStringGrid;
    Bevel1: TBevel;
    Label2: TLabel;
    hjjeEdit: TEdit;
    hjdsEdit: TEdit;
    hjzlsEdit: TEdit;
    Bevel2: TBevel;
    Label3: TLabel;
    Label4: TLabel;
    yearCombo: TComboBox;
    monthCombo: TComboBox;
    SpeedButton1: TSpeedButton;
    Bevel3: TBevel;
    StatusBar1: TStatusBar;
    SpeedButton2: TSpeedButton;
    SpeedButton7: TSpeedButton;
    procedure FormActivate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
  private
  procedure write_jfgs_table;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  jfgsForm: TjfgsForm;

implementation

uses htgl, Datamodule, jfgs_report;

{$R *.DFM}
procedure TjfgsForm.write_jfgs_table;
var I:Integer;
begin
with datamodule1.Query3 do
begin
Requestlive:=true;
sql.Clear;
sql.Add('select * From dbo.a_jfgs');
prepare;
open;
first;

if not isEmpty then
while not eof do
begin
delete;
end;

with stringGrid1 do
begin
For I:=1 to RowCount-1 do
begin
append;
FieldByName('xh').asInteger:=StrToInt(Cells[0,I]);
FieldByName('lb').asstring:=Cells[1,I];
FieldByName('je').asFloat:=StrToFloat(Cells[2,I]);
FieldByName('fs').asInteger:=StrToInt(Cells[3,I]);
FieldByName('wzzls').asInteger:=StrToInt(Cells[4,I]);
post;
end;
end;
append;
FieldByName('xh').asInteger:=stringGrid1.RowCount;
FieldByName('lb').asstring:='合计';
FieldByName('je').asFloat:=StrToFloat(hjjeEdit.Text);
FieldByName('fs').asInteger:=StrToInt(hjdsedit.Text);
FieldByName('wzzls').asInteger:=StrToInt(hjzlsedit.Text);
post;
end;
end;

procedure TjfgsForm.FormActivate(Sender: TObject);
var I:Integer;
begin
   datamodule1.PublicQuery1.RequestLive:=False;
   datamodule1.publicQuery2.RequestLive:=false;
   with stringGrid1 do
   begin
   For I:=0 to RowCount-1 do
   Cells[0,I+1]:=IntToStr(I+1);
   Cells[0,0]:='序号';
   cells[1,0]:='类别';
   cells[2,0]:='金额(元)';
   cells[3,0]:='份数';
   cells[4,0]:='物资种类数';
   cells[1,1]:='无线电产品';
   Cells[1,2]:='机电产品';
   Cells[1,3]:='劳保用品';
   Cells[1,4]:='地方物资';
   cells[1,5]:='稀贵金属';
   Cells[1,6]:='仪器设备';
   Cells[1,7]:='黑色金属';
   Cells[1,8]:='有色金属';
   Cells[1,9]:='非金属材料';
   Cells[1,10]:='其他';
   end;
end;

procedure TjfgsForm.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var Text:string;
begin
   if arow=0 then
   begin
   stringgrid1.Canvas.Brush.Color:=grid_headcolor;
   stringgrid1.Canvas.FillRect(rect);
   htlrForm.writetext(stringgrid1.canvas,rect.left,rect.top,rect.right,rect.bottom,4,1,stringgrid1.cells[acol,arow],font,1,true);
   exit;
   end;
   text:=stringgrid1.cells[acol,arow];
   if (arow mod 2) =0 then stringgrid1.Canvas.Brush.Color:=grid_highcolor
   else  stringgrid1.Canvas.Brush.Color:=grid_lowcolor;
   if gdSelected in state then  stringgrid1.Canvas.Brush.Color:=grid_selectedcolor;
   stringgrid1.Canvas.FillRect(rect);
   htlrForm.writetext(stringgrid1.canvas,rect.left,rect.top,rect.right,rect.bottom,1,1,text,font,2,true);
end;

procedure TjfgsForm.SpeedButton1Click(Sender: TObject);
var productkind:Array [0..9] of string;
    TotalMoney: Array [0..9] of Real;
    TotalTable: Array [0..9] of Integer;
    TotalProduct: Array [0..9] of Integer;
I:integer;
hjje:Real;
zbs,zjls:Integer;
monthstr:string;
begin
   hjje:=0;
   zbs:=0;
   zjls:=0;
   If length(monthCombo.Text)=1 then
   monthstr:=copy(yearCombo.Text,3,2)+'0'+monthcombo.Text
   else
   monthstr:=copy(yearCombo.Text,3,2)+monthcombo.Text;

   For I:=0 to 9 do
   begin
   if length(inttostr(I+1))=1 then
   ProductKind[I]:='0'+IntTostr(I+1)
   else ProductKind[I]:=IntToStr(I);
   TotalMoney[I]:=0;
   TotalTable[I]:=0;
   TotalProduct[I]:=0;
   end;


For I:=0 to 9 do
begin
with datamodule1.publicQuery2 do
begin
   sql.Clear;
   sql.Add('Select Distinct sqbid From dbo.a_cghzglb');
   sql.Add('Where cpbh like '+''''+productkind[I]+'%'+''''+' and sqbid like '+''''+monthstr+'%'+'''');
   prepare;
   open;
   TotalTable[I]:=RecordCount;
end;

with datamodule1.PublicQuery1 do
begin
   sql.Clear;
   sql.Add('Select * From dbo.a_cghzglb');
   sql.Add('Where cpbh like '+''''+productkind[I]+'%'+''''+' and sqbid like '+''''+monthstr+'%'+'''');
   prepare;
   open;
   First;
     if RecordCount<>0 then
   begin
   TotalProduct[I]:=RecordCount;
   While not Eof do
   begin
   TotalMoney[I]:=TotalMoney[I]+FieldByName('gjje').asfloat;
   next;
   end;
   end;
   end;
end;

For I:=0 to 9 do
with stringGrid1 do
begin
cells[2,I+1]:=Format('%8.2f',[Totalmoney[I]]);
Cells[3,I+1]:=IntTostr(TotalTable[I]);
Cells[4,I+1]:=IntTostr(TotalProduct[I]);
end;

For I:=0 to 9 do
begin
hjje:=hjje+Totalmoney[I];
//zbs:=zbs+TotalTable[I];
zjls:=zjls+TotalProduct[I];
end;

with datamodule1.PublicQuery1 do
begin
   sql.Clear;
   sql.Add('Select * From dbo.a_cgsqzb');
   sql.Add('Where sqbid like '+''''+monthstr+'%'+'''');
   prepare;
   open;
   zbs:=recordCount;
end;

hjjeEdit.Text:=Format('%8.2f',[hjje]);
hjdsEdit.Text:=IntTostr(zbs);
hjzlsEdit.Text:=IntToStr(zjls);
end;

procedure TjfgsForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   with datamodule1 do
   begin
   PublicQuery1.close;
   PublicQuery2.close;
   Query3.RequestLive:=False;
   Query3.Close;
   end;
end;

procedure TjfgsForm.SpeedButton2Click(Sender: TObject);
begin
    close;
end;

procedure TjfgsForm.SpeedButton7Click(Sender: TObject);
begin
   write_jfgs_table;
   with datamodule1.Query3 do
   begin
   sql.Clear;
   sql.Add('select * From dbo.a_jfgs');
   prepare;
   open;
   end;
   jfgs_reportForm:=Tjfgs_reportForm.Create(Application);
   //Report:=sqbReportform.QuickRep;
   with Datamodule1.Query3 do
   with jfgs_reportForm do
   begin
   xhQR.DataField:=FieldByName('xh').FieldName;
   lbQR.DataField:=FieldByname('lb').FieldName;
   jeQR.DataField:=FieldBYNAme('je').FieldName;
   fsQR.DataField:=FieldByName('fs').FieldName;
   wzzlsQR.DataField:=FieldByName('wzzls').FieldName;
   end;
   hide;
   jfgs_reportForm.quickrep1.Preview;
   jfgs_reportForm.Free;
   show;
end;

end.

⌨️ 快捷键说明

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