unit U_JGSet;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DB, ADODB, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, 
    cxTextEdit, cxMaskEdit, cxButtonEdit;

type
  TfrmJGSet = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Label1: TLabel;
    BCPH: TEdit;
    ADOQueryTemp: TADOQuery;
    Label2: TLabel;
    NewPrice: TEdit;
    ADOQueryCmd: TADOQuery;
    lbl6: TLabel;
    SX_Supplier: TcxButtonEdit;
    SX_SupplierNo: TcxButtonEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SX_SupplierPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
  private
    { Private declarations }
  public
    FY_Code: string;
    { Public declarations }
  end;

var
  frmJGSet: TfrmJGSet;

implementation

uses
  U_DataLink, U_RTFun, U_CompanySel;

{$R *.dfm}

procedure TfrmJGSet.Button1Click(Sender: TObject);
var
  JGID: string;
begin

  if Trim(SX_Supplier.text) = '' then
  begin
    Application.MessageBox('供应商不能为空!', '提示', 0);
    Exit;
  end;

  if Trim(BCPH.text) = '' then
  begin
    Application.MessageBox('本厂批号不能为空!', '提示', 0);
    Exit;
  end;

  if Trim(NewPrice.text) = '' then
  begin
    Application.MessageBox('价格不能为空!', '提示', 0);
    Exit;
  end;

  if GetLSNo(ADOQueryCmd, JGID, 'JG', 'BS_Yarn_Info_Price', 4, 1) = False then
    raise Exception.Create('取最大号失败！');

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('INSERT INTO Bs_Yarn_Info_Price(JGID,Y_Code,NewPrice,BCPH,Filler,SX_Supplier,SX_SupplierNo) VALUES(');
    sql.Add(' ' + quotedstr(JGID));
    sql.Add(',' + quotedstr(FY_Code));
    sql.Add(',' + trim(NewPrice.text));
    sql.Add(',' + quotedstr(BCPH.text));
    sql.Add(',' + quotedstr(Trim(DName)));
    sql.Add(',' + quotedstr(SX_Supplier.text));
    sql.Add(',' + quotedstr(SX_SupplierNo.text));
    sql.Add(')');

    sql.Add(' UPDATE Bs_Yarn_Info set ');
    sql.Add(' SXPrice = ' + trim(NewPrice.text) + '');
    sql.Add(',BCPH = ''' + trim(BCPH.text) + '''');
    sql.Add(',SX_Supplier = ''' + trim(SX_Supplier.text) + '''');
    sql.Add(',SX_SupplierNo = ''' + trim(SX_SupplierNo.text) + '''');
    sql.Add(',PurDate =CONVERT(VARCHAR(10),getdate(),120) ');
    sql.Add(' where Y_Code=''' + Trim(FY_Code) + '''');
//  ShowMessage(sql.text);
    ExecSQL;
  end;

  ModalResult := 1;
end;

procedure TfrmJGSet.FormShow(Sender: TObject);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select top 1 A.*  from  Bs_Yarn_Info_Price A  where A.Y_Code=' + quotedstr(Trim(FY_Code)));
    SQL.Add(' order by A.Filltime desc');
    Open;
  end;

  BCPH.text := Trim(ADOQueryTemp.fieldbyname('BCPH').AsString);
  NewPrice.text := Trim(ADOQueryTemp.fieldbyname('NewPrice').AsString);

  SX_Supplier.text := Trim(ADOQueryTemp.fieldbyname('SX_Supplier').AsString);
  SX_SupplierNo.text := Trim(ADOQueryTemp.fieldbyname('SX_SupplierNo').AsString);
end;

procedure TfrmJGSet.SX_SupplierPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '供应商';
      if ShowModal = 1 then
      begin
        SX_Supplier.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString);
        SX_SupplierNo.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString);
      end;
    end;

  finally
    frmCompanySel.Free;
  end;
end;

end.

