unit U_YGList;

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, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL, cxTLData,
  cxTimeEdit, cxLookAndFeels, cxLookAndFeelPainters, cxTLdxBarBuiltInMenu,
  dxBarBuiltInMenu, cxNavigator, jpeg, U_SLT, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmYGList = 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;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    Label1: TLabel;
    YGName: TEdit;
    Label2: TLabel;
    YGSex: TComboBox;
    Label3: TLabel;
    FHType: TEdit;
    Label4: TLabel;
    YGType: TComboBox;
    Label5: TLabel;
    GangWei: TEdit;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    DataSource2: TDataSource;
    CDS_Tree: TClientDataSet;
    ADOQueryTree: TADOQuery;
    cxSplitter1: TcxSplitter;
    cxTabControl1: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    TLZ: TToolButton;
    v1YGYearGL: TcxGridDBColumn;
    v1GRYearPF: TcxGridDBColumn;
    v1FHType: TcxGridDBColumn;
    ADOQuery1: TADOQuery;
    v1ZhuanZhengDate: TcxGridDBColumn;
    v1SYDate: TcxGridDBColumn;
    TNXCK: TToolButton;
    TCXLZ: TToolButton;
    v1SJLiZhiDate: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    TPrint: TToolButton;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    TFJ: TToolButton;
    cxStyle2: TcxStyle;
    v1XBTime: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Ssel: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ComboBox1: TComboBox;
    CDS_PRT: TClientDataSet;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    adoqueryPicture: TADOQuery;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    RM2: TRMGridReport;
    RMDBMain2: TRMDBDataSet;
    ToolButton6: TToolButton;
    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 N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure YGNameChange(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure TLZClick(Sender: TObject);
    procedure TNXCKClick(Sender: TObject);
    procedure TCXLZClick(Sender: TObject);
    procedure TPrintClick(Sender: TObject);
    procedure TFJClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure ToolButton6Click(Sender: TObject);
  private
    canshu1: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitTree();
    procedure InitImage();
    procedure GLAge();
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmYGList: TfrmYGList;
  Mach: array of TfrmSlt;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_YGInPut, U_YGYPZZChkList_NXZZJL, U_FjList_RZ,
  U_ZDYBZType, U_FileUp3, U_FileUp4 ,superobject, U_LabelPrintFun;

{$R *.dfm}

procedure TfrmYGList.FormDestroy(Sender: TObject);
begin
  frmYGList := nil;
end;

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

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

procedure TfrmYGList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工档案列表21', Tv1, 'OA管理');
end;

procedure TfrmYGList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' exec P_View_YGList :DPID,:LiZhiFlag');
      Parameters.ParamByName('DPID').Value := Trim(CDS_Tree.fieldbyname('DPID').AsString);
      Parameters.ParamByName('LiZhiFlag').Value := cxTabControl1.TabIndex;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYGList.GLAge();
var
  FXTGLNF, FYGGLNF, FGLYF: Double;
begin
  FXTGLNF := strtofloat(uppercase(formatdateTime('yyyy', SGetServerDate(ADOQueryTemp))));
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select ZhuanZhengDate,YGYearGL from OA_YG_DangAn where YGType=''正式'' ');
    open;
  end;
  with ADOQueryCmd do
  begin
    first;
    while not eof do
    begin
      edit;
      if ADOQueryCmd.fieldbyname('ZhuanZhengDate').asstring = '' then
      begin
        fieldbyname('YGYearGL').AsFloat := 0;
      end
      else
      begin
        FYGGLNF := strtofloat(uppercase(formatdateTime('yyyy', ADOQueryCmd.fieldbyname('ZhuanZhengDate').AsDateTime)));
        FGLYF := strtofloat(uppercase(formatdateTime('MM', ADOQueryCmd.fieldbyname('ZhuanZhengDate').AsDateTime)));
        if (FGLYF >= 1) and (FGLYF <= 3) then
          fieldbyname('YGYearGL').AsFloat := FXTGLNF - FYGGLNF + 1;
        if (FGLYF > 3) and (FGLYF <= 9) then
          fieldbyname('YGYearGL').AsFloat := FXTGLNF - FYGGLNF + 0.5;
        if (FGLYF > 9) and (FGLYF <= 12) then
          fieldbyname('YGYearGL').AsFloat := FXTGLNF - FYGGLNF;
      end;
      next;
    end;
  end;
end;

procedure TfrmYGList.InitTree();
var
  i: Integer;
begin
  try
    ADOQueryTree.DisableControls;
    with ADOQueryTree do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from SY_Dept order by DPlevel,DPOrder,DPName');
      Open;
    end;
    SCreateCDS20(ADOQueryTree, CDS_Tree);
    SInitCDSData20(ADOQueryTree, CDS_Tree);
    cxDBTreeList1.Items[0].Expand(True);
  finally
    ADOQueryTree.EnableControls;
  end;
end;

procedure TfrmYGList.InitForm();
begin
  ReadCxGrid('员工档案列表21', Tv1, 'OA管理');
  InitTree();
  GLAge();
  //InitGrid();
