unit U_YGYPInPut_GBLDJ;

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_GBLDJ = 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;
    Label1: TLabel;
    GSBiaoTi: TBtnEditA;
    ZDNote: TMemo;
    Label2: TLabel;
    FBType: TBtnEditA;
    Label3: TLabel;
    Label4: TLabel;
    filler: TEdit;
    filltime: TDateTimePicker;
    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 GSBiaoTiBtnClick(Sender: TObject);
    procedure FBTypeBtnClick(Sender: TObject);
  private
    TPInt:Integer;
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    PState,CopyInt:Integer;
    FCLID,FDeptType:String;
    { Public declarations }
  end;

var
  frmYGYPInPut_GBLDJ: TfrmYGYPInPut_GBLDJ;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_YGYPZZChkList_CLDJ;

{$R *.dfm}

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

procedure TfrmYGYPInPut_GBLDJ.InitData();
var FInt: Integer;
    FDEPT: String;
begin
  with ADOQuery2 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.* from OA_YG_DangAn A ');
    sql.Add('inner join SY_Dept B on A.DPID=B.DPID');
    SQL.Add('where isnull(A.YGEName,YGName)='''+trim(DName)+'''');
    Open;
  end;
  FDEPT:=ADOQuery2.fieldbyname('DPParent').AsString;
  for Fint:=2 to ADOQuery2.fieldbyname('DPlevel').AsInteger-1 do
  begin
    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from SY_Dept where DPID='''+trim(FDEPT)+'''');
      open;
    end;
    FDEPT:=Trim(ADOCmd.fieldbyname('DPParent').AsString);
  end;
  if ADOCmd.IsEmpty=False then
  FDeptType:=trim(ADOCmd.fieldbyname('DPName').asstring);
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from OA_YG_GSGZZD  ');
    sql.add('where ZDID='''+trim(FCLID)+'''');
    Open;
  end;
  if ADOCmd.IsEmpty=False then
  SCSHDataNew(ADOCmd,Panel1,0)
  else
  begin
    filler.Text:=trim(DName);
    filltime.DateTime:=SGetServerDate(ADOTemp);
  end;
  ZDNote.Text:=ADOCmd.fieldbyname('ZDNote').AsString;
end;

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

function TfrmYGYPInPut_GBLDJ.SaveData():Boolean;
var
  maxno:String;
begin
  Result:=False;
  try
    ADOCmd.Connection.BeginTrans;
    if trim(FCLID)='' then
    begin
      if GetLSNo(ADOCmd,FCLID,'ZD','OA_YG_GSGZZD',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_GSGZZD where ZDID='''+Trim(FCLID)+'''');
      Open;
      if isempty then
      begin
        append;
      end
      else
      edit;
      fieldbyname('ZDID').Value:=trim(FCLID);
      fieldbyname('filler').AsString:=trim(filler.Text);
      fieldbyname('filltime').AsDateTime:=filltime.DateTime;
      fieldbyname('DeptType').Value:=trim(FDeptType);
      fieldbyname('GSBiaoTi').Value:=trim(GSBiaoTi.Text);
      fieldbyname('ZDNote').AsString:=trim(ZDNote.Text);
      fieldbyname('FBType').AsString:=trim(FBType.Text);
      post;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYGYPInPut_GBLDJ.TBSaveClick(Sender: TObject);
var
  FSFNO:String;
begin
  ToolBar1.SetFocus;
  if trim(GSBiaoTi.Text)='' then
  begin
    application.MessageBox('发布标题不能为空','提示');
    exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    Modalresult:=1;
  end;
end;

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

procedure TfrmYGYPInPut_GBLDJ.FormDestroy(Sender: TObject);
begin
  frmYGYPInPut_GBLDJ:=nil;
end;

procedure TfrmYGYPInPut_GBLDJ.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_GBLDJ.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_GBLDJ.GSBiaoTiBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='GSBiaoTi';
    flagname:='发布标题';
    if showModal=1 then
    begin
      GSBiaoTi.text:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYGYPInPut_GBLDJ.FBTypeBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='FBType';
    flagname:='发布类型';
    if showModal=1 then
    begin
      FBType.text:=trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

end.
