unit U_YGYPInPut_YGFJDJ;

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_YGFJDJ = 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;
    Label4: TLabel;
    Label6: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SQName: TEdit;
    SQDay: TEdit;
    SQNote: TMemo;
    Label5: TLabel;
    SQBegDate: TDateTimePicker;
    Label8: TLabel;
    SQEndDate: TDateTimePicker;
    SQType: TBtnEditA;
    TaiTou: TBtnEditA;
    Label7: TLabel;
    SQXH: TEdit;
    Label9: TLabel;
    ZWName: TEdit;
    Label10: TLabel;
    Label11: 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 v1TOPlacePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1WXFactoryPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1WXXianMuPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure SQTypeBtnClick(Sender: TObject);
    procedure TaiTouBtnClick(Sender: TObject);
    procedure SQBegDateChange(Sender: TObject);
  private
    TPInt:Integer;

    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    PState,CopyInt:Integer;
    FCLID:String;
    Canshu1:string;
    { Public declarations }
  end;

var
  frmYGYPInPut_YGFJDJ: TfrmYGYPInPut_YGFJDJ;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_YGYPZZChkList_CLDJ;

{$R *.dfm}

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

procedure TfrmYGYPInPut_YGFJDJ.InitData();
begin
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from OA_YG_CLGLSW  ');
    sql.add('where SWID='''+trim(FCLID)+'''');
    Open;
  end;
  if ADOCmd.IsEmpty then
  begin
    SQName.Text:=trim(DName);
    SQBegDate.DateTime:=now;
    SQEndDate.DateTime:=now;
    SQDay.Text:='0';
  end;
  SCSHDataNew(ADOCmd,Panel1,0);
end;

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

function TfrmYGYPInPut_YGFJDJ.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    if trim(FCLID)='' then
    begin
      if GetLSNo(ADOCmd,FCLID,'SW','OA_YG_CLGLSW',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_CLGLSW where SWID='''+Trim(FCLID)+'''');
      Open;
      if isempty then
      begin
        append;
        fieldbyname('SQStatus').Value:='未提交';
        fieldbyname('filler').AsString:=trim(DName);
        fieldbyname('filltime').AsDateTime:=SGetServerDate(ADOTemp);
      end
      else
      edit;
      fieldbyname('SWID').Value:=trim(FCLID);
      RTSetsavedata(ADOCmd,'OA_YG_CLGLSW',Panel1,0);
      if trim(SQXH.Text)='' then
      fieldbyname('SQXH').Value:='0'
      else
      fieldbyname('SQXH').Value:=trim(SQXH.Text);
      post;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGYPInPut_YGFJDJ.TBSaveClick(Sender: TObject);
var
  FSFNO:String;
begin
  ToolBar1.SetFocus;
  if SQType.Text='' then
  begin
    application.MessageBox('申请类型不能为空','提示');
    exit;
  end;
  if ZWName.Text='' then
  begin
    application.MessageBox('中文姓名不能为空','提示');
    exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Modalresult:=1;
  end;
end;

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

procedure TfrmYGYPInPut_YGFJDJ.FormDestroy(Sender: TObject);
begin
  frmYGYPInPut_YGFJDJ:=nil;
end;

procedure TfrmYGYPInPut_YGFJDJ.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_YGFJDJ.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_YGFJDJ.v1TOPlacePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='TOPlace';
    flagname:='目的地';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('TOPlace').Value:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGFJDJ.v1WXFactoryPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='WXFactory';
    flagname:='维修厂';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('WXFactory').Value:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGFJDJ.v1WXXianMuPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='WXXianMu';
    flagname:='维修项目';
    if showModal=1 then
    begin
      with Order_Sub do
      begin
        edit;
        fieldbyname('WXXianMu').Value:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGFJDJ.SQTypeBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='SWSQType';
    flagname:='申请类型';
    if Self.Canshu1='高权限' then
    begin
      ViewFlag:=false;
    end
    else
    begin
      ViewFlag:=true;
    end;
    if showModal=1 then
    begin
      SQType.Text:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGFJDJ.TaiTouBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='SQTaiTou';
    flagname:='公司抬头';
    if showModal=1 then
    begin
      TaiTou.Text:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_YGFJDJ.SQBegDateChange(Sender: TObject);
begin
  SQDay.Text:=floattostr(SQEndDate.datetime+1-SQBegdate.datetime);
end;

end.
