unit U_LogInput;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu,
  dxDateRanges, U_BaseHelp, U_BaseList, System.ImageList, Vcl.ImgList,
  dxScrollbarAnnotations, dxSkinsCore, dxSkinsDefaultPainters, dxSkinWXI;

type
  TfrmLogInput = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TbDel: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_1: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    Label4: TLabel;
    Acction: TEdit;
    TbSaveFormat: TToolButton;
    TbAdd: TToolButton;
    TbSave: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Acction: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TbDelClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TbSaveFormatClick(Sender: TObject);
    procedure AcctionChange(Sender: TObject);
    procedure TbAddClick(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TbSaveClick(Sender: TObject);
  private
    canshu1, FSTKName, canshu3: string;
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    fWB_Code, fFlag, flogFlag: string;

    { Public declarations }
  end;

var
  frmLogInput: TfrmLogInput;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;

{$R *.dfm}

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

procedure TfrmLogInput.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(DParameters1);
  FSTKName := Trim(DParameters2);
  canshu3 := Trim(DParameters3);
end;

procedure TfrmLogInput.SetStatus();
begin
  if flogFlag = '整经工艺信息修改' then
  begin
    Tv1Acction.Caption := '整经工艺编号';
  end
  else if flogFlag = '整经计划信息修改' then
  begin
    Tv1Acction.Caption := '整经计划单号';
  end
  else if flogFlag = '浆纱计划信息修改' then
  begin
    Tv1Acction.Caption := '浆纱计划单号';
  end;

end;

procedure TfrmLogInput.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select * from sy_sysLog ');
      sql.Add(' where Model = ' + QuotedStr(flogFlag));
      if fFlag = '修改' then
      begin
        SQL.Add(' and 1=2')
      end
      else if fFlag = '查看' then
      begin
        SQL.Add(' and Acction = ' + QuotedStr(Trim(fWB_Code)));
      end;
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmLogInput.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLogInput.TbSaveClick(Sender: TObject);
var
  mOPEvent: string;
begin
  if CDS_1.IsEmpty then
  begin
    Application.MessageBox('请输入修改项目！', '提示信息', MB_OK);
    Exit;
  end;

//  if CDS_1.Locate('Operor', '', []) or CDS_1.Locate('Operor', null, []) then
//  begin
//    Application.MessageBox('修改人不能为空！', '提示信息', MB_OK);
//    Exit;
//  end;

  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      if (CDS_1.FieldByName('Operor').AsString = '') or (CDS_1.FieldByName('Operor').IsNull) then
      begin
        Application.MessageBox('修改人不能为空！', '提示信息', MB_OK);
        Exit;
      end;
      if (CDS_1.FieldByName('OPEvent').AsString = '') or (CDS_1.FieldByName('OPEvent').IsNull) then
      begin
        Application.MessageBox('修改项目不能为空！', '提示信息', MB_OK);
        Exit;
      end;
      Next;
    end;
  end;

  with CDS_1 do
  begin
    First;
    while not Eof do
    begin
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from SY_sysLog where 1 = 2 ');
        Open;
      end;
      with ADOQueryCmd do
      begin
        if ADOQueryCmd.IsEmpty then
          Append
        else
          Edit;
        RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_1, 'SY_sysLog', 0);
        FieldByName('Model').Value := flogFlag;
        FieldByName('Result').Value := '成功';
        Post;
      end;
      Next;
    end;
    Application.MessageBox('保存成功！', '提示信息', MB_OK);
  end;
  close;
end;

procedure TfrmLogInput.TbSaveFormatClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption, Tv1, '修改日志记录');
end;

procedure TfrmLogInput.TbAddClick(Sender: TObject);
begin
  with CDS_1 do
  begin
    Append;
    CDS_1.FieldByName('Acction').Value := fWB_Code;
    CDS_1.FieldByName('OperTime').value := SGetServerDatetime(ADOQueryTemp);
    Post;
  end;
end;

procedure TfrmLogInput.Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TcxButtonEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      MainType := 'loginput';
      flag := 'Operor';
      flagname := '修改人';
      if ShowModal = 1 then
      begin
        CDS_1.Edit;
        CDS_1.FieldByName(flag).Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        CDS_1.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmLogInput.Tv1DblClick(Sender: TObject);
begin

  ModalResult := 1;
end;

procedure TfrmLogInput.AcctionChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;
end;

procedure TfrmLogInput.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmLogInput.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmLogInput.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Self.Caption, Tv1, '修改日志记录');
  InitGrid();
  if fFlag = '查看' then
  begin
    TbAdd.Visible := false;
    TbDel.Visible := False;
    TbSave.Visible := false;
  end
  else if fFlag = '修改' then
  begin
    TBRafresh.Visible := False;
    TBFind.Visible := False;
    Panel1.Visible := False;
    TBClose.Visible := False;
  end;
end;

procedure TfrmLogInput.TbDelClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  with CDS_1 do
  begin
    Delete;
  end;
end;

procedure TfrmLogInput.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);
end;

procedure TfrmLogInput.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);
end;

end.

