unit U_ProductOrderNewList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxButtonEdit, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdFTP, Menus, RM_Common, RM_Class, RM_e_Xls,
  RM_Dataset, RM_System, RM_GridReport, DBClient, ADODB, cxGridCustomPopupMenu,
  cxGridPopupMenu, cxContainer, cxImage, cxDBEdit, StdCtrls, cxPC, cxSplitter,
  ExtCtrls, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, ComCtrls,
  ToolWin, ShellAPI, StrUtils, Clipbrd, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxBarBuiltInMenu, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinscxPCPainter, 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,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue;

type
  TfrmProductOrderNewList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: 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;
    TBExport: TToolButton;
    v1OrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1CustomerNoName: TcxGridDBColumn;
    Label4: TLabel;
    CustomerNoName: TEdit;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Label8: TLabel;
    MPRTCodeName: TEdit;
    Label9: TLabel;
    ConNo: TEdit;
    v1MPRTKZ: TcxGridDBColumn;
    Label10: TLabel;
    MPRTSpec: TEdit;
    Label11: TLabel;
    MPRTCode: TEdit;
    Label12: TLabel;
    MPRTKZ: TEdit;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    v1Column1: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1SOrddefstr1: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    V2Column1: TcxGridDBColumn;
    ToolButton4: TToolButton;
    cxTabControl1: TcxTabControl;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    TWC: TToolButton;
    TNowc: TToolButton;
    v1Column6: TcxGridDBColumn;
    Panel2: TPanel;
    GroupBox1: TGroupBox;
    Picture4: TcxDBImage;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    IdFTP1: TIdFTP;
    TRZ: TToolButton;
    v1Column11: TcxGridDBColumn;
    Order_Sub: TClientDataSet;
    V2Column6: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    Label5: TLabel;
    YWY: TEdit;
    ComboBox1: TComboBox;
    CDSPrt: TClientDataSet;
    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 N1Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure TWCClick(Sender: TObject);
    procedure TNowcClick(Sender: TObject);
    procedure TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure Picture4DblClick(Sender: TObject);
    procedure TRZClick(Sender: TObject);
    procedure TV2DblClick(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitGridFH();
    procedure InitSub();
    procedure SetStatus();
    procedure InitImage(fwbid: string);
    procedure DownloadImage(wbid: string);
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1: string;
    fFlileFlag: string;
    { Public declarations }
  end;

//var
//  frmProductOrderNewList: TfrmProductOrderNewList;

implementation

uses
  U_DataLink, U_OrderInPut, U_Fun, U_FjList_RZ, U_FjList10, U_SysLogHelp;

{$R *.dfm}
procedure TfrmProductOrderNewList.DownloadImage(wbid: string);
var
  SaveDialog: TSaveDialog;
  fFileName: string;
  fFilePath: string;
  ff: TADOBlobStream;
  FJStream: TMemoryStream;
begin
//  if adoqueryTmp.IsEmpty then exit;
//
//  try
//    fFileName:=adoqueryTmp.fieldbyname('FileName').AsString;
//    SaveDialog := TSaveDialog.Create(Self);
//    SaveDialog.FileName:=fFileName;
//    if SaveDialog.Execute then
//    begin
//      fFilePath:=SaveDialog.FileName;
//     try
//       ff := TADOBlobstream.Create(adoqueryTmp.fieldByName('FilesOther') as TblobField, bmRead);
//       fjStream:= TMemoryStream.Create ;
//       ff.SaveToStream(fjStream);
//       UnCompressionStream(fjStream);
//       fjStream.SaveToFile(fFilePath);
//      // ShellExecute(Handle, 'open',PChar(sFieldName),'', '', SW_SHOWNORMAL);
//     finally
//      fjStream.free;
//      ff.Free;
//     end;
//  //   if IdFTP1.Connected then IdFTP1.Quit;
//    end;
//  except
//
//  end;
end;

procedure TfrmProductOrderNewList.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 TfrmProductOrderNewList.SetStatus();
begin
  tchk.Visible := false;
  tnochk.Visible := false;
  tbedit.Visible := false;
  tbdel.Visible := false;
  twc.Visible := false;
  tNOwc.Visible := false;
//  TBPrint.Visible:=False;
//  ComboBox1.Visible:=False;
  if Trim(self.Caption) = '生产指示单录入（高权限）' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          tbedit.Visible := true;
          tbdel.Visible := true;
          tchk.Visible := true;
        end;
      1:
        begin
          twc.Visible := true;
          tnochk.Visible := true;
//       TBPrint.Visible:=true;
//       ComboBox1.Visible:=true;
        end;
      2:
        begin
          tNOwc.Visible := true;
          TBPrint.Visible := true;
//       ComboBox1.Visible:=true;
        end;
      3:
        begin

        end;
    end;
  end;
  if Trim(self.Caption) = '生产指示单录入' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          tbedit.Visible := true;
          tbdel.Visible := true;
          TBadd.Visible := true;
        end;
      1:
        begin
//       TBPrint.Visible:=true;
//       ComboBox1.Visible:=true;
        end;
      2:
        begin
//      TBPrint.Visible:=true;
//      ComboBox1.Visible:=true;
        end;
      3:
        begin

        end;
    end;
  end;
end;

procedure TfrmProductOrderNewList.InitSub();
begin
  ADOQuerySub.Close;
  if Order_Main.IsEmpty then
    exit;
  try
    ADOQuerySub.DisableControls;
    with ADOQuerySub do
    begin
      close;
      sql.Clear;
      sql.Add('select *,isprtprice=0 from JYOrder_sub ');
      sql.Add('where mainID =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
      open;
    end;
    SCreateCDS20(ADOQuerySub, Order_Sub);
    SInitCDSData20(ADOQuerySub, Order_Sub);
    if Trim(canshu1) = '查询' then
    begin
      with Order_Sub do
      begin
        First;
        while not Eof do
        begin
          Edit;
          FieldByName('prtprice').Value := 0;
          Post;
          Next;
        end;
      end;
    end;
  finally
    ADOQuerySub.EnableControls;
  end;
end;

procedure TfrmProductOrderNewList.FormDestroy(Sender: TObject);
begin
//  frmProductOrderNewList:=nil;
end;

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

procedure TfrmProductOrderNewList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
  canshu1 := trim(DParameters1);
end;

procedure TfrmProductOrderNewList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption), Tv1, '生产指示单管理');
end;

