unit U_YGYPZZSChkList_SH;

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;

type
  TfrmYGYPZZSChkList_SH = 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;
    TBSChk: TToolButton;
    TBSCancel: TToolButton;
    BegDate: TDateTimePicker;
    Label3: TLabel;
    EndDate: TDateTimePicker;
    Label4: TLabel;
    cxTabControl1: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    v1Column25: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    TJXCHK: TToolButton;
    TNOCHK: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    V2Chker: TcxGridDBColumn;
    V2Chktime: TcxGridDBColumn;
    V2OAType: TcxGridDBColumn;
    V2chkNote: TcxGridDBColumn;
    order_Sub: TClientDataSet;
    DataSource2: TDataSource;
    v1SYDate: TcxGridDBColumn;
    v1ZZQXDate: TcxGridDBColumn;
    Panel2: TPanel;
    Label1: TLabel;
    chkNote: TEdit;
    Label2: TLabel;
    YGName: TEdit;
    Label5: TLabel;
    YPNote: TMemo;
    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 TBSChkClick(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure TBSCancelClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TJXCHKClick(Sender: TObject);
    procedure TNOCHKClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure YGNameChange(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure setatus();
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmYGYPZZSChkList_SH: TfrmYGYPZZSChkList_SH;

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

{$R *.dfm}
procedure TfrmYGYPZZSChkList_SH.setatus();
begin
  TBSChk.Visible:=False;
  TBSCancel.Visible:=False;
  TNOCHK.Visible:=False;
  case cxTabControl1.TabIndex of
    0:begin
       TBSChk.Visible:=true;
       TNOCHK.Visible:=true;
      end;
    1:begin
        TBSCancel.Visible:=true;
      end;
    2:begin
      end;
  end;
end;

procedure TfrmYGYPZZSChkList_SH.FormDestroy(Sender: TObject);
begin
  frmYGYPZZSChkList_SH:=nil;
end;

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

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

procedure TfrmYGYPZZSChkList_SH.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工转正申请列表',Tv1,'OA管理');
end;

procedure TfrmYGYPZZSChkList_SH.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* ');
      sql.Add(' from OA_YG_DangAn A  ');
      sql.Add(' inner join OA_Chk B on B.Mainid=A.YGID and B.OAType=''员工转正送审''');
      sql.Add(' where A.QCType=''面试'' ');
      sql.Add('and isnull(A.ZZSChker,'''')<>'''' ');
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add(' and A.YPDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and A.YPDate<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(B.Chkstatus,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(B.Chkstatus,'''')=''转正通过'' ');
      end;
      sql.add(' and B.Chker='''+trim(DName)+''' ');
      sql.add(' and A.LiZhiFlag=0');
      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('Mainid').AsString)+''' ');
      sql.add('and A.OAType=''员工转正送审''');
      open;
    end;
    SCreateCDS20(ADOQueryCmd,Order_Sub);
    SInitCDSData20(ADOQueryCmd,Order_Sub);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGYPZZSChkList_SH.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('员工转正申请列表',Tv1,'OA管理');
  setatus();
  InitGrid();
end;

procedure TfrmYGYPZZSChkList_SH.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 TfrmYGYPZZSChkList_SH.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 TfrmYGYPZZSChkList_SH.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('员工转正送审列表',cxGrid1);
end;

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

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

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

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

procedure TfrmYGYPZZSChkList_SH.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmYGYPInPut:=TfrmYGYPInPut.Create(Application);
    with frmYGYPInPut do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('YGId').AsString);
      TBSave.Visible:=False;
      ToolButton1.Visible:=False;
      ToolButton2.Visible:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYGYPInPut.Free;
  end;
end;

procedure TfrmYGYPZZSChkList_SH.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 TfrmYGYPZZSChkList_SH.TBSChkClick(Sender: TObject);
var FOAType: string;
begin
  if Order_Main.IsEmpty then Exit;
  if chkNote.Text='' then
  begin
    if application.MessageBox('确定不审核备注吗','提示',1)=2 then exit;
  end;
  try
    if trim(DParameters1)='高权限' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('Update OA_Chk Set ');
        sql.Add(' ChkTime=getdate(),Chkstatus=''转正通过'' ');
        sql.Add(' where Mainid='''+trim(Order_Main.fieldbyname('Mainid').AsString)+''' ');
        sql.add('and OAType=''员工转正送审''');
        ExecSQL;
      end;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        sql.Add('Update OA_Chk Set ');
        sql.Add(' chkNote='''+trim(ChkNote.Text)+''' ');
        sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+''' ');
        ExecSQL;
      end;
    end
    else
    begin
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('Update OA_Chk Set ');
        sql.Add(' ChkTime=getdate(),Chkstatus=''转正通过'',chkNote='''+trim(ChkNote.Text)+''' ');
        sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+''' ');
        ExecSQL;
      end;
    end;
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.add('select A.* from OA_Chk A ');
      sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('Mainid').AsString)+''' ');
      sql.add('and isnull(A.ChkStatus,'''')<>''转正通过'' ');
      sql.add('and A.OAType=''员工转正送审''');
      open;
    end;
    if ADOQueryCmd.IsEmpty then
    begin
      with ADOQueryMain do
      begin
        close;
        sql.Clear;
        sql.add('update OA_YG_DangAn set ');
        sql.add('HZStatus=''转正通过'' ');
        sql.Add(' where YGID='''+trim(Order_Main.fieldbyname('YGID').AsString)+'''');
        execsql;
      end;
    end;
    application.MessageBox('审核成功','提示');
    initGrid();
  except;
    application.MessageBox('审核失败','提示');
    exit;
  end;
end;

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

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

procedure TfrmYGYPZZSChkList_SH.TBSCancelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add(' select * from OA_YG_DangAn where YGID='''+Trim(Order_Main.fieldbyname('YGID').AsString)+'''');
      sql.Add(' and ZhuanZhengFlag=1 ');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      Application.MessageBox('已产生数据，不能撤销!','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('Update OA_Chk Set ');
      sql.Add(' ChkTime=null,OAType=''员工转正送审'',chkNote='''',Chkstatus='''' ');
      sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.add('update OA_YG_DangAn set ');
      sql.add('HZStatus=''员工转正送审'' ');
      sql.Add(' where YGID='''+trim(Order_Main.fieldbyname('YGID').AsString)+'''');
      execsql;
    end;
    application.MessageBox('撤销成功','提示');
    initGrid();
  except;
    application.MessageBox('撤销失败','提示');
    exit;
  end;
end;

procedure TfrmYGYPZZSChkList_SH.cxTabControl1Change(Sender: TObject);
begin
  setatus();
  InitGrid();
end;

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

procedure TfrmYGYPZZSChkList_SH.TJXCHKClick(Sender: TObject);
var maxno: string;
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(self);
    with frmZDYHelpSel do
    begin
      if showmodal=1 then
      begin
        with ClientDataSet1 do
        begin
          first;
          while not eof do
          begin
            if fieldbyname('Ssel').AsBoolean=True then
            begin
              with self.ADOQueryCmd do
              begin
                close;
                sql.Clear;
                sql.Add('select * from SY_User where UserName='''+trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
                open;
                if isempty then
                begin
                  application.MessageBox('审核人定义错误!','提示');
                  exit;
                end;
              end;
              with self.ADOQueryTemp do
              begin
                close;
                sql.Clear;
                sql.Add('select * from OA_Chk where MainId='''+Trim(Order_Main.fieldbyname('YGID').AsString)+'''');
                sql.Add(' and isnull(OAType,'''')=''员工转正送审'' ');
                sql.Add(' and isnull(Chker,'''')='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
                Open;
              end;
              if self.ADOQueryTemp.IsEmpty then
              begin
                if GetLSNo(ADOQueryCmd,maxno,'JXSS','OA_Chk',4,1)=False then
                begin
                  Application.MessageBox('取最大号失败!','提示',0);
                  Exit;
                end;
                with self.ADOQuerycmd do
                begin
                  close;
                  sql.Clear;
                  sql.Add('select * from OA_Chk where 1=2');
                  Open;
                  append;
                  FieldByName('CKID').Value:=Trim(maxno);
                  FieldByName('MainID').Value:=Trim(Order_Main.fieldbyname('YGID').AsString);
                  FieldByName('OAType').Value:='员工转正送审';
                  FieldByName('Chker').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
                  post;
                end;
              end;
            end;
            next;
          end;
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('Update OA_YG_DangAn Set ');
          sql.Add(' ZZSChker='''+Trim(DName)+''',ZZSChkTime=getdate(),ZZSChkStatus=''员工转正送审'',HZStatus=''员工转正送审'',HZStatusTime=getdate()');
          sql.Add(' where YGID='''+trim(Order_Main.fieldbyname('YGID').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.free;
  end;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update OA_Chk Set ');
    sql.Add(' ChkTime=getdate(),OAType=''转正通过'' ');
    sql.Add(' where CKID='''+trim(Order_Main.fieldbyname('CKID').AsString)+''' ');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.clear;
    sql.add('select A.* from OA_Chk A ');
    sql.add('where A.Mainid='''+trim(Order_Main.fieldbyname('Mainid').AsString)+''' ');
    sql.add('and A.OAType=''员工转正送审''');
    open;
  end;
  if ADOQueryCmd.IsEmpty then
  begin
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.add('update OA_YG_DangAn set ');
      sql.add('HZStatus=''转正通过'' ');
      sql.Add(' where YGID='''+trim(Order_Main.fieldbyname('YGID').AsString)+'''');
      execsql;
    end;
  end;
end;

procedure TfrmYGYPZZSChkList_SH.TNOCHKClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('Update OA_YG_DangAn Set ');
      sql.Add(' ZZSChker=NUll,ZZSChkTime=NUll,ZZSChkStatus=NULL,ZZSChkNote=NUll');
      sql.Add(' ,HZStatus=''已试用'',HZStatusTime=SYDate,ZZQXDate=NULL');
      sql.Add(' where YGID='''+Order_Main.fieldbyname('YGID').AsString+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      close;
      sql.clear;
      sql.Add('delete from OA_Chk where MainId='''+Trim(Order_Main.fieldbyname('YGID').AsString)+''' ');
      sql.Add(' and isnull(OAType,'''')=''员工转正送审'' ');
      execsql;
    end;
    initGrid();
  except
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmYGYPZZSChkList_SH.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('Mainid').AsString)+''' ');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);
end;

procedure TfrmYGYPZZSChkList_SH.YGNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmYGYPZZSChkList_SH.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  YPNote.Text:=Trim(Order_Main.fieldbyname('YPNote').AsString);
end;

end.
