⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ywgl_bjrkform.pas

📁 明日腾龙编修管理系统,对于做相关软件的朋友是一个非常好的参考
💻 PAS
字号:
unit ywgl_BJRKFORM;

interface

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

type
  Tywgl_BJRK = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    ADOQuery3: TADOQuery;
    DataSource3: TDataSource;
    StringGrid1: TStringGrid;
    Label3: TLabel;
    GroupBox2: TGroupBox;
    Button2: TButton;
    Button1: TButton;
    Button3: TButton;
    Button4: TButton;
    Label4: TLabel;
    Label5: TLabel;
    Bevel1: TBevel;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    DBLookupComboBox1: TDBLookupComboBox;
    DBLookupComboBox2: TDBLookupComboBox;
    ADOQuery2: TADOQuery;
    DataSource2: TDataSource;
    DBGrid1: TDBGrid;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    ADOQuery4: TADOQuery;
    Label10: TLabel;
    Label11: TLabel;
    procedure  menuyp(sc:string);    
    procedure FormCreate(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure DBLookupComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBLookupComboBox2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure StringGrid1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ywgl_BJRK: Tywgl_BJRK;
  si:integer;
  sql1:string;
  i, j,k:integer;
implementation

{$R *.dfm}
PROCEDURE  Tywgl_BJRK.menuyp(sc:string);//准备并显示列表窗体
begin
  sql1:='select top 12 *  from 备件库存 where 编号  like '+''''+sc+'%'+''''+' or '+' 物品名称 like'+''''+sc+'%'+'''';//查询键盘输入相似的语句
   ADOQuery3.SQL.Clear;//准备查询
   ADOQuery3.SQL.Add(sql1);//设置查询语句
   ADOQuery3.Active:=true;//开始查询
   if ADOquery3.FieldByName('编号').AsString<>'' then //将查询到的结果附给列表
    begin
//     dbgrid1.Top:=SG1.Top;
//     dbgrid1.Left:=SG1.Left+100;
      dbgrid1.Visible:=true;
    End
//   else if dbgrid1.Visible=true then dbgrid1.Visible:=false;
end; //列表窗体准备完毕
procedure Tywgl_BJRK.FormShow(Sender: TObject);
begin
  Button1.SetFocus ;
end;
procedure Tywgl_BJRK.FormCreate(Sender: TObject);
begin
 stringgrid1.ColWidths[0]:=19;
 stringgrid1.ColWidths[1]:=70;
 stringgrid1.ColWidths[2]:=70;
 stringgrid1.ColWidths[3]:=60;
 stringgrid1.ColWidths[4]:=60;
 stringgrid1.ColWidths[5]:=50;
 stringgrid1.ColWidths[6]:=40;
 stringgrid1.ColWidths[7]:=50;
 stringgrid1.ColWidths[8]:=90;
 stringgrid1.ColWidths[9]:=150;
 stringgrid1.cells[1,0]:='名称';
 stringgrid1.cells[2,0]:='编码';
 stringgrid1.cells[3,0]:='型号';
 stringgrid1.cells[4,0]:='规格';
 stringgrid1.cells[5,0]:='数量';
 stringgrid1.cells[6,0]:='单位';
 stringgrid1.cells[7,0]:='单价';
 stringgrid1.cells[8,0]:='金额';
 stringgrid1.cells[9,0]:='备注';
for si:=1 to 50 do begin
 stringgrid1.cells[0,si]:=inttostr(si);
end;
stringgrid1.Col:=1;
label7.caption:=datetimetostr(date);
end;
procedure tywgl_BJRK.StringGrid1KeyUp(Sender: TObject; var Key: Word;Shift: TShiftState);
type
 tkeyset=set of 0..255;
Var
 keyset:tkeyset;
begin
 keyset:=[48..57,65..90,96..105,8];
 If (StringGrid1.Col > 1) Then
   begin
    dbgrid1.Visible:=FALSE;
    exit;
   END ;
  If (StringGrid1.Col = 1) Then begin
   if StringGrid1.Cells[1,StringGrid1.Row]<>'' then
    menuyp(StringGrid1.Cells[1,StringGrid1.row])
      else  dbgrid1.Visible:=false;
  end ;
end;

procedure tywgl_BJRK.StringGrid1KeyPress(Sender: TObject;var Key: Char);
begin
 if (key=#13) AND (StringGrid1.Col=9) then begin
      StringGrid1.ROW:=StringGrid1.ROW+1;
      StringGrid1.Col:=1;
  END ;
   if (key=#13) AND (StringGrid1.Col<9)AND  (StringGrid1.Col>1) then begin
      StringGrid1.Col:=StringGrid1.Col+1;
  END ;
  IF (StringGrid1.Cells[7,StringGrid1.Row]<>'')AND (StringGrid1.Cells[5,StringGrid1.Row]<>'') THEN BEGIN
     StringGrid1.Cells[8,StringGrid1.Row]:= FLOATTOSTR(STRTOFLOAT(StringGrid1.Cells[7,StringGrid1.Row])*STRTOFLOAT(StringGrid1.Cells[5,StringGrid1.Row]));
  END;
end;
procedure tywgl_BJRK.StringGrid1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
 If (StringGrid1.Col = 1) And (Dbgrid1.Visible = True) Then
 begin
 If (Key = 39) Then
 begin
   dbgrid1.SetFocus ;
 END;
 If (Key = 40) Then
 begin
   StringGrid1.ROW:=StringGrid1.ROW-1;
   dbgrid1.SetFocus ;
 END;
 If Key = 13 Then
 begin
    StringGrid1.Cells[1,StringGrid1.Row]:=ADOQUERY3.FieldByname('物品名称').Asstring;
    StringGrid1.Cells[2,StringGrid1.Row]:=ADOQUERY3.FieldByname('编号').Asstring;
    StringGrid1.Cells[3,StringGrid1.Row]:=ADOQUERY3.FieldByname('型号').Asstring;
    StringGrid1.Cells[4,StringGrid1.Row]:=ADOQUERY3.FieldByname('规格').Asstring;
    StringGrid1.Cells[6,StringGrid1.Row]:=ADOQUERY3.Fieldbyname('单位').Asstring;
    StringGrid1.Cells[5,StringGrid1.Row]:='';
    StringGrid1.Cells[8,StringGrid1.Row]:='';
    StringGrid1.Cells[9,StringGrid1.Row]:='';
    Dbgrid1.Visible:=false;
    StringGrid1.Col:=4;
    stringgrid1.SetFocus;
 END;
  END;
end;
procedure Tywgl_BJRK.Button1Click(Sender: TObject);  //添加备件
begin
 j:=1;
 for j:=1 to 50 do
 begin
   for i:=1 to 9 do
    begin
      StringGrid1.Cells[i,j]:='';
    end;
 end;
 DBLookupComboBox1.SetFocus ;
 Button1.Enabled:=FALSE;
 Button2.Enabled:=TRUE;
 Button3.Enabled:=TRUE;
 Button4.Enabled:=FALSE;
end;
procedure Tywgl_BJRK.DBLookupComboBox1KeyDown(Sender: TObject;var Key: Word; Shift: TShiftState);
begin
 If Key = 13 Then
  DBLookupComboBox2.SetFocus ;
end;
procedure Tywgl_BJRK.DBLookupComboBox2KeyDown(Sender: TObject;var Key: Word; Shift: TShiftState);
begin
 If Key = 13 Then begin
  stringgrid1.Col:=1;
  stringgrid1.Row:=1;
  stringgrid1.SetFocus ;
 END;
end;
procedure Tywgl_BJRK.DBGrid1KeyPress(Sender: TObject; var Key: Char); //选择备件
begin
 if key<>#27 then  begin
  if key=#13 then begin
   StringGrid1.Cells[1,StringGrid1.Row]:=ADOQUERY3.FieldByname('物品名称').Asstring;
   StringGrid1.Cells[2,StringGrid1.Row]:=ADOQUERY3.FieldByname('编号').Asstring;
   StringGrid1.Cells[3,StringGrid1.Row]:=ADOQUERY3.FieldByname('型号').Asstring;
   StringGrid1.Cells[4,StringGrid1.Row]:=ADOQUERY3.FieldByname('规格').Asstring;
   StringGrid1.Cells[6,StringGrid1.Row]:=ADOQUERY3.Fieldbyname('单位').Asstring;
   StringGrid1.Cells[7,StringGrid1.Row]:=ADOQUERY3.Fieldbyname('平均单价').Asstring;
  
   StringGrid1.Cells[5,StringGrid1.Row]:='';
   StringGrid1.Cells[8,StringGrid1.Row]:='';
   StringGrid1.Cells[9,StringGrid1.Row]:='';
   Dbgrid1.Visible:=false;
   StringGrid1.Col:=5;
   stringgrid1.SetFocus;
   exit;
  end;
  key:=#0;
 end else begin
  dbgrid1.Visible:=false;
  stringgrid1.Cells[1,StringGrid1.Row]:='';
  stringgrid1.Cells[2,StringGrid1.Row]:='';
  stringgrid1.Cells[3,StringGrid1.Row]:='';
  stringgrid1.Cells[4,StringGrid1.Row]:='';
  stringgrid1.Cells[5,StringGrid1.Row]:='';
  stringgrid1.Cells[6,StringGrid1.Row]:='';
  stringgrid1.Cells[7,StringGrid1.Row]:='';
  stringgrid1.Cells[8,StringGrid1.Row]:='';
 end;
end;

procedure Tywgl_BJRK.Button2Click(Sender: TObject);   //保存备件入库
begin
 for i:=1 to 50 DO
 begin
 if   stringgrid1.Cells[1,i]<>''then
 begin
  sql1:='select *  from 备件库存 where  编号 = '+''''+StringGrid1.Cells[2,i]+'''';
  ADOQuery3.SQL.Clear;//准备查询
  ADOQuery3.SQL.Add(sql1);//设置查询语句
  ADOQuery3.Active:=true;//开始查询
  if ADOQuery3.FieldByName('物品名称').asstring<>'' then begin
   ADOQuery3.Edit;
   ADOQuery3.FieldByName('数量').AsInteger:=ADOQuery3.FieldByName('数量').ASINTEGER+strtoint(StringGrid1.Cells[5,i]);
   ADOQuery3.FieldByName('库存金额').AsCurrency:=ADOQuery3.FieldByName('库存金额').ASFLOAT+strtoint(StringGrid1.Cells[8,i]);
   ADOQuery3.Post ;
   adoquery4.Insert;
   adoquery4.FieldByName('日期').ASDATETIME:=STRTODATETIME(LABEL7.CAPTION);
   adoquery4.FieldByName('经手人').ASSTRING:=DBLookupComboBox2.Text;
   adoquery4.FieldByName('备件来历').ASSTRING:=DBLookupComboBox1.Text;
   adoquery4.FieldByName('物品名称').ASSTRING:=stringgrid1.Cells[1,i];
   adoquery4.FieldByName('型号').ASSTRING:=stringgrid1.Cells[3,i];
   adoquery4.FieldByName('规格').ASSTRING:=stringgrid1.Cells[4,i];
   adoquery4.FieldByName('入库数量').ASinteger:=strtoint(stringgrid1.Cells[5,i]);
   adoquery4.FieldByName('单位').ASSTRING:=stringgrid1.Cells[6,i];
   adoquery4.FieldByName('入库单价').ASfloat:=strtofloat(stringgrid1.Cells[7,i]);
   adoquery4.FieldByName('金额').ASfloat:=strtofloat(stringgrid1.Cells[8,i]);
   adoquery4.FieldByName('详细说明').ASSTRING:=stringgrid1.Cells[9,i];
   adoquery4.Post;
   Button1.Enabled:=TRUE;
   Button4.Enabled:=TRUE;
   Button2.Enabled:=FALSE;
   Button3.Enabled:=FALSE;
  end;
 end;
 end;
end;
procedure Tywgl_BJRK.StringGrid1Click(Sender: TObject);
begin
 If (StringGrid1.Col > 4) And (StringGrid1.Col < 9) Then begin
  label11.caption:='0';
  j:=1;
  for j:=1 to 50 do
  begin
   if (StringGrid1.Cells[1,j] <>'')and (StringGrid1.Cells[8,j]<>'') then
     begin
      label10.Caption:=INTTOSTR(J);
      label11.Caption:=floattostr(strtofloat(label11.Caption)+strtofloat(StringGrid1.Cells[8,j]));
     end;
  end;
 end;
end;
procedure Tywgl_BJRK.Button3Click(Sender: TObject);   //取消备件入库
begin
 j:=1;
 for j:=1 to 50 do
  begin
    for i:=1 to 9 do
    begin
      StringGrid1.Cells[i,j]:='';
    end;
  end;
  label11.Caption:='';
  label10.Caption:='';
 DBLookupComboBox1.SetFocus ;
 Button1.Enabled:=TRUE;
 Button2.Enabled:=FALSE;
 Button3.Enabled:=FALSE;
 Button4.Enabled:=TRUE;
end;
procedure Tywgl_BJRK.Button4Click(Sender: TObject);  //退出
begin
  close;
end;
end.

⌨️ 快捷键说明

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