procedure TfrmProductOrderNewList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.add('select * from JYOrder_Main');
      sql.add(' where Filltime>=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
      sql.add(' and Filltime<' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1))));
      if cxTabControl1.TabIndex < 3 then
        sql.add(' and isnull(status,''0'')=' + quotedstr(trim(inttostr(cxTabControl1.TabIndex))));
      if Trim(self.Caption) = '生产指示单录入' then
        sql.add(' and Filler=' + quotedstr(trim(DName)));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderNewList.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.InitForm();
begin
  ReadCxGrid(trim(self.Caption), Tv1, '生产指示单管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 30;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  SetStatus();
  InitGrid();
end;

procedure TfrmProductOrderNewList.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;

procedure TfrmProductOrderNewList.TBEditClick(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;
  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);
      canshu1 := self.canshu1;
      conNo.Enabled := false;
      if ShowModal = 1 then
      begin

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

procedure TfrmProductOrderNewList.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;
//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    SQL.Add('select * from CK_SXPB_CR A  ');
//    SQL.Add('where ORDMainIdCK='''+Trim(Order_Main.fieldbyname('MainId').AsString)+''' ');
//    SQL.Add('and  ckName<>''坯布'' ');
//    Open;
//  end;
//  if ADOQueryTemp.IsEmpty=False then
//  begin
//    Application.MessageBox('已产生数据不能删除!','提示',0);
//    Exit;
//  end;
//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select * from YF_Money_CR where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
//    Open;
//  end;
//  if ADOQueryTemp.IsEmpty=False then
//  begin
//    Application.MessageBox('已产生数据不能删除!','提示',0);
//    Exit;
//  end;
//
//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select * from WFB_MJJY where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
//    Open;
//  end;
//  if ADOQueryTemp.IsEmpty=False then
//  begin
//    Application.MessageBox('已回仓不能删除数据!','提示',0);
//    Exit;
//  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmProductOrderNewList.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('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;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmProductOrderNewList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '生产指示单列表');
end;

procedure TfrmProductOrderNewList.TBPrintClick(Sender: TObject);
var
  fPrintFile: string;
  LBName, SYRName, FNote1, fnote2, fnote3: string;
  i: integer;
begin
  if Order_Main.IsEmpty then
    Exit;

  LBName := trim(ComboBox1.Text);
  ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.add('select *   ');
    sql.add(',HBSJGFactory=cast((select  '' '' + SJGFactory from JYOrder_Fact X where X.MainId=A.MainId order by SJGXH   for xml path('''')) as varchar(200))');
    sql.add('  from JYOrder_Main A ');
    sql.add('inner join JYOrder_Sub B on A.MainID=B.MainID ');
    sql.add('where A.mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));

    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDSPrt);
  SInitCDSData20(ADOQueryPrint, CDSPrt);
  FNote1 := trim(CDSPrt.fieldbyname('MPRTBZNote').AsString);
  fnote2 := trim(CDSPrt.fieldbyname('note').AsString);
  fnote3 := trim(CDSPrt.fieldbyname('lidan').AsString);
  for i := CDSPrt.RecordCount to 13 do
  begin
    CDSPrt.Last;
    CDSPrt.Append;
    CDSPrt.fieldbyname('MPRTBZNote').Value := trim(FNote1);
    CDSPrt.fieldbyname('note').Value := trim(fnote2);
    CDSPrt.fieldbyname('lidan').Value := trim(fnote3);
    CDSPrt.POST;
  end;
  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.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmProductOrderNewList.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 TfrmProductOrderNewList.FormShow(Sender: TObject);
begin
  fFlileFlag := UserDataFlag + 'HX';
  InitForm();
end;

procedure TfrmProductOrderNewList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if ToolButton1.Visible = False then
    Exit;
  case cxTabControl1.TabIndex of
    0:
      begin

      end;
    1:
      begin
        TBPrint.Click;
      end;
    2:
      begin
        TBPrint.Click;
      end;
    3:
      begin

      end;
  end;

end;

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

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

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

procedure TfrmProductOrderNewList.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.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 TfrmProductOrderNewList.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;
      ToolBar3.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.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);
      canshu1 := self.canshu1;
      if ShowModal = 1 then
      begin

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

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

procedure TfrmProductOrderNewList.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmFjList10 := TfrmFjList10.Create(Application);
    with frmFjList10 do
    begin
    //  PState:=1;
   //   if Trim(canshu1)<>'高权限'  then cxButton1.Visible:=false;
      fkeyNO := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      fType := '指示单';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFjList10.Free;
  end;
end;

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

procedure TfrmProductOrderNewList.TchkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''1'' ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').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.TnochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''0'' ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').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.TWCClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''2'' ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').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.TNowcClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''1'' ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').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.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  initImage(ADOQuerySub.fieldbyname('HXFile').AsString);
end;

procedure TfrmProductOrderNewList.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 TfrmProductOrderNewList.TRZClick(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
   // fModel:=self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmProductOrderNewList.TV2DblClick(Sender: TObject);
begin
  if ADOQuerySub.IsEmpty then
    Exit;
  try
    frmFjList_RZ := TfrmFjList_RZ.Create(Application);
    with frmFjList_RZ do
    begin
    //  PState:=1;
      fkeyNO := Trim(Self.ADOQuerySub.fieldbyname('SubId').AsString);
      fType := '合同明细';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFjList_RZ.Free;
  end;
end;

procedure TfrmProductOrderNewList.N2Click(Sender: TObject);
begin

  Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

end.

