unit U_CGRKInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit,
  ComCtrls, ToolWin, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient, cxButtonEdit,
  cxTextEdit;

type
  TfrmCGRKInPut = class(TForm)
    ToolBar1: TToolBar;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    TBSave: TToolButton;
    TBClose: TToolButton;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v2SPName: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1SPColor: TcxGridDBColumn;
    v1BZSpec: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Qty: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1BZNote: TcxGridDBColumn;
    v1YGName: TcxGridDBColumn;
    v1PRTHX: TcxGridDBColumn;
    v1PRTSeHao: TcxGridDBColumn;
    v1MXKCQty: TcxGridDBColumn;
    v1Money: TcxGridDBColumn;
    v1Price: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBAddClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column14PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column5PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column11PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column13PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure v1Column15PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2SPNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1BZSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1SPColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1SPSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1BZNotePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1YGNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PricePropertiesEditValueChanged(Sender: TObject);
    procedure v2Column6PropertiesEditValueChanged(Sender: TObject);
  private
    { Private declarations }
    function SaveCKData():Boolean;
  public
    { Public declarations }
    FBCId,canshu3:String;

  end;

var
  frmCGRKInPut: TfrmCGRKInPut;

implementation
uses
  U_DataLink,U_RTFun,U_ClothContractListHZCX,U_ZDYHelp, U_ZdyAttachGYS,U_ProductOrderListSel,
  U_ZdyAttachCP, U_BPShengChanListSel;

{$R *.dfm}

procedure TfrmCGRKInPut.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TfrmCGRKInPut.TBAddClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty=False then
  begin
    CopyAddRowCDS(CDS_Sub);
    with CDS_Sub do
    begin
      Edit;
      FieldByName('SPID').Value:=null;
      post;
    end;
  end else
  begin
    with CDS_Sub do
    begin
      Append;
      FieldByName('CRTime').Value:=Trim(FormatDateTime('yyyy-MM-dd',Now));
      Post;
    end;
  end;
end;

