unit U_CJDJ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DB, ADODB, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, Vcl.ComCtrls, dxCore, cxDateUtils,
  dxSkinsCore, dxSkinsDefaultPainters, cxTextEdit, cxMaskEdit, cxDropDownEdit,
  cxCalendar, cxButtonEdit;

type
  TfrmCJDJ = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Label1: TLabel;
    CJDate: TcxDateEdit;
    Label3: TLabel;
    Label2: TLabel;
    CJer: TcxButtonEdit;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    CJNote: TRichEdit;
    procedure Button1Click(Sender: TObject);
    procedure BegPortPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    FFFIDS, FBYIOID: string;
    { Public declarations }
  end;

var
  frmCJDJ: TfrmCJDJ;

implementation

uses
  U_ZDYHelp, U_RTFun;


{$R *.dfm}

procedure TfrmCJDJ.BegPortPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TcxButtonEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      MainType := 'SalesCon';
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TcxButtonEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCJDJ.Button1Click(Sender: TObject);
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('update BS_Yarn_IO set CJDate=''' + Trim(FormatDateTime('yyyy-MM-dd', CJDate.Date)) + '''');
      Sql.Add(',CJNote=''' + Trim(CJNote.text) + '''');
      Sql.Add(',CJer=''' + Trim(CJer.text) + '''');
      Sql.Add('where BYIOID=''' + Trim(FBYIOID) + '''');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;

  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), 'ΜαΚΎΠΕΟ’', 0);
  end;
  ModalResult := 1;
end;

procedure TfrmCJDJ.FormShow(Sender: TObject);
begin

  with ADOQueryCmd do
  begin
    Close;
    Sql.Clear;
    Sql.Add('select * from BS_Yarn_IO ');
    Sql.Add('where BYIOID=''' + Trim(FBYIOID) + '''');
//    showmessage(Sql.text);
    Open;
  end;

  if ADOQueryCmd.fieldbyname('CJDate').asstring = '' then
  begin
    CJDate.Date := SGetServerDate(ADOQueryTemp);

  end
  else
  begin
    CJDate.Date := ADOQueryCmd.fieldbyname('CJDate').asdatetime;
    CJNote.text := ADOQueryCmd.fieldbyname('CJNote').asstring;
    CJer.text := ADOQueryCmd.fieldbyname('CJer').asstring;
  end;

end;

end.