end;

procedure TfrmYGList.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 TfrmYGList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  //if cxTabControl1.TabIndex<>0 then Exit;
  try
    frmYGInPut := TfrmYGInPut.Create(Application);
    with frmYGInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('YGId').AsString);
      frmYGInPut.canshu1 := Trim(Self.canshu1);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmYGInPut.Free;
  end;
end;

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

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

procedure TfrmYGList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmYGInPut := TfrmYGInPut.Create(Application);
    with frmYGInPut do
    begin
      PState := 0;
      FMainId := '';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmYGInPut.Free;
  end;
end;

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

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

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

procedure TfrmYGList.TBViewClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmYGInPut := TfrmYGInPut.Create(Application);
    with frmYGInPut 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
    frmYGInPut.Free;
  end;
end;

procedure TfrmYGList.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 TfrmYGList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

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

procedure TfrmYGList.cxTabControl1Change(Sender: TObject);
begin
  TBDel.Visible := false;
  if cxTabControl1.TabIndex = 1 then
  begin
    TBDel.Visible := true;
  end;
  InitGrid();
end;

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

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

procedure TfrmYGList.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmYGList.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then
    Exit;
  CDS_Tree.Locate('DPID', Trim(Order_Main.fieldbyname('DPID').AsString), []);

end;

procedure TfrmYGList.InitImage();
var
  i, j: integer;
  jpg: TJpegImage;
  myStream: TADOBlobStream;
begin
  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  if Order_Main.IsEmpty then
    exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,B.FileName from TP_File A,XD_File B ');
      sql.add(' where A.TFID =B.XFID and A.WBID=' + quotedstr(trim(Order_Main.fieldbyname('YGID').AsString)));
      sql.Add(' and B.FileType in (''ZM'',''FM'') ');
//      ShowMessage(sql.text);
      open;
    end;
    j := adoqueryPicture.RecordCount;
    if j < 1 then
      exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg := TJpegImage.Create();
    for i := 0 to j - 1 do
    begin
      if triM(adoqueryPicture.fieldbyname('FilesOther').AsString) <> '' then
      begin
        myStream := tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')), bmread);
        jpg.LoadFromStream(myStream);
        Mach[i] := TfrmSlt.Create(Self);
        Mach[i].Name := trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[i].Left := 0 + i * 165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString, adoqueryPicture.fieldbyname('FileName').AsString, jpg);
      end;
      adoqueryPicture.Next;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmYGList.TLZClick(Sender: TObject);
