unit U_EmployeeInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxDropDownEdit, jpeg, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, cxPC, cxGridCustomPopupMenu, cxGridPopupMenu, Menus,
  ExtDlgs, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, dxScrollbarAnnotations, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinBasic, 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, dxSkinOffice2016Colorful,
  dxSkinOffice2016Dark, dxSkinOffice2019Black, dxSkinOffice2019Colorful,
  dxSkinOffice2019DarkGray, dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringtime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinTheBezier, dxSkinValentine, dxSkinVisualStudio2013Blue,
  dxSkinVisualStudio2013Dark, dxSkinVisualStudio2013Light, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinWXI, dxSkinXmas2008Blue;

type
  TfrmYGInPut = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    TBSave: TToolButton;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1YGName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1GangWei: TcxGridDBColumn;
    v1YGSex: TcxGridDBColumn;
    v1Phone: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v1RuZhiDate: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1SFZNo: TcxGridDBColumn;
    v1YGNo: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    Tv1Column33: TcxGridDBColumn;
    Tv1Column34: TcxGridDBColumn;
    Tv1Column35: TcxGridDBColumn;
    Tv1Column36: TcxGridDBColumn;
    Tv1Column37: TcxGridDBColumn;
    Tv1Column38: TcxGridDBColumn;
    Tv1Column39: TcxGridDBColumn;
    Tv1Column40: TcxGridDBColumn;
    Tv1Column41: TcxGridDBColumn;
    Tv1Column42: TcxGridDBColumn;
    Tv1Column43: TcxGridDBColumn;
    Tv1Column44: TcxGridDBColumn;
    Tv1Column45: TcxGridDBColumn;
    Tv1Column46: TcxGridDBColumn;
    Tv1Column47: TcxGridDBColumn;
    Tv1Column48: TcxGridDBColumn;
    Tv1Column49: TcxGridDBColumn;
    Tv1Column50: TcxGridDBColumn;
    Tv1Column51: TcxGridDBColumn;
    Tv1Column52: TcxGridDBColumn;
    cxgrdbclmnTv1Column14: TcxGridDBColumn;
    btn1: TToolButton;
    Tv1Column14: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure v1SYRNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure btn1Click(Sender: TObject);
    procedure v1GangWeiPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    TPInt: Integer;
    procedure InitData();
    function SaveData(): Boolean;
    function SaveMXData(Tv11: TcxGridDBTableView; CDS1: TClientDataSet; FMaxNo, FYOType: string): Boolean;
    procedure SaveImageOther();
    procedure InitImage();
    { Private declarations }
  public
    canshu1: string;
    PState, CopyInt: Integer;
    FMainId, FDPID, FDPName: string;
    { Public declarations }
  end;

var
  frmYGInPut: TfrmYGInPut;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun;

{$R *.dfm}

procedure TfrmYGInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('员工档案录入2', Tv1, '管理');
  Close;
end;

procedure TfrmYGInPut.InitData();
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from SY_Employee where EEID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS(ADOCmd, Order_Sub);
  SInitCDSData(ADOCmd, Order_Sub);
end;

procedure TfrmYGInPut.btn1Click(Sender: TObject);
begin
  WriteCxGrid('员工档案录入2', Tv1, '管理');
end;

procedure TfrmYGInPut.FormShow(Sender: TObject);
begin
  ReadCxGrid('员工档案录入2', Tv1, '管理');
  InitData();
end;

function TfrmYGInPut.SaveData(): Boolean;
var
  maxno, FHZStatus: string;
begin
  Result := False;
  try
    ADOCmd.Connection.BeginTrans;
    with Order_Sub do
    begin
      first;
      while not eof do
      begin
        if Trim(Order_Sub.fieldbyname('EEID').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'OA', 'SY_Employee', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('EEID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          SQL.Add('select * from SY_Employee where EEID=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if ADOCmd.IsEmpty then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('EEType').Value := '正式';
          end
          else
          begin
            edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('Edittime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('EEID').Value := Trim(maxno);
          fieldbyname('DPID').Value := Trim(FDPID);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'SY_Employee', 0);
          post;
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from SY_Employee where EECode=''' + Trim(Order_Sub.fieldbyname('EECode').AsString) + '''');
          Open;
        end;
        if ADOCmd.RecordCount > 1 then
        begin
          ADOCmd.Connection.RollbackTrans;
          application.MessageBox(PChar('员工编号' + trim(ADOCmd.fieldbyname('EECode').AsString) + '已存在'), '提示');
          Exit;
        end;

        with Order_Sub do
        begin
          Edit;
          FieldByName('EEID').Value := Trim(maxno);
        end;
        if Order_Sub.FieldByName('SFXTZH').AsString = '是' then
        begin
          with ADOTemp do
          begin
            Close;
            SQL.Clear;
            sql.Add('select * from SY_user e where USERID=''' + Trim(Order_Sub.fieldbyname('EECode').AsString) + '''');
            Open;
          end;
          if ADOTemp.IsEmpty then
          begin
            with ADOCmd do
            begin
              Close;
              SQL.Clear;
              sql.Add('exec P_EE_in_Account @DataID=''' + Trim(maxno) + '''');
              Open;
            end;
            if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
            begin
              ADOCmd.Connection.RollbackTrans;
              Application.MessageBox(PChar(ADOCmd.fieldbyname('ShowMsg').AsString), '提示', 0);
              exit;
            end;
          end;

        end;

        next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    ;
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

function TfrmYGInPut.SaveMXData(Tv11: TcxGridDBTableView; CDS1: TClientDataSet; FMaxNo, FYOType: string): Boolean;
begin

end;

procedure TfrmYGInPut.InitImage();
begin

end;

procedure TfrmYGInPut.TBSaveClick(Sender: TObject);
var
  FSFNO: string;
begin
  ToolBar1.SetFocus;
  if Order_Sub.Locate('IdCard', '', []) = true then
  begin
    application.MessageBox('身份证不能为空', '提示');
    exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmYGInPut.SaveImageOther();
begin

end;

procedure TfrmYGInPut.ToolButton1Click(Sender: TObject);
begin
  with Order_Sub do
  begin
    Append;
    fieldbyname('EntryDate').Value := SGetServerDate(ADOTemp);
    FieldByName('Dept').Value := Trim(FDPName);
    Post;
  end;
end;

procedure TfrmYGInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(Order_Sub.fieldbyname('EEID').AsString) <> '' then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete SY_Employee where EEID=''' + Trim(Order_Sub.fieldbyname('EEID').AsString) + '''');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('exec P_EE_in_Account @DataID=''' + Trim(Order_Sub.fieldbyname('EEID').AsString) + '''');
      Open;
    end;
    if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      Application.MessageBox(PChar(ADOCmd.fieldbyname('ShowMsg').AsString), '提示', 0);
      exit;
    end;
  end;

  Order_Sub.Delete;
end;

procedure TfrmYGInPut.v1SYRNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'SYRName';
    flagName := '车间';
    if ShowModal = 1 then
    begin
      with Order_Sub do
      begin
        edit;
        FieldByName('SYRName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGInPut.v1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      Flag := 'BZName';
      flagname := '班组名称';
      if ShowModal = 1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('BZName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYGInPut.v1GangWeiPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      Flag := 'Post';
      flagname := '岗位选择';
      if ShowModal = 1 then
      begin
        with Order_Sub do
        begin
          Edit;
          FieldByName('Post').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.

