unit U_BpRklist;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu,
  cxCheckBox, RM_System, RM_Common, RM_Class, RM_GridReport, Menus, MovePanel,
  cxButtons, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmBpRklist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1CRType: TcxGridDBColumn;
    v1CRTime: TcxGridDBColumn;
    v1Filler: TcxGridDBColumn;
    v1FillTime: TcxGridDBColumn;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    P_SPEC: TEdit;
    CRType: TComboBox;
    Label5: TLabel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1CPType: TcxGridDBColumn;
    ckName: TComboBox;
    Label6: TLabel;
    v1P_Color: TcxGridDBColumn;
    v1P_Code: TcxGridDBColumn;
    v1INoutNo: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    kuwei: TEdit;
    Label8: TLabel;
    v1Column2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    v1editer: TcxGridDBColumn;
    v1editTime: TcxGridDBColumn;
    v1DefStr6: TcxGridDBColumn;
    Label9: TLabel;
    factoryName: TEdit;
    v1Column8: TcxGridDBColumn;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    v1Column9: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    btnDelCX: TToolButton;
    btnDelData: TToolButton;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Label7: TLabel;
    P_CF: TEdit;
    Label10: TLabel;
    Label11: TLabel;
    P_CodeName: TEdit;
    KHCPName: TEdit;
    Label12: TLabel;
    P_Color: TEdit;
    Label13: TLabel;
    sehao: TEdit;
    Label14: TLabel;
    KHColor: TEdit;
    Label15: TLabel;
    KHSeHao: TEdit;
    P_Code: TEdit;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    RM2: TRMGridReport;
    CheckBox1: TCheckBox;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label16: TLabel;
    YPLX: TComboBox;
    Tv1Column2: TcxGridDBColumn;
    ComboBox1: TComboBox;
    Tv1Column3: TcxGridDBColumn;
    ToolButton2: TToolButton;
    edt1: TEdit;
    Panel3: TPanel;
    XGPrice: TEdit;
    Label17: TLabel;
    Button3: TButton;
    Button4: TButton;
    Tv1Column8: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure P_SPECChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure btnDelDataClick(Sender: TObject);
    procedure btnDelCXClick(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure XGPriceKeyPress(Sender: TObject; var Key: Char);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetComboBox();
    procedure Setstatus();
    { Private declarations }
  public
    fCKName: string;
    canshu1: string;
    { Public declarations }
  end;

//var
//  frmBpRklist: TfrmBpRklist;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_BpRk, U_BpSmRk;
{$R *.dfm}

procedure TfrmBpRklist.SetStatus();
begin

  TBedit.Visible := false;
  Tbdel.Visible := false;
  Tchk.Visible := false;
  Tnochk.Visible := false;
  btnDelData.Visible := false;
  btnDelCX.Visible := false;

  ToolButton2.Visible := false;

  if (DName = 'ADMIN') or (DName = 'MAOGE') or (DName = 'dsa') then
  begin
    ToolButton2.Visible := true;
  end;
  case cxTabControl1.TabIndex of
    0:
      begin
        TBedit.Visible := true;
        Tbdel.Visible := true;
        if trim(canshu1) = '管理' then
        begin
          Tchk.Visible := true;
        end;
      end;
    1:
      begin
        if trim(canshu1) = '管理' then
        begin
          Tnochk.Visible := true;
        end;
      end;
    2:
      begin
     //  tbcdel.Visible:=true;
      end;
    3:
      begin
        btnDelCX.Visible := true;
        btnDelData.Visible := true;
      end;
  end;

end;

procedure TfrmBpRklist.SetComboBox();
begin
  ckName.Items.Clear;
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''YPCK'' ');
    if trim(fCKName) <> '' then
      sql.Add('and zdyName=' + quotedstr(trim(fCKName)));
    open;
    while not eof do
    begin
      ckName.Items.Add(trim(fieldbyname('zdyName').AsString));
      next;
    end;
  end;
  if ckName.Items.Count > 0 then
    ckName.ItemIndex := 0;

  CRType.Items.Clear;
  CRType.Items.Add('');
  with adoQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_ZDY where Type=''YPRKTYPE''');
    if trim(fCKName) <> '' then
      sql.Add('and note=' + quotedstr(trim(fCKName)));
    open;
    while not eof do
    begin
      CRType.Items.Add(trim(fieldbyname('zdyName').AsString));
      next;
    end;
  end;
  if CRType.Items.Count > 0 then
    CRType.ItemIndex := 0;
end;

procedure TfrmBpRklist.InitGrid();
begin
  try
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select A.*  from YP_InOut2 A');

      sql.Add('where CRTime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
      sql.Add('and CRTime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
      sql.Add('and CRFlag=''入库'' ');
      sql.Add('and valid=''Y'' ');

      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add('and valid=''Y'' and A.status=''0'' ');
          end;
        1:
          begin
            sql.Add('and valid=''Y'' and A.status=''1'' ');
          end;
        2:
          begin
            sql.Add('and valid=''Y''  ');
          end;
        3:
          begin
            sql.Add('and valid=''N''  ');
          end;

      end;
      sql.add('order by filltime desc');
      open;
    end;
    SCreateCDS20(adoqueryTmp, CDS_Main);
    SInitCDSData20(adoqueryTmp, CDS_Main);
  finally
  end;
end;

procedure TfrmBpRklist.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  Action := cafree;
end;

procedure TfrmBpRklist.FormDestroy(Sender: TObject);
begin
//  frmBpRklist := nil;
end;

procedure TfrmBpRklist.TBAddClick(Sender: TObject);
begin
  frmbpRk := TfrmbpRk.create(self);
  with frmbpRk do
  begin
    fkeyNo := '';
    fType := 0;
    fckName := self.fckName;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmBpRklist.P_SPECChange(Sender: TObject);
begin
  if ADOQueryTmp.Active = False then
    Exit;
  SDofilter(ADOQueryTmp, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryTmp, CDS_Main);
  SInitCDSData20(ADOQueryTmp, CDS_Main);
end;

procedure TfrmBpRklist.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption + '1', Tv1, '样品仓库');
//  SetComboBox();
  SetStatus();
  InitGrid();
end;

procedure TfrmBpRklist.FormCreate(Sender: TObject);
begin
  BegDate.Date := DServerDate - 7;
  EndDate.Date := DServerDate;
  cxGrid1.Align := alclient;
end;

procedure TfrmBpRklist.TBCloseClick(Sender: TObject);
begin
  writeCxGrid(self.Caption + '1', Tv1, '样品仓库');
  close;
end;

procedure TfrmBpRklist.TBEditClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  frmbpRk := TfrmbpRk.create(self);
  with frmbpRk do
  begin
    fkeyNo := self.cds_main.fieldbyname('CRNO').AsString;
    fType := 1;
    fckName := self.fckName;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmBpRklist.TBDelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('是否要整单删除？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('update  YP_InOut2 SET valid=''N'' ');
      sql.Add(',editer=' + quotedstr(trim(DName)));
      sql.Add(',edittime=getdate()');
      SQL.Add('where CRID=' + quotedstr(CDS_Main.fieldbyname('CRID').AsString));
      execsql;
    end;
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('exec P_YP_Judge_KC ');
//      Open;
//    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select sum(A.Qty*A.CRQtyFlag)SL FROM  YP_InOut2 A ');

      sql.Add('where Valid=''Y''  AND isnull(FROMOrderno,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('FROMOrderno').AsString)));
      sql.Add('and isnull(frommainid,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('frommainid').AsString)));
      sql.Add('and isnull(fromsubid,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('fromsubid').AsString)));
      sql.Add('and isnull(ywy,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('ywy').AsString)));
      sql.Add('and isnull(Price,0)=' + Trim(CDS_Main.fieldbyname('Price').AsString));
      sql.Add('and isnull(factoryname,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('factoryname').AsString)));
      sql.Add('and isnull(P_Code,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_Code').AsString)));
      sql.Add('and isnull(P_codename,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_codename').AsString)));
      sql.Add('and isnull(P_spec,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_spec').AsString)));
      sql.Add('and isnull(P_cf,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_cf').AsString)));
      sql.Add('and isnull(P_Color,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_Color').AsString)));
      sql.Add('and isnull(P_HX,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_HX').AsString)));
      sql.Add('and isnull(QtyUnit,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('QtyUnit').AsString)));
      sql.Add('and isnull(shazhi,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('shazhi').AsString)));
      sql.Add('and isnull(kuwei,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('kuwei').AsString)));
      sql.Add('and isnull(P_SKZ,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('P_SKZ').AsString)));
      sql.Add('and isnull(YPCFD,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('YPCFD').AsString)));
      sql.Add('and isnull(JuanHao,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('JuanHao').AsString)));
      sql.Add('and isnull(ISCGPZ,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('ISCGPZ').AsString)));
      sql.Add('and isnull(YPType,'''')=' + quotedstr(Trim(CDS_Main.fieldbyname('YPType').AsString)));
      SQL.Add('   group by  FROMOrderno ,frommainid,fromsubid,isnull(A.ywy,''''),A.Price,A.factoryname,A.P_Code,A.P_codename,A.P_spec,A.P_cf,A.P_Color,A.P_HX,A.QtyUnit,A.shazhi,A.kuwei,A.P_SMF,A.P_SKZ,YPCFD,JuanHao,ISCGPZ,YPType');
//      ShowMessage(SQL.Text);
      Open;
    end;
    if ADOQueryCmd.IsEmpty = false then
    begin
      if ADOQueryCmd.FieldByName('SL').VALUE < 0 then
      begin
        ADOQueryCmd.Connection.RollbackTrans;

        Application.MessageBox('产生负数库存操作异常！', '提示', 0);
        exit;
      end;
    end;

//    if Trim(ADOQueryCmd.FieldByName('msg').AsString) = '异常' then
//    begin
//      ADOQueryCmd.Connection.RollbackTrans;
//      Application.MessageBox('已产生出库数据，不能删除！', '提示', 0);
//      exit;
//    end;

    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;

    Application.MessageBox('数据删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpRklist.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmBpRklist.TBPrintClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmBpRklist.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmBpRklist.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  initGrid();
end;

procedure TfrmBpRklist.TchkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  YP_InOut2 SET status=''1'' ');
      sql.Add('where CRNO=' + quotedstr(trim(CDS_Main.fieldbyname('CRNO').AsString)));
      execsql;
    end;
    application.MessageBox('审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpRklist.TnochkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  YP_InOut2 SET status=''0'' ');
      sql.Add('where CRNO=' + quotedstr(trim(CDS_Main.fieldbyname('CRNO').AsString)));
      execsql;
    end;
    application.MessageBox('撤销审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('撤销审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpRklist.btnDelDataClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('是否要删除数据？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete  YP_InOut2 SET where CRID=' + quotedstr(CDS_Main.fieldbyname('CRID').AsString));
      execsql;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;

    Application.MessageBox('数据删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpRklist.btnDelCXClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;

  if Application.MessageBox('是否撤销删除？', '提示', 32 + 4) <> IDYES then
    Exit;

  try

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;

      sql.Add('update  YP_InOut2 SET valid=''Y'' ');
      sql.Add(',editer=' + quotedstr(trim(DName)));
      sql.Add(',edittime=getdate()');
      SQL.Add('where  CRNO=''' + Trim(CDS_Main.fieldbyname('CRNO').AsString) + ''' ');

      execsql;
    end;
    TBRafresh.Click;
  except
    Application.MessageBox('数据撤销删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmBpRklist.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmBpRklist.ToolButton1Click(Sender: TObject);
var
  fPrintFile, FFCYID: string;
  DPS, i, j: Integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if Trim(edt1.Text) <> '' then
  begin
    if TryStrToInt(edt1.Text, j) = False then
    begin
      Application.MessageBox('份数录入错误!', '提示', 0);
      exit;
    end;
  end;
  if CDS_Main.Locate('ssel', true, []) = false then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

//  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\样品入库标签.rmf';
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf';
  CDS_Main.DisableControls;
  i := 1;
  if Trim(edt1.Text) = '' then
  begin
    j := 1;
  end
  else
  begin
    j := StrToInt(edt1.Text);
  end;

  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if CDS_Main.FieldByName('SSel').AsBoolean = True then
      begin
        for i := 1 to j do
        begin
          if FileExists(fPrintFile) then
          begin
            RM2.LoadFromFile(fPrintFile);
            RMVariables['factoryName'] := Trim(CDS_Main.fieldbyname('factoryName').AsString); //来样工厂
            RMVariables['kuwei'] := Trim(CDS_Main.fieldbyname('kuwei').AsString); //库位
            RMVariables['P_Code'] := Trim(CDS_Main.fieldbyname('P_Code').AsString);    //样品编号
            RMVariables['P_CodeName'] := Trim(CDS_Main.fieldbyname('P_CodeName').AsString);    //公司产品名称
            RMVariables['KHCPName'] := Trim(CDS_Main.fieldbyname('KHCPName').AsString);    //客户产品名称
            RMVariables['P_SPEC'] := Trim(CDS_Main.fieldbyname('P_SPEC').AsString);    //工艺
            RMVariables['P_SMF'] := Trim(CDS_Main.fieldbyname('P_SMF').AsString);    //门幅
            RMVariables['P_SKZ'] := Trim(CDS_Main.fieldbyname('P_SKZ').AsString);    //克重
            RMVariables['P_Color'] := Trim(CDS_Main.fieldbyname('P_Color').AsString);    //公司颜色
            RMVariables['sehao'] := Trim(CDS_Main.fieldbyname('sehao').AsString);    //公司色号
            RMVariables['KHColor'] := Trim(CDS_Main.fieldbyname('KHColor').AsString);    //客户颜色
            RMVariables['KHSeHao'] := Trim(CDS_Main.fieldbyname('KHSeHao').AsString);    //客户色号
            RMVariables['Qty'] := Trim(CDS_Main.fieldbyname('Qty').AsString);    //数量
            RMVariables['P_SPEC'] := Trim(CDS_Main.fieldbyname('P_SPEC').AsString);    //工艺
            if CheckBox1.Checked = True then
            begin
              RM2.ShowReport;
            end
            else
            begin
              RM2.PrintReport;
            end;

          end
          else
          begin
            Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf'), '提示', 0);
            Exit;
          end;
          Edit;
          CDS_Main.FieldByName('SSel').Value := false;
        end;
      end;
      Next;
    end;
  end;
  CDS_Main.EnableControls;
  edt1.Text := '1';

end;

procedure TfrmBpRklist.N1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  SelOKNo(CDS_Main, True);
end;

procedure TfrmBpRklist.N2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  SelOKNo(CDS_Main, false);
end;

procedure TfrmBpRklist.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  cxGrid1.Enabled := False;
  Panel3.Visible := True;
  XGPrice.Text := '';

end;

procedure TfrmBpRklist.XGPriceKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', '.', #8]) then
    Key := #0;
  if (Key = '.') and (Pos('.', XGPrice.Text) > 0) then
    Key := #0;
end;

procedure TfrmBpRklist.Button3Click(Sender: TObject);
begin
  if Trim(XGPrice.text) = '' then
  begin
    Application.MessageBox('单价不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改单价吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  Panel3.Visible := False;
  cxGrid1.Enabled := true;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        //修改样品仓库单价
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update  YP_InOut2 SET Price=' + trim(XGPrice.text) + '');
          sql.Add('where CRNO=' + quotedstr(trim(CDS_Main.fieldbyname('CRNO').AsString)));
//          ShowMessage(sql.text);
          ExecSQL;
        end;
        //修改公司产品单价
        if (trim(CDS_Main.fieldbyname('P_Code').AsString) <> '') and (CDS_Main.fieldbyname('XZLX').AsString = '公司产品') then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPDATE ZH_CP_Info set YPPrice =' + trim(XGPrice.text) + '');
            sql.Add('where ZIID =''' + CDS_Main.fieldbyname('P_Code').AsString + '''');
//            ShowMessage(sql.text);
            ExecSQL;
          end;
        end;
        //修改印花或者烫金
        if (trim(CDS_Main.fieldbyname('P_Code').AsString) <> '') and ((CDS_Main.fieldbyname('XZLX').AsString = '印花面料') or (CDS_Main.fieldbyname('XZLX').AsString = '烫金面料')) then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPDATE ML_Manage set YPPrice =' + trim(XGPrice.text) + '');
            sql.Add('where TJML =''' + CDS_Main.fieldbyname('P_Code').AsString + '''');
//            ShowMessage(sql.text);
            ExecSQL;
          end;
        end;
        //修改染色
        if (trim(CDS_Main.fieldbyname('P_Code').AsString) <> '') and (CDS_Main.fieldbyname('XZLX').AsString = '染色面料') then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPDATE ML_Manage set YPPrice =' + trim(XGPrice.text) + '');
            sql.Add('where MLID =''' + CDS_Main.fieldbyname('CPID').AsString + '''');
//            ShowMessage(sql.text);
            ExecSQL;
          end;
        end;
        CDS_Main.Edit;
        CDS_Main.FieldByName('SSel').Value := false;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Exit;
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('修改异常！', '提示', 0);
  end;
  XGPrice.text := '';

end;

procedure TfrmBpRklist.Button4Click(Sender: TObject);
begin
  XGPrice.text := '';
  cxGrid1.Enabled := true;
  Panel3.Visible := False;
end;

end.

