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

📄 outdepot.~pas

📁 1、系统环境要求:WindowsXP/2000 2、DELPHI7.0企业版 3、如果数据库为SQL Server数据库
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
unit outdepot;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, baseform, DB, DBGrids, Grids, ComCtrls, StdCtrls, ExtCtrls,adoDB;

type
  Tf_outdepot = class(Tf_baseform)
    Label1: TLabel;
    Panel2: TPanel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label13: TLabel;
    Barcode: TEdit;
    price: TEdit;
    Money: TEdit;
    Bookname: TEdit;
    Sum: TEdit;
    Storage: TComboBox;
    Panel3: TPanel;
    Label3: TLabel;
    Save: TButton;
    Quit: TButton;
    Cancel: TButton;
    summoney: TEdit;
    Panel1: TPanel;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label9: TLabel;
    Operator: TEdit;
    Principal: TEdit;
    Provider: TComboBox;
    Picker: TDateTimePicker;
    Grid: TStringGrid;
    Grid1: TDBGrid;
    Source1: TDataSource;
    procedure ProviderEnter(Sender: TObject);
    procedure ProviderKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure PickerKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BarcodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BarcodeKeyPress(Sender: TObject; var Key: Char);
    procedure BooknameKeyPress(Sender: TObject; var Key: Char);
    procedure priceKeyPress(Sender: TObject; var Key: Char);
    procedure Grid1DblClick(Sender: TObject);
    procedure Grid1Exit(Sender: TObject);
    procedure Grid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure GridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure GridSelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure QuitClick(Sender: TObject);
    procedure CancelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SaveClick(Sender: TObject);
    procedure BooknameChange(Sender: TObject);
    procedure priceChange(Sender: TObject);
  private
    { Private declarations }
  public
    Procedure ClearGrid;
    Function DetailIsNull: Boolean;
    Procedure ClearDetail;
    Function MasterIsNull: Boolean;
    Function GridIsNull: Boolean;
    Function ProviderIsValid: Boolean;//判断供应商名称是否合法
    { Public declarations }
  end;
  EPrividerIsValid = Class (Exception)
  public
    Constructor Create(const Msg: string);
  End;
  EBookinfoIsValid = Class(Exception)
  Public
    Constructor Create(Const Msg: string);
  End;
var
  f_outdepot: Tf_outdepot;
  x:integer = 1;
  y: Integer = 0;
const
  bar= 0; //条形码
  book = 1;
  unitprice = 2;
  amount = 3;
  sumprice = 4;
  Depot= 5;
implementation
  uses data,main;
{$R *.dfm}

{ Tf_outdepot }

procedure Tf_outdepot.ClearDetail;
var
  i: Integer;
begin
  For i := 0 to Panel2.ControlCount-1 do
    if Panel2.Controls[i]is TEdit then
      TEdit(Panel2.Controls[i]).Clear
    else if Panel2.Controls[i]is TComboBox then
      TComboBox(Panel2.Controls[i]).ItemIndex := -1;
  Barcode.SetFocus;
end;

procedure Tf_outdepot.ClearGrid;
var
  x,y: Integer;
begin
  For x := 1 to Grid.RowCount-1 do
    For y := 0 to Grid.ColCount-1 do
      Grid.Cells[y,x]:='';
  Grid.RowCount := 2;
end;

function Tf_outdepot.DetailIsNull: Boolean;
var
  i: Integer;
begin
  Result := False;
  For i := 0 to Panel2.ControlCount-1 do
  begin
    if Panel2.Controls[i]is TEdit then
    begin
      if Trim(TEdit(Panel2.Controls[i]).Text)='' then
      begin
        Result := True;
        Break;
      end;
    end
    else if Panel2.Controls[i]is TComboBox then
      if Trim(TComboBox(Panel2.Controls[i]).Text) = '' then
      begin
        Result := True;
        Break;
      end;
  end;
end;

function Tf_outdepot.GridIsNull: Boolean;
var
  i,j: Integer;
begin
  Result := False;
  if Grid.RowCount =2 then
  begin
    Result := True;
    Exit;
  end;
  For i := 1 to Grid.RowCount-2 do
  begin
    For j := 0 to Grid.ColCount-1 do
      if Trim(Grid.Cells[j,i])= '' then
      begin
        Result := True;
        Break;
      end;
  end;
end;

function Tf_outdepot.MasterIsNull: Boolean;
var
  i: Integer;