function TfrmCGRKInPut.SaveCKData():Boolean;
var
  FCRID,Maxno,FFSPID:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not eof do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
          open;
        end;
        FFSPID:=Trim(ADOQueryTemp.fieldbyname('SPID').AsString);
        if Trim(FFSPID)='' then
        begin
          if GetLSNo(ADOQueryCmd,Maxno,'PR','CK_SXPB_CR',3,1)=False then
          begin
            Result:=False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取车工入库编号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          Maxno:=Trim(FFSPID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID='''+Trim(Maxno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FFSPID)='' then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('SPID').Value:=Trim(Maxno);
          FieldByName('FZSPID').Value:=Trim(Maxno);
          FieldByName('CKName').Value:='车工';
          FieldByName('FactoryNo').Value:=Trim(CDS_Sub.fieldbyname('FactoryNo').AsString);
          FieldByName('FromFactoryNo').Value:=Trim(CDS_Sub.fieldbyname('FromFactoryNo').AsString);
          FieldByName('ToFactoryNo').Value:=Trim(CDS_Sub.fieldbyname('ToFactoryNo').AsString);
          FieldByName('ORDMainIdRK').Value:=Trim(CDS_Sub.fieldbyname('ORDMainIdRK').AsString);
          FieldByName('ORDSubIdRK').Value:=Trim(CDS_Sub.fieldbyname('ORDSubIdRK').AsString);
          FieldByName('CRFlag').Value:='入库';
          FieldByName('CRQtyFlag').Value:=1;
          //FieldByName('CRID').Value:=FCRID;
          RTSetSaveDataCDS(ADOQueryCmd,Tv1,CDS_Sub,'CK_SXPB_CR',2);
          FieldByName('MXKCQty').Value:=CDS_Sub.fieldbyname('MXKCQty').AsFloat;
          FieldByName('Qty').Value:=CDS_Sub.fieldbyname('Qty').AsFloat;
          if Trim(FFSPID)='' then
            FieldByName('Filler').Value:=Trim(DName)
          else
          begin
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDate(ADOQueryTemp);
          end;
          if Trim(CDS_Sub.fieldbyname('OrderNo').AsString)<>'' then
          begin
            FieldByName('QCOrderNo').Value:=Trim(CDS_Sub.fieldbyname('OrderNo').AsString);
          end;
          Post;
        end;
        {with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update CK_SXPB_CR Set MXKCQty=(select sum(isnull(Qty,0)*CRQtyFlag) from CK_SXPB_CR A where A.FZSPID=CK_SXPB_CR.SPID)');
          sql.Add(',MXKCPiQty=(select sum(isnull(PiQty,0)*CRQtyFlag) from CK_SXPB_CR A where A.FZSPID=CK_SXPB_CR.SPID)');
          sql.Add(' where SPID='''+Trim(Maxno)+'''');
          ExecSQL;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID='''+Trim(Maxno)+'''');
          Open;
        end;
        if ADOQueryTemp.FieldByName('MXKCQty').Value<0 then
        begin
          CDS_Sub.DisableControls;
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('入库数小于出库数不能保存!','提示',0);
          Exit;
        end;}
        Edit;
        FieldByName('SPID').Value:=Trim(Maxno);
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except;
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示',0);
  end;
end;

procedure TfrmCGRKInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('车工入库登记FM',Tv1,'车工仓库');
  Close;
end;

procedure TfrmCGRKInPut.FormShow(Sender: TObject);
var
  fsj:String;
begin
  ReadCxGrid('车工入库登记FM',Tv1,'车工仓库');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(',SCOrderNO=(select OrderNO from Cloth_Main JM where JM.MainId=A.SCMainIdRK)');
    sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
    sql.Add(' from CK_SXPB_CR A');
    sql.Add(' where SPID='''+Trim(FBCId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Sub);
  SInitCDSData20(ADOQueryTemp,CDS_Sub);
  if CDS_Sub.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_SXPB_CR where FZSPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
    sql.Add(' and CRQtyFlag=-1');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    v1Column4.Options.Focusing:=False;
    //v1Column15.Options.Focusing:=False;
    v1Column13.Options.Focusing:=False;
    Exit;
  end else
  begin
    v1Column4.Options.Focusing:=True;
    //v1Column15.Options.Focusing:=True;
    v1Column13.Options.Focusing:=True;

  end;
end;

procedure TfrmCGRKInPut.TBDelClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if Trim(CDS_Sub.fieldbyname('SPID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where FZSPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
      sql.Add(' and CRQtyFlag=-1');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      Application.MessageBox('已有出库记录，不能删除!','提示',0);
      Exit;
    end;
    try
      ADOQueryCmd.Connection.BeginTrans;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' delete CK_SXPB_CR where SPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
        ExecSQL;
      end;
      ADOQueryCmd.Connection.CommitTrans;
      CDS_Sub.Delete;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('删除异常!','提示',0);
    end;

  end else
  begin
    CDS_Sub.Delete;
  end;

end;

procedure TfrmCGRKInPut.TBSaveClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if CDS_Sub.Locate('CRTime',null,[])=True then
  begin
    Application.MessageBox('入库时间不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('CRType',null,[])=True then
  begin
    Application.MessageBox('入库类型不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('SPName',null,[])=True then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('Qty',null,[])=True then
  begin
    Application.MessageBox('数量不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('QtyUnit',null,[])=True then
  begin
    Application.MessageBox('数量单位不能为空!','提示',0);
    Exit;
  end;
  if SaveCKData() then
  begin
    Application.MessageBox('保存成功!','提示',0);
    //ModalResult:=1;
    Exit;
  end;
end;

procedure TfrmCGRKInPut.v1Column3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='QtyUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('QtyUnit').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1Column14PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          edit;
          FieldByName('FactoryNo').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyCode').AsString) ;
          FieldByName('FactoryName').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;

end;

procedure TfrmCGRKInPut.v2Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(canshu3)='' then
  begin
    try
      frmZDYHelp:=TfrmZDYHelp.Create(Application);
      with frmZDYHelp do
      begin
        flag:='PBName';
        flagname:='坯布名称';
        if ShowModal=1 then
        begin
          with Self.CDS_Sub do
          begin
            Edit;
            FieldByName('SPName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          end;
        end;
      end;
    finally
      frmZDYHelp.Free;
    end;
  end else
  begin
    try
      frmZdyAttachCP:=TfrmZdyAttachCP.Create(Application);
      with frmZdyAttachCP do
      begin
        if ShowModal=1 then
        begin
          with Self.CDS_Sub do
          begin
            Edit;
            FieldByName('SPName').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('ZdyName').AsString);
            FieldByName('SPSpec').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr1').AsString);
            FieldByName('SPCF').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr2').AsString);
            FieldByName('SPMF').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr7').AsString);
            FieldByName('SPKZ').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr8').AsString);
            FieldByName('SPKZ').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr8').AsString);
            FieldByName('SPCode').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('ZdyCode').AsString);
            FieldByName('CPID').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('ATID').AsString);
          end;
        end;
      end;
    finally
      frmZdyAttachCP.Free;
    end;
  end;

end;

procedure TfrmCGRKInPut.v1Column5PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='KuWei';
      flagname:='库位';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('KuWei').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1Column11PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          edit;
          FieldByName('ToFactoryNo').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyCode').AsString) ;
          FieldByName('ToFactoryName').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmCGRKInPut.v1Column16PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          edit;
          FieldByName('FromFactoryNo').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyCode').AsString) ;
          FieldByName('FromFactoryName').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmCGRKInPut.v1Column13PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmProductOrderListSel:=TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ORDMainIdRK').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MainId').AsString);
          FieldByName('ORDSubIdRK').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('SubId').AsString);
          FieldByName('OrderNo').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('OrderNo').AsString);
          FieldByName('PRTHX').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHX').AsString);
          FieldByName('PRTSeHao').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColorNo').AsString);
          FieldByName('SPName').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCodeName').AsString);
          FieldByName('SPSpec').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTSpec').AsString);
          FieldByName('SPColor').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColor').AsString);
        end;
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
end;

