unit U_ComponentIcons;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxEdit,
  DB, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  StdCtrls, U_BaseCommon, XPMenu, ComCtrls, ToolWin, ActnList, ActnMan,
  cxLookAndFeelPainters, cxButtons, cxEditRepositoryItems, ExtCtrls,
  cxDataStorage, cxImage, cxSpinEdit, cxCheckBox, cxCurrencyEdit,
  cxColorComboBox, cxDBLookupComboBox, cxTextEdit;

type
  TF_ComponentIcons = class(TForm)
    GroupBox1: TGroupBox;
    GT_ComponentIcons: TcxGridDBTableView;
    GL_ComponentIcons: TcxGridLevel;
    Grid_ComponentIcons: TcxGrid;
    ToolBar1: TToolBar;
    ToolButton2: TToolButton;
    XPMenu1: TXPMenu;
    ActionManager1: TActionManager;
    GT_ComponentIconsName: TcxGridDBColumn;
    GT_ComponentIconsIcon: TcxGridDBColumn;
    Act_AddIcon: TAction;
    Act_EditIcon: TAction;
    Act_DelIcon: TAction;
    ToolButton4: TToolButton;
    Button_Close: TcxButton;
    ToolButton1: TToolButton;
    Panel_OKCancel: TPanel;
    Button_OK: TcxButton;
    Button_Cancel: TcxButton;
    procedure FormShow(Sender: TObject);
    procedure Act_AddIconExecute(Sender: TObject);
    procedure Act_EditIconExecute(Sender: TObject);
    procedure Act_DelIconExecute(Sender: TObject);
  private
    { Private declarations }
  public
    GForm: TForm;
    //GDelIDsList: TStringList;

    procedure AddEdit(AAddEdit: TMakeEdit);
    procedure EnableEditDel;

    constructor Create(AOwner: TComponent; AForm: TForm);
    destructor  Destroy; override;
  end;

//var
  //F_ComponentIcons: TF_ComponentIcons;

implementation
Uses Unit_DM_SCS, U_Main, U_CaseForm;
{$R *.dfm}

{ TF_ComponentIcons }

// ##### Разрешить/Запретить редактирование/удаление #####
procedure TF_ComponentIcons.EnableEditDel;
begin
    if (GForm as TF_Main).DM.MemTable_ComponentIcons.RecordCount = 0 then
      begin
          //Act_EditIcon.Enabled := false;
          Act_DelIcon.Enabled := false;
      end
    else
      begin
          //Act_EditIcon.Enabled := true;
          Act_DelIcon.Enabled := true;
      end
end;




// ##### Добавить / изменить условное обозначение #####
procedure TF_ComponentIcons.AddEdit(AAddEdit: TMakeEdit);
var NPP_IDObjIcon: Integer;
begin
    with (GForm as TF_Main) do
      begin
          F_NormBase.F_CaseForm.GFormMode := fmEdit;
          F_NormBase.F_CaseForm.GViewKind := vkObjectIcons;
          F_NormBase.F_CaseForm.GUseMemTable := DM.MemTable_ComponentIcons;
          if F_NormBase.F_CaseForm.ShowModal = mrOk then
            begin
                NPP_IDObjIcon := F_NormBase.DM.DataSet_OBJECT_ICONS.FN('NPP_ID').AsInteger;
                DM.SelectCompIconsByNPP(NPP_IDObjIcon);
                DM.MemTable_ComponentIcons.First;
            end;
      end;
    EnableEditDel;
end;



// #############################################################################
// #############################################################################
constructor TF_ComponentIcons.Create(AOwner: TComponent; AForm: TForm);
begin
    GForm := AForm;
    inherited Create(AOwner);
end;

destructor TF_ComponentIcons.Destroy;
begin
  inherited;  //
end;

procedure TF_ComponentIcons.FormShow(Sender: TObject);
begin
    Caption := 'Условные обозначения компоненты';
end;


// ##### Добавить условное обозначение #####
procedure TF_ComponentIcons.Act_AddIconExecute(Sender: TObject);
begin
    AddEdit(meAdd);
end;


// ##### Изменить условное обозначение #####
procedure TF_ComponentIcons.Act_EditIconExecute(Sender: TObject);
begin
    AddEdit(meEdit);
end;

// ##### Убрать условное обозначение #####
procedure TF_ComponentIcons.Act_DelIconExecute(Sender: TObject);
begin
    (*if MessageBox(Application.Handle, 'Убрать условное обозначение?',
      'Удаление условного обозначения', MB_ICONQUESTION or MB_YESNO ) = IDYES then
      with (GForm as TF_Main).DM do
        begin
            {if GDelIDsList <> nil then
              GDelIDsList.Add(IntToStr(MemTable_ComponentIcons.FieldByName('ID').AsInteger) );}
            MemTable_ComponentIcons.Delete;
            EnableEditDel;
        end;       *)
      //*** Удалить предведущие иконки
      (GForm as TF_Main).DM.MemTable_ComponentIcons.Active := false;
      (GForm as TF_Main).DM.MemTable_ComponentIcons.Active := true;
      EnableEditDel;
end;

end.
