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, dxSkinOffice2013White, dxSkinSharpPlus, dxSkinWXI;

type
  TfrmCJDJ = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Label1: TLabel;
    CJDate: TcxDateEdit;
    Label3: TLabel;
    Label2: TLabel;
    CJer: TcxButtonEdit;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    CJNote: TRichEdit;
    CJQuantitly: TLabeledEdit;
    Label4: TLabel;
    CJJL: TcxComboBox;
    Label5: TLabel;
    SZ: TCheckBox;
    Label6: TLabel;
    QL: TCheckBox;
    TG: TCheckBox;
    MJ: TCheckBox;
    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
  if (Trim(CJJL.Text) = '不合格') and (not SZ.Checked and not QL.Checked and not TG.Checked and not MJ.Checked) then
  begin
    Application.MessageBox('请填写内容！', '提示', MB_ICONWARNING);
    Exit;
  end;
  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(',CJQuantitly=''' + Trim(CJQuantitly.text) + '''');
      Sql.Add(',CJJL=''' + Trim(CJJL.text) + '''');
      Sql.Add(',SZ=''' + IntToStr(Ord(SZ.Checked)) + '''');
      Sql.Add(',QL=''' + IntToStr(Ord(QL.Checked)) + '''');
      Sql.Add(',TG=''' + IntToStr(Ord(TG.Checked)) + '''');
      Sql.Add(',MJ=''' + IntToStr(Ord(MJ.Checked)) + '''');
      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) + '''');
    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;
    CJQuantitly.text := ADOQueryCmd.fieldbyname('CJQuantitly').asstring;
    CJJL.text := ADOQueryCmd.fieldbyname('CJJL').asstring;
    SZ.Checked := (ADOQueryCmd.fieldbyname('SZ').AsString = '1') or (ADOQueryCmd.fieldbyname('SZ').AsBoolean);
    QL.Checked := (ADOQueryCmd.fieldbyname('QL').AsString = '1') or (ADOQueryCmd.fieldbyname('QL').AsBoolean);
    TG.Checked := (ADOQueryCmd.fieldbyname('TG').AsString = '1') or (ADOQueryCmd.fieldbyname('TG').AsBoolean);
    MJ.Checked := (ADOQueryCmd.fieldbyname('MJ').AsString = '1') or (ADOQueryCmd.fieldbyname('MJ').AsBoolean);
  end;
end;

end.

