unit U_YGYPList;

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
  TfrmYGYPList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: 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;
    Label4: TLabel;
    cxTabControl1: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column9: 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;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(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);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmYGYPList: TfrmYGYPList;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp, U_YGYPInPut;

{$R *.dfm}

procedure TfrmYGYPList.FormDestroy(Sender: TObject);
begin
  frmYGYPList:=nil;
end;

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

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

procedure TfrmYGYPList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('应聘人员面试列表',Tv1,'OA管理');
end;

procedure TfrmYGYPList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.* ');
      sql.Add(' from OA_YG_DangAn A  ');
      sql.Add(' where QCType=''面试'' ');
      if Trim(canshu1)<>'高权限' then
      begin
        sql.Add(' and Filler='''+Trim(DName)+'''');
      end;
      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<>11 then
      begin
        sql.Add(' and isnull(HZStatus,'''')='''+Trim(cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption)+'''');
      end;
      {if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(SChker,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(SChker,'''')<>'''' ');
        sql.Add(' and isnull(ChuShiStatus,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add(' and isnull(ChuShiStatus,'''')=''初试不通过'' ');
      end else
      if cxTabControl1.TabIndex=3 then
      begin
        sql.Add(' and isnull(ChuShiStatus,'''')=''初试通过'' ');
        sql.Add(' and isnull(FuShiStatus,'''')='''' ');
      end  else
      if cxTabControl1.TabIndex=4 then
      begin
        sql.Add(' and isnull(FuShiStatus,'''')=''复试不通过'' ');
      end else
      if cxTabControl1.TabIndex=5 then
      begin
        sql.Add(' and isnull(FuShiStatus,'''')=''复试通过'' ');
        sql.Add(' and SYFlag=0 ');
      end else
      if cxTabControl1.TabIndex=6 then
      begin
        sql.Add(' and SYFlag=1 ');
        sql.Add(' and isnull(ShiYongStatus,'''')='''' ');
      end else
      if cxTabControl1.TabIndex=7 then
      begin
        sql.Add(' and isnull(ShiYongStatus,'''')=''试用不通过'' ');
      end else
      if cxTabControl1.TabIndex=8 then
      begin
        sql.Add(' and isnull(ShiYongStatus,'''')=''试用通过'' ');
        sql.Add(' and ZhuanZhengFlag=0 ');
      end else
      if cxTabControl1.TabIndex=9 then
      begin
        sql.Add(' and ZhuanZhengFlag=1 ');
      end; }
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmYGYPList.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('应聘人员面试列表',Tv1,'OA管理');
  InitGrid();
end;

procedure TfrmYGYPList.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;

procedure TfrmYGYPList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  //if cxTabControl1.TabIndex<>0 then Exit;
  try
    frmYGYPInPut:=TfrmYGYPInPut.Create(Application);
    with frmYGYPInPut do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('YGId').AsString);
      frmYGYPInPut.canshu1:=Trim(Self.canshu1);
      if ShowModal=1 then
      begin
        
      end;
    end;
  finally
    frmYGYPInPut.Free;
  end;
end;

procedure TfrmYGYPList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmYGYPList.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 TfrmYGYPList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('应聘人员面试列表',cxGrid1);
end;

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

procedure TfrmYGYPList.TBAddClick(Sender: TObject);
var
  maxno:string;
begin
  try
    frmYGYPInPut:=TfrmYGYPInPut.Create(Application);
    with frmYGYPInPut do
    begin
      PState:=0;
      FMainId:='';
      if ShowModal=1 then
      begin
       
      end;
    end;
  finally
    frmYGYPInPut.Free;
  end;
end;

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

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

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

procedure TfrmYGYPList.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 TfrmYGYPList.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 TfrmYGYPList.TBSChkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  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(' SChker='''+Trim(DName)+''',SChkTime=getdate(),HZStatus=''已送审'',HZStatusTime=getdate()');
          sql.Add(' where YGID='''+Order_Main.fieldbyname('YGID').AsString+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

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

procedure TfrmYGYPList.TBSCancelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>1 then Exit;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  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 isnull(HZStatus,'''')<>''已送审'' ');
          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(' SChker=NUll,SChkTime=NUll,HZStatus=''待送审'',HZStatusTime=NUll');
          sql.Add(' where YGID='''+Order_Main.fieldbyname('YGID').AsString+'''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

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

end.
