unit U_YGYPZZSChkList_SQ;

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_SQ = 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;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    TBSCancel: TToolButton;
    BegDate: TDateTimePicker;
    Label3: TLabel;
    EndDate: TDateTimePicker;
    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;
    Panel2: TPanel;
    Label1: TLabel;
    v1SYDate: TcxGridDBColumn;
    ZZQXDate: TDateTimePicker;
    v1ZZQXDate: TcxGridDBColumn;
    v1zhuanzhengDate: TcxGridDBColumn;
    Label2: TLabel;
    YPNote: TMemo;
    Label4: TLabel;
    YGName: TEdit;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2Chker: TcxGridDBColumn;
    V2Chktime: TcxGridDBColumn;
    V2ChkStatus: TcxGridDBColumn;
    V2chkNote: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource2: TDataSource;
    order_Sub: TClientDataSet;
    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 Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmYGYPZZSChkList_SQ: TfrmYGYPZZSChkList_SQ;

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

{$R *.dfm}

procedure TfrmYGYPZZSChkList_SQ.FormDestroy(Sender: TObject);
begin
  frmYGYPZZSChkList_SQ:=nil;
end;

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

procedure TfrmYGYPZZSChkList_SQ.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  //cxgrid1.Align:=alClient;
end;

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

procedure TfrmYGYPZZSChkList_SQ.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select * ');
      sql.Add(' from OA_YG_DangAn  ');
      sql.Add(' where QCType=''面试'' ');
      sql.add(' and YGType<>''离职'' ');
      sql.Add(' and SYFlag=1 ');
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add(' and YPDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and YPDate<='''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add('  and isnull(HZStatus,'''')=''已试用'' ');
        sql.Add(' and isnull(ZZSChker,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(ZZSChker,'''')<>'''' and ZhuanZhengFlag=0 ');
      end else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add('  and ZhuanZhengFlag=1 ');
      end;
      if trim(DParameters1)<>'高权限' then
      begin
        sql.add(' and isnull(YGEName,YGName)='''+trim(DName)+''' ');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGYPZZSChkList_SQ.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ZZQXDate.Date:=SGetServerDate(ADOQueryTemp);
  ReadCxGrid('员工转正送审列表',Tv1,'OA管理');
  InitGrid();
end;

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

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

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

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

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

procedure TfrmYGYPZZSChkList_SQ.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_SQ.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_SQ.TBSChkClick(Sender: TObject);
var maxno: string;
begin
  if Order_Main.IsEmpty then Exit;
  if ZZQXDate.Checked=False then
  begin
    Application.MessageBox('转正期限不能为空','提示');
    exit;
  end;
  if YPNote.Text='' then
  begin
    application.MessageBox('评语不能为空','提示');
    exit;
  end;
  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,'ZZSS','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(' ,ZZQXDate='''+formatdatetime('yyyy-MM-dd',ZZQXDate.DateTime)+''',');
          sql.add(' YPNote='''+trim(YPNote.Text)+''' ');
          sql.Add(' where YGID='''+trim(Order_Main.fieldbyname('YGID').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.free;
  end;
  initGrid();
end;

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

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

procedure TfrmYGYPZZSChkList_SQ.TBSCancelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  {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 OA_YG_DangAn where YGID='''+Trim(Order_Main.fieldbyname('YGID').AsString)+'''');
          sql.Add(' and ZhuanZhengFlag=1 ');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          Order_Main.EnableControls;
          Application.MessageBox('已产生数据，不能撤销!','提示',0);
          Exit;
        end;
      {end;
      Next;
    end;
  end;

  Order_Main.EnableControls;}
  if Application.MessageBox('确定要执行撤销操作吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    {Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while Order_Main.Locate('SSel',True,[]) do
      begin}
        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;
        {Delete;
      end;
    end;
    Order_Main.EnableControls;}
    initGrid();
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

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

procedure TfrmYGYPZZSChkList_SQ.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('YGID').AsString)+''' ');
    open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Sub);
  SInitCDSData20(ADOQueryCmd,Order_Sub);
  YPNote.Text:=Trim(Order_Main.fieldbyname('YPNote').AsString);
end;

end.
