jhyxg.pas

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

PAS
253
字号
unit jhyxg;

interface

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

const
  grid_headcolor=$00ACEEFF;
  grid_highcolor=$00F7FFFF;
  grid_lowcolor=$00CAFFFF;
  grid_selectedcolor=$0EFFAA00;

type
  TjhyxgForm = class(TForm)
    StringGrid1: TStringGrid;
    Label1: TLabel;
    Bevel1: TBevel;
    Bevel2: TBevel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormActivate(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
  procedure InitstrGrid;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  jhyxgForm: TjhyxgForm;

implementation

uses Datamodule, htgl;

{$R *.DFM}
var Opstate:integer;

procedure TjhyxgForm.InitstrGrid;
var I:integer;
begin
  Opstate:=0;
  with datamodule1.PublicQuery1 do
  begin
  requestlive:=true;
  sql.Clear;
  sql.Add('select * From dbo.p_jhyb');
  prepare;
  open;
  First;
  with stringgrid1 do
  begin
  cells[0,0]:='计划员ID';
  cells[1,0]:='计划员名';
  rowCount:=RecordCount+1;
  For I:=1 to RowCount-1 do
  begin
  cells[0,I]:=FieldByName('jhyid').asstring;
  Cells[1,I]:=FieldByname('jhy').asstring;
  next;
  end;
  end;
  end;
end;


procedure TjhyxgForm.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 TjhyxgForm.FormActivate(Sender: TObject);
begin
  InitStrGrid;
end;

procedure TjhyxgForm.SpeedButton5Click(Sender: TObject);
begin
  close;
end;

procedure TjhyxgForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    datamodule1.PublicQuery1.RequestLive:=False;
    datamodule1.PublicQuery1.close;
    datamodule1.PublicQuery2.RequestLive:=False;
    datamodule1.PublicQuery2.close;
end;

procedure TjhyxgForm.SpeedButton4Click(Sender: TObject);
begin
   opstate:=1;
   {with StringGrid1 do
   if not (GoEditing in Options) then
   Options:=Options+[GoEditing];}

   speedButton2.Enabled:=false;
   speedButton3.Enabled:=False;
   speedButton4.Enabled:=False;
end;

procedure TjhyxgForm.SpeedButton2Click(Sender: TObject);
begin
   Opstate:=2;
   with StringGrid1 do
   begin
    RowCount:=RowCount+1;
    if not (GoEditing in Options) then
    Options:=Options+[GoEditing];
   end;
   speedbutton2.Enabled:=false;
   speedButton4.Enabled:=False;
   speedButton3.Enabled:=False;
end;

procedure TjhyxgForm.SpeedButton3Click(Sender: TObject);
begin
    if messagedlg('您是否要删除记录:'+'计划员ID:'+stringgrid1.Cells[0,stringGrid1.row]+'计划员名:'+stringgrid1.Cells[1,stringGrid1.row],mtInformation,[mbOK,mbCancel],0)=mrOK then
    begin
    //Opstate:=3;
    with datamodule1.PublicQuery2 do
    begin
    requestlive:=true;
    sql.Clear;
    sql.Add('select * From dbo.p_jhyb');
    sql.Add('where jhyid='+''''+stringGrid1.cells[0,stringGrid1.row]+'''');
    prepare;
    open;
    delete;
    end;
    showmessage('记录被成功删除!请刷新!');
    end;
    speedbutton2.Enabled:=false;
    speedButton4.Enabled:=False;
    speedButton3.Enabled:=False;
end;

procedure TjhyxgForm.SpeedButton1Click(Sender: TObject);
var I:integer;
begin
if Opstate=1 then
begin
 with datamodule1.PublicQuery1 do
 begin
   first;
   while not Eof do
   delete;

   for I:=1 to stringGrid1.RowCount-1 do
   begin
   append;
   FieldByname('jhyid').asstring:=stringGrid1.Cells[0,I];
   FieldByName('jhy').asstring:=stringGrid1.Cells[1,I];
   post;
   end;
 end;
end;

if Opstate=2 then
begin
 if (stringGrid1.Cells[0,stringGrid1.RowCount-1]='') or (stringGrid1.Cells[1,stringGrid1.RowCount-1]='')  then
 begin
 showmessage('请输入完整的记录!');
 exit;
 end;

 with datamodule1.publicQuery3 do
 begin
 sql.Clear;
 sql.Add('Select * From dbo.p_jhyb');
 sql.Add('where jhyid='+''''+stringGrid1.cells[0,stringGrid1.rowcount-1]+'''');
 prepare;
 open;
 if not isempty then
 begin
 showmessage('您添加的计划员ID已经存在,请输入唯一ID!');
 exit;
 end;
 end;

 with datamodule1.PublicQuery1 do
 begin
 Insert;
 FieldByname('jhyid').asstring:=stringGrid1.cells[0,stringGrid1.rowcount-1];
 FieldByname('jhy').asstring:=stringGrid1.cells[1,stringGrid1.rowcount-1];
 post;
 end;
end;

{if Opstate=3 then
with datamodule1.PublicQuery1 do
begin
locate('jhyid;jhy',VarArrayOf([stringGrid1.cells[0,stringGrid1.row],stringGrid1.cells[1,stringGrid1.row]]),[]);
delete;
end;}
speedbutton2.Enabled:=true;
speedButton4.Enabled:=true;
speedButton3.Enabled:=true;
initstrGrid;
with StringGrid1 do
   begin
    if (GoEditing in Options) then
    Options:=Options-[GoEditing];
   end;
end;

procedure TjhyxgForm.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
    if opstate=1 then
    begin
    if ACol=0 then
    with StringGrid1 do
    if (GoEditing in Options) then
    Options:=Options-[GoEditing];
    if ACol=1 then
    with StringGrid1 do
    if not (GoEditing in Options) then
    Options:=Options+[GoEditing];
    end;
end;

end.

⌨️ 快捷键说明

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