unit U_YGYPZZChkList_YGCX;

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_YGCX = 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;
    TBADD: TToolButton;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    TCXTJ: TToolButton;
    BegDate: TDateTimePicker;
    Label3: TLabel;
    EndDate: TDateTimePicker;
    DataSource2: TDataSource;
    order_Sub: TClientDataSet;
    Label2: TLabel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ADOQuery1: TADOQuery;
    Label4: TLabel;
    SQType: TEdit;
    cxTabControl1: TcxTabControl;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2Chker: TcxGridDBColumn;
    V2Chktime: TcxGridDBColumn;
    V2Chkstatus: TcxGridDBColumn;
    V2chkNote: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxStyle2: TcxStyle;
    Panel4: TPanel;
    Label6: TLabel;
    Panel5: TPanel;
    Image1: TImage;
    TSure: TButton;
    ETaiTou: TEdit;
    Label5: TLabel;
    SJEndDate: TDateTimePicker;
    ADOQuery2: TADOQuery;
    v1SQName: TcxGridDBColumn;
    v1SQBegDate: TcxGridDBColumn;
    v1SQEndDate: TcxGridDBColumn;
    v1SQDay: TcxGridDBColumn;
    v1TaiTou: TcxGridDBColumn;
    v1SQNote: TcxGridDBColumn;
    v1SQStatus: TcxGridDBColumn;
    v1SQType: TcxGridDBColumn;
    v1SJEndDate: TcxGridDBColumn;
    v1filltime: TcxGridDBColumn;
    TGH: TToolButton;
    Label1: TLabel;
    SQName: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    v1ZWName: TcxGridDBColumn;
    Label9: TLabel;
    ZWName: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    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 TCXTJClick(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure CLNameChange(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TSureClick(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TBADDClick(Sender: TObject);
    procedure TGHClick(Sender: TObject);
    procedure ZWNameKeyPress(Sender: TObject; var Key: Char);
    procedure SQNameKeyPress(Sender: TObject; var Key: Char);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure setstatus();
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    { Public declarations }
  end;

var
  frmYGYPZZChkList_YGCX: TfrmYGYPZZChkList_YGCX;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp, U_YGYPInPut,
  U_ZDYHelpSel,U_YGYPInPut_YGFJDJ,U_YGYPInPut_CLWXDJ;  

{$R *.dfm}

procedure TfrmYGYPZZChkList_YGCX.setstatus();
begin
  TBADD.Visible:=False;
  TCXTJ.Visible:=False;
  TGH.Visible:=False;
  case cxTabControl1.TabIndex of
    0:begin
        TBADD.Visible:=true;
      end;
    1:begin
        TCXTJ.Visible:=true;
        TGH.Visible:=true;
      end;
    2:begin

      end;
    3:begin
      end;
  end;
end;

procedure TfrmYGYPZZChkList_YGCX.FormDestroy(Sender: TObject);
begin
  frmYGYPZZChkList_YGCX:=nil;
end;

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

procedure TfrmYGYPZZChkList_YGCX.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmYGYPZZChkList_YGCX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('公司事务列表',Tv1,'OA管理');
end;

procedure TfrmYGYPZZChkList_YGCX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select * ');
      sql.Add(' from OA_YG_CLGLSW ');
      sql.add(' where 1=1');
      if trim(CanShu1)<>'' then
      begin
        if CxtabControl1.TabIndex<>0 then
        begin
          sql.Add(' and filltime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
          sql.Add(' and filltime<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        end;
        sql.add(' and isnull(SQType,'''')='''+trim(Canshu1)+'''');
        if CxtabControl1.TabIndex=0 then
        begin
          sql.add(' and isnull(RLStatus,'''')='''' and isnull(SQStatus,'''')=''申请通过''');
        end;
        if CxtabControl1.TabIndex=1 then
        begin
          sql.add(' and RLStatus=''已认领'' and isnull(SQStatus,'''')=''申请通过''');
        end;
        if CxtabControl1.TabIndex=2 then
        begin
          sql.add(' and isnull(SQStatus,'''')=''已回归''');
        end;
      end
      else
      begin
        sql.add(' and isnull(SQType,'''')<>''公章使用''');
        sql.Add(' and filltime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and filltime<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
        sql.add(' and (isnull(SQStatus,'''')=''申请通过'' or isnull(SQStatus,'''')=''已回归'')');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.add('select A.* from OA_Chk A ');
      sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('SWID').AsString)+''' ');
      sql.Add('and isnull(OAType,'''')=''事务管理''');
      open;
    end;
    SCreateCDS20(ADOQueryCmd,Order_Sub);
    SInitCDSData20(ADOQueryCmd,Order_Sub);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGYPZZChkList_YGCX.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('公司事务列表',Tv1,'OA管理');
  setstatus();
  if trim(CanShu1)<>'' then
  begin
    cxTabControl1.Visible:=true;
  end
  else
  begin
    cxTabControl1.Visible:=False;
    TBADD.Visible:=False;
  end;
  InitGrid();
end;

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

function TfrmYGYPZZChkList_YGCX.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_YGCX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('员工加薪列表',cxGrid1);
end;

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

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

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

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

procedure TfrmYGYPZZChkList_YGCX.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  frmYGYPInPut_YGFJDJ:=TfrmYGYPInPut_YGFJDJ.create(self);
  with frmYGYPInPut_YGFJDJ do
  begin
    ToolBar1.Visible:=False;
    FCLID:=trim(Order_Main.fieldbyname('SWID').AsString);
    if showModal=1 then
    begin

    end;
    free;
  end;
end;

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

procedure TfrmYGYPZZChkList_YGCX.TCXTJClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update OA_YG_CLGLSW Set RLStatus='''' ');
    sql.Add(' where SWID='''+trim(Order_Main.fieldbyname('SWID').AsString)+'''');
    ExecSQL;
  end;
  initGrid();
end;

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

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

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

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

procedure TfrmYGYPZZChkList_YGCX.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('SWID').AsString)+''' ');
    sql.Add('and isnull(OAType,'''')=''事务管理''');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);
  Label7.Caption:=trim(Order_Main.fieldbyname('SQNote').AsString);
end;

procedure TfrmYGYPZZChkList_YGCX.TSureClick(Sender: TObject);
begin
  if application.MessageBox('确定执行此操作吗','提示',1)=2 then exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update OA_YG_CLGLSW set SJEndDate='''+trim(formatdatetime('yyyy-MM-dd',SJEndDate.DateTime))+''',SQStatus=''已回归'' ');
    sql.Add('where SWID='''+trim(Order_Main.fieldbyname('SWID').asstring)+''' ');
    ExecSQL;
  end;
  initGrid();
  Panel4.Visible:=False;
end;

procedure TfrmYGYPZZChkList_YGCX.Image1Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

procedure TfrmYGYPZZChkList_YGCX.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  initGrid();
end;

procedure TfrmYGYPZZChkList_YGCX.TBADDClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update OA_YG_CLGLSW Set RLStatus=''已认领'' ');
    sql.Add(' where SWID='''+trim(Order_Main.fieldbyname('SWID').AsString)+'''');
    ExecSQL;
  end;
  initGrid();
end;

procedure TfrmYGYPZZChkList_YGCX.TGHClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  Panel4.Visible:=True;
  SJEndDate.DateTime:=now;
end;

procedure TfrmYGYPZZChkList_YGCX.ZWNameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select * ');
      sql.Add(' from OA_YG_CLGLSW ');
      sql.Add(' where 1=1');
      sql.Add(' and ZWName='''+trim(ZWName.Text)+''' ');
      if trim(CanShu1)<>'' then
      begin
        sql.add(' and isnull(SQType,'''')='''+trim(Canshu1)+'''');
        if CxtabControl1.TabIndex=0 then
        begin
          sql.add(' and isnull(RLStatus,'''')='''' and isnull(SQStatus,'''')=''申请通过''');
        end;
        if CxtabControl1.TabIndex=1 then
        begin
          sql.add(' and RLStatus=''已认领'' and isnull(SQStatus,'''')=''申请通过''');
        end;
        if CxtabControl1.TabIndex=2 then
        begin
          sql.add(' and isnull(SQStatus,'''')=''已回归''');
        end;
      end
      else
      begin
        sql.add(' and isnull(SQType,'''')<>''公章使用''');
        sql.add(' and (isnull(SQStatus,'''')=''申请通过'' or isnull(SQStatus,'''')=''已回归'')');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.add('select A.* from OA_Chk A ');
      sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('SWID').AsString)+''' ');
      sql.Add('and isnull(OAType,'''')=''事务管理''');
      open;
    end;
    SCreateCDS20(ADOQueryCmd,Order_Sub);
    SInitCDSData20(ADOQueryCmd,Order_Sub);
  end;
end;

procedure TfrmYGYPZZChkList_YGCX.SQNameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select * ');
      sql.Add(' from OA_YG_CLGLSW ');
      sql.Add(' where 1=1');
      sql.Add(' and SQName='''+trim(SQName.Text)+''' ');
      if trim(CanShu1)<>'' then
      begin
        sql.add(' and isnull(SQType,'''')='''+trim(Canshu1)+'''');
        if CxtabControl1.TabIndex=0 then
        begin
          sql.add(' and isnull(RLStatus,'''')='''' and isnull(SQStatus,'''')=''申请通过''');
        end;
        if CxtabControl1.TabIndex=1 then
        begin
          sql.add(' and RLStatus=''已认领'' and isnull(SQStatus,'''')=''申请通过''');
        end;
        if CxtabControl1.TabIndex=2 then
        begin
          sql.add(' and isnull(SQStatus,'''')=''已回归''');
        end;
      end
      else
      begin
        sql.add(' and isnull(SQType,'''')<>''公章使用''');
        sql.add(' and (isnull(SQStatus,'''')=''申请通过'' or isnull(SQStatus,'''')=''已回归'')');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.add('select A.* from OA_Chk A ');
      sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('SWID').AsString)+''' ');
      sql.Add('and isnull(OAType,'''')=''事务管理''');
      open;
    end;
    SCreateCDS20(ADOQueryCmd,Order_Sub);
    SInitCDSData20(ADOQueryCmd,Order_Sub);
  end;
end;

end.
