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, cxCheckBox, cxDropDownEdit, cxLookAndFeels,
  cxLookAndFeelPainters, dxBarBuiltInMenu, cxNavigator, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans,
  dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmProductOrderList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    TBCK: TToolButton;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    DS_PB: TDataSource;
    ToolButton4: TToolButton;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    TWC: TToolButton;
    TNowc: TToolButton;
    TRZ: TToolButton;
    N1: TMenuItem;
    cxPageControl1: TcxPageControl;
    cxTabSheet3: TcxTabSheet;
    cxTabSheet4: TcxTabSheet;
    cxTabControl1: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column11: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxTabControl2: TcxTabControl;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1Ssel: TcxGridDBColumn;
    v1MJXH: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    v1P_CodeName: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel2: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label12: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    CustomerNoName: TEdit;
    MPRTCodeName: TEdit;
    ConNo: TEdit;
    MPRTSpec: TEdit;
    MPRTKZ: TEdit;
    CDS_PB: TClientDataSet;
    PopupMenu2: TPopupMenu;
    N3: TMenuItem;
    V2Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    N4: TMenuItem;
    Panel1: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    CPColor: TEdit;
    fromFactoryName: TEdit;
    CodeName: TEdit;
    BatchNo: TEdit;
    Edit6: TEdit;
    V2Column2: TcxGridDBColumn;
    PBbegdate: TDateTimePicker;
    PBenddate: TDateTimePicker;
    chkCRTime: TCheckBox;
    cxGridPopupMenu2: TcxGridPopupMenu;
    V2Column4: TcxGridDBColumn;
    V2Column5: TcxGridDBColumn;
    V2Column6: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(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 FormShow(Sender: TObject);
    procedure TBTPClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBCKClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    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 TRZClick(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure cxPageControl1Change(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure cxTabControl2Change(Sender: TObject);
    procedure chkCRTimeClick(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitGridFH();
    procedure SetStatus();
    procedure InitGrid();
    procedure InitPBKC();
    procedure InitPage();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1, canshu2: string;
    fFlileFlag: string;
    { Public declarations }
  end;

implementation

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

{$R *.dfm}
procedure TfrmProductOrderList.InitPage();
begin

  case cxPageControl1.ActivePageIndex of
    0:
      begin
        InitPBKC();
      end;
    1:
      begin
        InitGrid();
      end;
  end;
end;

procedure TfrmProductOrderList.InitPBKC();
var
  strwhere: string;
begin
  strwhere := SGetFilters(Panel1, 1, 2);
  try
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.*  ');
      sql.Add(' ,FPPS=(Select SUM(FPPS) from JYOrder_PBKC X where X.KCId=A.KCId) ');
      sql.Add(' ,KFPPS=PS-isnull((Select SUM(FPPS) from JYOrder_PBKC X where X.KCId=A.KCId),0) ');
      sql.Add('   from CK_PB_CR A ');
      sql.Add(' where CRFlag=''入库'' and Valid=''Y'' and A.KCPS>0 and CKName=''坯布仓库'' ');
      if chkCRTime.Checked then
      begin
        sql.Add('and A.CRTime>=' + Quotedstr(formatdateTime('yyyy-MM-dd', PBbegdate.Date)));
        sql.Add('and A.CRTime<' + Quotedstr(formatdateTime('yyyy-MM-dd', PBenddate.Date + 1)));
      end;
      case cxTabControl2.TabIndex of
        0:
          begin
            SQL.Add(' and not exists( select KCId from JYOrder_PBKC X where X.KCId=A.KCId )');
          end;
        1:
          begin
            SQL.Add(' and exists( select KCId from JYOrder_PBKC X where X.KCId=A.KCId )');
          end;
      end;

      if strwhere <> '' then
        SQL.Add(' and  ' + strwhere);
      sql.Add('   order by  CRTime   ');
//      ShowMessage(SQL.Text);
      open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_PB);
    SInitCDSData20(ADOQueryMain, CDS_PB);
  finally
  end;
end;

procedure TfrmProductOrderList.InitGrid();
var
  strwhere: string;
begin
  strwhere := SGetFilters(Panel2, 1, 2);
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('select AA.* from (');
      sql.add('select A.*,B.SubId,B.XHNo,B.PRTColor,B.PRTPs,B.PRTOrderQty,B.OrderUnit,B.DBColor');
      sql.add('from JYOrder_Main A inner join JYOrder_Sub B on A.MainId=B.MainId');
      sql.Add('where A.FILLTime>=' + Quotedstr(formatdateTime('yyyy-MM-dd', begdate.Date)));
      sql.Add('and A.FILLTime<' + Quotedstr(formatdateTime('yyyy-MM-dd', enddate.Date + 1)));
      if Trim(canshu1) = '录入' then
        sql.Add('and Filler=' + Quotedstr(Trim(DName)));
      if cxTabControl1.TabIndex < 3 then
      begin
        sql.Add(' and  isnull(A.status,''0'')=' + Quotedstr(Trim(inttostr(cxTabControl1.TabIndex))));
      end;
      SQL.Add(') AA  ');
      if strwhere <> '' then
        SQL.Add(' where  ' + strwhere);
      sql.Add(' order by Priority ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderList.SetStatus();
begin
  tchk.Visible := false;
  tnochk.Visible := false;
  tbedit.Visible := false;
  tbdel.Visible := false;
  twc.Visible := false;
  tNOwc.Visible := false;
  N4.Visible := false;
  N3.Visible := false;
  Panel1.Visible := false;
  Panel2.Visible := false;
  case cxPageControl1.ActivePageIndex of
    0:
      begin
        Panel1.Visible := true;
        case cxTabControl2.TabIndex of
          0:
            begin
              N3.Visible := true;
            end;
          1:
            begin
              N3.Visible := true;
            end;
        end;
      end;
    1:
      begin
        Panel2.Visible := 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;
                N4.Visible := true;
              end;
            2:
              begin
                tNOwc.Visible := true;
              end;
          end;
        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;
                N4.Visible := true;
              end;
            2:
              begin

              end;

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

  end;
  N4.Visible := true;
end;

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

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

end;

procedure TfrmProductOrderList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单列表FF', Tv1, '生产指示单管理');
  WriteCxGrid('坯布库存查询FF', Tv2, '生产指示单管理');
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
  ReadCxGrid('指示单列表FF', Tv1, '生产指示单管理');
  ReadCxGrid('坯布库存查询FF', Tv2, '生产指示单管理');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  PBEndDate.DateTime := EndDate.DateTime;
  PBBegDate.DateTime := PBEndDate.DateTime - 10;
  if trim(DdataBase) = '查询' then
  begin
    TBadd.Visible := false;
    tbedit.Visible := false;
    ToolButton2.Visible := false;
    tbdel.Visible := false;
  end;
  SetStatus();
  InitPage();
end;

procedure TfrmProductOrderList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
  begin
    Application.MessageBox('不能操作他人的数据!', '提示', 0);
    Exit;
  end;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      FOrderNo := Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      canshu1 := self.canshu1;
      conNo.Enabled := false;
      if ShowModal = 1 then
      begin
        InitPage();
      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(Order_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
  begin
    Application.MessageBox('不能操作他人的数据!', '提示', 0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrder_car A  ');
    SQL.Add('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('delete JYOrder_PBKC where YYPS=0 and 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;

  LBName := '染整指示单';
  ExportFtErpFile(Trim(LBName) + '.rmf', ADOQueryTemp);
  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.LoadFromFile(fPrintFile);
    RMVariables['SYRName'] := Trim(SYRName);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\' + Trim(LBName) + '.rmf'), '提示', 0);
  end;
end;

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

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

procedure TfrmProductOrderList.FormShow(Sender: TObject);
begin
  fFlileFlag := UserDataFlag + 'HX';
  cxTabControl1.TabIndex := 3;
  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.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, false);
end;

procedure TfrmProductOrderList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, true);
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);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      FOrderNo := Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      ToolBar2.Visible := False;
      ToolBar3.Visible := False;
      TBSave.Visible := False;
      ScrollBox1.Enabled := False;
      Tv1.OptionsSelection.CellSelect := False;
      if ShowModal = 1 then
      begin

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

procedure 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);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      canshu1 := self.canshu1;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  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.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 Order_Main.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('是否核实好数据？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    while Order_Main.Locate('', True, []) do
    begin
      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;
      Order_Main.Delete;
    end;
    application.MessageBox('订单审核成功！', '提示信息');
  except
    application.MessageBox('订单审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderList.TnochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrder_car A  ');
    SQL.Add('where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + ''' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('开卡数据不能操作!', '提示', 0);
    Exit;
  end;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''0'',chker=null,Chktime=null,Priority=0 ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('订单撤销审核')));
      sql.Add(',' + quotedstr(trim('订单号：' + trim(Order_Main.FieldByName('orderNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('订单撤销审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('订单撤销审核失败！', '提示信息', 0);
  end;
end;

procedure 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'',Priority=0 ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('订单完成')));
      sql.Add(',' + quotedstr(trim('订单号：' + trim(Order_Main.FieldByName('orderNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('订单完成成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('订单完成失败！', '提示信息', 0);
  end;
end;

procedure 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.TRZClick(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
    showmodal;
    free;
  end;
end;

procedure TfrmProductOrderList.N3Click(Sender: TObject);
begin
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 0;
      FOrderNo := '';
      FMainId := '';
      FSubId := '';
      FKCID := Trim(Self.CDS_PB.fieldbyname('KCID').AsString);
      canshu1 := self.canshu1;
      if ShowModal = 1 then
      begin
        InitPage();
      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    InitPage();
end;

procedure TfrmProductOrderList.cxPageControl1Change(Sender: TObject);
begin
  SetStatus();
  InitPage();
end;

procedure TfrmProductOrderList.N4Click(Sender: TObject);
var
  str: string;
begin
  str := '1';
  if InputQuery('优先级', '请输入数字', str) then
  begin
    try
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('update  JYOrder_Main SET Priority=Priority+1');
        sql.Add('where Priority>=' + str);
        sql.Add(' and  isnull(status,''0'')= ''1'' ');

        sql.Add('update  JYOrder_Main SET Priority=' + str);
        sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
//        ShowMessage(SQL.Text);
        execsql;
      end;
      application.MessageBox('操作成功！', '提示信息');
      InitPage();
    except
      application.MessageBox('操作失败！', '提示信息', 0);
    end;
  end;
end;

procedure TfrmProductOrderList.cxTabControl2Change(Sender: TObject);
begin
  SetStatus();
  InitPage();
end;

procedure TfrmProductOrderList.chkCRTimeClick(Sender: TObject);
begin
  InitPage();
end;

end.

