unit U_ContractDCList;

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,
  cxDropDownEdit, ShellAPI, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, IniFiles, StrUtils, BtnEdit, cxPC, 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
  TfrmContractDCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    v1OrdPerson1: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1CustomerNoName: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ToolButton3: TToolButton;
    PopupMenu2: TPopupMenu;
    N11: TMenuItem;
    N21: TMenuItem;
    N31: TMenuItem;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    zorderno: TEdit;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    cxSplitter1: TcxSplitter;
    CDS_Chk: TClientDataSet;
    DS_Chk: TDataSource;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Panel2: TPanel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column2: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    CDS_Sub: TClientDataSet;
    DSSub: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    CDS_Chker: TClientDataSet;
    v1Column7: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    cxGridPopupMenu4: TcxGridPopupMenu;
    CDS_SC: TClientDataSet;
    DS_SC: TDataSource;
    SaveDialog1: TSaveDialog;
    IdFTP1: TIdFTP;
    ODPat: TOpenDialog;
    Panel3: TPanel;
    Panel6: TPanel;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    N1: TMenuItem;
    v1FKPayment: TcxGridDBColumn;
    v1YJDCDate: TcxGridDBColumn;
    v1YJSHDate: TcxGridDBColumn;
    ToolButton8: TToolButton;
    v1EditNote: TcxGridDBColumn;
    v1EditSQTime: TcxGridDBColumn;
    v1LCChuanQ: TcxGridDBColumn;
    v1YiDuanZ: TcxGridDBColumn;
    v1LCQty: TcxGridDBColumn;
    Panel4: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Panel5: TPanel;
    Image1: TImage;
    TSure: TButton;
    TaiTou: TBtnEditA;
    ETaiTou: TEdit;
    IFTT: TCheckBox;
    ToolButton9: TToolButton;
    ADOQuery1: TADOQuery;
    cxGrid2: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    DCNO: TEdit;
    Label3: TLabel;
    TOPlace: TEdit;
    Label5: TLabel;
    KHName: TEdit;
    cxTabControl1: TcxTabControl;
    ToolButton10: TToolButton;
    ToolButton11: TToolButton;
    ComboBox1: TComboBox;
    ToolButton12: TToolButton;
    DS_MAIN: TDataSource;
    ToolButton13: TToolButton;
    ToolButton14: TToolButton;
    ToolButton15: TToolButton;
    cxTabControl2: TcxTabControl;
    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 TBRafreshClick(Sender: TObject);
    procedure TBAddClick(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 zordernoChange(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton4Click(Sender: TObject);
    procedure zordernoKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure TvSCCellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton8Click(Sender: TObject);
    procedure TaiTouBtnClick(Sender: TObject);
    procedure TSureClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure ToolButton11Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
    procedure ToolButton13Click(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
    procedure ToolButton15Click(Sender: TObject);
    procedure DCNOKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl2Change(Sender: TObject);
  private
    lstPat: TStringList;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure SetSatas();
    procedure InitForm();
    function DelData(): Boolean;
    procedure ReadINIFile10();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    CANSHU1, canshu2: string;

    { Public declarations }
  end;

var
  frmContractDCList: TfrmContractDCList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ConLCInPutDC, U_ZDYHelpSel;

{$R *.dfm}

procedure DrawDeskTop;
var
  Canvas: TCanvas;
begin
  Canvas := TCanvas.Create;
  Canvas.Handle := GetDC(0);
  Canvas.Pen.Color := clRed;
  Canvas.MoveTo(100, 100);
  Canvas.LineTo(200, 200);
  ReleaseDC(0, Canvas.Handle);
  Canvas.Free;
end;

procedure TfrmContractDCList.SetSatas();
begin
  if CANSHU1 = '确认' then
  begin
    cxTabControl1.TabIndex := 2;
    cxTabControl1.Visible := False;
  end;

  ToolButton3.Visible := False;
  TBDel.Visible := False;
  TBEdit.Visible := False;
  TBAdd.Visible := False;
  ToolButton4.Visible := False;
  ToolButton9.Visible := False;
  ToolButton10.Visible := False;
  ToolButton11.Visible := False;

  ToolButton13.Visible := False;
  ToolButton14.Visible := False;

  case cxTabControl1.TabIndex of
    0:
      begin
        TBDel.Visible := True;
        TBEdit.Visible := True;
        TBAdd.Visible := True;
        ToolButton4.Visible := True;
      end;
    1:
      begin
        ToolButton9.Visible := True;
        if CANSHU1 = '管理' then
        begin
          ToolButton10.Visible := true;
        end;
      end;
    2:
      begin
        if CANSHU1 = '管理' then
        begin
          ToolButton11.Visible := true;
          ToolButton13.Visible := TRUE;
          ToolButton14.Visible := TRUE;

        end;
        if CANSHU1 = '确认' then
        begin
          ToolButton2.Visible := false;
          ToolButton13.Visible := TRUE;
          ToolButton14.Visible := TRUE;

        end;
      end;
    3:
      begin

      end;

  end;

end;

procedure TfrmContractDCList.ReadINIFile10();
var
  programIni: Tinifile;  //配置文件名
  FileName: string;
begin
  FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI';
  programIni := Tinifile.create(FileName);
  server := programIni.ReadString('SERVER', '服务器地址', '127.0.0.1');
  programIni.Free;
end;

procedure TfrmContractDCList.FormDestroy(Sender: TObject);
begin
  frmContractDCList := nil;
end;

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

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

procedure TfrmContractDCList.TBCloseClick(Sender: TObject);
begin
  Close;

  WriteCxGrid('订舱明细', Tv3, '生产指示单管理');
  WriteCxGrid('订舱列表', Tv1, '生产指示单管理');

end;

procedure TfrmContractDCList.InitGrid();
var
  fwhere, Pwhere: string;
begin
  Pwhere := SGetFilters(Panel1, 1, 2);

  begin
    if trim(Pwhere) <> '' then
      fwhere := fwhere + ' and ' + trim(Pwhere);
  end;

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('SELECT * FROM (');
      sql.Add('select   ');
      sql.Add('A.*');
      SQL.Add(',GSNAME=''振永纺织''');
      sql.Add(',isdc=(case when QRDATE IS NOT NULL  THEN ''√'' else '''' end )');
      sql.Add(',isbg=(case when (select count(*) from JYOrder_BaoGuan_Main E where E.DCNO=A.DCNO AND E.VALID=''Y'' AND bgStatus=''√'')>0 THEN ''√'' else '''' end )');
      SQL.Add(',ZORDERNO=CAST((SELECT  STUFF(( SELECT  '','' +convert(VARCHAR, FROMORDERNO) FROM JYOrderCon_TT_Sub B WHERE A.TTID=B.TTId FOR XML PATH('''')), 1, 1, '''') )AS VARCHAR)');
      SQL.Add(',ZQTY=(SELECT SUM(PRTORDERQTY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZMONEY=(SELECT SUM(MONEY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZMAOZHONG=(SELECT SUM(MAOZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZJINGZHONG=(SELECT SUM(JINGZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZTIJI=(SELECT SUM(tiji) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      SQL.Add(',ZBZJS=(SELECT SUM(BZJS) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
      sql.Add(' from JYOrderCon_TT A ');
      SQL.Add('where ((FILLTIME>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + '''');
      SQL.Add('and  FILLTIME<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''') or ChkStatus=''审核不通过'') ');
//      if canshu2 = '组长' then
//      begin
//        sql.Add('and filler in (select UserName from SY_User where Udept=(select Udept from SY_User where SY_User.UserName=' + QuotedStr(Trim(DName)));
//        sql.Add('))');
//      end
//      else if CANSHU1 = '录入' then
//      begin
//        sql.Add('and filler=' + QuotedStr(Trim(DName)));
//      end;

      if cxTabControl1.TabIndex = 0 then
      begin
        SQL.Add('AND ISNULL(SChkFlag,0)=0 ');
        if CANSHU1 = '管理' then
        begin
          SQL.Add('AND 1<>1 ');
        end;
      end
      else if cxTabControl1.TabIndex = 1 then
      begin
        SQL.Add('AND ISNULL(SChkFlag,0)=1 AND  ISNULL(ChkStatus,0)=0 ');
      end
      else if cxTabControl1.TabIndex = 2 then
      begin
        SQL.Add(' AND  ChkStatus=1 ');
      end;
      SQL.Add(') AA WHERE 1=1');
      SQL.Add(fwhere);

      sql.Add('order by filltime desc');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmContractDCList.InitForm();
begin

  ReadCxGrid('订舱明细', Tv3, '生产指示单管理');
  ReadCxGrid('订舱列表', Tv1, '生产指示单管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 90;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);

  SetSatas();
  InitGrid();

end;

procedure TfrmContractDCList.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 TfrmContractDCList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if CANSHU1 = '录入' then
  begin
    if canshu2 = '组长' then
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from JYOrderCon_TT A  ');
        SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
        SQL.Add('and   filler in ( select username from SY_User where UType=(select UType from SY_User where UserName=' + quotedstr(Trim(dname)));
        SQL.Add('))');
        Open;
      end;
      if ADOQueryTemp.ISEMPTY = True then
      begin
        Application.MessageBox('不能操作他组的数据!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
      begin
        Application.MessageBox('不能操作他人的数据!', '提示', 0);
        Exit;
      end;
    end;

  end;

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from JYOrderCon_TT where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
    Open;
  end;
  if (Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString) = '审核通过') or (Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString) = '单据修改') then
  begin
    Application.MessageBox('已审核不能修改!', '提示', 0);
    Exit;
  end
  else if Trim(ADOQueryTemp.FieldByName('ChkStatus').AsString) = '' then
  begin
    if ADOQueryTemp.FieldByName('SChkFlag').AsBoolean = True then
    begin
      Application.MessageBox('审核中不能修改!', '提示', 0);
      Exit;
    end;

  end;
  try
    frmConLCInPutDC := TfrmConLCInPutDC.Create(Application);
    with frmConLCInPutDC do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('TTId').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmConLCInPutDC.Free;
  end;

end;

procedure TfrmContractDCList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if CANSHU1 = '录入' then
  begin
    if canshu2 = '组长' then
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from JYOrderCon_TT A  ');
        SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
        SQL.Add('and   filler in ( select username from SY_User where UType=(select UType from SY_User where UserName=' + quotedstr(Trim(dname)));
        SQL.Add('))');
        Open;
      end;
      if ADOQueryTemp.ISEMPTY = True then
      begin
        Application.MessageBox('不能操作他组的数据!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
      begin
        Application.MessageBox('不能操作他人的数据!', '提示', 0);
        Exit;
      end;
    end;

  end;
//  if Trim(Order_Main.fieldbyname('FillCode').AsString) <> Trim(DCode) then
//  begin
//    Application.MessageBox('不能操作他人的数据!', '提示', 0);
//    Exit;
//  end;
  if Order_Main.FieldByName('SChkFlag').AsBoolean = True 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 TfrmContractDCList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_TT where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
      ExecSQL;
    end;

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

procedure TfrmContractDCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '订舱指示书');
end;

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

procedure TfrmContractDCList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmConLCInPutDC := TfrmConLCInPutDC.Create(Application);
    with frmConLCInPutDC do
    begin
      PState := 0;
      FMainId := '';
//      BTDate.Checked := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmConLCInPutDC.Free;
  end;
end;

procedure TfrmContractDCList.FormShow(Sender: TObject);
begin
  if CANSHU1 = '管理' then
  begin
    cxTabControl1.Visible := false;
    cxTabControl2.Visible := True;
    cxTabControl1.TabIndex := 1;
  end;
  if CANSHU1 = '录入' then
  begin
    cxTabControl1.Tabs[3].Free;
  end;
  InitForm();
end;

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

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

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

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

procedure TfrmContractDCList.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 TfrmContractDCList.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 TfrmContractDCList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

procedure TfrmContractDCList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmContractDCList.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmConLCInPutDC := TfrmConLCInPutDC.Create(Application);
    with frmConLCInPutDC do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('TTId').AsString);
      TBSave.Visible := False;
      ToolBar2.Visible := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmConLCInPutDC.Free;
  end;
end;

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

      end;
    end;
  finally
    frmConLCInPutDC.Free;
  end;
end;

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

procedure TfrmContractDCList.zordernoChange(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 TfrmContractDCList.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin

    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        SQL.Clear;
        sql.Add('select ');
        sql.add('SYRName=(select Top 1 T.SYRName From JYOrderCon_Main T where T.ConNO=A.ConNo),');
        sql.add('JHDate=(select Top 1 M.DlyDate from JYOrder_Main M where M.OrderNo=A.DCNO),');
        sql.add(' PRTMaoZ=isnull(A.PRTMaoZ,(select Sum(D.CHMZ) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0))');
        sql.add(' ,PRTJIngZ=isnull(A.PRTJIngZ,(select Sum(D.CHJZ) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0))');
        sql.add(' ,PRTJianQty=isnull(A.PRTJianQty,(select Sum(D.QtyJian) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0))');

        sql.add(',A.*, ');
        sql.add('LCChuanQ=(select Top 1 B.LCChuanQ from JYOrderCon_TT B where B.ConNo=A.ConNo and B.TTType=''LC''),');
        sql.add('YiDuanZ=(select Top 1 B.YiDuanZ from JYOrderCon_TT B where B.ConNo=A.ConNo and B.TTType=''LC''),');
        sql.add('LCQty=(select Sum(C.PRTOrderQty) from JYOrderCon_TT_Sub C where C.TTID in (select B.TTID from JYOrderCon_TT B where B.ConNo=A.ConNo and B.TTType=''LC'')),');
        sql.add('FKPayment=isnull(A.PayMent,(select Top 1 Payment from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo and JRM.ZuoFeiFlag=0)),');
        sql.Add('YWYZhuLi1=(select Top 1 YWYZhuLi from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo and JRM.ZuoFeiFlag=0),');
        sql.Add('YWY1=(select Top 1 YWY from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo and JRM.ZuoFeiFlag=0) ');
        sql.Add(' from JYOrderCon_TT A  where 1=1 ');
        if Trim(DParameters1) <> '高权限' then
        begin
          sql.Add('and A.FillCode=''' + Trim(DCode) + '''');
        end;
//        sql.Add(' and ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');
        sql.Add(' and TTType=''' + Trim(DParameters2) + '''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmContractDCList.ToolButton5Click(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdConChkerLC';
      flagname := '订舱审核人';
      MainType := Trim(DName);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmContractDCList.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
var
  maxno: string;
begin
  if Order_Main.IsEmpty then
    exit;
//  Label3.Caption := Trim(Order_Main.fieldbyname('FKPayment').AsString);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrderCon_TT_Sub ');
    SQL.Add('  where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sub);
  SInitCDSData20(ADOQueryTemp, CDS_Sub);
//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select * from OrdConDanZH_Chk where MainId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
//    Open;
//  end;
//  SCreateCDS20(ADOQueryTemp, CDS_Chk);
//  SInitCDSData20(ADOQueryTemp, CDS_Chk);
//  EditNote.Text := trim(Order_Main.fieldbyname('EditNote').AsString);
//  label10.Caption := trim(Order_Main.fieldbyname('LCChuanQ').AsString);
//  label7.Caption := trim(Order_Main.fieldbyname('YiDuanZ').AsString);
//  label12.Caption := trim(floattostr(Order_Main.fieldbyname('LCQty').AsFloat));
end;

procedure TfrmContractDCList.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.FieldByName('ConFlag1').AsBoolean = False then
  begin
    if CDS_Chk.IsEmpty then
      Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete OrdCon_Chk where CKID=''' + Trim(CDS_Chk.fieldbyname('CKID').AsString) + '''');
      ExecSQL;
    end;
    CDS_Chk.Delete;
  end;
end;

procedure TfrmContractDCList.ToolButton4Click(Sender: TObject);
var
  maxno: string;
  FCount: Integer;
begin

  if Order_Main.IsEmpty then
    Exit;
  if CANSHU1 = '录入' then
  begin
    if canshu2 = '组长' then
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from JYOrderCon_TT A  ');
        SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
        SQL.Add('and   filler in ( select username from SY_User where UType=(select UType from SY_User where UserName=' + quotedstr(Trim(dname)));
        SQL.Add('))');
        Open;
      end;
      if ADOQueryTemp.ISEMPTY = True then
      begin
        Application.MessageBox('不能操作他组的数据!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
      begin
        Application.MessageBox('不能操作他人的数据!', '提示', 0);
        Exit;
      end;
    end;

  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderCon_TT A  ');
    SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
    SQL.Add('AND ISNULL(SChkFlag,0)=0 ');
    Open;
  end;
  if ADOQueryTemp.ISEMPTY = True then
  begin
    Application.MessageBox('当前数据状态已改变，请刷新后操作!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrderCon_TT Set SChkFlag=1,SChkTime=getdate() where TTId=''' + Trim(Order_Main.fieldbyname('TTId').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('TTId：' + trim(Order_Main.FieldByName('TTID').AsString))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
      Order_Main.Delete;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmContractDCList.zordernoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(DCNO.Text) < 3 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        SQL.Clear;
        sql.Add('select A.*, ');
        sql.add('SYRName=(select Top 1 T.SYRName From JYOrderCon_Main T where T.ConNO=A.ConNo),');
        sql.add('JHDate=(select Top 1 M.DlyDate from JYOrder_Main M where M.OrderNo=A.DCNO),');
        sql.add('FKPayment=isnull((select Top 1 Payment from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo),A.PayMent),');
        sql.Add('YWYZhuLi1=(select Top 1 YWYZhuLi from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo),');
        sql.Add('YWY1=(select Top 1 YWY from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo), ');
        sql.add('LCChuanQ=(select Top 1 B.LCChuanQ from JYOrderCon_TT B where B.ConNo=A.ConNo and B.TTType=''LC''),');
        sql.add('YiDuanZ=(select Top 1 B.YiDuanZ from JYOrderCon_TT B where B.ConNo=A.ConNo and B.TTType=''LC''),');
        sql.add('LCQty=(select Sum(C.PRTOrderQty) from JYOrderCon_TT_Sub C where C.TTID in (select B.TTID from JYOrderCon_TT B where B.ConNo=A.ConNo and B.TTType=''LC''))');
        sql.Add(' from JYOrderCon_TT A  where 1=1 ');
        if Trim(DParameters1) <> '高权限' then
        begin
          sql.Add('and A.FillCode=''' + Trim(DCode) + '''');
        end;
        sql.Add(' and DCNO like ''' + '%' + Trim(DCNO.Text) + '%' + '''');
        sql.Add(' and TTType=''' + Trim(DParameters2) + '''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmContractDCList.ToolButton6Click(Sender: TObject);
var
  i, j: Integer;
  PatFile, HZStr: string;
  FTPPath, FConNo, MaxNo: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  lstPat := TStringList.Create;
  lstPat.Clear;
  if ODPat.Execute then
  begin
    lstPat.AddStrings(ODPat.Files);
  end;

  if lstPat.Count > 0 then
  begin
    try
      ReadINIFile10();
      server := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
      IdFTP1.Host := server; //PicSvr;
      IdFTP1.Username := 'three';
      IdFTP1.Password := '641010';
      IdFTP1.Connect();
    except
      IdFTP1.Quit;
      Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
      Exit;
    end;
  end
  else
  begin
    Exit;
  end;
  Panel6.Visible := True;
  Panel6.Refresh;
 { with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select isnull(Count(*),0) MM from XD_File where  ');
    SQL.Add(' filetype=''LC''');
    Open;
    j:=fieldbyname('MM').AsInteger;
  end;}
  try
    ADOQueryCmd.Connection.BeginTrans;
    for i := 0 to lstPat.Count - 1 do
    begin

      PatFile := ExtractFileName(lstPat[i]);
      HZStr := Copy(PatFile, (Pos('.', PatFile) + 1), (Length(PatFile) - Pos('.', PatFile)));
      if IdFTP1.Connected then
      begin

        if GetLSNo(ADOQueryCmd, MaxNo, 'LC', 'XD_File', 4, 1) = False then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('取文件最大号失败！', '提示', 0);
          Exit;
        end;
        IdFTP1.Put(lstPat[i], Trim('\LC') + '\' + Trim(MaxNo) + '.' + Trim(HZStr));
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from XD_File where 1<>1');
          Open;
        end;
        with ADOQueryCmd do
        begin
          Append;
          FieldByName('XFID').Value := Trim(MaxNo);
          FieldByName('CYID').Value := Trim(Order_Main.fieldbyname('TTID').AsString);
          FieldByName('CYNO').Value := Trim(Order_Main.fieldbyname('LCNO').AsString);
          FieldByName('filename').Value := Trim(PatFile);
          FieldByName('FileDate').Value := SGetServerDate(ADOQueryTemp);
          fieldbyname('FileType').value := Trim('LC');
          FieldByName('Filler').Value := Trim(DName);
          FieldByName('HZStr').Value := '.' + Trim(HZStr);
          Post;
        end;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    if IdFTP1.Connected then
      IdFTP1.Quit;
    Panel6.Visible := False;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from XD_File where CYId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_SC);
    SInitCDSData20(ADOQueryTemp, CDS_SC);
    Application.MessageBox('上传成功！', '提示', 0);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('上传失败！', '提示', 0);
  end;
end;

procedure TfrmContractDCList.ToolButton7Click(Sender: TObject);
var
  fHandle: THandle;
  FInt: Integer;
  FFName, FFName10, FPath: string;
begin
  if CDS_SC.IsEmpty then
    Exit;
  Panel3.Visible := True;
  Panel3.Refresh;
  try
    ReadINIFile10();
    server := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    if Length(server) < 6 then
    begin
      server := '127.0.0.1';
    end;
    IdFTP1.Host := server; //PicSvr;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  FPath := 'D:\Right1209\';
  if not DirectoryExists(ExtractFileDir(FPath)) then
    CreateDir(ExtractFileDir(FPath));
  FFName := Trim(CDS_SC.fieldbyname('XFID').AsString) + Trim(CDS_SC.fieldbyname('HZStr').AsString);
  FPath := FPath + FFName;
  if FileExists(FPath) = false then
  begin
    IdFTP1.Get('LC\' + FFName, FPath);
  end;
  Panel3.Visible := False;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(FPath), '', '', SW_SHOWNORMAL);

end;

procedure TfrmContractDCList.TvSCCellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_SC.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete XD_File where XFID=''' + Trim(CDS_SC.fieldbyname('XFID').AsString) + '''');
    ExecSQL;
  end;
  CDS_SC.Delete;
end;

procedure TfrmContractDCList.ToolButton8Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;

  if Order_Main.FieldByName('SChkFlag').AsBoolean = False then
  begin
    application.MessageBox('没有送审不能修改申请', '提示');
    exit;
  end;
  frmZDYHelpSel := TfrmZDYHelpSel.Create(self);
  with frmZDYHelpSel do
  begin
    flag := 'OrdConChker';
    flagname := '订单合同审核人';
    MainType := Trim(DName);
    if showModal = 1 then
    begin
      with ClientDataSet1 do
      begin
        first;
        while not eof do
        begin
          if fieldbyname('Ssel').AsBoolean = true then
          begin
            if CDS_Chk.Locate('Chker', Trim(fieldbyname('ZdyName').AsString), []) = False then
            begin
              application.MessageBox('没有该合同的审核人', '提示');
              exit;
            end;
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('Update OrdConDanZH_Chk Set ChkStatus=''单据修改'',chknote='''',ChkTime=getdate()');
              sql.Add(' where Mainid=''' + Trim(Order_Main.fieldbyname('TTID').AsString) + '''');
              sql.Add(' and Chker=''' + Trim(ClientDataSet1.fieldbyname('ZdyName').AsString) + '''');
              ExecSQL;
            end;
          end;
          next;
        end;
      end;

      with Order_Main do
      begin
        Edit;
        fieldbyname('ChkStatus').Value := '单据修改';

        fieldbyname('EditSQTime').Value := SGetServerDate10(ADOQueryTemp);
        fieldbyname('EditFlag').Value := '1';
        Post;
      end;
    end;
    free;
  end;

end;

procedure TfrmContractDCList.TaiTouBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag := 'taitou1';
    flagname := '公司抬头';
    if ShowModal = 1 then
    begin
      TaiTou.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmContractDCList.TSureClick(Sender: TObject);
var
  fPrintFile, FTaiTou: string;
  EngMoney: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(Order_Main.FieldByName('ChkStatus').AsString) <> '审核通过' then
  begin
    RM1.PreviewButtons := [pbExit];
  end
  else
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbExport, pbNavigator];
  end;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\订舱指示书.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    SQL.Add('select B.PRTPrice, ');
    sql.Add('YWYZhuLi=(select Top 1 YWYZhuLi from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo and JRM.ZuoFeiFlag=0),');
    sql.Add('YWY=(select Top 1 YWY from JYOrderCon_Main JRM where JRM.ConNO=A.ConNo and JRM.ZuoFeiFlag=0), ');
    sql.add(' PRTMaoZ=isnull(A.PRTMaoZ,(select Sum(D.CHMZ) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0))');
    sql.add(' ,PRTJIngZ=isnull(A.PRTJIngZ,(select Sum(D.CHJZ) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0))');
    sql.add(' ,PRTJianQty=isnull(A.PRTJianQty,(select Sum(D.QtyJian) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0))');
    sql.add(' ,SumPRTQty=(select Sum(D.Qty) from JYOrderCon_Main E inner join JYOrderCon_Sub C on C.Mainid=E.Mainid Inner join JYOrder_CR D on D.ConSubid=C.Subid where E.conNo=A.conNo and isnull(D.CRFlag,'''')=''出库'' and E.ZuoFeiFlag=0)');
    sql.Add(' ,A.*,B.*');
    sql.Add(' from JYOrderCon_TT A');
    sql.Add(' left join JYOrderCon_TT_Sub B on A.TTID=B.TTID');
    sql.Add(' where A.TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  if FileExists(fPrintFile) then
  begin
    if iftt.Checked = true then
      FTaiTou := 'SHAOXING MNC IMP & EXP CO.,LTD'
    else
      FTaiTou := '';
    RMVariables['Taitou'] := trim(TaiTou.Text);
    RMVariables['FTaiTou'] := trim(FTaiTou);
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\订舱指示书.rmf'), '提示', 0);
  end;
end;

procedure TfrmContractDCList.TBPrintClick(Sender: TObject);
var
  fPrintFile, FTaiTou: string;
  EngMoney: string;
  THID: DWORD;
begin
  if Order_Main.IsEmpty then
    Exit;
  if combobox1.Text = '' then
    exit;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf';
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryPrint);
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT A.*');
    SQL.Add(',GSNAME=''振永纺织''');
    SQL.Add(',ZORDERNO=CAST((SELECT  STUFF(( SELECT  '','' +convert(VARCHAR, FROMORDERNO) FROM JYOrderCon_TT_Sub B WHERE A.TTID=B.TTId FOR XML PATH('''')), 1, 1, '''') )AS VARCHAR)');
    SQL.Add(',ZQTY=(SELECT SUM(PRTORDERQTY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZMONEY=(SELECT SUM(MONEY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZMAOZHONG=(SELECT SUM(MAOZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZJINGZHONG=(SELECT SUM(JINGZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZTIJI=(SELECT SUM(tiji) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZBZJS=(SELECT SUM(BZJS) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',DJYQ1= REPLACE(REPLACE(DJYQ, CHAR(13), ''''), CHAR(10), '''') ');
    SQL.Add(',DJYQ2=REPLACE(REPLACE(DJYQ, CHAR(13) + CHAR(10), CHAR(10)), CHAR(13), CHAR(10)) ');
    sql.Add(' from JYOrderCon_TT A ');
    SQL.Add('where ((FILLTIME>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + '''');
    SQL.Add('and  FILLTIME<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''') or ChkStatus=''审核不通过'') ');
    SQL.ADD('AND TTID=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  if FileExists(fPrintFile) then
  begin

    CreateThread(nil, 0, @DrawDeskTop, nil, 0, THID);
    RM1.LoadFromFile(fPrintFile);
    Sleep(1000);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf'), '提示', 0);
  end;
end;

procedure TfrmContractDCList.Image1Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmContractDCList.ToolButton9Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
//  if Trim(Order_Main.fieldbyname('FillCode').AsString) <> Trim(DCode) then
//  begin
//    Application.MessageBox('不能操作他人的数据!', '提示', 0);
//    Exit;
//  end;
  if CANSHU1 = '录入' then
  begin
    if canshu2 = '组长' then
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from JYOrderCon_TT A  ');
        SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
        SQL.Add('and   filler in ( select username from SY_User where UType=(select UType from SY_User where UserName=' + quotedstr(Trim(dname)));
        SQL.Add('))');
        Open;
      end;
      if ADOQueryTemp.ISEMPTY = True then
      begin
        Application.MessageBox('不能操作他组的数据!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
      begin
        Application.MessageBox('不能操作他人的数据!', '提示', 0);
        Exit;
      end;
    end;

  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderCon_TT A  ');
    SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
    SQL.Add('AND ISNULL(SChkFlag,0)=1 AND  ISNULL(ChkStatus,0)=0 ');
    Open;
  end;
  if ADOQueryTemp.ISEMPTY = True then
  begin
    Application.MessageBox('当前数据状态已改变，请刷新后操作!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      with ADOQuery1 do
      begin
        Close;
        sql.Clear;
        sql.Add('update JYOrderCon_TT set SChkFlag=0,SChkTime=NULL where TTId=''' + Trim(Order_Main.fieldbyname('TTId').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('TTId：' + trim(Order_Main.FieldByName('TTID').AsString))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        execsql;
      end;
      Order_Main.Delete;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmContractDCList.ToolButton10Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderCon_TT A  ');
    SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
    SQL.Add('AND ISNULL(SChkFlag,0)=1 AND  ISNULL(ChkStatus,0)=0 ');
    Open;
  end;
  if ADOQueryTemp.ISEMPTY = True then
  begin
    Application.MessageBox('当前数据状态已改变，请刷新后操作!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrderCon_TT Set ChkStatus=1,ChkTime=getdate(),   ');
        sql.Add('Chker=' + QUOTEDSTR(Trim(DNAME)));
        SQL.Add(' where TTId=''' + Trim(Order_Main.fieldbyname('TTId').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('TTId：' + trim(Order_Main.FieldByName('TTID').AsString))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
      Order_Main.Delete;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmContractDCList.ToolButton11Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderCon_TT A  ');
    SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
    SQL.Add(' AND  ChkStatus=1 ');
    Open;
  end;
  if ADOQueryTemp.ISEMPTY = True then
  begin
    Application.MessageBox('当前数据状态已改变，请刷新后操作!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrderCon_TT Set ChkStatus=NULL,ChkTime=NULL,   ');
        sql.Add('Chker=NULL');
        SQL.Add(' where TTId=''' + Trim(Order_Main.fieldbyname('TTId').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('TTId：' + trim(Order_Main.FieldByName('TTID').AsString))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
      Order_Main.Delete;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmContractDCList.cxTabControl1Change(Sender: TObject);
begin
  SetSatas();
  InitGrid();
end;

procedure TfrmContractDCList.ToolButton12Click(Sender: TObject);
var
  fPrintFile, FTaiTou, fImagePath2: string;
  EngMoney: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if combobox1.Text = '' then
    exit;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf';
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryPrint);
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT A.*');
    SQL.Add(',GSNAME=''振永纺织''');
    SQL.Add(',ZORDERNO=CAST((SELECT  STUFF(( SELECT  '','' +convert(VARCHAR, FROMORDERNO) FROM JYOrderCon_TT_Sub B WHERE A.TTID=B.TTId FOR XML PATH('''')), 1, 1, '''') )AS VARCHAR)');
    SQL.Add(',ZQTY=(SELECT SUM(PRTORDERQTY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZMONEY=(SELECT SUM(MONEY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZMAOZHONG=(SELECT SUM(MAOZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZJINGZHONG=(SELECT SUM(JINGZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZTIJI=(SELECT SUM(tiji) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZBZJS=(SELECT SUM(BZJS) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    sql.Add(' from JYOrderCon_TT A ');
    SQL.Add('where ((FILLTIME>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + '''');
    SQL.Add('and  FILLTIME<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''') or ChkStatus=''审核不通过'') ');
    SQL.ADD('AND TTID=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  if FileExists(fPrintFile) then
  begin

    RM1.LoadFromFile(fPrintFile);
    fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\label0001.xls';
    if FileExists(fImagePath2) then
      DeleteFile(fImagePath2);                                  //label.xls
    fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\' + '订舱托书' + Trim(Order_Main.fieldbyname('ZORDERNO').AsString) + '.xls';
    RM1.PrepareReport;
    Sleep(1000);
    RM1.ExportTo(RMXLSExport1, fImagePath2);
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf'), '提示', 0);
  end;
end;

procedure TfrmContractDCList.ToolButton13Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderCon_TT A  ');
    SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
    SQL.Add(' AND  ChkStatus=1 ');
    Open;
  end;
  if ADOQueryTemp.ISEMPTY = True then
  begin
    Application.MessageBox('当前数据状态已改变，请刷新后操作!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrderCon_TT Set QRDATE=getdate()   ');
//        sql.Add('Chker=' + QUOTEDSTR(Trim(DNAME)));
        SQL.Add(' where TTId=''' + Trim(Order_Main.fieldbyname('TTId').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('TTId：' + trim(Order_Main.FieldByName('TTID').AsString))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
//      Order_Main.Delete;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!', '提示', 0);
    initgrid();
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmContractDCList.ToolButton14Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderCon_TT A  ');
    SQL.Add('where TTId=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + ''' ');
    SQL.Add(' AND  ChkStatus=1 ');
    Open;
  end;
  if ADOQueryTemp.ISEMPTY = True then
  begin
    Application.MessageBox('当前数据状态已改变，请刷新后操作!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要执行此操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update JYOrderCon_TT Set QRDATE=NULL   ');
        SQL.Add(' where TTId=''' + Trim(Order_Main.fieldbyname('TTId').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('TTId：' + trim(Order_Main.FieldByName('TTID').AsString))));
        sql.Add(',' + quotedstr(trim('成功')));
        sql.Add(')');
        ExecSQL;
      end;
//      Order_Main.Delete;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('操作成功!', '提示', 0);
    initgrid();
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmContractDCList.ToolButton15Click(Sender: TObject);
var
  fPrintFile, FTaiTou: string;
  EngMoney: string;
  Canvas: TCanvas;
begin
  if Order_Main.IsEmpty then
    Exit;
  if combobox1.Text = '' then
    exit;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf';
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryPrint);
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT A.*');
    SQL.Add(',GSNAME=''振永纺织''');
    SQL.Add(',ZORDERNO=CAST((SELECT  STUFF(( SELECT  '','' +convert(VARCHAR, FROMORDERNO) FROM JYOrderCon_TT_Sub B WHERE A.TTID=B.TTId FOR XML PATH('''')), 1, 1, '''') )AS VARCHAR)');
    SQL.Add(',ZQTY=(SELECT SUM(PRTORDERQTY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZMONEY=(SELECT SUM(MONEY) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZMAOZHONG=(SELECT SUM(MAOZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZJINGZHONG=(SELECT SUM(JINGZHONG) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZTIJI=(SELECT SUM(tiji) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    SQL.Add(',ZBZJS=(SELECT SUM(BZJS) FROM JYOrderCon_TT_Sub C WHERE A.TTID=C.TTId)');
    sql.Add(' from JYOrderCon_TT A ');
    SQL.Add('where ((FILLTIME>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + '''');
    SQL.Add('and  FILLTIME<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''') or ChkStatus=''审核不通过'') ');
    SQL.ADD('AND TTID=''' + Trim(Order_Main.fieldbyname('TTId').AsString) + '''');
//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  Canvas := TCanvas.Create;

  Canvas := TCanvas.Create;

  if FileExists(fPrintFile) then
  begin

    RM1.LoadFromFile(fPrintFile);
    Sleep(1000);
    RM1.PrintReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf'), '提示', 0);
  end;
end;

procedure TfrmContractDCList.DCNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmContractDCList.cxTabControl2Change(Sender: TObject);
begin
  cxTabControl1.TabIndex := cxTabControl2.TabIndex + 1;
end;

end.

