unit U_GRYearPFList_ZPF;

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, cxCalendar, cxButtonEdit, cxSplitter,
  RM_Common, RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport,
  cxTextEdit, cxPC, cxCheckBox, Menus;


type
  TfrmGRYearPFList_ZPF = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    ToolButton1: TToolButton;
    ToolButton4: TToolButton;
    ADOQueryPrint: TADOQuery;
    lbl1: TLabel;
    lbl3: TLabel;
    GRName: TEdit;
    Dept: TEdit;
    Source1: TDataSource;
    Order_Sub: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Filltime: TcxGridDBColumn;
    v1GRName: TcxGridDBColumn;
    v1YWNum: TcxGridDBColumn;
    v1XZNum: TcxGridDBColumn;
    v1SCNum: TcxGridDBColumn;
    v1CWNum: TcxGridDBColumn;
    TVZPFNum: TcxGridDBColumn;
    v1Dept: TcxGridDBColumn;
    v1GangWei: TcxGridDBColumn;
    v1RZDate: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1PFSumNum: TcxGridDBColumn;
    v1WPFSumNum: TcxGridDBColumn;
    cxGrid3: TcxGrid;
    TV2: TcxGridDBTableView;
    TPFYDian: TcxGridDBColumn;
    TPFMNum: TcxGridDBColumn;
    TPFYWNum: TcxGridDBColumn;
    TPFXZNum: TcxGridDBColumn;
    TPFSCNum: TcxGridDBColumn;
    V2FPCWNum: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    TPFZPNum: TcxGridDBColumn;
    TPFSJNum: TcxGridDBColumn;
    TPFXJNum: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource3: TDataSource;
    ADOQuery1: TADOQuery;
    v1PFMonth: TcxGridDBColumn;
    Label3: TLabel;
    PFYear: TEdit;
    Label4: TLabel;
    PFMonth: TEdit;
    v1PFYear: TcxGridDBColumn;
    Label2: TLabel;
    ZDept: TEdit;
    v1ZDept: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure GRNameChange(Sender: TObject);

  private
    FInt,PFInt:Integer;
    canshu1,canshu2:string;
    FNowDate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGRYearPFList_ZPF: TfrmGRYearPFList_ZPF;

implementation
uses
  U_DataLink,U_RTFun,U_KDInPut,U_ModuleNote, U_ZDYHelp,U_GRYearPFList_Sub,
  U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmGRYearPFList_ZPF.FormDestroy(Sender: TObject);
begin
  frmGRYearPFList_ZPF:=nil;
end;

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

procedure TfrmGRYearPFList_ZPF.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('个人年度考核总评分',Tv1,'薪酬管理');
end;

