unit MainUnit; interface uses { Delphi } Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Actions, Vcl.ActnList, System.ImageList, Vcl.ImgList, Vcl.Menus, Vcl.StdCtrls, Data.DB, { DevExpress } dxForms, cxGraphics, dxUIAClasses, cxControls, dxLayoutControlAdapters, dxLayoutContainer, cxButtons, cxClasses, dxLayoutControl, cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, cxNavigator, dxDateRanges, dxScrollbarAnnotations, cxDBData, cxGridLevel, cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, dxmdaset, dxLayoutcxEditAdapters, cxTextEdit, cxCurrencyEdit, cxContainer, cxImageList, cxMaskEdit, cxSpinEdit, cxDBEdit, dxCore, dxStatusBar, { DevExpress Skin } cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinWXI, dxLayoutLookAndFeels, dxSkinsForm, { Custom } DataUnit; type TfrmMain = class(TdxForm, IDataStateNotifier) lgRoot: TdxLayoutGroup; lcMain: TdxLayoutControl; lgToolbar: TdxLayoutGroup; lgInput: TdxLayoutGroup; lgGrid: TdxLayoutGroup; btnAdd: TcxButton; liAdd: TdxLayoutItem; btnEdit: TcxButton; liEdit: TdxLayoutItem; btnDelete: TcxButton; liDelete: TdxLayoutItem; btnPost: TcxButton; liSave: TdxLayoutItem; btnCancel: TcxButton; liCancel: TdxLayoutItem; dbtvEmployee: TcxGridDBTableView; grdEmployeeLevel1: TcxGridLevel; grdEmployee: TcxGrid; liGird: TdxLayoutItem; dbtvEmployeeRecId: TcxGridDBColumn; dbtvEmployeename: TcxGridDBColumn; dbtvEmployeeage: TcxGridDBColumn; dbtvEmployeeposition: TcxGridDBColumn; dbtvEmployeesalary: TcxGridDBColumn; dbtvEmployeeaddress: TcxGridDBColumn; dbteName: TcxDBTextEdit; dxLayoutItem2: TdxLayoutItem; dbseAge: TcxDBSpinEdit; dxLayoutItem3: TdxLayoutItem; dbtePosition: TcxDBTextEdit; dxLayoutItem4: TdxLayoutItem; dbseSalary: TcxDBSpinEdit; dxLayoutItem5: TdxLayoutItem; dbteAddress: TcxDBTextEdit; dxLayoutItem6: TdxLayoutItem; dxLayoutAutoCreatedGroup1: TdxLayoutAutoCreatedGroup; acToolbar: TActionList; acAdd: TAction; acEdit: TAction; acDelete: TAction; acSave: TAction; acCancel: TAction; scTheme: TdxSkinController; dxLayoutLookAndFeelList: TdxLayoutLookAndFeelList; dxLayoutSkinLookAndFeel1: TdxLayoutSkinLookAndFeel; sbMain: TdxStatusBar; procedure DataSetCRUD(Sender: TObject); procedure FormCreate(Sender: TObject); private procedure NotifyDataSetStateChange(const AState: TDataSetState); public { Public declarations } end; var frmMain: TfrmMain; implementation {$R *.dfm} procedure TfrmMain.DataSetCRUD(Sender: TObject); // action에 Tag로 하나의 함수로 리펙토링 begin var Tag:= TAction(Sender).Tag; Case Tag of 1: // 추가 begin dmData.mdEmployee.Append; dbteName.SetFocus; end; 2: dmData.mdEmployee.Edit; // 수정 3: dmData.mdEmployee.Delete; // 삭제 4: dmData.mdEmployee.Post; // 저장 5: dmData.mdEmployee.Cancel; // 취소 End; end; procedure TfrmMain.FormCreate(Sender: TObject); begin // DataSet State를 DataUnit으로 분리(유닛간 결합도를 분리) 리펙토링 if Assigned(dmData) then dmData.SetNotifier(Self); end; procedure TfrmMain.NotifyDataSetStateChange(const AState: TDataSetState); begin acSave.Enabled:= Not(AState in [dsBrowse]); end; end.