unit U_YGXQInPut;

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;

type
  TfrmYGXQInPut = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    TBSave: TToolButton;
    Panel3: TPanel;
    Label1: TLabel;
    Label13: TLabel;
    Label33: TLabel;
    GangWei: TEdit;
    XQQty: TEdit;
    Dept: TEdit;
    Label2: TLabel;
    XQNote: TRichEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SKBankBtnDnClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
  private
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    canshu1:String;
    PState,CopyInt:Integer;
    FMainId:String;
    { Public declarations }
  end;

var
  frmYGXQInPut: TfrmYGXQInPut;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmYGXQInPut.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmYGXQInPut.InitData();
begin

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from OA_YG_XQ where YXID='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel3,2);
  Dept.SetFocus;
end;


procedure TfrmYGXQInPut.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmYGXQInPut.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'YR','OA_YG_XQ',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end else
    begin
      maxno:=Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from OA_YG_XQ where YXId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
      end
      else begin
        Edit;
      end;
      FieldByName('YXId').Value:=Trim(maxno);
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('SQDate').Value:=Trim(FormatDateTime('yyyy-MM-dd',SGetServerDate(ADOTemp)));
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      RTSetsavedata(ADOCmd,'OA_YG_XQ',Panel3,2);
      FieldByName('OAType').Value:='用人申请';
      Post;
    end;
    ADOCmd.Connection.CommitTrans;
    FMainId:=Trim(maxno);
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGXQInPut.SKBankBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text:='';
  TBtnEditC(Sender).TxtCode:='';
end;



procedure TfrmYGXQInPut.TBSaveClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if Trim(Dept.Text)='' then
  begin
    Application.MessageBox('部门不能为空！','提示',0);
    Exit;
  end;
  if Trim(GangWei.Text)='' then
  begin
    Application.MessageBox('岗位不能为空!','提示',0);
    Exit;
  end;
  if Trim(XQQty.Text)='' then
  begin
    Application.MessageBox('人数不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
  end;
end;

end.