procedure TfrmCGRKInPut.Tv1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if CDS_Sub.IsEmpty then Exit;
end;

procedure TfrmCGRKInPut.v1Column15PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmBPShengChanListSel:=TfrmBPShengChanListSel.Create(Application);
    with frmBPShengChanListSel do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SCMainIdRK').Value:=Trim(frmBPShengChanListSel.Order_Main.fieldbyname('MainId').AsString);
          FieldByName('SCSubIdRK').Value:=Trim(frmBPShengChanListSel.Order_Main.fieldbyname('SubId').AsString);
          FieldByName('SCOrderNo').Value:=Trim(frmBPShengChanListSel.Order_Main.fieldbyname('ConNo').AsString);
          //FieldByName('ORDMainIdRK').Value:=Trim(frmBPShengChanListSel.Order_Main.fieldbyname('OrdMainId').AsString);
          //FieldByName('ORDSubIdRK').Value:=Trim(frmProductOrderListSel.Order_Main.fieldbyname('SubId').AsString);
          fieldbyname('OrderNo').Value:=trim(frmBPShengChanListSel.Order_Main.fieldbyname('OrderNo').AsString);
          fieldbyname('SPName').Value:=trim(frmBPShengChanListSel.Order_Main.fieldbyname('C_CodeName').AsString);
          fieldbyname('SPMF').Value:=trim(frmBPShengChanListSel.Order_Main.fieldbyname('MFQty').AsString);
          fieldbyname('SPKZ').Value:=trim(frmBPShengChanListSel.Order_Main.fieldbyname('KZQty').AsString);
        end;
      end;
    end;
  finally
    frmBPShengChanListSel.Free;
  end;
end;

procedure TfrmCGRKInPut.v2SPNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SPName';
      flagname:='品名';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SPName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1BZSpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BZSpec';
      flagname:='工艺';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('BZSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1SPColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SPColor';
      flagname:='颜色';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SPColor').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1SPSpecPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SPSpec';
      flagname:='尺寸';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SPSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1BZNotePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BZNote';
      flagname:='包装';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('BZNote').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1YGNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CGYGName';
      flagname:='员工';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YGName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGRKInPut.v1PricePropertiesEditValueChanged(Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with CDS_Sub do
  begin
    edit;
    FieldByName('Price').Value:=mavlue;
  end;
  with CDS_Sub do
  begin
    edit;
    FieldByName('Money').Value:=fieldbyname('Qty').AsFloat*fieldbyname('Price').AsFloat;
  end;
end;

procedure TfrmCGRKInPut.v2Column6PropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  with CDS_Sub do
  begin
    edit;
    FieldByName('Qty').Value:=mavlue;
  end;
  with CDS_Sub do
  begin
    edit;
    FieldByName('Money').Value:=fieldbyname('Qty').AsFloat*fieldbyname('Price').AsFloat;
  end;
end;

end.
