unit U_YGYPInPut_YiJiao;

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;

type
  TfrmYGYPInPut_yijiao = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    TBSave: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    Panel3: TPanel;
    Label4: TLabel;
    Label11: TLabel;
    Label27: TLabel;
    YGName: TEdit;
    SJLiZhiDate: TDateTimePicker;
    LiZhiNote: TRichEdit;
    Label3: TLabel;
    YIJiaoDate: TDateTimePicker;
    Dept: TEdit;
    Label6: TLabel;
    GangWei: TEdit;
    Label7: TLabel;
    YiJiaoOther: TRichEdit;
    Label1: TLabel;
    Label2: TLabel;
    YiJiaoDaiBan: TRichEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    ToolBar2: TToolBar;
    Tadd: TToolButton;
    TDel: TToolButton;
    v1YJName: TcxGridDBColumn;
    v1YJQty: TcxGridDBColumn;
    v1JieShouRen: TcxGridDBColumn;
    v1YJUnit: TcxGridDBColumn;
    v1JianJiaoRen: TcxGridDBColumn;
    v1YJNote: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure TaddClick(Sender: TObject);
    procedure TDelClick(Sender: TObject);
    procedure v1YJNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1YJUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1JieShouRenPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1JianJiaoRenPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    TPInt:Integer;
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    canshu1,FDName:String;
    PState,CopyInt:Integer;
    { Public declarations }
  end;

var
  frmYGYPInPut_yijiao: TfrmYGYPInPut_yijiao;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel;

{$R *.dfm}

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

procedure TfrmYGYPInPut_yijiao.InitData();
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* from OA_YG_DangAn A ');
    if trim(FDname)='' then
    sql.add('where isnull(A.YGEName,A.YGName)='''+Trim(DName)+''' ')
    else
    sql.add('where A.YGName='''+Trim(FDName)+'''');
    Open;
  end;
  SCSHDataNew(ADOCmd,Panel3,2);
  if trim(ADOCmd.FieldByName('YIJiaoDate').AsString)='' then
  begin
    YiJiaoDate.DateTime:=SGetServerDate(ADOTemp);
  end;
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.add('select * from OA_YG_LZYJQD ');
    sql.Add('where YGID='''+trim(ADOCmd.fieldbyname('YGID').asstring)+'''');
    open;
  end;
  SCreateCDS20(ADOTemp,Order_Sub);
  SInitCDSData20(ADOTemp,Order_Sub);
end;

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

function TfrmYGYPInPut_yijiao.SaveData():Boolean;
var
  maxno,FYGID:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from OA_YG_DangAn where isnull(YGEName,YGName)='''+Trim(DName)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      Edit;
      RTSetsavedata(ADOCmd,'OA_YG_DangAn',Panel3,2);
      FieldByName('YiJiaoStatus').Value:='待提交';
      Post;
    end;
    FYGID:=trim(ADOCmd.fieldbyname('YGID').AsString);
    with Order_Sub do
    begin
      first;
      while not eof do
      begin
        if fieldbyname('YJID').AsString='' then
        begin
          if GetLSNo(ADOTemp,maxno,'YJ','OA_YG_LZYJQD',3,1)=False then
          begin
            Application.MessageBox('取主流水号失败!','提示',0);
            Exit;
          end;
        end
        else
        maxno:=trim(fieldbyname('YJID').AsString);
        with ADOTemp do
        begin
          close;
          sql.Clear;
          sql.Add('select * from OA_YG_LZYJQD where YGID='''+Trim(FYGID)+'''');
          sql.add(' and YJID='''+trim(Maxno)+'''');
          open;
          if IsEmpty then append
          else edit;
          fieldbyname('YGID').Value:=trim(FYGID);
          fieldbyname('YJID').Value:=trim(maxno);
          RTSetSaveDataCDS(ADOTemp,Tv1,Order_Sub,'OA_YG_LZYJQD',0);
          post;
        end;
        next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGYPInPut_yijiao.TBSaveClick(Sender: TObject);
var
  FSFNO:String;
begin
  ToolBar1.SetFocus;
  if Trim(YGName.Text)='' then
  begin
    Application.MessageBox('姓名不能为空！','提示',0);
    Exit;
  end;
  if Trim(LiZhiNote.Text)='' then
  begin
    Application.MessageBox('离职原因不能为空!','提示',0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Modalresult:=1;
  end;
end;

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

procedure TfrmYGYPInPut_yijiao.FormDestroy(Sender: TObject);
begin
  FrmYGYPInPut_yijiao:=nil;
end;

procedure TfrmYGYPInPut_yijiao.TaddClick(Sender: TObject);
begin
  with Order_Sub do
  begin
    append;
    post;
  end;
end;

procedure TfrmYGYPInPut_yijiao.TDelClick(Sender: TObject);
begin
  if order_Sub.IsEmpty then exit;
  if application.MessageBox('确定要删除吗','提示',1)=2 then exit;
  with ADOCmd do
  begin
    close;
    sql.Clear;
    sql.Add('delete from OA_YG_LZYJQD where YJID='''+trim(Order_Sub.fieldbyname('YJID').AsString)+'''');
    execsql;
  end;
  order_Sub.Delete;
end;

procedure TfrmYGYPInPut_yijiao.v1YJNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
  with frmZDYHelpSel do
  begin
    flag:='YJName';
    flagname:='物品名称';
    if ShowModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('YJName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_yijiao.v1YJUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
  with frmZDYHelpSel do
  begin
    flag:='YJUnit';
    flagname:='数量单位';
    if ShowModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('YJUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_yijiao.v1JieShouRenPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
  with frmZDYHelpSel do
  begin
    flag:='JieShouRen';
    flagname:='接收人';
    if ShowModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('JieShouRen').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_yijiao.v1JianJiaoRenPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
  with frmZDYHelpSel do
  begin
    flag:='JianJiaoRen';
    flagname:='监交人';
    if ShowModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('JianJiaoRen').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

end.
