unit U_LXList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxDropDownEdit, cxPC, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL, cxTLData,
  cxLookAndFeels, cxLookAndFeelPainters, cxTLdxBarBuiltInMenu, dxBarBuiltInMenu,
  cxNavigator, U_BaseList, dxDateRanges, cxContainer, cxTextEdit,
  dxScrollbarAnnotations, cxProgressBar, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmLXList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    TBView: TToolButton;
    Panel1: TPanel;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    DataSource2: TDataSource;
    CDS_Tree: TClientDataSet;
    ADOQueryTree: TADOQuery;
    cxSplitter1: TcxSplitter;
    cxTabControl1: TcxTabControl;
    ADOQuery1: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    Label7: TLabel;
    LXName: TEdit;
    v1Column4: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure EENameChange(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    canshu1: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();

    procedure InitTree();
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmLXList: TfrmLXList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LXInPut, U_DeptTypeHelp; // U_FjList_RZ,

{$R *.dfm}

procedure TfrmLXList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmLXList := nil;
end;

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

procedure TfrmLXList.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(DParameters1);
  cxgrid1.Align := alClient;
end;

procedure TfrmLXList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('类型档案', Tv1, 'OA管理');
end;

procedure TfrmLXList.InitGrid();
var
  SqlStr, FilterStr: string;
begin

  if cxTabControl1.TabIndex = 0 then
  begin
    Tv1Column1.Visible := False;
    Tv1Column1.Hidden := true;
  end
  else
  begin
    Tv1Column1.Visible := true;
    Tv1Column1.Hidden := False;
  end;

  FilterStr := SGetFilters(Panel1, 1, 2);
  SqlStr := ' exec P_EE_Get_All2 @DPID=' + quotedstr(Trim(CDS_Tree.fieldbyname('DPID').AsString));
  SqlStr := SqlStr + ' ,@LiZhiFlag=' + quotedstr(Trim(inttostr(cxTabControl1.TabIndex)));
  InitCDSData(ADOQueryMain, Order_Main, Tv1, SqlStr, FilterStr, '');

end;

procedure TfrmLXList.InitTree();
var
  i: Integer;
begin
  try
    ADOQueryTree.DisableControls;
    with ADOQueryTree do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from LX_Dept order by DPlevel,DPOrder,DPName');
      Open;
    end;
    SCreateCDS(ADOQueryTree, CDS_Tree);
    SInitCDSData(ADOQueryTree, CDS_Tree);
    cxDBTreeList1.Items[0].Expand(True);
  finally
    ADOQueryTree.EnableControls;
  end;
end;

procedure TfrmLXList.InitForm();
begin
  ReadCxGrid('类型档案', Tv1, 'OA管理');
  InitTree();
  InitGrid();
end;

procedure TfrmLXList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, Order_Main);
  SInitCDSData(ADOQueryMain, Order_Main);
end;

procedure TfrmLXList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmLXInPut := TfrmLXInPut.Create(Application);
    with frmLXInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('EEID').AsString);
      FDPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      FDPName := trim(CDS_Tree.fieldbyname('DPName').AsString);
      frmLXInPut.canshu1 := Trim(Self.canshu1);
      ToolButton1.Visible := false;

      if ShowModal = 1 then
      begin
        initgrid();
      end;
    end;
  finally
    frmLXInPut.Free;
  end;
end;

procedure TfrmLXList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Delete LX_List where EEID=''' + Trim(Order_Main.fieldbyname('EEID').AsString) + '''');
            ExecSQL;
          end;
        end;
        next;
      end;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Order_Main.EnableControls;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;

end;

procedure TfrmLXList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('类型列表', cxGrid1);
end;

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

procedure TfrmLXList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmLXInPut := TfrmLXInPut.Create(Application);
    with frmLXInPut do
    begin
      PState := 0;
      FMainId := '';
      FDPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      FDPName := trim(CDS_Tree.fieldbyname('DPName').AsString);
      if ShowModal = 1 then
      begin
        initgrid();
      end;
    end;
  finally
    frmLXInPut.Free;
  end;
end;

procedure TfrmLXList.FormShow(Sender: TObject);
begin
  inherited;

  InitForm();
end;

procedure TfrmLXList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLXList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmLXList.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmLXInPut := TfrmLXInPut.Create(Application);
    with frmLXInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('EEID').AsString);
      FDPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      TBSave.Visible := False;
      ToolButton1.Visible := False;
      ToolButton2.Visible := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmLXInPut.Free;
  end;
end;

procedure TfrmLXList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, Order_Main);
  SInitCDSData(ADOQueryMain, Order_Main);
end;

procedure TfrmLXList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmLXList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

procedure TfrmLXList.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmLXList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  TBView.Click;
end;

procedure TfrmLXList.EENameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmLXList.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLXList.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then
    Exit;
  CDS_Tree.Locate('DPID', Trim(Order_Main.fieldbyname('DPID').AsString), []);
end;

end.