procedure TfrmGRYearPFList_ZPF.InitGrid();
var Fint: integer;
FDEPT,ZDept: string;
begin
  if trim(DParameters1)='部门' then
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* from OA_YG_DangAn A ');
      sql.Add('inner join SY_Dept B on A.DPID=B.DPID');
      SQL.Add('where isnull(A.YGEName,YGName)='''+trim(DName)+'''');
      Open;
    end;
    FDEPT:=ADOQuery1.fieldbyname('DPParent').AsString;
    for Fint:=2 to ADOQuery1.fieldbyname('DPlevel').AsInteger-1 do
    begin
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from SY_Dept where DPID='''+trim(FDEPT)+'''');
        open;
      end;
      FDEPT:=Trim(ADOQueryCmd.fieldbyname('DPParent').AsString);
    end;
    if ADOQueryCmd.IsEmpty=False then
    ZDept:=trim(ADOQueryCmd.fieldbyname('DPName').asstring);
  end;
  with ADOQueryMain DO
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*, ');
    sql.add('ZPFNum=isnull(A.PFSumNum*0.6+B.WPFSumNum*0.4,0) ');
    sql.add('from GRYearPF_Sub A ');
    sql.Add('inner join GRYearPFWB_Sub B on B.PFSubid=A.PFSubid ');
    sql.Add('where A.Filltime>='''+formatdatetime('yyyy-MM-dd',BegDate.Time)+''' ');
    sql.Add('and A.Filltime<'''+formatdatetime('yyyy-MM-dd',enddate.Time+1)+''' ');
    sql.Add('and (isnull(A.PFStatus,'''')=''评分完成'' ');
    sql.Add('or isnull(B.PFStatus,'''')=''评分完成'') ');
    if trim(DParameters1)='' then
    begin
      sql.Add('and B.GRName='''+trim(DName)+''' ');
    end;
    if trim(DParameters1)='部门' then
    begin
      sql.Add('and A.ZDept='''+trim(ZDept)+''' ');
      //sql.Add('and B.ZDept='''+trim(ZDept)+'''')
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from GRYearPFWB_SubMX ');
    sql.Add('where PFSubID='''+trim(Order_Main.fieldbyname('PFSubID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from GRYearPF_SubMX ');
    sql.Add('where PFSubID='''+trim(Order_Main.fieldbyname('PFSubID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_PRT);
  SInitCDSData20(ADOQueryCmd,CDS_PRT);
end;

procedure TfrmGRYearPFList_ZPF.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=SGetServerDate(ADOQueryTemp)-7;
  ReadCxGrid('个人年度考核总评分',Tv1,'薪酬管理');
  InitGrid();
end;

procedure TfrmGRYearPFList_ZPF.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('个人年度总评分',cxGrid1);
end;

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

procedure TfrmGRYearPFList_ZPF.FormShow(Sender: TObject);
var
  i:Integer;
begin
  InitForm();
end;

procedure TfrmGRYearPFList_ZPF.ToolButton1Click(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmGRYearPFList_ZPF.ToolButton4Click(Sender: TObject);
var
  fPrintFile:String;
begin
  if Order_Main.IsEmpty then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据！','提示',0);
    Exit;
  end;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\检验指示单标签.rmf' ;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not eof do
    begin
      if Order_Main.FieldByName('SSel').AsBoolean=True then
      begin
        {with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_Main_MD where MDID='''+Trim(Order_Main.fieldbyname('MDID').AsString)+'''');
          Open;
        end;
        if ADOQueryTemp.FieldByName('NotPrint').AsBoolean=True then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('不能打印《不打印》的缸条码!','提示',0);
          Exit;
        end;  }
        if FileExists(fPrintFile) then
        begin
          with ADOQueryPrint do
          begin
            Close;
            sql.Clear;
            sql.Add('select B.OrderNo,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,C.PRTHX,C.PRTColorNo,C.PRTColor,GangNo=A.GangNo,A.PS,A.Qty,A.QtyUnit,A.MDID ');
            SQL.Add(',B.MPRTCode,B.MPRTGY,C.PRTColorEng,A.SelfGangNo');
            sql.Add('from JYOrder_Main_MD A');
            sql.Add('inner join JYOrder_Main B on A.OrdMainid=B.Mainid');
            sql.Add(' inner join JYOrder_Sub C on A.OrdSubid=C.SubId');
            sql.Add(' where A.MDID='''+Trim(Order_Main.fieldbyname('MDID').AsString)+'''');
            Open;
          end;
          RM1.LoadFromFile(fPrintFile);
          //RM1.ShowReport;
          RM1.PrintReport;
        end else
        begin
          Order_Main.DisableControls;
          Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\检验指示单标签.rmf'),'提示',0);
          Exit;
        end;
      end;

      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

procedure TfrmGRYearPFList_ZPF.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from GRYearPFWB_SubMX ');
    sql.Add('where PFSubID='''+trim(Order_Main.fieldbyname('PFSubID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from GRYearPF_SubMX ');
    sql.Add('where PFSubID='''+trim(Order_Main.fieldbyname('PFSubID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_PRT);
  SInitCDSData20(ADOQueryCmd,CDS_PRT);
end;

procedure TfrmGRYearPFList_ZPF.GRNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

end.
