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

📄 stockoutfrm.pas

📁 这是一个本人初定的小制作
💻 PAS
字号:
unit StockOutFrm;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, ComCtrls, ToolWin, Grids, DBGrids, DBCtrls, Mask,
  MainDM, CommonFunc, Messages;

type
  TStockOutDlg = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    DBEdtAmount: TDBEdit;
    DBMRemark: TDBMemo;
    DBEdtGoodId: TDBEdit;
    DBGrid1: TDBGrid;
    TBMain: TToolBar;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDelete: TToolButton;
    TBOK: TToolButton;
    TBCancel: TToolButton;
    TBExit: TToolButton;
    procedure TBExitClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDeleteClick(Sender: TObject);
    procedure TBOKClick(Sender: TObject);
    procedure TBCancelClick(Sender: TObject);
    procedure DBEdtAmountKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FMode: string;
    FPriorAmount: integer;
    FPriorGoodId :string;
    procedure MakeMode(AValue: string);
    procedure SavePrior;//保存修改之前的值
  public
    { Public declarations }
  end;

var
  StockOutDlg: TStockOutDlg;

implementation

{$R *.dfm}

procedure TStockOutDlg.SavePrior;
begin
  FPriorAmount := StrToInt(DBEdtAmount.Text);
  FPriorGoodId := DBEdtGoodId.Text;
end;

procedure TStockOutDlg.MakeMode(AValue: string);
begin
  FMode := AValue;
  if AValue = 'add' then
  begin
    TBEdit.Enabled := false;
    TBDelete.Enabled := false;
    TBOK.Enabled := true;
    TBCancel.Enabled := true;
    TBAdd.Enabled := false;
    if DBEdtGoodId.Enabled = false then
      DBEdtGoodId.Enabled := true;
  end
  else if AValue = 'edit' then
  begin
    TBAdd.Enabled := false;
    TBDelete.Enabled := false;
    TBOK.Enabled := true;
    TBCancel.Enabled := true;
    TBAdd.Enabled := false;
    DBEdtGoodId.Enabled := false;
  end
  else if AValue = 'ok' then
  begin
    TBAdd.Enabled := true;
    TBDelete.Enabled := true;
    TBEdit.Enabled := true;
    TBOK.Enabled := false;
    TBCancel.Enabled := false;
    TBAdd.Enabled := true;
    DBEdtGoodId.Enabled := true;
  end
  else
  begin
    LCShowMessage('无法识别的状态!');
  end;
end;

procedure TStockOutDlg.TBExitClick(Sender: TObject);
begin
  Close;
end;

procedure TStockOutDlg.TBAddClick(Sender: TObject);
begin
  DMMain.ADOTStockOut.Append;
  MakeMode('add');
end;

procedure TStockOutDlg.TBEditClick(Sender: TObject);
begin
  SavePrior;
  DMMain.ADOTStockOut.Edit;
  MakeMode('edit');
end;

procedure TStockOutDlg.TBDeleteClick(Sender: TObject);
begin
  if LCConfirmEx('stockoutinput','您确实想删除此条记录吗?') = mrYes then
  begin
    SavePrior;
    DMMain.ADOTStockOut.Delete;
    MakeMode('ok');
  end;
end;

procedure TStockOutDlg.TBOKClick(Sender: TObject);
var
  LGoodId: string;
begin
  CheckInput(DBEdtGoodId);
  CheckInput(DBEdtAmount);
  DMMain.ADOTStockOut.FieldByName('StockOutDate').Value:=
    Now();
  if FMode = 'add' then
  begin
    DMMain.ADOTGood.Open;
    DMMain.ADOTGood.First;
    DMMain.ADOTStorageRecord.First;
    LGoodId := Trim(DBEdtGoodId.Text);
    if DMMain.ADOTGood.Locate('id', LGoodId, []) then
    begin
      if DMMain.ADOTStorageRecord.Locate('GoodId',LGoodId, []) then
      begin
        DMMain.ADOTStorageRecord.Edit;
        DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger :=
          DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger - FPriorAMount;
          DMMain.ADOTStorageRecord.Post;
      end
      else
      begin
        DMMain.ADOTStorageRecord.Edit;
        DMMain.ADOTStorageRecord.FieldByName('GoodId').AsString := LGoodId;
        DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger := -FPriorAMount;
        DMMain.ADOTStorageRecord.Post;
      end;
    end
    else
    begin
      LCShowMessage('货物编号不存在!');
      MakeMode('ok');
      DMMain.ADOTStockOut.Cancel;
      Exit;
    end;
  end
  else if FMode = 'edit' then
  begin
    DMMain.ADOTStorageRecord.Locate('GoodId',FPriorGoodId, []);
    DMMain.ADOTStorageRecord.Edit;
    DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger :=
      DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger + FPriorAMount -
        StrToInt(DBEdtAmount.Text);
    DMMain.ADOTStorageRecord.Post;
  end
  else if FMode = 'del' then
  begin
    DMMain.ADOTStorageRecord.Locate('GoodId',FPriorGoodId, []);
    DMMain.ADOTStorageRecord.Edit;
    DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger :=
      DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger + FPriorAMount;
    DMMain.ADOTStorageRecord.Post;
  end;
  //DMMain.ADOTGood.Close;
  //DMMain.ADOTGood.Close;
  DMMain.ADOTStockOut.Post;
  MakeMode('ok');

end;

procedure TStockOutDlg.TBCancelClick(Sender: TObject);
begin
  DMMain.ADOTStockOut.Cancel;
  MakeMode('ok');
end;

procedure TStockOutDlg.DBEdtAmountKeyPress(Sender: TObject; var Key: Char);
begin
  ForbitInValidNum(Key);
end;

procedure TStockOutDlg.FormShow(Sender: TObject);
begin
    DMMain.ADOTStockIn.Open;
    DMMain.ADOTStockIn.First;
end;

procedure TStockOutDlg.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  Key := #0;
end;

procedure TStockOutDlg.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    Perform(WM_NEXTDLGCTL, 0, 0);
end;

procedure TStockOutDlg.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
end;

end.

⌨️ 快捷键说明

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