unit U_YarnInput;

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,
  cxDBEdit, cxLookAndFeelPainters, cxButtons, strUtils;

type
  TfrmYarnInput = class(TForm)
    ToolBar1: TToolBar;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuerymain: TADOQuery;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label11: TLabel;
    Y_Code: TEdit;
    Y_CodeName: TEdit;
    Y_CF: TEdit;
    Y_Spec: TMemo;
    procedure FormDestroy(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    function savedata(): Boolean;
    procedure InitGrid();
 
    { Private declarations }
  public
    FCYID: string;
    fFlileFlag: string;
    CopyInt: Integer;
    { Public declarations }
  end;

var
  frmYarnInput: TfrmYarnInput;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;
{$R *.dfm}

function TfrmYarnInput.savedata(): Boolean;
begin
  result := false;
  try
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BS_SX_YDang where ATID=''' + Trim(FCYID) + '''');
      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, 'BS_SX_YDang', Panel1, 2);
      FieldByName('ATID').Value := Trim(FCYID);
      FieldByName('Y_Type').Value := 'SX';
      post;
    end;

    result := true;
  except
  end;
end;

procedure TfrmYarnInput.InitGrid();
begin
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from BS_SX_YDang A');
    sql.Add('where ATID=' + quotedstr(trim(FCYID)));
    open;
  end;
  if not ADOQueryMain.IsEmpty then
  begin
    SCSHDataNew(ADOQueryMain, Panel1, 2);
  end;
end;

procedure TfrmYarnInput.FormDestroy(Sender: TObject);
begin
  frmYarnInput := nil;
end;

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

procedure TfrmYarnInput.FormCreate(Sender: TObject);
begin
  Panel1.Align := alclient;
  clearControl(Panel1, 2);
end;

procedure TfrmYarnInput.ToolButton3Click(Sender: TObject);
begin
  if trim(Y_Code.Text) = '' then
  begin
    application.MessageBox('产品ID不能为空！', '提示信息', MB_ICONERROR);
    exit;
  end;
  if trim(Y_CodeName.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;
    application.MessageBox('保存成功！', '提示信息');
    self.ModalResult := 1;
  except
    AdoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('保存失败！', '提示信息', MB_ICONERROR);
  end;
end;

procedure TfrmYarnInput.FormShow(Sender: TObject);
begin
  initGrid();
  if CopyInt = 99 then
  begin
    FCYID := '';
  end;
  if FCYID = '' then
  begin
    if GetLSNo(ADOQueryCmd, FCYID, 'SX', 'BS_SX_YDang', 4, 1) = False then
    begin
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;
    Y_Code.Text := trim(FCYID);
  end;
end;

end.

