unit U_ProductOrderNewListJD;

interface

uses
  Windows, Messages, SysUtils, strUtils, 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, cxContainer,
  cxImage, cxDBEdit, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, shellAPI, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, 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
  TfrmProductOrderNewListJD = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    v1OrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RMXLSExport1: TRMXLSExport;
    v1CustomerNoName: TcxGridDBColumn;
    Label4: TLabel;
    CustomerNoName: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    Label8: TLabel;
    PBFactory: TEdit;
    Label9: TLabel;
    ConNo: TEdit;
    Label10: TLabel;
    RanFactory: TEdit;
    Label11: TLabel;
    OrdPerson2: TEdit;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    Panel4: TPanel;
    Label14: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    v1ZQty: TcxGridDBColumn;
    v1OrderUnit3: TcxGridDBColumn;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource21: TDataSource;
    v1SYRName: TcxGridDBColumn;
    v1filler: TcxGridDBColumn;
    RMDBMain: TRMDBDataSet;
    RM1: TRMGridReport;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    IdFTP1: TIdFTP;
    Orddefstr5: TEdit;
    Label2: TLabel;
    PRTCodeName: TEdit;
    Label5: TLabel;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    Label6: TLabel;
    cxTabControl1: TcxTabControl;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Panel2: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    DataSource3: TDataSource;
    DataSource2: TDataSource;
    Order_PB: TClientDataSet;
    Order_DJB: TClientDataSet;
    TV2Column1: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    TV2Column5: TcxGridDBColumn;
    TV2Column6: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    TV2Column8: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    Tv3Column6: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    TV2Column9: TcxGridDBColumn;
    Tv3Column8: TcxGridDBColumn;
    Tv3Column9: TcxGridDBColumn;
    ADOQueryPB: TADOQuery;
    ADOQueryDJB: TADOQuery;
    ToolButton1: TToolButton;
    RMDB_PB: TRMDBDataSet;
    RMDB_DJB: TRMDBDataSet;
    TV2Column10: TcxGridDBColumn;
    TV2Column11: TcxGridDBColumn;
    Tv3Column10: TcxGridDBColumn;
    Tv3Column11: 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 TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    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 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 TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure Picture4DblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitSub();
    procedure InitPB();
    procedure InitDJB();
    procedure InitImage(fwbid: string);
    procedure SetStatus();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmProductOrderNewListJD: TfrmProductOrderNewListJD;

implementation

uses
  U_DataLink, U_OrderInPut, U_Fun, U_FjList, U_MJSJFX, U_ZDYHelp;

{$R *.dfm}
procedure TfrmProductOrderNewListJD.SetStatus();
begin

  case cxTabControl1.TabIndex of
    0:
      begin

      end;
    1:
      begin

      end;
  end;
end;

procedure TfrmProductOrderNewListJD.InitImage(fwbid: string);
begin
  ADOQueryImage.close;
  if fwbid = '' then
    exit;
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID=' + quotedstr(trim(fwbid)));
    open;
  end;
end;

procedure TfrmProductOrderNewListJD.InitSub();
begin
  ADOQuerySub.Close;
  if Order_Main.IsEmpty then
    exit;
  with ADOQuerySub do
  begin
    close;
    sql.Clear;
    sql.Add('select *,DJStatus=case when JYRoll=MaxRoll then 0 else 1 end from (');
    sql.Add('select A.*,  ');
    sql.Add('JYRoll=(select count(MJID) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID),');
    sql.Add('JYQty=(select sum(MJLen) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID),');
    sql.Add('JYJZ=(select sum(MJQty4) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID),');
    sql.Add('JYMZ=(select sum(MJMaoZ) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID),');
    sql.Add('JYCRoll=(select count(MJID) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and X.MJType=''次品''),');
    sql.Add('JYCQty=(select sum(MJLen) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and X.MJType=''次品''),');
    sql.Add('JYCJZ=(select sum(MJQty4) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and X.MJType=''次品''),');
    sql.Add('JYCMZ=(select sum(MJMaoZ) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and X.MJType=''次品''),');
    sql.Add('CKRoll=(select count(MJID) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and ckflag=''已出库'' ), ');
    sql.Add('CKQty=(select sum(MJLen) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and ckflag=''已出库''), ');
    sql.Add('CKJZ=(select sum(MJQty4) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and ckflag=''已出库''),');
    sql.Add('CKMZ=(select sum(MJMaoZ) from WFB_MJJY X where X.MainID=A.mainID and X.subID=A.subID and ckflag=''已出库''),');
    SQL.Add('MaxRoll=(select isnull(sum(maxroll),0) from (select Subid,mjstr4,max(mjxh) as maxroll from wfb_mjjy X group by mjstr4,Subid) XX where XX.subid=A.subid)');
    sql.Add('from JYOrder_sub A ');
    sql.Add('where A.mainID =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    sql.Add(')AA');
    open;
  end;
