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

📄 ywgl_bjckform.pas

📁 这是用Delphi编写的维修管理系统。主要功能包括业务管理
💻 PAS
字号:
unit YWGL_BJCKFORM;

interface

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

type
  TYWGL_BJCK = 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_BJCK: TYWGL_BJCK;
  si:integer;
  sql1:string;
  i, j,k:integer;
implementation

{$R *.dfm}
PROCEDURE  TYWGL_BJCK.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.Visible:=true;
 End
end;
procedure TYWGL_BJCK.FormCreate(Sender: TObject);     //初始化stringgrid1
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]:=100;
 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_BJCK.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_BJCK.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_BJCK.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[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:=4;
  stringgrid1.SetFocus;
  END;
 END;
end;
procedure TYWGL_BJCK.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_BJCK.DBLookupComboBox1KeyDown(Sender: TObject;
 var Key: Word; Shift: TShiftState);
 begin
  If Key = 13 Then
  DBLookupComboBox2.SetFocus ;
end;
procedure TYWGL_BJCK.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_BJCK.FormShow(Sender: TObject);
begin
 Button1.SetFocus ;
end;
procedure TYWGL_BJCK.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_BJCK.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('单位').ASSTRING:=stringgrid1.Cells[6,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_BJCK.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_BJCK.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_BJCK.Button4Click(Sender: TObject);    //退出
begin
close;
end;
end.

⌨️ 快捷键说明

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