unit U_SPDJEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, DB, ADODB, cxControls, cxContainer, cxEdit,
  cxTextEdit, cxCurrencyEdit, BtnEdit, StdCtrls, ExtCtrls, cxStyles,
  cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxDBData,
  cxButtonEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, DBClient, cxDropDownEdit, Menus, cxLookAndFeelPainters,
  strUtils, cxButtons, cxImage, cxDBEdit, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, ShellAPI, IdFTP, cxLookAndFeels, cxMemo;

type
  TfrmSPDJEdit = class(TForm)
    ToolBar1: TToolBar;
    TSAVE: TToolButton;
    Tclose: TToolButton;
    ADOQueryTMP: TADOQuery;
    ADOQueryCMD: TADOQuery;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGridPopupMenu2: TcxGridPopupMenu;
    CDS_HZ: TClientDataSet;
    ADOQueryMain: TADOQuery;
    DS_HZ: TDataSource;
    ADOQueryImage: TADOQuery;
    DataSource1: TDataSource;
    Panel1: TPanel;
    Label11: TLabel;
    Label5: TLabel;
    Label2: TLabel;
    Label12: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label13: TLabel;
    Note: TMemo;
    CRTime: TDateTimePicker;
    ywy: TEdit;
    qxkhje: TEdit;
    kkje: TEdit;
    OrderNo: TBtnEditA;
    Label1: TLabel;
    FSTIME: TDateTimePicker;
    fpno: TBtnEditA;
    Panel2: TPanel;
    cxMemo1: TcxMemo;
    jinebz: TComboBox;
    koukbz: TComboBox;
    procedure TcloseClick(Sender: TObject);
    procedure TSAVEClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure qxkhjeKeyPress(Sender: TObject; var Key: Char);

    procedure NoteDblClick(Sender: TObject);

    procedure OrderNoBtnClick(Sender: TObject);
  private
    procedure savedata();
    procedure initdata();

    { Private declarations }
  public
    fkeyNo: string;
    fflag: integer;
    fSYRName: string;
    canshu1: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmSPDJEdit: TfrmSPDJEdit;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZDYHelpSel, U_ZdyAttachment, U_ZdyAttachGYS,
  U_ProductOrderListSel, U_JHDMAKELISTSEL;

{$R *.dfm}

procedure TfrmSPDJEdit.initdata();
begin
  with ADOQueryMain do
  begin
    close;
    sql.clear;
    sql.Add(' select * from KH_LIST ');
    sql.Add(' where KHID=' + quotedstr(trim(fkeyNo)));
    open;
    if not IsEmpty then
    begin
      SCSHDataNew(ADOQueryMain, Panel1, 0);
    end;
  end;
end;

procedure TfrmSPDJEdit.savedata();
begin
  try
    ADOQueryCMD.Connection.BeginTrans;

    with ADOQueryCMD do
    begin
      Close;
      sql.Clear;
      SQL.Add(' select * from KH_LIST where khid=''' + Trim(fkeyNo) + ''' ');
      Open;
    end;
    if ADOQueryCMD.IsEmpty then
    begin
      ADOQueryCMD.Append;
      ADOQueryCMD.FieldByName('Filler').Value := Trim(Dname);
      ADOQueryCMD.FieldByName('khid').Value := Trim(fkeyNo);
    end
    else
    begin
      ADOQueryCMD.Edit;
      ADOQueryCMD.FieldByName('Editer').Value := Trim(Dname);
      ADOQueryCMD.FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTMP);
    end;
    SSetsaveSqlNew(ADOQueryCMD, 'KH_LIST', Panel1, 0);

    ADOQueryCMD.Post;

    ADOquerycmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  except
    ADOquerycmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmSPDJEdit.TcloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmSPDJEdit.TSAVEClick(Sender: TObject);
begin
  savedata();
end;

procedure TfrmSPDJEdit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cahide;
end;

procedure TfrmSPDJEdit.FormDestroy(Sender: TObject);
begin
  frmSPDJEdit := nil;
end;

procedure TfrmSPDJEdit.FormShow(Sender: TObject);
begin
  SClearData(Panel1, 0);
  CRTime.DateTime := SGetServerDate10(adoqueryTmp);
  fsTime.DateTime := SGetServerDate10(adoqueryTmp);
  if Trim(fkeyNo) = '' then
  begin
    if GetLSNo(ADOQueryCMD, fkeyNo, 'BM', 'KH_LIST', 3, 1) = False then
    begin
      ADOQueryCMD.Connection.RollbackTrans;
      Application.MessageBox('取流水号失败!', '提示');
      Exit;
    end;
  end;
  initData();
end;

procedure TfrmSPDJEdit.qxkhjeKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', '.', '-', #8]) then
    Key := #0;
  if (Key = '.') and (Pos('.', Tedit(Sender).Text) > 0) then
    Key := #0;
end;

procedure TfrmSPDJEdit.NoteDblClick(Sender: TObject);
begin
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := 'KSNote';
      flagname := '索赔事件及诉求';
      if ShowModal = 1 then
      begin
        Note.Text := Trim(ReturnStr);
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmSPDJEdit.OrderNoBtnClick(Sender: TObject);
var
  AA: array[0..100] of string;
  i, J, K, Count: Integer;
begin

  try
    frmJHDMAKEListsel := TfrmJHDMAKEListsel.Create(Application);
    with frmJHDMAKEListsel do
    begin
      if ShowModal = 1 then
      begin
        fpno.Text := CDS_Main.fieldbyname('A4FPNO').AsString;
        orderno.Text := CDS_Main.fieldbyname('hZORDERNO').AsString;
        YWY.Text := CDS_Main.fieldbyname('YWY').AsString;
      end;
    end;
  finally
    frmJHDMAKEListsel.Free;
  end;
end;

end.