end;

procedure TfrmProductOrderNewListJD.InitPB();
begin

  if Order_Main.IsEmpty then
    exit;
  try
    ADOQueryPB.DisableControls;
    with ADOQueryPB do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' where isnull(CKName,'''')=''坯布'' ');
      sql.Add('and  A.ORDMainIdRK =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      SQL.Add(' and CRFlag=''入库''  ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryPB, Order_PB);
    SInitCDSData20(ADOQueryPB, Order_PB);
  finally
    ADOQueryPB.EnableControls;
  end;
end;

procedure TfrmProductOrderNewListJD.InitDJB();
begin
  if Order_Main.IsEmpty then
    exit;
  try
    ADOQueryDJB.DisableControls;
    with ADOQueryDJB do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' where isnull(CKName,'''')=''待检布'' ');
      sql.Add('and  A.ORDMainIdRK =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      SQL.Add(' and CRFlag=''入库''  ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryDJB, Order_DJB);
    SInitCDSData20(ADOQueryDJB, Order_DJB);
  finally
    ADOQueryDJB.EnableControls;
  end;
end;

procedure TfrmProductOrderNewListJD.FormDestroy(Sender: TObject);
begin
  frmProductOrderNewListJD := nil;
end;

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

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

procedure TfrmProductOrderNewListJD.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('指示单主表列表1', Tv1, '生产指示单进度管理');

  Close;
end;

procedure TfrmProductOrderNewListJD.InitGrid();
var
  strwhere: string;
begin
  strwhere := '';
