unit U_ProductOrderList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxCurrencyEdit, cxImage, cxDBEdit, Menus, RM_Common, RM_Class, RM_e_Xls,
  RM_Dataset, RM_System, RM_GridReport, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxPC, cxSplitter, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, ShellAPI, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, cxDropDownEdit, Printers, 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
  TfrmProductOrderList = 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;
    OrderNoM: TEdit;
    TBExport: TToolButton;
    v1OrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    Label4: TLabel;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    TBCK: TToolButton;
    Label9: TLabel;
    ConNo: TEdit;
    v1MPRTKZ: TcxGridDBColumn;
    Label11: TLabel;
    MPRTCode: TEdit;
    Label12: TLabel;
    MPRTKZ: TEdit;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    v1Column5: TcxGridDBColumn;
    ToolButton4: TToolButton;
    cxTabControl1: TcxTabControl;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    TWC: TToolButton;
    TNowc: TToolButton;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Panel2: TPanel;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    IdFTP1: TIdFTP;
    TRZ: TToolButton;
    v1Column4: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    RMDBMX: TRMDBDataSet;
    CDSPRTMX: TClientDataSet;
    CDSPRTHZ: TClientDataSet;
    RMDBHZ: TRMDBDataSet;
    RM2: TRMGridReport;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    ToolButton1: TToolButton;
    cxGridPopupMenu2: TcxGridPopupMenu;
    RMDBPZ: TRMDBDataSet;
    CDS_PZ: TClientDataSet;
    RMDBSJ: TRMDBDataSet;
    CDS_SJ: TClientDataSet;
    ToolButton3: TToolButton;
    v1Column13: TcxGridDBColumn;
    ToolButton5: TToolButton;
    ComboBox1: TComboBox;
    CustomerNoName: TComboBox;
    ToolButton6: TToolButton;
    Panel3: TPanel;
    Label2: TLabel;
    Edit1: TEdit;
    Label5: TLabel;
    Edit2: TEdit;
    Label6: TLabel;
    Edit3: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label7: TLabel;
    Label8: TLabel;
    Edit4: TEdit;
    Label10: TLabel;
    Edit5: TEdit;
    combobox2: TBtnEditC;
    Label13: TLabel;
    Edit6: TEdit;
    Label14: TLabel;
    KHConNo: TEdit;
    Label15: TLabel;
    Edit7: TEdit;
    Label16: TLabel;
    Edit8: TEdit;
    Label17: TLabel;
    HZPRTKUANNO: TEdit;
    Tv1Column1: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1PRTColor: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxgrdbclmnv1Column8: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxgrdbclmnv1Column9: TcxGridDBColumn;
    cxgrdbclmnv1Column10: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label34: TLabel;
    ComboBox3: TComboBox;
    Label18: TLabel;
    Edit9: TEdit;
    Label19: TLabel;
    Edit10: TEdit;
    Button3: TButton;
    Label20: TLabel;
    ComboBox4: TComboBox;
    Label33: TLabel;
    ComboBox5: TComboBox;
    Tv1Column2: TcxGridDBColumn;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Label21: TLabel;
    HZPRTCOLOR: TEdit;
    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 OrderNoMChange(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 TBCKClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure OrderNoMKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    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 TRZClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure combobox2BtnDnClick(Sender: TObject);
    procedure combobox2BtnUpClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitGridFH();
    procedure InitSub();
    procedure SetStatus();
    procedure InitImage(fwbid: string);
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1, canshu2: string;
    fFlileFlag: string;

    { Public declarations }
  end;

function GetCurrentPrinterHandle: THandle;
//var
//  frmProductOrderList: TfrmProductOrderList;

implementation

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

{$R *.dfm}
function GetCurrentPrinterHandle: THandle;
var
  Device, Driver, Port: array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
//  if not OpenPrinter(@Device, Result, nil) then
//    RaiseLastWin32Error;
end;

procedure TfrmProductOrderList.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 TfrmProductOrderList.SetStatus();
begin
  tchk.Visible := false;
  tnochk.Visible := false;
  tbedit.Visible := false;
  tbdel.Visible := false;
  twc.Visible := false;
  tNOwc.Visible := false;
  Tv1Column2.Visible := FALSE;
  Tv1Column2.Hidden := TRUE;
  if Trim(canshu1) = '高权限' 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;

        end;
      2:
        begin
          tNOwc.Visible := true;

        end;
      3:
        begin

        end;
    end;
    Tv1Column2.Visible := TRUE;
    Tv1Column2.Hidden := FALSE;
  end;

  if Trim(canshu1) = '录入' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          tbedit.Visible := true;
          tbdel.Visible := true;
          tchk.Visible := true;
        end;
      1:
        begin
          tnochk.Visible := true;
        end;
      2:
        begin

        end;
      3:
        begin
        end;
    end;
  end;
  if Trim(canshu1) = '查询' then
  begin
    ToolButton2.Visible := false;
    tbadd.Visible := false;
  end;
end;

procedure TfrmProductOrderList.InitSub();
begin
  ADOQuerySub.Close;
  if Order_Main.IsEmpty then
    exit;
  ADOQuerySub.DisableControls;
  with ADOQuerySub do
  begin
    close;
    sql.Clear;
    sql.Add('select * from JYOrder_sub ');
    sql.Add('where mainID =' + quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    open;
  end;
  ADOQuerySub.EnableControls;
end;

procedure TfrmProductOrderList.FormDestroy(Sender: TObject);
begin
//  frmProductOrderList:=nil;
end;

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

procedure TfrmProductOrderList.FormCreate(Sender: TObject);
var
  hPrinter: THandle;
begin
//  hPrinter := GetCurrentPrinterHandle; //如果想取得详细的打印机信息，可用此句柄，否删除这行
  ComboBox5.Items.Assign(Printer.Printers);
//  ComboBox2.ItemIndex := 0; //指向第一台打印机
  ComboBox5.Items.Add('默认打印机');
  ComboBox5.ItemIndex := Self.ComboBox5.Items.IndexOf(trim('默认打印机'));

  ReadCxGrid('指示单列表SD', Tv1, '生产指示单管理');
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);

end;

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

procedure TfrmProductOrderList.InitGrid();
var
  strwhere: string;
begin
  strwhere := '';
  if Trim(canshu1) = '录入' then
    strwhere := strwhere + ' and (Filler=''' + Trim(DName) + '''' + 'or lidan=''' + Trim(DName) + '''' + 'or gdy=''' + Trim(DName) + ''')';
//  SHOWMESSAGE(strwhere);
  if cxTabControl1.TabIndex < 3 then
  begin
    strwhere := strwhere + ' and  isnull(A.status,''0'')=''' + inttostr(cxTabControl1.TabIndex) + '''';
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.add('exec P_View_Order :begdate,:enddate,:WSql');

      Parameters.ParamByName('WSql').Value := strwhere;
      Parameters.ParamByName('begdate').Value := FormatDateTime('yyyy-MM-dd', BegDate.DateTime);
      Parameters.ParamByName('enddate').Value := FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1);

      ExecSQL;

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderList.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 TfrmProductOrderList.InitForm();
begin

  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 30;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);

  if canshu1 <> '高权限' then
  begin
    ToolButton1.visible := false;

  end;
  if trim(DdataBase) = '查询' then
  begin
    TBadd.Visible := false;
    tbedit.Visible := false;
    ToolButton2.Visible := false;
    tbdel.Visible := false;

  end;
  SetStatus();
  InitGrid();
end;

procedure TfrmProductOrderList.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 TfrmProductOrderList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if canshu1 <> '高权限' then
  begin
    if (Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName)) and (Trim(Order_Main.fieldbyname('lidan').AsString) <> Trim(DName)) then
    begin
      Application.MessageBox('不能操作他人的数据!', '提示', 0);
      Exit;
    end;
  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; }
  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('OrderNoM').AsString);
      canshu1 := self.canshu1;
      conNo.Enabled := false;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
  self.TBRafresh.Click;
end;

procedure TfrmProductOrderList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if canshu1 <> '高权限' then
  begin
    if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
    begin
      Application.MessageBox('不能操作他人的数据!', '提示', 0);
      Exit;
    end;
  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('or ORDMainIdRK=''' + 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 CK_PBMX_CR A  ');
//    SQL.Add('where ToMainId='''+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 TfrmProductOrderList.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 TfrmProductOrderList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '生产指示单列表');
end;

procedure TfrmProductOrderList.TBPrintClick(Sender: TObject);
var
  fPrintFile: string;
  Porderno, LBName, SYRName: string;
  i, j: Integer;
  OrderKg: Double;
begin
  if Order_Main.IsEmpty then
    Exit;
  if ComboBox1.Text = '' then
    Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select SellName from SalesContract_Main where conno=' + quotedstr(trim(Order_Main.fieldbyname('conno').AsString)));
//    showmessage(sql.Text);
    Open;
  end;
  if ADOQueryCmd.IsEmpty = False then
  begin
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴拓轩纺织品有限公司' then
    begin
      LBName := '拓轩计划单';
      ExportFtErpFile('拓轩计划单.rmf', ADOQueryTemp);
    end;
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴御函纺织品有限公司' then
    begin
      LBName := '御函计划单';
      ExportFtErpFile('御函计划单.rmf', ADOQueryTemp);
    end;
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴雨函纺织品有限公司' then
    begin
      LBName := '雨函计划单';
      ExportFtErpFile('雨函计划单.rmf', ADOQueryTemp);
    end;

    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴钹纺国际贸易有限公司' then
    begin
      LBName := '钹纺计划单';
      ExportFtErpFile('钹纺计划单.rmf', ADOQueryTemp);
    end;
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴铱研纺织品有限公司' then
    begin
      LBName := '铱研计划单';
      ExportFtErpFile('铱研计划单.rmf', ADOQueryTemp);
    end;
  end
  else
  begin
    LBName := ComboBox1.Text + '计划单';
    ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);
  end;

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Print_Order');
    sql.add('@mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
    Open;
  end;

  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
    RM1.LoadFromFile(fPrintFile);
    RMVariables['SYRName'] := Trim(SYRName);
    RM1.ShowPrintDialog := True;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
  end;
  RM1.ShowPrintDialog := False;
end;

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

procedure TfrmProductOrderList.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 TfrmProductOrderList.OrderNoMChange(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 TfrmProductOrderList.FormShow(Sender: TObject);
var
  fsj: string;
begin
  fFlileFlag := UserDataFlag + 'HX';
  cxTabControl1.TabIndex := 1;

  fsj := 'select distinct(CustomerNoName) Name from JYORDER_MAIN  order by CustomerNoName ';
  SInitComBoxBySql(ADOQueryCmd, CustomerNoName, False, fsj);
  InitForm();
end;

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

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

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

procedure TfrmProductOrderList.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 TfrmProductOrderList.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 TfrmProductOrderList.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 TfrmProductOrderList.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 TfrmProductOrderList.TBCKClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      ToolBar2.Visible := False;
      TBSave.Visible := False;
      ScrollBox1.Enabled := False;
      Tv1.OptionsSelection.CellSelect := False;
      if ShowModal = 1 then
      begin

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

procedure TfrmProductOrderList.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 TfrmProductOrderList.OrderNoMKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(OrderNoM.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(canshu1) <> '高权限' then
        begin
          Parameters.ParamByName('WSql').Value := ' and Filler=''' + Trim(DName) + '''';
        end;
        begin
          Parameters.ParamByName('WSql').Value := ' and orderno like ''' + '%' + Trim(OrderNoM.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 TfrmProductOrderList.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(canshu1) <> '高权限' 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 TfrmProductOrderList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitSub();
end;

procedure TfrmProductOrderList.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 TfrmProductOrderList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

procedure TfrmProductOrderList.TchkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Application.MessageBox('是否核实好数据？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''1'',chker=''' + trim(DName) + ''',Chktime=getdate() ');
      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 TfrmProductOrderList.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'',chker=null,Chktime=null ');
      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 TfrmProductOrderList.TWCClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Application.MessageBox('是否核实好数据？', '提示', 32 + 4) <> IDYES 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 TfrmProductOrderList.TNowcClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Application.MessageBox('是否撤销审核数据？', '提示', 32 + 4) <> IDYES 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 TfrmProductOrderList.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
//  initImage(ADOQuerySub.fieldbyname('HXFile').AsString);
  if Panel3.Visible = true then
  begin
    Edit2.Text := Trim(ADOQuerySub.fieldbyname('PRTColor').AsString) + ' ' + Trim(ADOQuerySub.fieldbyname('PRTeColor').AsString);
    Edit4.Text := Trim(ADOQuerySub.fieldbyname('PRTColorno').AsString);
    Edit5.Text := Trim(ADOQuerySub.fieldbyname('prtkuanno').AsString);
    Edit6.Text := Trim(ADOQuerySub.fieldbyname('PRTEColor').AsString);

  end;
end;

procedure TfrmProductOrderList.TRZClick(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmProductOrderList.ToolButton1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, LBName, SYRName: string;
  i, j: Integer;
  OrderKg: Double;
begin
  if Order_Main.IsEmpty then
    Exit;
  if ComboBox1.Text = '' then
    Exit;

//  LBName := ComboBox1.Text + '采购单';
//  ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select SellName from SalesContract_Main where conno=' + quotedstr(trim(Order_Main.fieldbyname('conno').AsString)));
//    showmessage(sql.Text);
    Open;
  end;
  if ADOQueryCmd.IsEmpty = False then
  begin
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴拓轩纺织品有限公司' then
    begin
      LBName := '拓轩采购单';
      ExportFtErpFile('拓轩采购单.rmf', ADOQueryTemp);
    end;
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴御函纺织品有限公司' then
    begin
      LBName := '御函采购单';
      ExportFtErpFile('御函采购单.rmf', ADOQueryTemp);
    end;
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴雨函纺织品有限公司' then
    begin
      LBName := '雨函采购单';
      ExportFtErpFile('雨函采购单.rmf', ADOQueryTemp);
    end;

    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴钹纺国际贸易有限公司' then
    begin
      LBName := '钹纺采购单';
      ExportFtErpFile('钹纺采购单.rmf', ADOQueryTemp);
    end;
    if ADOQueryCmd.fieldbyname('sellname').AsString = '绍兴铱研纺织品有限公司' then
    begin
      LBName := '铱研采购单';
      ExportFtErpFile('铱研采购单.rmf', ADOQueryTemp);
    end;

  end;

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Print_Order2');
    sql.add('@mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select SPZ1=PZ1,SPZ2=PZ2,SPZ3=PZ3,SPZ4=PZ4,SPZ5=PZ5,SPZ6=PZ6,SPZ7=PZ7,SPZ8=PZ8,SPZ9=PZ9,SPZ10=PZ10, ');
    sql.Add(' SPZ11=PZ11,SPZ12=PZ12,SPZ13=PZ13,SPZ14=PZ14,SPZ15=PZ15,SPZ16=PZ16,SPZ17=PZ17,SPZ18=PZ18,SPZ19=PZ19,SPZ20=PZ20, ');
    sql.Add(' SPZ21=PZ21,SPZ22=PZ22,SPZ23=PZ23,SPZ24=PZ24,SPZ25=PZ25,SPZ26=PZ26,SPZ27=PZ27,SPZ28=PZ28,SPZ29=PZ29,SPZ30=PZ30, ');
    sql.Add(' SPZ31=PZ31,SPZ32=PZ32,SPZ33=PZ33,SPZ34=PZ34,SPZ35=PZ35,SPZ36=PZ36 ');
    sql.Add(' from Cloth_PaiZhen B INNER JOIN CP_YDang A on A.CYID=B.MainId  where A.CYNO=''' + Trim(Order_Main.fieldbyname('MPRTCode').AsString) + '''');
    sql.Add(' and RTrim(PZType)=''单面三角'' ');
//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PZ);
  SInitCDSData20(ADOQueryTemp, CDS_PZ);
  if CDS_PZ.IsEmpty then
  begin
    CDS_PZ.Append;
    CDS_PZ.Post;
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select SPZ1=PZ1,SPZ2=PZ2,SPZ3=PZ3,SPZ4=PZ4,SPZ5=PZ5,SPZ6=PZ6,SPZ7=PZ7,SPZ8=PZ8,SPZ9=PZ9,SPZ10=PZ10, ');
    sql.Add(' SPZ11=PZ11,SPZ12=PZ12,SPZ13=PZ13,SPZ14=PZ14,SPZ15=PZ15,SPZ16=PZ16,SPZ17=PZ17,SPZ18=PZ18,SPZ19=PZ19,SPZ20=PZ20, ');
    sql.Add(' SPZ21=PZ21,SPZ22=PZ22,SPZ23=PZ23,SPZ24=PZ24,SPZ25=PZ25,SPZ26=PZ26,SPZ27=PZ27,SPZ28=PZ28,SPZ29=PZ29,SPZ30=PZ30, ');
    sql.Add(' SPZ31=PZ31,SPZ32=PZ32,SPZ33=PZ33,SPZ34=PZ34,SPZ35=PZ35,SPZ36=PZ36 ');
    sql.Add(' from Cloth_PaiZhen B INNER JOIN CP_YDang A on A.CYID=B.MainId   where A.CYNO=''' + Trim(Order_Main.fieldbyname('MPRTCode').AsString) + '''');
    sql.Add(' and RTrim(PZType)=''双面三角'' ');
//   ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_SJ);
  SInitCDSData20(ADOQueryTemp, CDS_SJ);
  if CDS_SJ.IsEmpty then
  begin
    CDS_SJ.Append;
    CDS_SJ.Post;
  end;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
    RM1.LoadFromFile(fPrintFile);
    RMVariables['SYRName'] := Trim(SYRName);
    RM1.ShowPrintDialog := True;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
  end;
  RM1.ShowPrintDialog := False;
end;

procedure TfrmProductOrderList.ToolButton3Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    exit;
  if trim(Order_Main.fieldbyname('LBName').AsString) = '' then
    exit;
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add('exec P_Print_Cs_Roll ');
    sql.Add('@mainID=''' + trim(Order_Main.fieldbyname('mainID').AsString) + ''' ');
    Open;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('MJID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;
  ExportFtErpFile(Trim(Order_Main.fieldbyname('LBName').AsString) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(Order_Main.fieldbyname('LBName').AsString) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
    RMVariables['QRBARCODE'] := fImagePath;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
  end;
end;

procedure TfrmProductOrderList.Button1Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  i: integer;
begin
  if Order_Main.IsEmpty then
    exit;
  if trim(ComboBox2.Text) = '' then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update JYOrder_Main SET CYLABNAME=' + QuotedStr(combobox2.Text));
    SQL.Add('WHERE MAINID=' + QuotedStr(Trim(Order_Main.fieldbyname('MAINID').AsString)));
//    ShowMessage(sql.Text);
    EXECSQL;
  end;
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT *,gstt=(select top 1 sellname from SalesContract_Main c where a.conno=c.conno) FROM JYORDER_MAIN A  WHERE A.MAINID=' + QuotedStr(Trim(Order_Main.fieldbyname('MAINID').AsString)));
//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  ExportFtErpFile(Trim(ComboBox2.Text) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ComboBox2.Text) + '.rmf';

  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('MAINID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;

  if FileExists(fPrintFile) then
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
    RMVariables['QRBARCODE'] := fImagePath;

    RMVariables['gangno'] := Edit1.Text;
    RMVariables['color'] := Edit2.Text;
    RMVariables['MJLEN'] := Edit3.Text;
    RMVariables['MJMAOZ'] := Edit8.Text;
    RMVariables['MJYLEN'] := Edit7.Text;
    RMVariables['MXMJXH'] := Edit9.Text;
    RMVariables['mxqty'] := Edit8.Text;
    RMVariables['mxqty2'] := Edit7.Text;
//    RMVariables['mjmaoz'] := Edit8.Text;
    RMVariables['colorno'] := Edit4.Text;
    RMVariables['PRTKUANNO'] := Edit5.Text;
    RMVariables['PRTEColor'] := Edit6.Text;

    RMVariables['SELLNAME'] := Order_Main.fieldbyname('SELLNAME').AsString;
    RMVariables['SPCODE'] := Order_Main.fieldbyname('MPRTCODE').AsString;

    RMVariables['mxkh'] := Order_Main.fieldbyname('CustomerNoName').AsString;
    RMVariables['spcolor'] := Edit2.Text;
    RMVariables['specolor'] := Edit6.Text;
    RMVariables['spname'] := Order_Main.fieldbyname('MPRTCODENAME').AsString;
    RMVariables['mxspec'] := Order_Main.fieldbyname('MPRTspec').AsString;
    RMVariables['spmf'] := Order_Main.fieldbyname('MPRTMF').AsString;
    RMVariables['spKZ'] := Order_Main.fieldbyname('MPRTKZ').AsString;
    RMVariables['MXkuanno'] := Edit5.Text;
    RMVariables['spkuanno'] := Edit5.Text;
    RMVariables['PRTColorNo'] := Edit4.Text;
    RMVariables['MXGangHao'] := Edit1.Text;
//    RMVariables['MXmjxh'] := 1;

    RMVariables['mxtt'] := Order_Main.fieldbyname('BJTT').AsString;  
    //IntToStr(StrToInt(Edit9.Text) + i - 1);
    RM1.DefaultCopies := strtointdef(trim(ComboBox3.Text), 1);
    RM1.LoadFromFile(fPrintFile);
    if ComboBox4.Text = '预览' then
    begin
      RM1.ShowReport;
    end
    else
    begin
      RM1.PrintReportL(ComboBox5.Text);
    end;

  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
  end;

end;

procedure TfrmProductOrderList.Button2Click(Sender: TObject);
begin
  Panel3.Visible := False;
end;

procedure TfrmProductOrderList.ToolButton6Click(Sender: TObject);
begin
  Panel3.Visible := True;
  combobox2.Text := Order_Main.FIELDBYNAME('lbname').AsString;
  if Panel3.Visible = true then
  begin
    Edit2.Text := Trim(ADOQuerySub.fieldbyname('PRTColor').AsString) + ' ' + Trim(ADOQuerySub.fieldbyname('PRTeColor').AsString);
    Edit4.Text := Trim(ADOQuerySub.fieldbyname('PRTColorno').AsString);
    Edit5.Text := Trim(ADOQuerySub.fieldbyname('prtkuanno').AsString);
    Edit6.Text := Trim(ADOQuerySub.fieldbyname('PRTEColor').AsString);

  end;
end;

procedure TfrmProductOrderList.combobox2BtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmProductOrderList.combobox2BtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      fnote := True;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmProductOrderList.Button3Click(Sender: TObject);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  i: integer;
begin
  if Order_Main.IsEmpty then
    exit;
  if trim(ComboBox2.Text) = '' then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update JYOrder_Main SET CYLABNAME=' + QuotedStr(combobox2.Text));
    SQL.Add('WHERE MAINID=' + QuotedStr(Trim(Order_Main.fieldbyname('MAINID').AsString)));
//    ShowMessage(sql.Text);
    EXECSQL;
  end;
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT *,gstt=(select top 1 sellname from SalesContract_Main c where a.conno=c.conno) FROM JYORDER_MAIN A  WHERE A.MAINID=' + QuotedStr(Trim(Order_Main.fieldbyname('MAINID').AsString)));
//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  ExportFtErpFile(Trim(ComboBox2.Text) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ComboBox2.Text) + '.rmf';
  for i := 1 to StrToIntDef(Edit10.Text, 1) do
  begin

    try
      Moudle := LoadLibrary('MakeQRBarcode.dll');
      @Makebar := GetProcAddress(Moudle, 'Make');
      @Mixtext := GetProcAddress(Moudle, 'MixText');
      Txt := Trim(ADOQueryPrint.fieldbyname('MAINID').AsString);
      fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
      if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
        CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
      if FileExists(fImagePath) then
        DeleteFile(fImagePath);
      Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
    except
      application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
      exit;
    end;

    if FileExists(fPrintFile) then
    begin
      RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
      RMVariables['QRBARCODE'] := fImagePath;

      RMVariables['MJMAOZ'] := '';
      RMVariables['MJYLEN'] := '';
      RMVariables['mxqty'] := '';
      RMVariables['mxqty2'] := '';
      RMVariables['gangno'] := Edit1.Text;
      RMVariables['color'] := Edit2.Text;
      RMVariables['mxkh'] := Order_Main.fieldbyname('CustomerNoName').AsString;
      RMVariables['colorno'] := Edit4.Text;
      RMVariables['PRTKUANNO'] := Edit5.Text;
      RMVariables['PRTEColor'] := Edit6.Text;
      RMVariables['SELLNAME'] := Order_Main.fieldbyname('SELLNAME').AsString;
      RMVariables['SPCODE'] := Order_Main.fieldbyname('MPRTCODE').AsString;
      RMVariables['spcolor'] := Edit2.Text;
      RMVariables['specolor'] := Edit6.Text;
      RMVariables['spname'] := Order_Main.fieldbyname('MPRTCODENAME').AsString;
      RMVariables['mxspec'] := Order_Main.fieldbyname('MPRTspec').AsString;
      RMVariables['spmf'] := Order_Main.fieldbyname('MPRTMF').AsString;
      RMVariables['spKZ'] := Order_Main.fieldbyname('MPRTKZ').AsString;
      RMVariables['MXkuanno'] := Edit5.Text;
      RMVariables['spkuanno'] := Edit5.Text;
      RMVariables['PRTColorNo'] := Edit4.Text;
      RMVariables['MXGangHao'] := Edit1.Text;
      RMVariables['MXmjxh'] := IntToStr(StrToInt(Edit9.Text) + i - 1);
      RMVariables['mxtt'] := Order_Main.fieldbyname('BJTT').AsString;
      RM1.DefaultCopies := strtointdef(trim(ComboBox3.Text), 1);
      RM1.LoadFromFile(fPrintFile);
      if ComboBox4.Text = '预览' then
      begin
        RM1.ShowReport;
      end
      else
      begin
        RM1.PrintReportL(ComboBox5.Text);

      end;
    end
    else
    begin
      Application.MessageBox(PChar('没有找到' + trim(fPrintFile)), '提示信息', 0);
    end;
  end;
end;

procedure TfrmProductOrderList.ToolButton7Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, LBName, SYRName: string;
  i, j: Integer;
  OrderKg: Double;
begin
  if Order_Main.IsEmpty then
    Exit;
  if ComboBox1.Text = '' then
    Exit;
  LBName := '检验报告(中)';
  ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Print_Order_K');
    sql.add('@mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
    Open;
  end;

  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
    RM1.LoadFromFile(fPrintFile);
    RMVariables['SYRName'] := Trim(SYRName);
    RM1.ShowPrintDialog := True;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
  end;
  RM1.ShowPrintDialog := False;
end;

procedure TfrmProductOrderList.ToolButton8Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, LBName, SYRName: string;
  i, j: Integer;
  OrderKg: Double;
begin
  if Order_Main.IsEmpty then
    Exit;
  if ComboBox1.Text = '' then
    Exit;
  LBName := '检验报告(英)';
  ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Print_Order_K');
    sql.add('@mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
    Open;
  end;

  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.PreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit, pbSaveToXLS, pbExport, pbNavigator];
    RM1.LoadFromFile(fPrintFile);
    RMVariables['SYRName'] := Trim(SYRName);
    RM1.ShowPrintDialog := True;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
  end;
  RM1.ShowPrintDialog := False;
end;

end.

