unit U_YGYPSYList;

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, BtnEdit;

type
  TfrmYGYPSYList = 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;
    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;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Panel2: TPanel;
    Label1: TLabel;
    FDept: TBtnEditA;
    Label2: TLabel;
    FGangWei: TBtnEditA;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label35: TLabel;
    FKSYSTEM: TBtnEditA;
    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 FDeptBtnClick(Sender: TObject);
    procedure FGangWeiBtnClick(Sender: TObject);
    procedure FKSYSTEMBtnClick(Sender: TObject);
  private
    canshu1:string;
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    { Private declarations }
  public
    FFInt,FCloth:Integer;

    { Public declarations }
  end;

var
  frmYGYPSYList: TfrmYGYPSYList;

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

{$R *.dfm}

procedure TfrmYGYPSYList.FormDestroy(Sender: TObject);
begin
  frmYGYPSYList:=nil;
end;

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

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

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

procedure TfrmYGYPSYList.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=''面试'' ');
      sql.Add(' and isnull(FuShiStatus,'''')=''复试通过'' ');
      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<>6 then
      begin
        sql.Add(' and isnull(HZStatus,'''')='''+Trim(cxTabControl1.Tabs[cxTabControl1.TabIndex].Caption)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


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

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

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

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

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

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

procedure TfrmYGYPSYList.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 TfrmYGYPSYList.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 TfrmYGYPSYList.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 Trim(FDept.Text)='' then
  begin
    Application.MessageBox('部门不能为空!','提示',0);
    Exit;
  end;
  if Trim(FGangWei.Text)='' 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(' SYPerson='''+Trim(DName)+''',SYDate=getdate(),SYFlag=1');
          Sql.Add(',HZStatus=''已试用'',HZStatusTime=getdate()');
          sql.Add(',YGType=''试用'',Dept='''+Trim(FDept.Text)+''',DPID='''+Trim(FGangWei.TxtCode)+'''');
          sql.Add(',GangWei='''+Trim(FGangWei.Text)+'''');
          sql.Add(' where YGID='''+Order_Main.fieldbyname('YGID').AsString+'''');
          ExecSQL;
        end;
        Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

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

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

procedure TfrmYGYPSYList.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(ShiYongPerson,'''')<>'''' ');
          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(' SYPerson=NUll,SYDate=NUll,SYFlag=0,YGType=NULL,GangWei=NUll,Dept=Null,DPID=Null');
          sql.Add(' ,HZStatus=''复试通过'',HZStatusTime=FuShiDate');
          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 TfrmYGYPSYList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmYGYPSYList.FDeptBtnClick(Sender: TObject);
begin
  try
    frmSYDeptView:=TfrmSYDeptView.Create(Application);
    with frmSYDeptView do
    begin
      if ShowModal=1 then
      begin
        Self.FDept.Text:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPName').AsString);
        //Self.FDept.TxtCode:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPID').AsString);
      end;
    end;
  finally
    frmSYDeptView.Free;
  end;
end;

procedure TfrmYGYPSYList.FGangWeiBtnClick(Sender: TObject);
begin
  try
    frmSYDeptView:=TfrmSYDeptView.Create(Application);
    with frmSYDeptView do
    begin
      if ShowModal=1 then
      begin
        Self.FGangWei.Text:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPName').AsString);
        Self.FGangWei.TxtCode:=Trim(frmSYDeptView.CDS_Tree.fieldbyname('DPID').AsString);
      end;
    end;
  finally
    frmSYDeptView.Free;
  end;
end;

procedure TfrmYGYPSYList.FKSYSTEMBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='FKSYSTEM';
    flagname:='付款抬头';
    if ShowModal=1 then
    begin
      FKSYSTEM.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

end.
