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

📄 udepartment.pas

📁 天涯進銷存系統
💻 PAS
字号:
unit uDepartment;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids, LBDBGrid, StdCtrls, LBCtrls, LBDBCtrls,
  ActnList, DBCtrls, FR_DSet, FR_DBSet, FR_Class, LBDBScrollBar;

type
  TfrmDepartment = class(TForm)
    Panel1: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    DataDBGrid: TLBDBGrid;
    plData: TPanel;
    Panel8: TPanel;
    Shape1: TShape;
    Shape2: TShape;
    Label1: TLabel;
    Shape3: TShape;
    LBDBEdit1: TLBDBEdit;
    Shape4: TShape;
    LBDBEdit2: TLBDBEdit;
    Shape5: TShape;
    LBDBEdit3: TLBDBEdit;
    Shape6: TShape;
    LBDBEdit4: TLBDBEdit;
    Shape7: TShape;
    LBDBEdit5: TLBDBEdit;
    Label6: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Shape21: TShape;
    Label7: TLabel;
    LBDBEdit18: TLBDBEdit;
    ActionList1: TActionList;
    Action1: TAction;
    Action2: TAction;
    Action3: TAction;
    Action5: TAction;
    Action6: TAction;
    Action4: TAction;
    Action7: TAction;
    Action8: TAction;
    Report: TfrReport;
    ReportDataSet: TfrDBDataSet;
    Panel7: TPanel;
    Image1: TImage;
    Shape22: TShape;
    Shape23: TShape;
    Shape24: TShape;
    Shape25: TShape;
    Panel2: TPanel;
    Panel5: TPanel;
    Panel9: TPanel;
    Panel11: TPanel;
    EnterButton: TLBButton;
    CancelButton: TLBButton;
    LBDBScrollBar1: TLBDBScrollBar;
    LBSpeecButton2: TLBSpeecButton;
    LBSpeecButton1: TLBSpeecButton;
    LBSpeecButton3: TLBSpeecButton;
    LBSpeecButton4: TLBSpeecButton;
    LBSpeecButton5: TLBSpeecButton;
    LBSpeecButton6: TLBSpeecButton;
    procedure FormShow(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Action2Execute(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure Action3Execute(Sender: TObject);
    procedure Action5Execute(Sender: TObject);
    procedure Action6Execute(Sender: TObject);
    procedure Action4Execute(Sender: TObject);
    procedure Action7Execute(Sender: TObject);
    procedure Action8Execute(Sender: TObject);
    procedure LBDBEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DataDBGridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormDestroy(Sender: TObject);
    procedure LBDBEdit18KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    procedure SetView;
  public
    { Public declarations }
  end;

var
  frmDepartment: TfrmDepartment;
  isStateEdit, isEdit: Boolean;
  OldCode: string;


implementation

uses uDataMo, uPublicvar, uMain, uConst;

{$R *.dfm}

procedure TfrmDepartment.SetView;
begin
  DataDBGrid.Enabled:=not DataDBGrid.Enabled;
  plData.Enabled:=not plData.Enabled;

  Action1.Enabled:=not Action1.Enabled;
  Action2.Enabled:=not Action2.Enabled;
  Action3.Enabled:=not Action3.Enabled;
  Action4.Enabled:=not Action4.Enabled;
  Action5.Enabled:=not Action5.Enabled;
  Action6.Enabled:=not Action6.Enabled;
  Action7.Enabled:=not Action7.Enabled;
  Action8.Enabled:=not Action8.Enabled;

  EnterButton.Visible:=not EnterButton.Visible;
  CancelButton.Visible:=not CancelButton.Visible;
end;

procedure TfrmDepartment.FormShow(Sender: TObject);
begin
  SetView;
  OpenData('select * from Department', dmData.sdsDepartment);
  isStateEdit:=False;
end;

procedure TfrmDepartment.FormActivate(Sender: TObject);
begin
  GetWindowsItem(Caption, Self);
end;

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


procedure TfrmDepartment.Action1Execute(Sender: TObject);
begin
  SetView;
  LBDBEdit1.SetFocus;
  with dmData.sdsDepartment do
  begin
    Append;
    FieldByName('Del').asstring:='0';
  end;  
  OldCode:='';
  isEdit:=False;
  isStateEdit:=True;
end;

procedure TfrmDepartment.Action2Execute(Sender: TObject);
begin
  if dmData.sdsDepartment.IsEmpty then
  begin
    Application.MessageBox(NotEditData, Hintinfo,$30);
    Exit;
  end;
  SetView;
  LBDBEdit1.SetFocus;
  dmData.sdsDepartment.Edit;
  OldCode:=dmData.sdsDepartment.Fieldbyname('DEPTCODE').asstring ;
  isEdit:=True;
  isStateEdit:=True;
end;

procedure TfrmDepartment.Action3Execute(Sender: TObject);
begin
  DeleteData(dmData.sdsDepartment, True);
end;

procedure TfrmDepartment.Action5Execute(Sender: TObject);
begin
  FindData(dmData.sdsDepartment, '部门资料查询', 'Department');
end;

procedure TfrmDepartment.Action6Execute(Sender: TObject);
begin
  OpenData('select * from Department', dmData.sdsDepartment);
end;

procedure TfrmDepartment.Action4Execute(Sender: TObject);
begin
  PrintView('RepDepartment.frf', Report);
end;

procedure TfrmDepartment.Action7Execute(Sender: TObject);
begin
  if Trim(LBDBEdit1.Text)='' then
  begin
    Application.MessageBox('请输入部门编号。', HintInfo,$30);
    LBDBEdit1.SetFocus;
    Exit;
  end;
  if Trim(LBDBEdit2.Text)='' then
  begin
    Application.MessageBox('请输入部门名称。',HintInfo,$30);
    LBDBEdit2.SetFocus;
    Exit;
  end;
  if isExist('DEPARTMENT', 'DEPTCODE', Trim(LBDBEdit1.Text), OldCode, '') then
  begin
    Application.MessageBox('此部门编号已存在,请重新输入。',HintInfo,$30);
    LBDBEdit1.SetFocus;
    Exit; 
  end;
  dmData.sdsDepartment.ApplyUpdates(-1);
  if not isEdit then
  begin
    LBDBEdit1.SetFocus;
    with dmData.sdsDepartment do
    begin
      Append;
      FieldByName('Del').asstring:='0';
    end;  
  end
  else
  begin
    SetView;
    isStateEdit:=False;
  end;  
end;

procedure TfrmDepartment.Action8Execute(Sender: TObject);
begin
  if dmData.sdsDepartment.Modified then
  begin
    if Application.MessageBox(OnCancelEdit,HintInfo,$24)=idYes then
    begin
      dmData.sdsDepartment.CancelUpdates;
      SetView;
    end;
  end
  else
  begin
    dmData.sdsDepartment.CancelUpdates;
    SetView;
  end;
  isStateEdit:=False;
end;

procedure TfrmDepartment.LBDBEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=13 then  Perform(WM_NEXTDLGCTL,0,0);
end;

procedure TfrmDepartment.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=27 then Close;
end;

procedure TfrmDepartment.DataDBGridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (key=VK_NEXT) or (key=VK_Down) then
    if dmData.sdsDepartment.Eof then
       dmData.sdsDepartment.GetNextPacket;
end;

procedure TfrmDepartment.FormDestroy(Sender: TObject);
begin
  WindowItem.Delete(WindowItem.IndexOfObject(Self)); 
end;

procedure TfrmDepartment.LBDBEdit18KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=13 then Action7Execute(Sender);
end;

end.

⌨️ 快捷键说明

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