unit U_MJEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxTextEdit, DBClient, ADODB, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, StdCtrls, ExtCtrls, ComCtrls, ToolWin,
  cxButtonEdit, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL, cxTLData;

type
  TfrmMJEdit = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOTmp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOCmd: TADOQuery;
    DS_Glide: TDataSource;
    CDS_Glide: TClientDataSet;
    Label2: TLabel;
    cxGrid4: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Label13: TLabel;
    Label5: TLabel;
    UserID: TEdit;
    UserName: TEdit;
    ToolButton1: TToolButton;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    ADOQueryTree: TADOQuery;
    CDS_Tree: TClientDataSet;
    DataSource2: TDataSource;
    ToolButton2: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    V3Column1: TcxGridDBColumn;
    V3Column2: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure UserIDChange(Sender: TObject);
    procedure TV3CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    procedure InitData();
    procedure InitTree();
    procedure GLAge();
    { Private declarations }
  public
    FZDYNo:string;
    { Public declarations }
  end;

var
  frmMJEdit: TfrmMJEdit;

implementation

uses
  U_Fun, U_ZDYHelp, U_DataLink;

{$R *.dfm}
procedure TfrmMJEdit.InitData();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' exec P_View_YGList :DPID,:LiZhiFlag');
      Parameters.ParamByName('DPID').Value:=Trim(CDS_Tree.fieldbyname('DPID').AsString);
      Parameters.ParamByName('LiZhiFlag').Value:=0;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Glide);
    SInitCDSData20(ADOQueryMain,CDS_Glide);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmMJEdit.FormDestroy(Sender: TObject);
begin
  frmMJEdit := nil;
end;

procedure TfrmMJEdit.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption, Tv3, '人员管理管理');
  Close;
end;

procedure TfrmMJEdit.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption, Tv3, '人员管理管理');
  InitTree();
  GLAge();
 // InitData();
end;

procedure TfrmMJEdit.InitTree();

begin
  try
    ADOQueryTree.DisableControls;
    with ADOQueryTree do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from SY_Dept order by DPlevel,DPOrder,DPName');
    //  ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTree,CDS_Tree);
    SInitCDSData20(ADOQueryTree,CDS_Tree);
    cxDBTreeList1.Items[0].Expand(True);
  finally
    ADOQueryTree.EnableControls;
  end;
end;

procedure TfrmMJEdit.GLAge();
var FXTGLNF,FYGGLNF,FGLYF: Double;
begin
  FXTGLNF:=strtofloat(uppercase(formatdateTime('yyyy',SGetServerDate(ADOQueryTemp))));
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select ZhuanZhengDate,YGYearGL from OA_YG_DangAn where YGType=''正式'' ');
    //ShowMessage(SQL.Text);
    open;
  end;
  with ADOQueryCmd do
  begin
    first;
    while not eof do
    begin
      edit;
      if ADOQueryCmd.fieldbyname('ZhuanZhengDate').asstring='' then
      begin
        fieldbyname('YGYearGL').AsFloat:=0;
      end
      else
      begin
        FYGGLNF:=strtofloat(uppercase(formatdateTime('yyyy',ADOQueryCmd.fieldbyname('ZhuanZhengDate').AsDateTime)));
        FGLYF:=strtofloat(uppercase(formatdateTime('MM',ADOQueryCmd.fieldbyname('ZhuanZhengDate').AsDateTime)));
        if (FGLYF>=1) and (FGLYF<=3) then
        fieldbyname('YGYearGL').AsFloat:=FXTGLNF-FYGGLNF+1;
        if (FGLYF>3) and (FGLYF<=9) then
        fieldbyname('YGYearGL').AsFloat:=FXTGLNF-FYGGLNF+0.5;
        if (FGLYF>9) and (FGLYF<=12) then
        fieldbyname('YGYearGL').AsFloat:=FXTGLNF-FYGGLNF;
      end;
      next;
    end;
  end;
end;

procedure TfrmMJEdit.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmMJEdit.UserIDChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQuerymain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQuerymain, CDS_Glide);
  SInitCDSData20(ADOQuerymain, CDS_Glide);
end;

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

procedure TfrmMJEdit.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitData();
end;

procedure TfrmMJEdit.ToolButton2Click(Sender: TObject);
begin
  InitData();
end;

end.

