unit U_YGYPInPut_YGDJ;

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_YGDJ = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    TBSave: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ADOQuery2: TADOQuery;
    Panel1: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    YGName: TEdit;
    filltime: TDateTimePicker;
    FLNote: TMemo;
    Label5: TLabel;
    Label1: TLabel;
    FLMoney: TEdit;
    FLType: TBtnEditA;
    Label2: TLabel;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure v1BGUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1CLNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FLTypeBtnClick(Sender: TObject);
  private
    TPInt:Integer;
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    PState,CopyInt:Integer;
    FCLID,FDeptType:String;
    { Public declarations }
  end;

var
  frmYGYPInPut_YGDJ: TfrmYGYPInPut_YGDJ;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_YGYPZZChkList_CLDJ;

{$R *.dfm}

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

procedure TfrmYGYPInPut_YGDJ.InitData();
var FInt: Integer;
    FDEPT: String;
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from OA_YG_GSFL ');
    sql.add('where FLID='''+trim(FCLID)+'''');
    Open;
  end;
  if ADOCmd.IsEmpty=False then
  begin
    SCSHDataNew(ADOCmd,Panel1,0);
  end
  else
  begin
    filltime.DateTime:=SGetServerDate(ADOTemp);
  end;
end;

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

function TfrmYGYPInPut_YGDJ.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    if trim(FCLID)='' then
    begin
      if GetLSNo(ADOCmd,FCLID,'FL','OA_YG_GSFL',4,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from OA_YG_GSFL where FLID='''+Trim(FCLID)+'''');
      Open;
      if isempty then
      begin
        append;
      end
      else
      edit;
      fieldbyname('FLID').Value:=trim(FCLID);
      fieldbyname('filler').AsString:=trim(DName);
      fieldbyname('filltime').AsDateTime:=filltime.DateTime;
      RTSetsavedata(ADOCmd,'OA_YG_GSFL',Panel1,0);
      if FLMoney.Text='' then
      fieldbyname('FLMoney').AsFloat:=0;
      post;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGYPInPut_YGDJ.TBSaveClick(Sender: TObject);
var
  FSFNO:String;
begin
  ToolBar1.SetFocus;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Modalresult:=1;
  end;
end;

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

procedure TfrmYGYPInPut_YGDJ.FormDestroy(Sender: TObject);
begin
  frmYGYPInPut_YGDJ:=nil;
end;

procedure TfrmYGYPInPut_YGDJ.v1BGUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='BGUnit';
    flagname:='数量单位';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('BGUnit').Value:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGDJ.v1CLNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='CLName';
    flagname:='车辆名称';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('CLName').Value:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGDJ.FLTypeBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='FLType';
    flagname:='福利类型';
    if ShowModal=1 then
    begin
      FLType.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

end.
