unit U_LXInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxDropDownEdit, jpeg, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, cxPC, cxGridCustomPopupMenu, cxGridPopupMenu, Menus,
  ExtDlgs, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, 
   dxDateRanges, dxBarBuiltInMenu, dxScrollbarAnnotations;

type
  TfrmLXInPut = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    TBSave: TToolButton;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
  private
    TPInt: Integer;
    procedure InitData();
    function SaveData(): Boolean;
    function SaveMXData(Tv11: TcxGridDBTableView; CDS1: TClientDataSet; FMaxNo, FYOType: string): Boolean;
    procedure SaveImageOther();
    procedure InitImage();
    { Private declarations }
  public
    canshu1: string;
    PState, CopyInt: Integer;
    FMainId, FDPID, FDPName: string;
    { Public declarations }
  end;

var
  frmLXInPut: TfrmLXInPut;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun;

{$R *.dfm}

procedure TfrmLXInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('类型录入', Tv1, '管理');
  Close;
end;

procedure TfrmLXInPut.InitData();
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from LX_List where EEID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS(ADOCmd, Order_Sub);
  SInitCDSData(ADOCmd, Order_Sub);
end;

procedure TfrmLXInPut.FormShow(Sender: TObject);
begin
  ReadCxGrid('类型录入', Tv1, '管理');
  InitData();
end;

function TfrmLXInPut.SaveData(): Boolean;
var
  maxno, FHZStatus: string;
begin
  Result := False;
  try
    ADOCmd.Connection.BeginTrans;
    with Order_Sub do
    begin
      first;
      while not eof do
      begin
        if Trim(Order_Sub.fieldbyname('EEID').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'LX', 'LX_List', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('EEID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from LX_List where EEID=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if ADOCmd.IsEmpty then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
          end
          else
          begin
            edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('Edittime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('EEID').Value := Trim(maxno);
          fieldbyname('DPID').Value := Trim(FDPID);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'LX_List', 0);
          post;
        end;

        with Order_Sub do
        begin
          Edit;
          FieldByName('EEID').Value := Trim(maxno);
        end;

        next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    ;
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

function TfrmLXInPut.SaveMXData(Tv11: TcxGridDBTableView; CDS1: TClientDataSet; FMaxNo, FYOType: string): Boolean;
begin

end;

procedure TfrmLXInPut.InitImage();
begin

end;

procedure TfrmLXInPut.TBSaveClick(Sender: TObject);
var
  FSFNO: string;
begin
  ToolBar1.SetFocus;
  if Order_Sub.Locate('LXName', '', []) = true then
  begin
    application.MessageBox('类型不能为空', '提示');
    exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmLXInPut.SaveImageOther();
begin

end;

procedure TfrmLXInPut.ToolButton1Click(Sender: TObject);
begin

  with Order_Sub do
  begin
    Append;
    FieldByName('Dept').Value := Trim(FDPName);
    Post;
  end;
end;

procedure TfrmLXInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(Order_Sub.fieldbyname('EEID').AsString) <> '' then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete LX_List where EEID=''' + Trim(Order_Sub.fieldbyname('EEID').AsString) + '''');
      ExecSQL;
    end;
  end;

  Order_Sub.Delete;
end;

procedure TfrmLXInPut.Tv1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'LXName';
    flagName := '类型';
    if ShowModal = 1 then
    begin
      with Order_Sub do
      begin
        edit;
        FieldByName('LXName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    free;
  end;
end;

end.

