unit U_ZdyAttInputCP10;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, cxPC, cxControls, ComCtrls, ToolWin, StdCtrls, Menus,
  cxTextEdit, cxCurrencyEdit, BtnEdit, cxContainer, cxEdit, cxImage, DB,
  ADODB;

type
  TfrmZdyAttInputCP10 = class(TForm)
    ToolBar1: TToolBar;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    zdyCode: TEdit;
    Label2: TLabel;
    zdyName: TEdit;
    Label3: TLabel;
    DEFstr1: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    DEFstr2: TEdit;
    DEFstr3: TEdit;
    DEFstr4: TEdit;
    defnote1: TMemo;
    defnote2: TMemo;
    DEFstr5: TComboBox;
    Label13: TLabel;
    cxImage1: TcxImage;
    Label14: TLabel;
    defnote3: TMemo;
    Label15: TLabel;
    DEFstr8: TEdit;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label21: TLabel;
    DEFstr6: TEdit;
    DEFstr7: TEdit;
    DEFstr9: TBtnEditA;
    Label20: TLabel;
    cxImage2: TcxImage;
    Label22: TLabel;
    DEFstr10: TEdit;
    Label23: TLabel;
    Label24: TLabel;
    DEFstr11: TComboBox;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    DEFFlt2: TcxCurrencyEdit;
    DEFFlt5: TcxCurrencyEdit;
    DEFFlt6: TcxCurrencyEdit;
    DEFFlt4: TcxCurrencyEdit;
    DEFFlt7: TcxCurrencyEdit;
    Label28: TLabel;
    DEFFlt8: TcxCurrencyEdit;
    Label29: TLabel;
    DEFFlt9: TcxCurrencyEdit;
    Label30: TLabel;
    DEFFlt10: TcxCurrencyEdit;
    Label31: TLabel;
    DEFFlt11: TcxCurrencyEdit;
    Label32: TLabel;
    DEFFlt12: TcxCurrencyEdit;
    Label33: TLabel;
    DEFFlt13: TcxCurrencyEdit;
    DEFFlt1: TcxCurrencyEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    DEFFlt3: TcxCurrencyEdit;
    DEFDate1: TDateTimePicker;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQueryImage: TADOQuery;
    ADOQuerymain: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    function savedata():Boolean;
    procedure InitGrid();
    { Private declarations }
  public
    FATID:string;
    { Public declarations }
  end;

var
  frmZdyAttInputCP10: TfrmZdyAttInputCP10;

implementation
 uses
  U_DataLink,U_Fun10,U_ZDYHelp;
{$R *.dfm}
function TfrmZdyAttInputCP10.savedata():Boolean;
begin
  result:=false;
  try
    if GetLSNo(ADOQueryCmd,FATID,'AT','KH_Zdy_Attachment',4,1)=False then
    begin
      Result:=False;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from KH_Zdy_Attachment where ATID='''+Trim(FATID)+'''');
      Open;
      If IsEmpty then
      begin
        append;
        FieldByName('Filler').Value:=Trim(DName);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('Edittime').Value:=SGetServerDateTime(ADOQueryTmp);
      end;
      SSetsaveSqlNew(ADOQueryCmd,'KH_Zdy_Attachment',GroupBox1,2);
      SSetsaveSqlNew(ADOQueryCmd,'KH_Zdy_Attachment',GroupBox2,2);
      SSetsaveSqlNew(ADOQueryCmd,'KH_Zdy_Attachment',GroupBox3,2);
      FieldByName('ATID').Value:=Trim(FATID);
      FieldByName('Type').Value:='CP';
      post;
    end;

    result:=true;
  except
  end;
end;
procedure TfrmZdyAttInputCP10.InitGrid();
begin
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_Attachment A');
    sql.Add('where ATID='+quotedstr(trim(FATID)));
    open;
  end;
  IF not ADOQueryMain.IsEmpty then
  begin
    SCSHDataNew(ADOQueryMain,GroupBox1,2);
    SCSHDataNew(ADOQueryMain,GroupBox2,2);
    SCSHDataNew(ADOQueryMain,GroupBox3,2);
  end;
end;

procedure TfrmZdyAttInputCP10.FormDestroy(Sender: TObject);
begin
  frmZdyAttInputCP10:=nil;
end;

procedure TfrmZdyAttInputCP10.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmZdyAttInputCP10.FormCreate(Sender: TObject);
begin
  Panel1.Align:=alclient;
  clearControl(GroupBox1,2);
  clearControl(GroupBox2,2);
  clearControl(GroupBox3,2);
end;

procedure TfrmZdyAttInputCP10.ToolButton3Click(Sender: TObject);
begin
  IF trim(zdyCode.Text)='' then
  begin
    application.MessageBox('产品编号不能为空！','提示信息',MB_ICONERROR);
    exit;
  end;

  AdoqueryCmd.Connection.BeginTrans;
  try
    IF not savedata() then
    begin
      AdoqueryCmd.Connection.RollbackTrans;
    end;
    AdoqueryCmd.Connection.CommitTrans;
  except
    AdoqueryCmd.Connection.RollbackTrans;
  end;
end;

end.
