unit U_DJBRKList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridDBTableView,
  cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxDropDownEdit, cxCheckBox, RM_Common,
  RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, Menus,
  cxCalendar, cxButtonEdit, cxTextEdit, cxPC, BtnEdit;

type
  TfrmDJBRKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    TBDel: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    SPName: TEdit;
    FactoryName: TEdit;
    SPID: TEdit;
    SPSpec: TEdit;
    Label6: TLabel;
    SPCF: TEdit;
    Label7: TLabel;
    OrderNo: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label9: TLabel;
    ToFactoryName: TEdit;
    Label12: TLabel;
    CRType: TComboBox;
    v1Column18: TcxGridDBColumn;
    Label10: TLabel;
    KuWei: TEdit;
    v1Column19: TcxGridDBColumn;
    Label11: TLabel;
    RCGangNo: TEdit;
    Label13: TLabel;
    PRTColor: TEdit;
    Label14: TLabel;
    SOrddefstr1: TEdit;
    Label15: TLabel;
    PRTHX: TEdit;
    v1Column20: TcxGridDBColumn;
    prtkuanNo: TEdit;
    Label16: TLabel;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    TBCHK: TToolButton;
    TBNOchk: TToolButton;
    cxTabControl1: TcxTabControl;
    v1Column24: TcxGridDBColumn;
    v1Column25: TcxGridDBColumn;
    Panel5: TPanel;
    Label28: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label24: TLabel;
    Button5: TButton;
    Button6: TButton;
    factoryName1: TBtnEditA;
    Com_CRype: TComboBox;
    Button1: TButton;
    edit_defstr2: TEdit;
    edit_gangNo: TEdit;
    Button2: TButton;
    Button3: TButton;
    edit_note: TEdit;
    Button4: TButton;
    TBTSedit: TToolButton;
    v1Column26: TcxGridDBColumn;
    defstr2: TEdit;
    Label20: TLabel;
    note: TEdit;
    Label21: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure SPIDKeyPress(Sender: TObject; var Key: Char);
    procedure SPIDChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure TBCHKClick(Sender: TObject);
    procedure TBNOchkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure factoryName1BtnClick(Sender: TObject);
    procedure TBTSeditClick(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure defstr2KeyPress(Sender: TObject; var Key: Char);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    Procedure setstatus();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDJBRKList: TfrmDJBRKList;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut, U_ZdyAttachGYS;

{$R *.dfm}
Procedure TfrmDJBRKList.setstatus();
begin
  TBedit.Visible:=false;
  TBdel.Visible:=false;
  TBchk.Visible:=false;
  TBNochk.Visible:=false;
  TBTSedit.Visible:=false;
  IF canshu1='高权限'then
  begin

    case cxTabControl1.TabIndex of
      0:
      begin
        TBedit.Visible:=true;
        TBdel.Visible:=true;
        TBchk.Visible:=true;
        TBTSedit.Visible:=true;
      end;
      1:
      begin
        TBNochk.Visible:=True;
        TBTSedit.Visible:=true;
      end;

    end;
  end
  else
  begin
    case cxTabControl1.TabIndex of
      0:
      begin
        TBedit.Visible:=true;
        TBdel.Visible:=true;
     //   TBchk.Visible:=true;
      end;
      1:
      begin
      //  TBNochk.Visible:=True;
      end;

    end;
  end;
end;

procedure TfrmDJBRKList.FormDestroy(Sender: TObject);
begin
  frmDJBRKList:=nil;
end;

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

procedure TfrmDJBRKList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime;
end;

procedure TfrmDJBRKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ,AvgQty=case when piQty<>0 then cast(Qty/piQty as decimal(18,2)) else 0 end');
      sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
      sql.Add(' ,SOrddefstr1=(select SOrddefstr1 from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' ,PRTColor=(select PRTColor from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' ,PRTkuanNo=(select PRTkuanNo from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' ,PRTHX=(select PRTHX from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' where A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
      sql.Add(' and A.CRTime<='''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''');
      sql.Add(' and isnull(CKName,'''')=''待检布''');
      SQL.Add(' and CRFlag=''入库''  ');
      IF cxTabControl1.TabIndex<2 then
      SQL.Add(' and isnull(A.chkstatus,''0'')='''+inttostr(cxTabControl1.TabIndex)+''' ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmDJBRKList.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

procedure TfrmDJBRKList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  end;
end;

procedure TfrmDJBRKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('待检布入库列表',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDJBRKList.FormShow(Sender: TObject);
begin
  if Trim(canshu2)='查看' then
  begin
    TBAdd.Visible:=False;
    TBDel.Visible:=False;
    TBEdit.Visible:=False;
  end else
  begin
    TBAdd.Visible:=True;
    TBDel.Visible:=True;
    TBEdit.Visible:=True;
  end;
  ReadCxGrid('待检布入库列表',Tv1,'待检布仓库');
  setstatus();
 // InitGrid();
end;

procedure TfrmDJBRKList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('待检布入库列表',cxGrid2);
end;

procedure TfrmDJBRKList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmDJBRKList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmDJBRKList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;

procedure TfrmDJBRKList.TBDelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if Trim(CDS_Main.fieldbyname('SPID').AsString)<>'' then
  begin
    if Trim(CDS_Main.fieldbyname('CRType').AsString)='平移入库' then
    begin
      Application.MessageBox('平移入库的数据为自动生成，不能删除!','提示',0);
      Exit;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where FZSPID='''+Trim(CDS_Main.fieldbyname('SPID').AsString)+'''');
      sql.Add(' and CRQtyFlag=-1');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      Application.MessageBox('已有出库记录，不能删除!','提示',0);
      Exit;
    end;
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    try
      ADOQueryCmd.Connection.BeginTrans;

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' delete CK_SXPB_CR where SPID='''+Trim(CDS_Main.fieldbyname('SPID').AsString)+'''');
        {sql.Add('Update CK_SXPB_KC Set KCKGQty=(select sum(isnull(KGQty,0)*CRQtyFlag) from CK_SXPB_CR A where A.CRID=CK_SXPB_KC.CRID)');
        sql.Add(',KCPiQty=(select sum(isnull(PiQty,0)*CRQtyFlag) from CK_SXPB_CR A where A.CRID=CK_SXPB_KC.CRID)');
        sql.Add(' where CRID='+Trim(CDS_Main.fieldbyname('CRID').AsString));}
        ExecSQL;
      end;
     { with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select KCKGQty=isnull(KCKGQty,0) from CK_SXPB_KC where CRID='+Trim(CDS_Main.fieldbyname('CRID').AsString));
        Open;
      end;
      if ADOQueryTemp.IsEmpty=False then
      begin
        if ADOQueryTemp.FieldByName('KCKGQty').Value<0 then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('入库公斤数小于出库公斤数不能删除!','提示',0);
          Exit;
        end;
      end;  }

      ADOQueryCmd.Connection.CommitTrans;
      CDS_Main.Delete;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('删除异常!','提示',0);
    end;

  end else
  begin
    CDS_Main.Delete;
  end;
end;

procedure TfrmDJBRKList.TBAddClick(Sender: TObject);
begin
  try
    frmDJBCKInPut:=TfrmDJBCKInPut.Create(Application);
    with frmDJBCKInPut do
    begin
      FBCId:='';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmDJBCKInPut.Free;
  end;
end;

procedure TfrmDJBRKList.TBEditClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if Trim(CDS_Main.fieldbyname('CRType').AsString)='平移入库' then
  begin
    Application.MessageBox('平移入库的数据为自动生成，不能修改!','提示',0);
    Exit;
  end;
  try
    frmDJBCKInPut:=TfrmDJBCKInPut.Create(Application);
    with frmDJBCKInPut do
    begin
      FBCId:=Trim(CDS_Main.fieldbyname('SPID').AsString);
      TBDel.Visible:=False;
      TBAdd.Visible:=False;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmDJBCKInPut.Free;
  end;
end;

procedure TfrmDJBRKList.SPIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    {if Length(Trim(SPID.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(',ConNo=(select ConNo from Contract_Main CM where CM.MainId=A.CGMainId)');
        //sql.Add(' ,ConNo=(select ConNo from Contract_Main CM where CM.MainId=A.CGMainId )');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where SPID like :SXID');
        Parameters.ParamByName('SXID').Value:='%'+Trim(SXID.Text)+'%';
        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end; }
  end;
end;

procedure TfrmDJBRKList.SPIDChange(Sender: TObject);
begin
  if Length(Trim(SPID.Text))<4 then
  begin
    if Trim(SPID.Text)<>'' then Exit;
  end;
  TBFind.Click;
end;

procedure TfrmDJBRKList.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  IF trim(OrderNo.Text)='' then exit;
  IF Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        Filtered:=False;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
        sql.Add(' ,SOrddefstr1=(select SOrddefstr1 from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' ,PRTColor=(select PRTColor from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' ,PRTkuanNo=(select PRTkuanNo from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' ,PRTHX=(select PRTHX from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where exists(select MainID from JYOrder_Main X where X.mainID=A.ORDMainIdRK and X.orderNo like '+quotedstr('%'+trim(OrderNo.text)+'%')+')');
        sql.Add(' and isnull(CKName,'''')=''待检布''');
        SQL.Add(' and CRFlag=''入库''  ');
        IF cxTabControl1.TabIndex<2 then
        SQL.Add(' and isnull(A.chkstatus,''0'')='''+inttostr(cxTabControl1.TabIndex)+''' ');
        Open;
      //ShowMessage(SQL.Text);
        end;
        SCreateCDS20(ADOQueryMain,CDS_Main);
        SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmDJBRKList.TBCHKClick(Sender: TObject);
begin
 if CDS_Main.IsEmpty then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    with CDS_Main do
    begin
      DisableControls;
      while not eof do
      begin
        IF fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update  CK_SXPB_CR SET chkstatus=''1'',chker='''+trim(DName)+''',chkTime=getdate() ');
            sql.Add('where SPID='+quotedstr(trim(CDS_Main.fieldbyname('SPID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      EnableControls;
    end;
    application.MessageBox('审核成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('审核失败！','提示信息',0);
  end;
end;

procedure TfrmDJBRKList.TBNOchkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    with CDS_Main do
    begin
      DisableControls;
      while not eof do
      begin
        IF fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update CK_SXPB_CR SET chkstatus=''0'',chker='''+trim(DName)+''',chkTime=getdate() ');
            sql.Add('where SPID='+quotedstr(trim(CDS_Main.fieldbyname('SPID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      EnableControls;
    end;
    application.MessageBox('撤销审核成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('撤销审核失败！','提示信息',0);
  end;
end;

procedure TfrmDJBRKList.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  InitGrid();

end;

procedure TfrmDJBRKList.Button5Click(Sender: TObject);
begin
  IF CDS_Main.IsEmpty then exit;
  IF  trim(factoryName1.Text)='' then
  begin
    application.MessageBox('加工厂不能为空！','提示信息',0);
    exit;
  end;
  if Application.MessageBox('确定要修改加工厂吗？','提示',32+4)<>IDYES then Exit;
  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('update CK_SXPB_CR SET factoryName='''+trim(factoryName1.Text)+''' where SPID='''+Trim(CDS_Main.fieldbyname('SPID').AsString)+'''');
    //  sql.Add('update WFB_MJJY SET factoryName='''+trim(factoryName1.Text)+''' where APID='''+Trim(CDS_Main.fieldbyname('SPID').AsString)+'''');
      ExecSQL;
    end;
    Application.MessageBox('保存成功!','提示',0);
    Panel5.Visible:=false;
    TBRafresh.Click;
  except
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmDJBRKList.Button1Click(Sender: TObject);
begin
  IF CDS_Main.IsEmpty then exit;
  IF  trim(Com_CRype.Text)='' then
  begin
    application.MessageBox('入库类型不能为空！','提示信息',0);
    exit;
  end;
  if Application.MessageBox('确定要修改入库类型吗？','提示',32+4)<>IDYES then Exit;
  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('update CK_SXPB_CR SET CRType='''+trim(Com_CRype.Text)+''' where SPID='''+Trim(CDS_Main.fieldbyname('SPID').AsString)+'''');
      ExecSQL;
    end;
    Application.MessageBox('保存成功!','提示',0);
    Panel5.Visible:=false;
    TBRafresh.Click;
  except
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmDJBRKList.factoryName1BtnClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
         factoryName1.Text:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmDJBRKList.TBTSeditClick(Sender: TObject);
begin
  factoryName1.Text:='';
  Com_CRype.Text:='';
  edit_defstr2.Text:='';
  edit_gangNo.Text:='';
  edit_note.Text:='';
  Panel5.Left:=(self.Width-Panel5.Width) div 2;
  Panel5.Visible:=true;
end;

procedure TfrmDJBRKList.Button6Click(Sender: TObject);
begin
  Panel5.Visible:=false;
end;

procedure TfrmDJBRKList.Button2Click(Sender: TObject);
begin
 IF CDS_Main.IsEmpty then exit;
  IF  trim(edit_defstr2.Text)='' then
  begin
    application.MessageBox('统计单号不能为空！','提示信息',0);
    exit;
  end;
  if Application.MessageBox('确定要修改统计单号吗？','提示',32+4)<>IDYES then Exit;
  try
    with CDS_Main do
    begin
      DisableControls;
      first;
      while not eof do
      begin
        IF fieldbyName('Ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update CK_SXPB_CR SET defstr2='''+trim(edit_defstr2.Text)+''' where SPID='''+Trim(CDS_Main.fieldbyname('SPID').AsString)+'''');
            ExecSQL;
          end;
        end;
        next;
      end;
      EnableControls;
    end;

    Application.MessageBox('保存成功!','提示',0);
    Panel5.Visible:=false;
    TBRafresh.Click;
  except
    Application.MessageBox('保存失败!','提示',0);
  end;
end;

procedure TfrmDJBRKList.defstr2KeyPress(Sender: TObject; var Key: Char);
begin
  IF trim(defstr2.Text)='' then exit;
  IF Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        Filtered:=False;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
        sql.Add(' ,SOrddefstr1=(select SOrddefstr1 from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' ,PRTColor=(select PRTColor from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' ,PRTkuanNo=(select PRTkuanNo from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' ,PRTHX=(select PRTHX from JYOrder_Sub JM where JM.SubId=A.OrdSubIdRK )');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where A.defstr2 like '+quotedstr('%'+trim(OrderNo.text)+'%'));
        sql.Add(' and isnull(CKName,'''')=''待检布''');
        SQL.Add(' and CRFlag=''入库''  ');
        IF cxTabControl1.TabIndex<2 then
        SQL.Add(' and isnull(A.chkstatus,''0'')='''+inttostr(cxTabControl1.TabIndex)+''' ');
        Open;
      //ShowMessage(SQL.Text);
        end;
        SCreateCDS20(ADOQueryMain,CDS_Main);
        SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

end.
