unit U_CKProductBCPKCList1;

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, MovePanel, cxCheckBox,
  Menus, cxCalendar, RM_System, RM_Common, RM_Class, RM_GridReport,
  RM_e_Xls, RM_Dataset;

type
  TfrmCKProductBCPKCList1 = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    PRTCodeName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    orderNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label8: TLabel;
    PRTKZ: TEdit;
    Label9: TLabel;
    PRTMF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    MovePanel2: TMovePanel;
    v1Column11: TcxGridDBColumn;
    TBZD: TToolButton;
    v1Column12: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column10: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label4: TLabel;
    Label10: TLabel;
    PRTColor: TComboBox;
    AOrdDefStr1: TComboBox;
    v1Column14: TcxGridDBColumn;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    ToolButton1: TToolButton;
    Label12: TLabel;
    baoNo: TEdit;
    CheckBox1: TCheckBox;
    ComboBox1: TComboBox;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    RM1: TRMGridReport;
    v1Column2: TcxGridDBColumn;
    CustomerNoName: TEdit;
    Label13: TLabel;
    v1Column15: TcxGridDBColumn;
    mjstr4: TEdit;
    RMDBMain: TRMDBDataSet;
    RMDBHZ: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    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 PRTCodeNameChange(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TBZDClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure PRTColorChange(Sender: TObject);
    procedure AOrdDefStr1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
  private
    FLeft,FTop:Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCKProductBCPKCList1: TfrmCKProductBCPKCList1;

implementation
uses
  U_DataLink,U_Fun,U_ProductOrderListSel;

{$R *.dfm}

procedure TfrmCKProductBCPKCList1.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPKCList1:=nil;
end;

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

procedure TfrmCKProductBCPKCList1.FormCreate(Sender: TObject);
begin
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCKProductBCPKCList1.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('exec P_View_CPKCMX :WSQl');
      if Trim(DParameters2)<>'管理' then
      begin
        Parameters.ParamByName('WSQl').Value:=' and B.Filler='''+Trim(DName)+'''';
      end else
      begin
        Parameters.ParamByName('WSQl').Value:='';
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  tbfind.Click;
end;

procedure TfrmCKProductBCPKCList1.TBRafreshClick(Sender: TObject);
begin
 // BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

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

procedure TfrmCKProductBCPKCList1.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('仓库库存列表',Tv1,'成品仓库');
  Close;
end;

procedure TfrmCKProductBCPKCList1.FormShow(Sender: TObject);
begin
  ReadCxGrid('仓库库存列表',Tv1,'成品仓库');
  if Trim(DParameters2)='管理' then
  begin
  //  TBZD.Visible:=True;
    ToolButton1.Visible:=true;
     TBZD.Visible:=False;
    v1Column12.Visible:=true;
  //  v1Column14.Options.Editing:=true;
  end else
  begin
    TBZD.Visible:=False;
    ToolButton1.Visible:=false;
     v1Column12.Visible:=true;
    v1Column14.Options.Editing:=False;
  end;
  InitGrid();
end;

procedure TfrmCKProductBCPKCList1.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('库存列表',cxGrid2);
end;

procedure TfrmCKProductBCPKCList1.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 TfrmCKProductBCPKCList1.PRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPKCList1.Panel10MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND,$F012,0);
end;

procedure TfrmCKProductBCPKCList1.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

procedure TfrmCKProductBCPKCList1.Tv1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft:=X;
  FTop:=Y;
end;

procedure TfrmCKProductBCPKCList1.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  {if Trim(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName)<>'CDQK' then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select CDQK=dbo.F_Get_Order_SubStr(:MJID,''MJCDHZSL'')');
    Parameters.ParamByName('MJID').Value:=Trim(CDS_Main.fieldbyname('MJID').AsString);
    Open;
  end;
  with CDS_Main do
  begin
    Edit;
    FieldByName('CDQK').Value:=Trim(ADOQueryTemp.fieldbyname('CDQK').AsString);
    Post;
  end; }
  Panel4.Left:=FLeft;
  Panel4.Top:=FTop+110;
  Panel4.Visible:=True;
  Panel4.Refresh;
  Panel10.Caption:=Trim(TV1.Controller.FocusedColumn.Caption);

  RichEdit1.Text:=CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmCKProductBCPKCList1.TBZDClick(Sender: TObject);
var
  FMainid,FSubId,FOrderNo,FColor,FSH,FHX,FCodeName,FMPRTMF,FMPRTKZ:String;
begin
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  FMainid:='';
  try
    frmProductOrderListSel:=TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      FFInt:=1;
      if ShowModal=1 then
      begin
        FMainid:=frmProductOrderListSel.Order_Main.fieldbyname('Mainid').AsString;
        FSubId:=frmProductOrderListSel.Order_Main.fieldbyname('SubId').AsString;
        FOrderNo:=frmProductOrderListSel.Order_Main.fieldbyname('OrderNo').Value;
        FCodeName:=frmProductOrderListSel.Order_Main.fieldbyname('PRTCodeName').Value;
        FColor:=frmProductOrderListSel.Order_Main.fieldbyname('PRTColor').Value;
        if Trim(frmProductOrderListSel.Order_Main.fieldbyname('SOrddefstr1').AsString)<>'' then
          FSH:=frmProductOrderListSel.Order_Main.fieldbyname('SOrddefstr1').AsString;
        if Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHX').AsString)<>'' then
          FHX:=frmProductOrderListSel.Order_Main.fieldbyname('PRTHX').Value;
        FMPRTMF:=frmProductOrderListSel.Order_Main.fieldbyname('PRTMF').AsString;
        FMPRTKZ:=frmProductOrderListSel.Order_Main.fieldbyname('PRTKZ').AsString;
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
  if Trim(FMainid)<>'' then
  begin
    if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
    MovePanel2.Visible:=True;
    MovePanel2.Refresh;
    try
      Self.ADOQueryCmd.Connection.BeginTrans;
      Self.CDS_Main.DisableControls;
      with Self.CDS_Main do
      begin
        while not Eof do
        begin
          if Self.CDS_Main.FieldByName('SSEl').AsBoolean=True then
          begin
            with Self.ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('UPdate CK_BanCP_CR Set MainId='''+Trim(FMainid)+'''');
              sql.Add(',SubId='''+Trim(FSubId)+'''');
              sql.Add(',ZDPerson='''+Trim(DName)+''',ZDTime=getdate() ');
              sql.Add(' where CRID='+self.CDS_Main.fieldbyname('CRID').AsString);
              SQL.Add(' and CRType=''检验入库'' ');
              sql.Add('UPdate WFB_MJJY Set MainId='''+Trim(FMainid)+'''');
              sql.Add(',SubId='''+Trim(FSubId)+'''');
              //sql.Add(',ZDPerson='''+Trim(DName)+''',ZDTime=getdate() ');
              sql.Add(' where MJID='+self.CDS_Main.fieldbyname('MJID').AsString);
              ExecSQL;
            end;
            Edit;
            FieldByName('OrderNo').Value:=FOrderNo;
            FieldByName('PRTCodeName').Value:=FCodeName;
            FieldByName('PRTColor').Value:=FColor;
            FieldByName('SOrddefstr1').Value:=FSH;
            FieldByName('PRTHX').Value:=FHX;
            FieldByName('PRTMF').Value:=FMPRTMF;
            FieldByName('PRTKZ').Value:=FMPRTKZ;
            Post;
          end;
          Next;
        end;
      end;
      Self.CDS_Main.EnableControls;
      Self.ADOQueryCmd.Connection.CommitTrans;
      MovePanel2.Visible:=False;
    except
      Self.ADOQueryCmd.Connection.RollbackTrans;
      MovePanel2.Visible:=False;
      Application.MessageBox('转单失败!','提示',0) ;
    end;
  end;
end;

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

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

procedure TfrmCKProductBCPKCList1.Tv1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_Main.IsEmpty=False then
  begin
//    InitOrderColor(Trim(CDS_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
//    InitBCGangNo(Trim(CDS_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmCKProductBCPKCList1.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
  if CDS_Main.IsEmpty=False then
  begin
    //InitOrderColor(Trim(CDS_Main.fieldbyname('MainId').AsString),PRTColor,ADOQueryTemp);
    InitBCGangNo(Trim(CDS_Main.fieldbyname('SubId').AsString),AOrdDefStr1,ADOQueryTemp);
  end;
end;

procedure TfrmCKProductBCPKCList1.AOrdDefStr1Change(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPKCList1.ToolButton1Click(Sender: TObject);
begin
  IF CDS_main.IsEmpty then exit;
  orderNo.SetFocus;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;

  ADOQueryCmd.Connection.BeginTrans;
  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_BanCP_CR ');
            sql.Add('SET baoNO='+quotedstr(CDS_Main.fieldbyname('baoNO').AsString));
            sql.Add('where BCID='+quotedstr(CDS_Main.fieldbyname('BCID').AsString));
            sql.Add('and MJID='+quotedstr(CDS_Main.fieldbyname('MJID').AsString));
            execsql;
          end;
        end;
        next;
      end;
      first;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    application.MessageBox('数据保存成功！','提示信息');
    exit;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('数据保存失败！','提示信息',MB_ICONERROR);
    exit;
  end;
end;

procedure TfrmCKProductBCPKCList1.CheckBox1Click(Sender: TObject);
begin
    with  CDS_Main do
    begin
      DisableControls;
      first;
      while not eof do
      begin
        edit;
        fieldbyname('ssel').Value:=checkbox1.Checked;
        post;
        next;
      end;
      first;
      EnableControls;
    end;
end;

procedure TfrmCKProductBCPKCList1.TBPrintClick(Sender: TObject);
var
  fPrintFile,fPrintFile10,FMainID:String;
begin
  if CDS_Main.IsEmpty then Exit;
  if trim(ComboBox1.Text)='' then exit;
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据','提示',0);
    Exit;
  end;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+trim(ComboBox1.Text)+'.rmf' ;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete TBSubID where DName='''+Trim(DCode)+'''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM TBSubID where 1=2 ');
    open;
  end;
  FMainID:='';
  CDS_Main.DisableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Main do
    begin
    First;
    while not Eof do
    begin
      If Fieldbyname('Ssel').AsBoolean then
      begin
        IF FMainID='' then
        begin
          FMainID:=Trim(CDS_Main.fieldbyname('mainID').AsString);
        end
        else
        begin
          IF Trim(CDS_Main.fieldbyname('mainID').AsString)<>FMainID then
          begin
            application.MessageBox('选择的不是同一个指示单，不能一起打印！','提示信息',0);
            ADOQueryCmd.Connection.RollbackTrans;
            EnableControls;
            exit;
          end;
        end;
          ADOQueryCmd.append;
          ADOQueryCmd.fieldbyname('SubId').Value:=Trim(CDS_Main.fieldbyname('MJID').AsString);
          ADOQueryCmd.fieldbyname('Dname').Value:=Trim(DCode);
          ADOQueryCmd.post;
      end;
      Next;
    end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
  CDS_Main.EnableControls;

      IF (trim(ComboBox1.Text)='销售码单') then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMD ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''2'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  IF (trim(ComboBox1.Text)='单色包装') OR (trim(ComboBox1.Text)='单色包装-长度') then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd20 ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      sql.add(',@CNum=''10'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  IF trim(ComboBox1.Text)='销售码单1' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMD ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''2'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  
  IF (trim(ComboBox1.Text)='销售码单2') then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMD ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''2'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;

  IF trim(ComboBox1.Text)='混色包装-10色' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd30 ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      sql.add(',@CNum=''10'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''1'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;
  IF trim(ComboBox1.Text)='混色包装-重量' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd30 ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''0'' ');
      sql.add(',@CNum=''10'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_HZ);
    SInitCDSData20(ADOQueryTemp,CDS_HZ);

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('exec P_Do_PrintMd_HZ ');
      sql.add('@mainID='+quotedstr(Trim('')));
      sql.add(',@DName='+quotedstr(Trim(DCode)));
      sql.add(',@flag=''1'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,CDS_PRT);
    SInitCDSData20(ADOQueryTemp,CDS_PRT);
  end;



  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+fPrintFile),'提示',0);
  end;
end;


end.