begin
  Result := False;
  For i := 0 to Panel1.ControlCount-1 do
    if Panel1.Controls[i]is TEdit then
    begin
      if Trim(TEdit(Panel1.Controls[i]).Text)= '' then
      begin
        Result := True;
        Exit;
      end;
    end
    else if Panel1.Controls[i]is TComboBox then
      if Trim(TComboBox(Panel1.Controls[i]).Text) = '' then
      begin
        Result := True;
        Exit;
      end;
end;

function Tf_outdepot.ProviderIsValid: Boolean;
begin
  Result := True;
  With t_data.Query1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from tb_providerinfo where providername = :name');
    Parameters.ParamByName('name').Value := Trim(provider.Text);
    Open;
  end;
  if t_data.Query1.RecordCount<1 then
    Result := False;
end;

procedure Tf_outdepot.ProviderEnter(Sender: TObject);
begin
  inherited;
  Grid1.Visible := False;
end;

procedure Tf_outdepot.ProviderKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key = vk_Return then
  begin
    FindNext(True);
  end
end;

procedure Tf_outdepot.PickerKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key = vk_Return then
    Barcode.SetFocus;
end;

procedure Tf_outdepot.BarcodeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key = vk_delete then
    Key := 0;
  if Key = vk_Return then
  begin
    if Sender is TEdit then
      if (Trim(Barcode.Text)<>'')and(Trim(Bookname.Text)='')and(TEdit(Sender).Name = 'Barcode') then
      begin
        With t_data.Query1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from tb_bookinfo where barcode = :barcode');
          Parameters.ParamByName('barcode').Value := Trim(Barcode.Text);
          Open;
        end;
        if t_data.Query1.RecordCount>0 then
        begin
          Barcode.Text := Trim(t_data.Query1.FieldByName('barcode').AsString);
          Bookname.Text := Trim(t_data.Query1.FieldByName('bookname').AsString);
          Price.Text :=Trim(t_data.Query1.FieldByName('price').AsString);
        end
        else
          Application.MessageBox('该条形码不存在.','提示',64);
      end
      else if (TEdit(Sender).Name = 'Bookname')and(Trim(Bookname.Text)<>'')and(Trim(Barcode.Text)='') then
      begin
        With t_data.Query1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from tb_bookinfo where bookname = :name');
          Parameters.ParamByName('name').Value := Trim(Bookname.Text);
          Open;
        end;
        if t_data.Query1.RecordCount>0 then
        begin
          Barcode.Text := Trim(t_data.Query1.FieldByName('barcode').AsString);
          Bookname.Text := Trim(t_data.Query1.FieldByName('bookname').AsString);
          Price.Text :=Trim(t_data.Query1.FieldByName('price').AsString);
        end
        else
          Application.MessageBox('该书籍不存在.','提示',64);
      end;
    FindNext(True);
  end
  else if (Key = vk_control)and(Grid1.Visible = True) then
    Grid1.SetFocus
  else if (Key = vk_insert)and(DetailIsNull = False) then
  begin
    Grid.Cells[bar,Grid.RowCount-1]:= Trim(Barcode.Text);
    Grid.Cells[book,Grid.RowCount-1]:= Trim(Bookname.Text);
    Grid.Cells[unitprice,Grid.RowCount-1]:= Trim(Price.Text);
    Grid.Cells[amount,Grid.RowCount-1] := Trim(Sum.Text);
    Grid.Cells[sumprice,Grid.RowCount-1]:= Trim(Money.Text);
    Grid.Cells[depot,Grid.RowCount-1]:= Trim(Storage.Text);
    Grid.RowCount := Grid.RowCount+1;
    if Trim(Summoney.Text)= '' then
      SumMoney.Text := Money.Text
    else
      SumMoney.Text := FloatToStr(StrToFloat(SumMoney.Text)+ StrToFloat(Money.Text));
    ClearDetail;
  end
  else if Key =vk_escape then
  begin
    ClearDetail;
  end;
end;

procedure Tf_outdepot.BarcodeKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
   if (Not (Key in ['0'..'9',#8]))or(Trim(Bookname.Text)<>'') then
    Key := #0;
end;

procedure Tf_outdepot.BooknameKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if Trim(barcode.Text)<>'' then
    Key := #0;
end;

procedure Tf_outdepot.priceKeyPress(Sender: TObject; var Key: Char);

⌨️ 快捷键说明

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