//  if Trim(DParameters1) <> '高权限' then
//    strwhere := strwhere + ' and Filler=''' + Trim(DName) + '''';

  if cxTabControl1.TabIndex < 2 then
  begin
    strwhere := strwhere + ' and  isnull(A.status,''0'')=''' + inttostr(cxTabControl1.TabIndex) + '''';
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin

      Close;
      Filtered := False;
      sql.Clear;
      sql.add('exec P_View_Order_JD :begdate,:enddate,:WSql');
      Parameters.ParamByName('begdate').Value := FormatDateTime('yyyy-MM-dd', BegDate.DateTime);
      Parameters.ParamByName('enddate').Value := FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1);
      Parameters.ParamByName('WSql').Value := strwhere;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  tbfind.Click;
end;

procedure TfrmProductOrderNewListJD.InitForm();
begin

  readCxGrid('指示单主表列表1', Tv1, '生产指示单进度管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 15;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  SetStatus();
  InitGrid();
end;

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

function TfrmProductOrderNewListJD.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 TfrmProductOrderNewListJD.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '生产指示单进度列表');
end;

procedure TfrmProductOrderNewListJD.TBPrintClick(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
  i, j: Integer;
begin
  Panel4.Left := (self.Width - Panel4.Width) div 2;
  Panel4.Visible := True;
end;

procedure TfrmProductOrderNewListJD.TBRafreshClick(Sender: TObject);
begin
  InitGrid();

end;

procedure TfrmProductOrderNewListJD.OrderNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmProductOrderNewListJD.FormShow(Sender: TObject);
begin
  fFlileFlag := UserDataFlag + 'HX';
  InitForm();
end;

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

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

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

procedure TfrmProductOrderNewListJD.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 TfrmProductOrderNewListJD.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 TfrmProductOrderNewListJD.N1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
begin
  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 TfrmProductOrderNewListJD.N2Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
begin
  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 TfrmProductOrderNewListJD.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(OrderNo.Text) < 3 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        sql.add('exec P_View_Order_JD :begdate,:enddate,:WSql');
        if Trim(DParameters1) <> '高权限' then
        begin
          Parameters.ParamByName('WSql').Value := ' and Filler=''' + Trim(DName) + '''';
        end;
        begin
          Parameters.ParamByName('WSql').Value := ' and orderno like ''' + '%' + Trim(OrderNo.Text) + '%' + '''';
        end;
        Parameters.ParamByName('begdate').Value := '2014-01-01';
        Parameters.ParamByName('enddate').Value := '2064-01-01';
        ExecSQL;
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmProductOrderNewListJD.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 TfrmProductOrderNewListJD.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TfrmProductOrderNewListJD.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 LBName = '订单汇总表' then
  begin
    with ADOQueryPrint do
    begin
      Close;
      Filtered := False;
      sql.Clear;
      sql.add('exec P_View_Order_JD_DY  ');
      sql.add('@mainid=' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      Open;
    end;
    SCreateCDS20(ADOQueryPrint, CDS_Print);
    SInitCDSData20(ADOQueryPrint, CDS_Print);
    with ADOQueryPB do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' where isnull(CKName,'''')=''坯布'' ');
      sql.Add('and  A.ORDMainIdRK =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      SQL.Add(' and CRFlag=''入库''  ');
      Open;
    end;
    SCreateCDS20(ADOQueryPB, Order_PB);
    SInitCDSData20(ADOQueryPB, Order_PB);

    with ADOQueryDJB do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
      sql.Add(' from CK_SXPB_CR A');
      sql.add(' where isnull(CKName,'''')=''待检布'' ');
      sql.Add('and  A.ORDMainIdRK =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      SQL.Add(' and CRFlag=''入库''  ');
      Open;

    end;
    SCreateCDS20(ADOQueryDJB, Order_DJB);
    SInitCDSData20(ADOQueryDJB, Order_DJB);
  end
  else
  begin                                   
    with ADOQueryPrint do
    begin
      Close;
      Filtered := False;
      sql.Clear;
      sql.add('exec P_View_Order_JD_DY_MX  ');
      sql.add('@mainid=' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      Open;
    end;
    SCreateCDS20(ADOQueryPrint, CDS_Print);
    SInitCDSData20(ADOQueryPrint, CDS_Print);
  end;
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + trim(fPrintFile)), '提示信息', 0);
    exit;
  end;
end;

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

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

end;

procedure TfrmProductOrderNewListJD.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  initImage(ADOQuerySub.fieldbyname('HXFile').AsString);
end;

procedure TfrmProductOrderNewListJD.Picture4DblClick(Sender: TObject);
var
  sFieldName: string;
  fileName: string;
 //	ff: TADOBlobStream;
 // FJStream : TMemoryStream;
begin
//  if Picture4.Picture.Height = 0 then
//    exit;
//  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';
//
//  if not DirectoryExists(pchar(sFieldName)) then
//    CreateDirectory(pchar(sFieldName), nil);
//  fileName := ADOQuerySub.fieldbyname('hxFile').AsString;
//  sFieldName := sFieldName + '\' + trim(fileName);
//
//  try
//    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
//    IdFTP1.Username := 'three';
//    IdFTP1.Password := '641010';
//    IdFTP1.Connect();
//  except
//    ;
//  end;
//
//  if IdFTP1.Connected then
//  begin
//
//    application.ProcessMessages;
//    try
//      IdFTP1.Get(fFlileFlag + '\' + Trim(fileName), sFieldName, true, false);
//    except
//      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
//      IdFTP1.Quit;
//      Exit;
//    end;
//  end
//  else
//  begin
//    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
//    IdFTP1.Quit;
//    Exit;
//  end;
//  if IdFTP1.Connected then
//    IdFTP1.Quit;
//  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);

end;

procedure TfrmProductOrderNewListJD.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

procedure TfrmProductOrderNewListJD.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  InitPB();
  InitDJB();
end;

procedure TfrmProductOrderNewListJD.ToolButton1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, SYRName: string;
begin
  if Order_Main.IsEmpty then
    Exit;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\订单汇总表.rmf';
  with ADOQueryPrint do
  begin
    Close;
    Filtered := False;
    sql.Clear;
    sql.add('exec P_View_Order_JD_DY  ');
    sql.add('@mainid=' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  with ADOQueryPB do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
    sql.Add(' from CK_SXPB_CR A');
    sql.add(' where isnull(CKName,'''')=''坯布'' ');
    sql.Add('and  A.ORDMainIdRK =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    SQL.Add(' and CRFlag=''入库''  ');
    Open;
  end;
  SCreateCDS20(ADOQueryPB, Order_PB);
  SInitCDSData20(ADOQueryPB, Order_PB);

  with ADOQueryDJB do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(',OrderNO=(select OrderNO from JYOrder_Main JM where JM.MainId=A.ORDMainIdRK)');
    sql.Add(' from CK_SXPB_CR A');
    sql.add(' where isnull(CKName,'''')=''待检布'' ');
    sql.Add('and  A.ORDMainIdRK =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    SQL.Add(' and CRFlag=''入库''  ');
    Open;

  end;
  SCreateCDS20(ADOQueryDJB, Order_DJB);
  SInitCDSData20(ADOQueryDJB, Order_DJB);

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

procedure TfrmProductOrderNewListJD.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '检验报告');
  SelExportData(Tv2, ADOQueryPB, '检验报告2');
  SelExportData(Tv3, ADOQueryDJB, '检验报告3');
end;

end.

