unit U_ProductOrderNewList_PB;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, ComObj, dxBarBuiltInMenu,
  cxPC, cxContainer, cxImage, cxDBEdit, 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
  FdDy = record
    inc: integer; //客户端套接字句柄
    FDdys: string[32]; //客户端套接字
    FdDysName: string[32]; //客户端套接字
  end;

  TfrmProductOrderNewList_PB = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RMXLSExport1: TRMXLSExport;
    Label4: TLabel;
    CustomerNoName: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Label8: TLabel;
    SYRName: TEdit;
    Label9: TLabel;
    ConNo: TEdit;
    Label10: TLabel;
    MPRTJiBenNote: TEdit;
    Label11: TLabel;
    OrdPerson2: TEdit;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ToolButton3: TToolButton;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    TFJ: TToolButton;
    RMDBMain: TRMDBDataSet;
    RM1: TRMGridReport;
    ToolButton4: TToolButton;
    OpenDialog1: TOpenDialog;
    N1: TMenuItem;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    Panel2: TPanel;
    Button2: TButton;
    Button3: TButton;
    Label2: TLabel;
    Edit1: TEdit;
    Label5: TLabel;
    prtcode: TEdit;
    ADOQuery1: TADOQuery;
    cxTabControl1: TcxTabControl;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    Panel3: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2PRTCode: TcxGridDBColumn;
    V2PRTCodeName: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    V2PRTMF: TcxGridDBColumn;
    V2PRTKZ: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1SOrddefstr2: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxSOrdDefNote1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ADOQueryImageYS: TADOQuery;
    DSImage: TDataSource;
    CDS_Sub: TClientDataSet;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    TV2Column5: TcxGridDBColumn;
    TV2Column6: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    Panel4: TPanel;
    Label6: TLabel;
    Button1: TButton;
    Button4: TButton;
    Edit2: TEdit;
    TV2Column8: TcxGridDBColumn;
    TV2Column9: TcxGridDBColumn;
    Label7: TLabel;
    DlyDate: TDateTimePicker;
    Label3: TLabel;
    OrderNo: TEdit;
    DateTimePicker1: TDateTimePicker;
    Label12: TLabel;
    ZOrderNo: TEdit;
    TV2Column10: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure TBTPClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure v1DeliveryDateCustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure TFJClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure DlyDateChange(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();              
    function DelData(): Boolean;
    procedure InitGridFH();
    procedure InitSub();
    procedure CJEWM(FMainid: string; FSubid: string);
    procedure InitImageYS(fwbid: string);
    procedure SelExportDatae(FTv: TcxGridDBTableView; CDS_Sub: TClientDataSet; FTile: string);
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmProductOrderNewList_PB: TfrmProductOrderNewList_PB;
  dFdDy: array[0..120] of FdDy;

implementation

uses
  U_DataLink, U_OrderInPut, U_Fun, U_FjList_RZ, U_SelExportField;

{$R *.dfm}
procedure TfrmProductOrderNewList_PB.InitSub();
begin
//  ADOQuerySub.Close;
  if Order_Main.IsEmpty then
    exit;
  with ADOQuerySub do
  begin
    close;
    sql.Clear;
    sql.Add('select * from JYOrder_sub ');
    sql.Add('where mainID =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    open;
  end;
  SCreateCDS20(ADOQuerySub, CDS_Sub);
  SInitCDSData20(ADOQuerySub, CDS_Sub);
end;

procedure TfrmProductOrderNewList_PB.FormDestroy(Sender: TObject);
begin
  frmProductOrderNewList_PB := nil;
end;

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

procedure TfrmProductOrderNewList_PB.FormCreate(Sender: TObject);
begin
  cxgrid2.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmProductOrderNewList_PB.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单列表FF', Tv2, '生产指示单管理');
end;

procedure TfrmProductOrderNewList_PB.InitGrid();
var
  sqlwhere: string;
begin
  sqlwhere := '';
  if Trim(DParameters1) <> '高权限' then
  begin
    sqlwhere := sqlwhere + ' and Filler=''' + Trim(DName) + '''';
  end;
//  if cxTabControl1.TabIndex < 2 then
//  begin
//    sqlwhere := sqlwhere + ' and  isnull(A.status,''0'')=''' + inttostr(cxTabControl1.TabIndex) + '''';
//  end;
  if cxTabControl1.TabIndex = 0 then
  begin
    sqlwhere := sqlwhere + ' and  isnull(B.PBFlag,''未排版'')=''未排版''';

  end;
  if cxTabControl1.TabIndex = 1 then
  begin
    sqlwhere := sqlwhere + ' and  isnull(B.PBFlag,''未排版'')=''已排版''';
  end;
  try
    ADOQuerySub.DisableControls;
    with ADOQuerySub do
    begin                      
      Filtered := False;                      
      Close;
      sql.Clear;
      sql.add('exec P_View_Order_PB :begdate,:enddate,:WSql');
      Parameters.ParamByName('WSql').Value := sqlwhere;
      Parameters.ParamByName('begdate').Value := FormatDateTime('yyyy-MM-dd', BegDate.DateTime);
      Parameters.ParamByName('enddate').Value := FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1);
//      ShowMessage(sql.text);
      ExecSQL;
      Open;
    end;
    SCreateCDS20(ADOQuerySub, CDS_Sub);
    SInitCDSData20(ADOQuerySub, CDS_Sub);

  finally
    ADOQuerySub.EnableControls;
  end;
end;

procedure TfrmProductOrderNewList_PB.InitGridFH();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec Order_QryList :MainId,:WSql');
      Parameters.ParamByName('WSql').Value := ' and FillTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''' + ' and FillTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderNewList_PB.InitForm();
begin
  ReadCxGrid('指示单列表FF', Tv2, '生产指示单管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 15;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmProductOrderNewList_PB.TBFindClick(Sender: TObject);
begin
  if ADOQuerySub.Active = False then
    Exit;
  SDofilter(ADOQuerySub, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQuerySub, CDS_Sub);
  SInitCDSData20(ADOQuerySub, CDS_Sub);
end;

procedure TfrmProductOrderNewList_PB.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FOrderNo := Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderNewList_PB.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
{  if Trim(Order_Main.fieldbyname('Filler').AsString)<>Trim(DName) then
  begin
    Application.MessageBox('不能操作他人的数据!','提示',0);
    Exit;
  end;   }

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
  InitGrid();
end;

function TfrmProductOrderNewList_PB.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      sql.Add('delete JYOrder_Sub where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      sql.Add('delete TP_File where WBID=''' + Trim(Order_Main.fieldbyname('Mainid').AsString) + ''' and TFType=''EWM'' ');
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('指示单删除')));
      sql.Add(',' + quotedstr(trim('指示单号：' + trim(Order_Main.FieldByName('OrderNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      ExecSQL;
    end;
    {with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Sub where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      Open;
      if IsEmpty then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete JYOrder_Main where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
    if Trim(Order_Main.fieldbyname('SubId').AsString)='' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete JYOrder_Main where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
        ExecSQL;
      end;
    end;   }
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmProductOrderNewList_PB.TBExportClick(Sender: TObject);
var
  str: string;
begin
  if ADOQuerySub.IsEmpty then
    Exit;
//  SelExportData(Tv2, ADOQuerySub, '生产指示单列表');

  str := SGetFilters(Panel1, 1, 2);
  str := str + 'ssel=true';                  
  SDofilter10(CDS_Sub, str);

  SelExportDatae(Tv2, CDS_Sub, '订生产指示单排版列表');
end;

procedure TfrmProductOrderNewList_PB.SelExportDatae(FTv: TcxGridDBTableView; CDS_Sub: TClientDataSet; FTile: string);
var
  i, j: Integer;
  fsj: string;
begin
  if CDS_Sub.IsEmpty then
    Exit;

  try
    frmSelExportField := TfrmSelExportField.Create(Application);
    with frmSelExportField do
    begin
      with frmSelExportField.ExpGrid do
      begin
       // ExpGrid.Columns.Clear;
        ExpGrid.ClearItems;
        frmSelExportField.IniName := FTile;
        {if FTv.OptionsView.Footer=true then
        begin
          ExpGrid.OptionsView.Footer:=True;
        end else
        begin
          ExpGrid.OptionsView.Footer:=False;
        end;    }
        ExpGrid.OptionsView.Footer := FTv.OptionsView.Footer;
        for i := 0 to FTv.ColumnCount - 1 do
        begin
          //if FTv.Columns[i].Visible=True then
          begin
            ExpGrid.CreateColumn;
            j := ExpGrid.ColumnCount - 1;
            ExpGrid.Columns[j].Caption := FTv.Columns[i].Caption;
            ExpGrid.Columns[i].Visible := FTv.Columns[i].Visible;
            ExpGrid.Columns[j].DataBinding.FieldName := FTv.Columns[i].DataBinding.FieldName;
            ExpGrid.Columns[j].Width := FTv.Columns[i].Width;
            ExpGrid.Columns[i].Summary.FooterKind := FTv.Columns[i].Summary.FooterKind;

          end;
        end;
      end;
//      TcxGridToExcel('订单核算表', cxGrid1);
      ExportDataSource.DataSet := CDS_Sub;
      CDS_Sub.Open;
      if ShowModal = 1 then
      begin

      end;
    end;
    frmSelExportField.Free;
  except

  end;
  InitGrid();
end;

procedure TfrmProductOrderNewList_PB.TBPrintClick(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
  i, j: Integer;
begin
  if CDS_Sub.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\包装指示单.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*, ColorCount=(select isnull(Count(*),0) from JYOrder_Sub where MainId=A.MainId),  ');
    sql.add('ZQty=(select sum(PRTOrderQty) from JYOrder_Sub where MainId=A.MainId),');
    sql.Add('PrtImage=(select Top 1 FilesOther from TP_File X where X.WBID=B.PRTCode) ');
    sql.Add(' from JYOrder_Main A inner join JYOrder_Sub B on A.MainId=B.MainId ');
    sql.Add(' Where A.MainId=''' + Trim(CDS_Sub.fieldbyname('MainId').AsString) + '''');
    sql.Add(' order by B.PRTCode,B.PRTCodeName,B.subID ');
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\包装指示单.rmf'), '提示', 0);
    exit;
  end;
//  Panel4.Visible:=True;
  //Button1.Click;
end;

procedure TfrmProductOrderNewList_PB.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmProductOrderNewList_PB.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 0;
      FMainId := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderNewList_PB.OrderNoChange(Sender: TObject);
var
  sqlwhere: string;
begin
  if Length(OrderNo.Text) < 2 then
    Exit;
  sqlwhere := '';
  if Trim(DParameters1) <> '高权限' then
  begin
    sqlwhere := sqlwhere + ' and Filler=''' + Trim(DName) + '''';
  end
  else
  begin
    sqlwhere := sqlwhere + ' and A.orderno like ''' + '%' + Trim(OrderNo.Text) + '%' + '''';
  end;

  if cxTabControl1.TabIndex = 0 then
  begin
    sqlwhere := sqlwhere + ' and  B.PBFlag=''未排版''';

  end;
  if cxTabControl1.TabIndex = 1 then
  begin
    sqlwhere := sqlwhere + ' and  B.PBFlag=''已排版''';
  end;

  try
    ADOQuerySub.DisableControls;
    with ADOQuerySub do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.add('exec P_View_Order_PB :begdate,:enddate,:WSql');
//        if Trim(DParameters1) <> '高权限' then
//        begin
//          Parameters.ParamByName('WSql').Value := ' and Filler=''' + Trim(DName) + '''';
//        end;
//        begin
//          Parameters.ParamByName('WSql').Value := ' and A.orderno like ''' + '%' + Trim(OrderNo.Text) + '%' + '''';
//        end;
      Parameters.ParamByName('WSql').Value := sqlwhere;
      Parameters.ParamByName('begdate').Value := FormatDateTime('yyyy-MM-dd', BegDate.DateTime);
      Parameters.ParamByName('enddate').Value := FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1);
//      Parameters.ParamByName('begdate').Value := '1899-01-01';
//      Parameters.ParamByName('enddate').Value := '2050-01-01';
      ExecSQL;
      Open;
    end;

    SCreateCDS20(ADOQuerySub, CDS_Sub);
    SInitCDSData20(ADOQuerySub, CDS_Sub);
  finally
    ADOQuerySub.EnableControls;
  end;
//  end;
end;

procedure TfrmProductOrderNewList_PB.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmProductOrderNewList_PB.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if ToolButton1.Visible = False then
    Exit;
  ToolButton1.Click;
end;

procedure TfrmProductOrderNewList_PB.TBTPClick(Sender: TObject);
var
  FQty, FQty1, FMxQty, FPQty, FMxQtyS, FPQtyS: string;
begin
end;

procedure TfrmProductOrderNewList_PB.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmProductOrderNewList_PB.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmProductOrderNewList_PB.Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id, id10: Integer;
begin
  {try
    if Tv1.GroupedItemCount=0 then
    begin
      Id:=Tv1.GetColumnByFieldName('DeliveryDate').Index-tv1.GroupedItemCount;
      Id10:=Tv1.GetColumnByFieldName('SubStatus').Index-tv1.GroupedItemCount;
      if Trim(VarToStr(ARecord.Values[id]))='' then Exit;
      if Id<0 then Exit;
      if ARecord.Values[id10]='完成' then exit;
      if (ARecord.Values[id]-DQdate)>=4 then Exit;
      if ((ARecord.Values[id]-DQdate)>=0) and ((ARecord.Values[id]-DQdate)<4) then
        AStyle:=DataLink_.QHuangSe
      else
      if ARecord.Values[id]-DQdate<0 then
      begin
        AStyle:=DataLink_OrderManage.FenHongS;
      end;
    end else
    begin

    end;
  except
  end; }
end;

procedure TfrmProductOrderNewList_PB.v1DeliveryDateCustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
 { Id:=TV1.GetColumnByFieldName('DeliveryDate').Index;//;-TV1.GroupedItemCount;
  Id10:=TV1.GetColumnByFieldName('SubStatus').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[Id10]='完成' then Exit;
  if AViewInfo.GridRecord.Values[Id]-SGetServerDate(ADOQueryTemp)>=4 then Exit;
  if ((AViewInfo.GridRecord.Values[id]-SGetServerDate10(ADOQueryTemp))>=0) and ((AViewInfo.GridRecord.Values[id]-SGetServerDate(ADOQueryTemp))<4) then
    ACanvas.Brush.Color:=clYellow
  else
  if (AViewInfo.GridRecord.Values[id])-(SGetServerDate10(ADOQueryTemp)<0) then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  begin
    ACanvas.Brush.Color:=clRed;
  end else
  if AViewInfo.GridRecord.Values[Id]='Purple' then
  begin
    ACanvas.Brush.Color:=clPurple;
  end else
  if AViewInfo.GridRecord.Values[Id]='Olive' then
  begin
    ACanvas.Brush.Color:=clOlive;
  end else
  if AViewInfo.GridRecord.Values[Id]='Teal' then
  begin
    ACanvas.Brush.Color:=clTeal;
  end else
  if AViewInfo.GridRecord.Values[Id]='Background' then
  begin
    ACanvas.Brush.Color:=clBackground;
  end;   }
end;

procedure TfrmProductOrderNewList_PB.N1Click(Sender: TObject);
//var
//  fPrintFile: string;
//  Porderno: string;
begin
  SelOKNo(CDS_Sub, false);
//  if Order_Main.IsEmpty then
//    Exit;
//  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf';
//  SDofilter(ADOQueryMain, ' OrderNoM=''' + Trim(Order_Main.fieldbyname('OrderNoM').AsString) + '''');
//  SCreateCDS20(ADOQueryMain, Order_Main);
//  SInitCDSData20(ADOQueryMain, Order_Main);
//  Porderno := Trim(Order_Main.fieldbyname('OrderNoM').AsString);
//  if FileExists(fPrintFile) then
//  begin
//    //RMVariables['begindate']:=begindate.DateTime;
//    //RMVariables['enddate']:=enddate.DateTime;
//    //RMVariables['printtime']:=Now;
//    //RMVariables['printer']:=Trim(gUserName);
//    RM1.LoadFromFile(fPrintFile);
//    RM1.ShowReport;
//  end
//  else
//  begin
//    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf'), '提示', 0);
//  end;
//  SDofilter(ADOQueryMain, '');
//  SCreateCDS20(ADOQueryMain, Order_Main);
//  SInitCDSData20(ADOQueryMain, Order_Main);
//  Order_Main.Locate('ordernoM', Porderno, []);
end;

procedure TfrmProductOrderNewList_PB.N2Click(Sender: TObject);
//var
//  fPrintFile: string;
//  Porderno: string;
begin
  SelOKNo(CDS_Sub, True);
//  if Order_Main.IsEmpty then
//    Exit;
//  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf';
//  SDofilter(ADOQueryMain, ' OrderNoM=''' + Trim(Order_Main.fieldbyname('OrderNoM').AsString) + '''');
//  SCreateCDS20(ADOQueryMain, Order_Main);
//  SInitCDSData20(ADOQueryMain, Order_Main);
//  Porderno := Trim(Order_Main.fieldbyname('OrderNoM').AsString);
//  if FileExists(fPrintFile) then
//  begin
//    //RMVariables['begindate']:=begindate.DateTime;
//    //RMVariables['enddate']:=enddate.DateTime;
//    //RMVariables['printtime']:=Now;
//    //RMVariables['printer']:=Trim(gUserName);
//    RM1.LoadFromFile(fPrintFile);
//    RM1.ShowReport;
//  end
//  else
//  begin
//    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf'), '提示', 0);
//  end;
//  SDofilter(ADOQueryMain, '');
//  SCreateCDS20(ADOQueryMain, Order_Main);
//  SInitCDSData20(ADOQueryMain, Order_Main);
//  Order_Main.Locate('ordernoM', Porderno, []);
end;

procedure TfrmProductOrderNewList_PB.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      ToolBar2.Visible := False;
      TBSave.Visible := False;
      ScrollBox1.Enabled := False;
      Tv1.OptionsSelection.CellSelect := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderNewList_PB.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      CopyInt := 99;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderNewList_PB.ToolButton3Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmProductOrderNewList_PB.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin                                 
    if Length(OrderNo.Text) < 3 then
      Exit;
    try
      ADOQuerySub.DisableControls;
      with ADOQuerySub do                         
      begin
        Filtered := False;
        Close;
        sql.Clear;
        sql.add('exec P_View_Order_PB :begdate,:enddate,:WSql');
        if Trim(DParameters1) <> '高权限' then
        begin
          Parameters.ParamByName('WSql').Value := ' and Filler=''' + Trim(DName) + '''';
        end;
        begin
          Parameters.ParamByName('WSql').Value := ' and A.orderno like ''' + '%' + Trim(OrderNo.Text) + '%' + '''';
        end;
        Parameters.ParamByName('begdate').Value := '1899-01-01';
        Parameters.ParamByName('enddate').Value := '2050-01-01';
        ExecSQL;
        Open;
      end;

      SCreateCDS20(ADOQuerySub, CDS_Sub);
      SInitCDSData20(ADOQuerySub, CDS_Sub);
    finally
      ADOQuerySub.EnableControls;
    end;
  end;
end;

procedure TfrmProductOrderNewList_PB.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(conno.Text) < 3 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        sql.add('exec P_View_Order :begdate,:enddate,:WSql');
        if Trim(DParameters1) <> '高权限' then
        begin
          Parameters.ParamByName('WSql').Value := ' and A.Filler=''' + Trim(DName) + '''';
        end;
        begin
          Parameters.ParamByName('WSql').Value := ' and conno like ''' + '%' + Trim(conno.Text) + '%' + '''';
        end;
        Parameters.ParamByName('begdate').Value := '1899-01-01';
        Parameters.ParamByName('enddate').Value := '2050-01-01';
        ExecSQL;
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

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

procedure TfrmProductOrderNewList_PB.Button1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, LBName, SYRName: string;
  i, j: Integer;
  OrderKg: Double;
begin
//  if Order_Main.IsEmpty then
//    Exit;
//  LBName := RadioGroup1.Items.Strings[RadioGroup1.ItemIndex];
//  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';
//  if Trim(Order_Main.fieldbyname('SYRName').AsString) = '' then
//  begin
//    with ADOQueryTemp do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('select Top 1 B.ZdyName SYRName from JYOrderCon_Main A');
//      sql.Add(' left join KH_Zdy B on A.SYRName=B.Note');
//      sql.Add(' where A.ConNo=''' + Trim(Order_Main.fieldbyname('ConNo').AsString) + '''');
//      Open;
//    end;
//    SYRName := Trim(ADOQueryTemp.fieldbyname('SYRName').AsString);
//  end
//  else
//  begin
//    SYRName := Trim(Order_Main.fieldbyname('SYRName').AsString);
//  end;
//
//  with ADOQueryPrint do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('exec F_Get_Print_Order ');
//    sql.add('@mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
//    Open;
//  end;
//  SCreateCDS20(ADOQueryPrint, CDS_Print);
//  SInitCDSData20(ADOQueryPrint, CDS_Print);
//
//  if FileExists(fPrintFile) then
//  begin
//    RM1.LoadFromFile(fPrintFile);
//    RMVariables['SYRName'] := Trim(SYRName);
//    RM1.ShowReport;
//  end
//  else
//  begin
//    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
//  end;
end;

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

procedure TfrmProductOrderNewList_PB.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitSub();
end;

procedure TfrmProductOrderNewList_PB.TFJClick(Sender: TObject);
begin
  if order_Main.IsEmpty then
    exit;
  frmFjList_RZ := TfrmFjList_RZ.create(self);
  with frmFjList_RZ do
  begin
    fkeyNo := trim(order_Main.fieldbyname('Mainid').AsString);
    ftype := 'ZSDFJ';
    if showmodal = 1 then
    begin

    end;
    ;
  end;
  frmFjList_RZ.Free;
end;

procedure TfrmProductOrderNewList_PB.ToolButton4Click(Sender: TObject);
var
  FMainid: string;
  fPrintFile: string;
  Porderno: string;
  i, j: Integer;
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if CDS_Sub.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  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_Sub.DisableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        if Fieldbyname('Ssel').AsBoolean then
        begin
          if FMainid = '' then
          begin
            FMainid := Trim(CDS_Sub.fieldbyname('CustomerNoName').AsString);
          end
          else
          begin
            if Trim(CDS_Sub.fieldbyname('CustomerNoName').AsString) <> FMainid then
            begin
              application.MessageBox('选择的不是同一个客户，不能一起打印！', '提示信息', 0);
              ADOQueryCmd.Connection.RollbackTrans;
              EnableControls;
              exit;
            end;
          end;
          ADOQueryCmd.append;
          ADOQueryCmd.fieldbyname('SubId').Value := Trim(CDS_Sub.fieldbyname('Mainid').AsString);
          ADOQueryCmd.fieldbyname('Dname').Value := Trim(DCode);
          ADOQueryCmd.post;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
  CDS_Sub.EnableControls;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\包装指示单合并.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Print_OrderHZ ''' + trim(DCode) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\包装指示单合并.rmf'), '提示', 0);
    exit;
  end;
end;

procedure TfrmProductOrderNewList_PB.CJEWM(FMainid: string; FSubid: string);
var
  Txt, fImagePath, maxNo: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(FSubid);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from TP_File ');
      sql.Add('where TFID=' + quotedstr(trim(Txt)));
      sql.Add('and TFType=''EWM''');
      open;
      if isempty then
      begin
        append;
        fieldbyname('TFID').Value := trim(Txt);
        fieldbyname('WBID').Value := trim(FMainid);
        fieldbyname('TFType').Value := 'EWM';
        fieldbyname('FillTime').Value := SGetServerDateTime(ADOQuery1);
        tblobfield(FieldByName('Filesother')).LoadFromFile(fImagePath);
        post;
      end;
    end;
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;
end;

procedure TfrmProductOrderNewList_PB.ToolButton7Click(Sender: TObject);
var
  maxno: string;
begin
  if Order_Main.IsEmpty then
    Exit;

  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;

  if Application.MessageBox('确定要合并订单吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  if GetLSNo(ADOQueryCmd, maxno, 'Z', 'JYOrder_Main', 3, 1) = False then
  begin
    Application.MessageBox('取最大号失败!', '提示', 0);
    Exit;
  end;

  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;

  Order_Main.DisableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Fieldbyname('Ssel').AsBoolean then
        begin
          ADOQueryCmd.append;
          ADOQueryCmd.fieldbyname('SubId').Value := Trim(Order_Main.fieldbyname('mainid').AsString);
          ADOQueryCmd.fieldbyname('Dname').Value := Trim(DCode);
          ADOQueryCmd.post;

          with Order_Main do
          begin
            Edit;
            FieldByName('ZOrderNo').Value := maxno;
            Post;
          end;
        end;

        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
  Order_Main.EnableControls;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('update jyorder_main set ZOrderNo=''' + Trim(maxno) + ''' ');
      sql.Add('WHERE EXISTS(select SubId from TBSubID X where X.SubId=jyorder_main.Mainid and X.DName=''' + Trim(DCode) + ''' )');
//      ShowMessage(sql.Text);
      ExecSQL;
    end;
    application.MessageBox('订单合并成功！', '提示信息');
//    TBRafresh.Click;
  except
    application.MessageBox('订单合并失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderNewList_PB.ToolButton8Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Order_Main.FieldByName('zOrderNo').AsString = '' then
    Exit;
  if Application.MessageBox('确定要取消合并吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET ZOrderNo=null ');
      sql.Add('where zOrderNo=' + quotedstr(trim(Order_Main.fieldbyname('zOrderNo').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('订单取消合并')));
      sql.Add(',' + quotedstr(trim('订单号：' + trim(Order_Main.FieldByName('orderNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('订单取消合并成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('订单取消合并失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderNewList_PB.ToolButton6Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if CDS_Sub.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  panel4.Visible := True;
end;

procedure TfrmProductOrderNewList_PB.Button2Click(Sender: TObject);
var
  FMainid: string;
  fPrintFile: string;
  Porderno: string;
  i, j: Integer;
begin
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from  KH_Zdy_CPCB where cbtype=''CPCBGY'' and zdycode like ''%' + trim(edit1.text) + '%'' ');
    Open;
  end;

  if ADOQueryTemp.IsEmpty then
  begin
    if Application.MessageBox('未输入工艺，是否打印？', '提示', 32 + 4) <> IDYES then
      Exit;
  end;

  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_Sub.DisableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        if Fieldbyname('Ssel').AsBoolean then
        begin
          if FMainid = '' then
          begin
            FMainid := Trim(CDS_Sub.fieldbyname('CustomerNoName').AsString);
          end
          else
          begin
            if Trim(CDS_Sub.fieldbyname('CustomerNoName').AsString) <> FMainid then
            begin
              application.MessageBox('选择的不是同一个客户，不能一起打印！', '提示信息', 0);
              ADOQueryCmd.Connection.RollbackTrans;
              EnableControls;
              exit;
            end;
          end;
          ADOQueryCmd.append;
          ADOQueryCmd.fieldbyname('SubId').Value := Trim(CDS_Sub.fieldbyname('Mainid').AsString);
          ADOQueryCmd.fieldbyname('Dname').Value := Trim(DCode);
          ADOQueryCmd.post;
        end;
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
  CDS_Sub.EnableControls;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf';

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Print_OrderSCHZ ''' + trim(DCode) + '''');
    sql.Add(',''' + trim(Edit1.Text) + ''' ');
//    showmessage(sql.Text);
    Open;
  end;
  if ADOQuery1.RecordCount < 1 then
  begin
    application.MessageBox('该产品已备！', '提示信息', 0);
  end
  else
  begin
    with ADOQueryPrint do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Print_OrderSCHZ ''' + trim(DCode) + '''');
      sql.Add(',''' + trim(Edit1.Text) + ''' ');
//    showmessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryPrint, CDS_Print);
    SInitCDSData20(ADOQueryPrint, CDS_Print);
    if FileExists(fPrintFile) then
    begin
      RM1.LoadFromFile(fPrintFile);
      RM1.ShowReport;
    end
    else
    begin
      Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf'), '提示', 0);
      exit;
    end;
  end;
end;

procedure TfrmProductOrderNewList_PB.Button3Click(Sender: TObject);
begin
  Panel4.Visible := false;
end;

procedure TfrmProductOrderNewList_PB.ToolButton9Click(Sender: TObject);
var
  sqlstr: string;
begin
  if CDS_Sub.IsEmpty then
    exit;
  try
    sqlstr := '';
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        if CDS_Sub.FieldByName('SSel').AsBoolean = True then
        begin

//            close;
//            sql.Clear;
//            sql.Add('update  JYOrder_sub SET PBFlag=''已排版'',PBTime=getdate() ');
//            sql.Add('where subid=' + quotedstr(trim(CDS_Sub.fieldbyname('subid').AsString)));
//            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
//            sql.Add(' ' + quotedstr(trim(DName)));
//            sql.Add(',getdate() ');
//            sql.Add(',' + quotedstr(trim(self.Caption)));
//            sql.Add(',' + quotedstr(trim('订单排版完成')));
//            sql.Add(',' + quotedstr(trim('订单号：' + trim(CDS_Sub.FieldByName('OrderNO').AsString))));
//            sql.Add(',' + quotedstr(trim('成功')));
//            sql.Add(')');
//            execsql;
          sqlstr := sqlstr + 'insert into SY_SysLog(operor,opertime,Model,acction,opevent,result)';
          sqlstr := sqlstr + ' values( ';
          sqlstr := sqlstr + ' ' + quotedstr(trim(DName));
          sqlstr := sqlstr + ' ,getdate(), ';
          sqlstr := sqlstr + ' ' + quotedstr(trim(self.Caption));
          sqlstr := sqlstr + ' ,' + quotedstr(trim('订单排版完成'));
          sqlstr := sqlstr + ' ,' + quotedstr(trim('订单号：' + trim(CDS_Sub.FieldByName('OrderNO').AsString)));
          sqlstr := sqlstr + ' ,' + quotedstr(trim('成功'));
          sqlstr := sqlstr + ' ) ';
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update  JYOrder_sub SET PBFlag=''已排版'',PBTime=getdate() ');
            sql.Add('where subid=' + quotedstr(trim(CDS_Sub.fieldbyname('subid').AsString)));
            execsql;
          end;
//          end;
//          Next;
        end;
        CDS_Sub.Delete;
      end;
    end;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
//      showmessage(sql.Text);
      execsql;
    end;

    application.MessageBox('排版完成！', '提示信息', 0);
    TBRafresh.Click;
  except
    application.MessageBox('未完成！', '提示信息', 0);
  end;

end;

procedure TfrmProductOrderNewList_PB.ToolButton10Click(Sender: TObject);
var
  sqlstr: string;
begin
  if CDS_Sub.IsEmpty then
    exit;
  try
    sqlstr := '';
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        if CDS_Sub.FieldByName('SSel').AsBoolean = True then
        begin
          sqlstr := sqlstr + 'insert into SY_SysLog(operor,opertime,Model,acction,opevent,result)';
          sqlstr := sqlstr + ' values( ';
          sqlstr := sqlstr + ' ' + quotedstr(trim(DName));
          sqlstr := sqlstr + ' ,getdate(), ';
          sqlstr := sqlstr + ' ' + quotedstr(trim(self.Caption));
          sqlstr := sqlstr + ' ,' + quotedstr(trim('订单撤销排版完成'));
          sqlstr := sqlstr + ' ,' + quotedstr(trim('订单号：' + trim(CDS_Sub.FieldByName('OrderNO').AsString)));
          sqlstr := sqlstr + ' ,' + quotedstr(trim('成功'));
          sqlstr := sqlstr + ' ) ';
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update  JYOrder_sub SET PBFlag=''未排版'',PBTime=getdate() ');
            sql.Add('where subid=' + quotedstr(trim(CDS_Sub.fieldbyname('subid').AsString)));
            execsql;
          end;
//          end;
//          Next;
        end;
        CDS_Sub.Delete;
      end;
    end;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
//      showmessage(sql.Text);
      execsql;
    end;

    application.MessageBox('订单撤销完成成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('订单撤销完成失败！', '提示信息', 0);
  end;

end;
//begin
//  if CDS_Sub.IsEmpty then
//    exit;
//  try
//    with CDS_Sub do
//    begin
//      First;
//      while not Eof do
//      begin
//        if CDS_Sub.FieldByName('SSel').AsBoolean = True then
//        begin
//          with ADOQueryCmd do
//          begin
//            close;
//            sql.Clear;
//            sql.Add('update  JYOrder_sub SET PBFlag=''未排版'' ');
//            sql.Add('where subid=' + quotedstr(trim(CDS_Sub.fieldbyname('subid').AsString)));
//            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
//            sql.Add(' ' + quotedstr(trim(DName)));
//            sql.Add(',getdate() ');
//            sql.Add(',' + quotedstr(trim(self.Caption)));
//            sql.Add(',' + quotedstr(trim('订单撤销排版完成')));
//            sql.Add(',' + quotedstr(trim('订单号：' + trim(CDS_Sub.FieldByName('orderNO').AsString))));
//            sql.Add(',' + quotedstr(trim('成功')));
//            sql.Add(')');
//            execsql;
//          end;
//          Next;
//        end;
//      end;
//    end;
//    application.MessageBox('订单撤销完成成功！', '提示信息');
//    TBRafresh.Click;
//  except
//    application.MessageBox('订单撤销完成失败！', '提示信息', 0);
//  end;
//end;

procedure TfrmProductOrderNewList_PB.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
//  TBFind.Click;
end;

procedure TfrmProductOrderNewList_PB.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
//   ADOQuerySub.Close;
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_YS ');
    sql.Add('where code =' + quotedstr((CDS_Sub.fieldbyname('PRTCode').AsString)));
    sql.Add('and  CYYS =' + quotedstr((CDS_Sub.fieldbyname('PRTColor').AsString)));
//    ShowMessage(sql.text);
    open;
  end;
  initImageYS(ADOQueryTemp.fieldbyname('YSId').AsString);
end;

procedure TfrmProductOrderNewList_PB.InitImageYS(fwbid: string);
begin
  ADOQueryImageYS.close;
  if fwbid = '' then
    exit;
  with ADOQueryImageYS do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID=' + quotedstr(trim(fwbid)));
//    sql.Add('where WBid=''' + ADOQuerySub.fieldbyname('subid').asstring + '''');
    open;
  end;
end;

procedure TfrmProductOrderNewList_PB.DlyDateChange(Sender: TObject);
begin
  TBFind.click;
end;

procedure TfrmProductOrderNewList_PB.ConNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.