begin
  if CxTabConTrol1.TabIndex <> 0 then
    exit;
  {if Order_Main.FieldByName('LiZhiStatus').AsString<>'离职通过' then
  begin
    application.MessageBox('离职未审核通过,不能离职','提示');
    exit;
  end;
  if order_Main.FieldByName('SJLiZhiDate').AsDateTime>SGetServerDate(ADOQueryTemp) then
  begin
    application.MessageBox('实际离职日期未到,不能离职','提示');
    exit;
  end;}
  if application.MessageBox('确定要执行此操作', '提示', 1) = 2 then
    exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('update OA_YG_DangAn set LiZhiFlag=1,YGType=''离职'',LiZhiStatus=''离职通过''');
    sql.Add(' where YGID=''' + trim(Order_Main.fieldbyname('YGID').AsString) + '''');
    execsql;
  end;
  initGrid();
end;

procedure TfrmYGList.TNXCKClick(Sender: TObject);
begin
  if self.Order_Main.IsEmpty then
    exit;
  if cxTabControl1.TabIndex <> 0 then
    exit;
  if self.Order_Main.FieldByName('FHType').AsString <> '年薪制' then
  begin
    application.MessageBox('该员工不是年薪制不能查看', '提示');
    exit;
  end;
  frmYGYPZZChkList_NXZZJL := TfrmYGYPZZChkList_NXZZJL.create(self);
  with frmYGYPZZChkList_NXZZJL do
  begin
    FYGID := trim(self.Order_Main.fieldbyname('YGID').AsString);
    if showModal = 1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmYGList.TCXLZClick(Sender: TObject);
begin
  if order_Main.IsEmpty then
    exit;
  if application.MessageBox('确定要撤销离职吗', '提示', 1) = 2 then
    exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('update OA_YG_DangAn set LiZhiFlag=0,YGType=''正式'',SJLiZhiDate=NULL,LiZhiStatus=''''');
    sql.Add(' where YGID=''' + trim(Order_Main.fieldbyname('YGID').AsString) + '''');
    execsql;
  end;
  initGrid();
end;

procedure TfrmYGList.TPrintClick(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\员工卡.rmf';
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(Order_Main.fieldbyname('YGID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;

  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM2.LoadFromFile(fPrintFile);
    RM2.PrintReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\员工卡.rmf'), '提示', 0);
    Exit;
  end;
end;

procedure TfrmYGList.TFJClick(Sender: TObject);
begin
  frmFjList_RZ := TfrmFjList_RZ.Create(self);
  with frmFjList_RZ do
  begin
    fkeyNO := Trim(Order_Main.fieldbyname('YGId').AsString);
    fType := '地图';
    if ShowModal = 1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmYGList.ToolButton1Click(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  if Order_Main.Locate('Ssel', True, []) = false then
  begin
    Application.MessageBox('请选择数据', '提示');
    exit;
  end;
  try
    frmZDYBZType := TfrmZDYBZType.Create(Application);
    with frmZDYBZType do
    begin
      flag := 'FHType';
      flagname := '薪酬类型';
      if ShowModal = 1 then
      begin
        Order_Main.DisableControls;
        with Order_Main do
        begin
          First;
          while not eof do
          begin
            if FieldByName('Ssel').AsBoolean = true then
            begin
              with ADOQueryCmd do
              begin
                close;
                sql.Clear;
                sql.Add('update OA_YG_DangAn set FHType=''' + Trim(ClientDataSet1.fieldbyname('ZDYName').AsString) + ''' ');
                sql.add(',SYDate=''' + Trim(ClientDataSet1.fieldbyname('SBTime').AsString) + '''');
                sql.add(',XBTime=''' + Trim(ClientDataSet1.fieldbyname('XBTime').AsString) + '''');
                sql.Add(' where YGID=''' + trim(Order_Main.FieldByName('YGID').Asstring) + '''');
                ExecSQL;
              end;
            end;
            next;
          end;
        end;
        Order_Main.EnableControls;
        TBRafresh.Click;
      end;
    end;
  finally
    frmZDYBZType.Free;
  end;
end;

procedure TfrmYGList.ToolButton2Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * ');
    sql.Add(' ,ZM=(select top 1 FilesOther from XD_File X  ');
    sql.Add(' INNER JOIN TP_File Y on X.XFID=Y.TFID   ');
    sql.Add(' where X.FileType =''ZM'' and X.CYID =A.YGID) ');
    sql.Add(' ,FM=(select top 1 FilesOther from XD_File X  ');
    sql.Add(' INNER JOIN TP_File Y on X.XFID=Y.TFID   ');
    sql.Add(' where X.FileType =''FM'' and X.CYID =A.YGID) ');
    sql.Add(' from OA_YG_DangAn A where YGId =''' + Trim(Order_Main.fieldbyname('YGId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\入职表.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
//    RMVariables['ZM'] := 'D:\Right1209\罗梦-19.jpg';
    Rm1.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);
    RM1.ShowReport;
//    RM1.PrintReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\入职表.rmf'), '提示', 0);
    Exit;
  end;
end;

procedure TfrmYGList.ToolButton3Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from OA_YG_DangAn where YGType =''正式'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\员工花名册.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.showReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\员工花名册.rmf'), '提示', 0);
    Exit;
  end;
end;

procedure TfrmYGList.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  begin
    try
      frmFileUp3 := TfrmFileUp3.Create(Application);
      with frmFileUp3 do
      begin
        Label1.Caption := '员工姓名';
        Code.Text := Trim(Self.Order_Main.fieldbyname('YGName').AsString);
        CYID := trim(Self.Order_Main.fieldbyname('YGID').AsString);
        if ShowModal = 1 then
        begin
          Self.InitGrid();
          Self.Order_Main.Locate('YGID', CYID, []);
        end;
      end;
    finally
      frmFileUp3.Free;
    end;
  end;
end;

procedure TfrmYGList.ToolButton5Click(Sender: TObject);
begin
  begin
    if Order_Main.IsEmpty then
      Exit;
    try
      frmFileUp4 := TfrmFileUp4.Create(Application);
      with frmFileUp4 do
      begin
        Label1.Caption := '员工姓名';
        Code.Text := Trim(Self.Order_Main.fieldbyname('YGName').AsString);
        CYID := trim(Self.Order_Main.fieldbyname('YGID').AsString);
        if ShowModal = 1 then
        begin
          Self.InitGrid();
          Self.Order_Main.Locate('YGID', CYID, []);
        end;
      end;
    finally
      frmFileUp4.Free;
    end;
  end;
end;

procedure TfrmYGList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  if Order_Main.IsEmpty then
    Exit;
  InitImage();
end;

procedure TfrmYGList.ToolButton6Click(Sender: TObject);
var
  FPrintJson, JsonResult, MFiltration: string;
  RTValues: TStringArray;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) then
  begin
    RTValues := SelCDSKey(Order_Main, ['YGID']);
    MFiltration := RTValues[0];
  end
  else
  begin
    MFiltration := Trim(Order_Main.fieldbyname('YGID').AsString);
  end;
  FPrintJson := '{ "LMType": "LMType","QrCodeField": "YGID","PreviewPrint": true,"DConString": "' + DConString + '","DCode": "' + DCode + '","DName": "' + DName + '", "PrtArgs": [ { "IsSql": true, "Filtration": " ' + MFiltration + '" }] }';

  FormPrint(Application, PChar(FPrintJson));
end;

end.

