unit U_YGYPZZChkList_BGYPSQCX;

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, ActnMan, ActnColorMaps;

type
  TfrmYGYPZZChkList_BGYPSQCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: 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;
    BegDate: TDateTimePicker;
    Label3: TLabel;
    EndDate: TDateTimePicker;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1GangWei: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1BGUnit: TcxGridDBColumn;
    v1Dept: TcxGridDBColumn;
    DataSource2: TDataSource;
    order_Sub: TClientDataSet;
    Label2: TLabel;
    v1SQDate: TcxGridDBColumn;
    v1BGQty: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1BGName: TcxGridDBColumn;
    v1BGNote: TcxGridDBColumn;
    ADOQuery1: TADOQuery;
    YGName: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    BGName: TEdit;
    Label5: TLabel;
    Dept: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure YGNameChange(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    Ftype:string;
    { Public declarations }
  end;

var
  frmYGYPZZChkList_BGYPSQCX: TfrmYGYPZZChkList_BGYPSQCX;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp, U_YGYPInPut,
  U_ZDYHelpSel,U_YGYPInput_BGYPDJ;

{$R *.dfm}

procedure TfrmYGYPZZChkList_BGYPSQCX.FormDestroy(Sender: TObject);
begin
  frmYGYPZZChkList_BGYPSQCX:=nil;
end;

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

procedure TfrmYGYPZZChkList_BGYPSQCX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工办公列表',Tv1,'OA管理');
end;

procedure TfrmYGYPZZChkList_BGYPSQCX.InitGrid();
var FDEPT,ZDept: string;
    Fint:integer;
begin
  if trim(Ftype)='部门' 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;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,C.* ');
      sql.Add(' from OA_YG_DangAN_BGYP A  ');
      sql.add(' inner join OA_YG_DangAN_BGYP_Sub B on B.BGMainid=A.BGMainid ');
      sql.add(' inner join OA_YG_DangAN C on C.YGID=A.YGID ');
      sql.Add(' where A.SQDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and A.SQDate<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      sql.add(' and isnull(B.SQStatus,'''')=''审核通过''');
      if trim(Ftype)='个人' then
      begin
        sql.add(' and isnull(C.YGEName,C.YGName)='''+trim(DName)+''' ');
      end;
      if trim(Ftype)='部门' then
      begin
        sql.Add('and A.ZDept='''+trim(ZDept)+''' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmYGYPZZChkList_BGYPSQCX.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('员工办公列表',Tv1,'OA管理');
  InitGrid();
end;

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

function TfrmYGYPZZChkList_BGYPSQCX.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete OA_YG_DangAn  where YGId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete OA_YG_DangAn_Other  where YGId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Delete TP_File  where WBId='''+Trim(Order_Main.fieldbyname('YGId').AsString)+'''');
      sql.Add(' and TFType=''YG'' ');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmYGYPZZChkList_BGYPSQCX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('员工加薪列表',cxGrid1);
end;

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

procedure TfrmYGYPZZChkList_BGYPSQCX.FormShow(Sender: TObject);
begin
  InitForm();
end;

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

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

procedure TfrmYGYPZZChkList_BGYPSQCX.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  frmYGYPInPut_BGYPDJ:=TfrmYGYPInPut_BGYPDJ.create(self);
  with frmYGYPInPut_BGYPDJ do
  begin
    TBSave.Visible:=False;
    FBGMainID:=trim(Order_Main.fieldbyname('BGMainID').AsString);
    if showModal=1 then
    begin

    end;
    free;
  end;
  initGrid();
end;

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

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

procedure TfrmYGYPZZChkList_BGYPSQCX.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  {with ADOQueryCmd do
  begin
    close;
    sql.clear;
    sql.add('select A.* from OA_Chk A ');
    sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('BGMainID').AsString)+''' ');
    sql.Add(' and isnull(OAType,'''')=''办公申请'' ');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);}
end;

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

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

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

end.
