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

📄 stockinfrm.pas

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

interface

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

type
  TStockInDlg = 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
  StockInDlg: TStockInDlg;

implementation

{$R *.dfm}
procedure TStockInDlg.SavePrior;
begin
  FPriorAmount := StrToInt(DBEdtAmount.Text);
  FPriorGoodId := DBEdtGoodId.Text;
end;

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



procedure TStockInDlg.TBAddClick(Sender: TObject);
begin
  SavePrior;
  DMMain.ADOTStockIn.Append;
  MakeMode('add');
end;

procedure TStockInDlg.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 TStockInDlg.TBEditClick(Sender: TObject);
begin
  SavePrior;
  DMMain.ADOTStockIn.Edit;
  MakeMode('edit');
end;

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

procedure TStockInDlg.TBOKClick(Sender: TObject);
var
  LGoodId: string;
begin
  CheckInput(DBEdtGoodId);
  CheckInput(DBEdtAmount);
  DMMain.ADOTStockIn.FieldByName('StockDate').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.Append;
        DMMain.ADOTStorageRecord.FieldByName('GoodId').AsString := LGoodId;
        DMMain.ADOTStorageRecord.FieldByName('AMount').AsInteger := FPriorAMount;
        DMMain.ADOTStorageRecord.Post;
      end;
    end
    else
    begin
      LCShowMessage('货物编号不存在!');
      MakeMode('ok');
      DMMain.ADOTStockIn.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.ADOTStockIn.Post;
  MakeMode('ok');

end;

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

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

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

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

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

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

end.

⌨️ 快捷键说明

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