unit U_ProductOrderNewList;

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, cxPC, cxCurrencyEdit,
  BtnEdit, cxButtonEdit, cxTextEdit, cxContainer, cxImage, cxDBEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu;

type
  TfrmProductOrderNewList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    TBExport: TToolButton;
    v1OrderNo: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1CustomerNoName: TcxGridDBColumn;
    Label4: TLabel;
    CustomerNoName: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    ToolButton1: TToolButton;
    Label2: TLabel;
    conno: TEdit;
    Label5: TLabel;
    OrdPerson1: TEdit;
    Label8: TLabel;
    PRTCodeName: TEdit;
    v1Column8: TcxGridDBColumn;
    Label11: TLabel;
    OrdDefStr1: TEdit;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    tchk: TToolButton;
    tNochk: TToolButton;
    v1EditTime: TcxGridDBColumn;
    v1ordderNote1: TcxGridDBColumn;
    TBPrint1: TToolButton;
    v1Filler: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    orderType: TComboBox;
    Label24: TLabel;
    CDSPrice: TClientDataSet;
    DSPrice: TDataSource;
    Trz: TToolButton;
    ADOPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RMDB_MD: TRMDBDataSet;
    ToolButton4: TToolButton;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    Pan_image: TPanel;
    Picture4: TcxDBImage;
    cxGrid3: TcxGrid;
    TV2: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v1Sorddefnote1: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolButton3: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    V2Column1: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    Label6: TLabel;
    Label7: TLabel;
    PRTCode: 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 OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure TBTPClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure 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 OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure tchkClick(Sender: TObject);
    procedure tNochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TBPrint1Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure TrzClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure TV2CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitGridFH();
    procedure SetStatus();
    procedure InitSub();
    procedure InitImage();
        { Private declarations }
  public
    FFInt, FCloth: Integer;
    fDParameters1: string;
    fCustomerNoName: string;
    forderType: string;
    fsyrName: string;
        { Public declarations }
  end;

//var
//  frmProductOrderNewList: TfrmProductOrderNewList;

implementation

uses
  U_DataLink, U_Fun, U_OrderInPut, U_ZdyAttachment, U_SysLogHelp;

{$R *.dfm}
procedure TfrmProductOrderNewList.InitSub();
begin

  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from JYOrder_sub ');
    sql.Add('where MainId =' + quotedstr((Order_Main.fieldbyname('MainId').AsString)));
    if Trim(fDParameters1) = '查询' then
    begin
      V2Column4.Visible := False;
    end
    else
    begin
      V2Column4.Visible := True;
    end;

//    if Trim(fDParameters1) <> '管理' then
//    begin
//      V2Column4.Visible := False;
//      V2Column3.Visible := False;
//      sql.Add('select * from JYOrder_sub ');
//      sql.Add('where MainId =' + quotedstr((Order_Main.fieldbyname('MainId').AsString)));
//    end
//    else
//    begin
//      V2Column4.Visible := True;
//      V2Column3.Visible := True;
//      sql.Add('SELECT  * FROM ( SELECT A.*,B.ZDYName,C.YGuPrice, ');
//      sql.Add(' CASE WHEN C.QSFanW<=A.PRTOrderQty and A.PRTOrderQty<=C.JZFanW THEN ''在'' ELSE ''不在'' END as Status  ');
//      sql.Add(' FROM JYOrder_sub A ');
//      sql.Add(' INNER JOIN KH_Zdy_Attachment B ON B.ATID= A.FromOrdATID ');
//      sql.Add(' INNER JOIN KH_Zdy_Attachment_Sub C ON C.ATID= A.FromATID  ');
//      sql.Add(' where MainId =' + quotedstr((Order_Main.fieldbyname('MainId').AsString)));
//      sql.Add(' ) AA WHERE AA.Status=''在'' ');
//    end;

    open;
   // ShowMessage(SQL.Text);
  end;
  SCreateCDS20(ADOQueryTemp, CDSPrice);
  SInitCDSData20(ADOQueryTemp, CDSPrice);
end;

procedure TfrmProductOrderNewList.InitImage();
begin
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    if trim(CDSPrice.fieldbyname('FromOrdATID').AsString) <> '' then
    begin
      sql.Add('where WBID=' + quotedstr(trim(CDSPrice.fieldbyname('FromOrdATID').AsString)));
    end
    else
      sql.Add('where 1<>1');
//    ShowMessage(SQL.Text);
    open;
  end;
end;

procedure TfrmProductOrderNewList.SetStatus();
begin
  Tchk.Visible := false;
  tNochk.Visible := false;
  TBEdit.Enabled := false;
  TBDel.Enabled := false;
  TBPrint.Visible := false;
  TBPrint1.Visible := false;
  ToolButton3.Visible := False;
  ToolButton5.Visible := False;
  ToolButton6.Visible := False;
  ToolButton7.Visible := False;
  if Trim(fDParameters1) = '查询' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          ToolButton3.Visible := True;
          TBEdit.Enabled := true;
          TBDel.Enabled := true;
        end;
      1:
        begin
          ToolButton5.Visible := True;
        end;
    end;

  end
  else if Trim(fDParameters1) = '审核' then
  begin
    TBADD.Visible := false;
    case cxTabControl1.TabIndex of
      0:
        begin
          TBEdit.Enabled := true;
          Tchk.Visible := true;
          TBDel.Enabled := true;
        end;
      1:
        begin
          tNochk.Visible := true;
          TBPrint.Visible := true;

        end;
    end;
  end
  else if Trim(fDParameters1) = '管理' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          TBEdit.Enabled := true;
          TBDel.Enabled := true;
          ToolButton3.Visible := True;
        end;
      1:
        begin
          Tchk.Visible := true;
          ToolButton5.Visible := True;
        end;
      2:
        begin
          tNochk.Visible := true;
          TBPrint.Visible := true;
          ToolButton6.Visible := True;
        end;
      3:
        begin
          ToolButton7.Visible := True;
        end;
    end;
  end;
end;

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

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

procedure TfrmProductOrderNewList.FormCreate(Sender: TObject);
begin
  //cxgrid1.Align:=alClient;
end;

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

procedure TfrmProductOrderNewList.InitGrid();
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.* ');
      sql.Add(',PrtCode=cast((select distinct ''''+PrtCode from JYOrder_Sub JCS where JCS.MainId=A.MainId for xml path('''')) as varchar(100))');
      sql.Add(',PrtCodeName=cast((select distinct ''''+PrtCodeName from JYOrder_Sub JCS where JCS.MainId=A.MainId for xml path('''')) as varchar(100))');
      sql.Add(' from JYOrder_Main A  ');
      SQL.Add('where isnull(A.OrdDate,FillTime)>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + '''');
      SQL.Add('and  isnull(A.OrdDate,FillTime)<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + '''');
      if Trim(fDParameters1) = '查询' then
      begin
        sql.Add('and FromBuM=''' + trim(forderType) + ''' ');
        sql.Add('and OrdPerson1=''' + trim(DName) + ''' ');
      end;
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and  isnull(A.status,''-1'')=''-1''');
          end;
        1:
          begin
            sql.Add(' and  isnull(A.status,''-1'')=''0''');
          end;
        2:
          begin
            sql.Add(' and  isnull(A.status,''-1'')=''1''');
          end;
        3:
          begin
            sql.Add(' and  isnull(A.status,''-1'')=''2''');
          end;
      end;
    //showmessage(sql.text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

procedure TfrmProductOrderNewList.InitGridFH();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec Order_QryList :MainId,:WSql');
      Parameters.ParamByName('WSql').Value := ' and FillTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''' + ' and FillTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderNewList.InitForm();
begin

  ReadCxGrid(self.Caption + tv1.Name, Tv1, '生产指示单管理');

  if FCloth = 1 then
  begin
    v1Column4.Visible := True;

  end
  else
  begin
    v1Column4.Visible := False;
  end;

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

  InitGrid();
  InitSub();
end;

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

procedure TfrmProductOrderNewList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      forderType := self.forderType;
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FOrderNo := Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
      FDHCYID := Trim(Self.Order_Main.fieldbyname('FDHCYID').AsString);
      fsyrName := self.fsyrName;
      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmProductOrderNewList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from CK_BanCP_CR A   ');
    SQL.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  if not ADOQueryTemp.IsEmpty then
  begin
    Application.MessageBox('已产生发货数据,不能删除!', '提示', 0);
    Exit;
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from CK_BanCP_PH A   ');
    SQL.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  if not ADOQueryTemp.IsEmpty then
  begin
    Application.MessageBox('已产生配货数据,不能删除!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    TBRafresh.Click;
  end;
end;

function TfrmProductOrderNewList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      sql.Add('delete JYOrder_Sub where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('生产指示单删除')));
      sql.Add(',' + quotedstr(trim('订单号：' + trim(Order_Main.FieldByName('orderNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');

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

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

procedure TfrmProductOrderNewList.TBPrintClick(Sender: TObject);
var
  fPrintFile: string;
  Porderno, PRTCodeName, funit: string;
  i, j, k: Integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf';

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Sub A');
    sql.Add('inner join JYOrder_Main  B on B.mainID=A.MainID ');
    sql.Add('where A.mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);

  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);
    Order_Main.EnableControls;
    exit;
  end;

  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RMVariables['customerNoName'] := Trim(Order_Main.fieldbyname('customerNoName').AsString);
    RMVariables['OrderNo'] := Trim(Order_Main.fieldbyname('OrderNo').AsString);
    RMVariables['Note'] := Trim(Order_Main.fieldbyname('Note').AsString);
    RMVariables['ShuoAddress'] := Trim(Order_Main.fieldbyname('ShuoAddress').AsString);
    RMVariables['SHPerson'] := Trim(Order_Main.fieldbyname('SHPerson').AsString);
    RMVariables['OrdDate'] := Order_Main.fieldbyname('OrdDate').Value;
    RMVariables['OrdPerson1'] := Order_Main.fieldbyname('OrdPerson1').Value;
    RMVariables['WlFshi'] := Order_Main.fieldbyname('WlFshi').Value;
    RMVariables['FromBuM'] := Order_Main.fieldbyname('FromBuM').Value;
    RMVariables['FromConNo'] := Order_Main.fieldbyname('FromConNo').Value;
    RMVariables['BAnOrder'] := Order_Main.fieldbyname('BAnOrder').Value;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('update JYOrder_Main Set PrintInt=PrintInt+1,OrdFlag1=1 ');
      sql.Add('where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      ExecSQL;
    end;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单.rmf'), '提示', 0);
    exit;
  end;
end;

procedure TfrmProductOrderNewList.TBRafreshClick(Sender: TObject);
begin
  Panel1.SetFocus;
  InitGrid();
end;

procedure TfrmProductOrderNewList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 0;
      FMainId := '';
      FDHCYID := '';
      OrdPerson1.Text := Trim(DName);
      fCustomerNoName := self.fCustomerNoName;
      forderType := self.forderType;
      fsyrName := self.fsyrName;

      if ShowModal = 1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmOrderInPut.Free;
  end;

end;

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

procedure TfrmProductOrderNewList.FormShow(Sender: TObject);
begin

  SetStatus();
  InitForm();
 // ShowMessage(forderType+fDParameters1);
end;

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

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

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

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

procedure TfrmProductOrderNewList.Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id, id10: Integer;
begin

end;

procedure TfrmProductOrderNewList.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 TfrmProductOrderNewList.N1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf';
  SDofilter(ADOQueryMain, ' OrderNoM=''' + Trim(Order_Main.fieldbyname('OrderNoM').AsString) + '''');
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  Porderno := Trim(Order_Main.fieldbyname('OrderNoM').AsString);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['begindate']:=begindate.DateTime;
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    //RMVariables['printer']:=Trim(gUserName);
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf'), '提示', 0);
  end;
  SDofilter(ADOQueryMain, '');
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  Order_Main.Locate('ordernoM', Porderno, []);
end;

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

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

procedure TfrmProductOrderNewList.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      forderType := self.forderType;
      PState := 1;
      CopyInt := 99;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FDHCYID := Trim(Self.Order_Main.fieldbyname('FDHCYID').AsString);
      fsyrName := self.fsyrName;
      if ShowModal = 1 then
      begin

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

procedure TfrmProductOrderNewList.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
{  if Key=#13 then
  begin
    if Length(OrderNo.Text)<3 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.add('exec P_View_Order :begdate,:enddate,:WSql') ;
        if Trim(fDParameters1)<>'高权限'  then
        begin
          Parameters.ParamByName('WSql').Value:=' and A.Filler='''+Trim(DName)+'''';
        end;
        begin
          Parameters.ParamByName('WSql').Value:=' and orderno like '''+'%'+Trim(OrderNo.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 TfrmProductOrderNewList.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(fDParameters1) <> '高权限' 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 TfrmProductOrderNewList.tchkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''1'',Chktime=getdate(),ChkNote=' + quotedstr(trim(DCode)) + ',Chker=' + quotedstr(trim(DName)));
      sql.Add('where MainId=' + quotedstr(trim(Order_Main.fieldbyname('MainId').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('大货单审核')));
      sql.Add(',' + quotedstr(trim('申请单号：' + trim(Order_Main.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('审核成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderNewList.tNochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from CK_BanCP_PH ');
    sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
    //  sql.Add('and  isnull(substatus,'''')>''0'' ');
    open;
    if not ADOQueryCmd.IsEmpty then
    begin
      application.MessageBox('此单已经配货， 不能撤销审核！', '提示信息', 0);
      exit;
    end;
  end;

  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from BP_inout ');
    sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
    sql.Add('and cRType =''样品销售出库''');
    //  sql.Add('and  isnull(substatus,'''')>''0'' ');
    open;
    if not ADOQueryCmd.IsEmpty then
    begin
      application.MessageBox('此单已经样品出库， 不能撤销审核！', '提示信息', 0);
      exit;
    end;
  end;

  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''0'',Chktime=null,Chker=null,ChkNote=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 TfrmProductOrderNewList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();

  application.ProcessMessages;
  initGrid();
end;

procedure TfrmProductOrderNewList.TBPrint1Click(Sender: TObject);
var
  fPrintFile: string;
  Porderno, PRTCodeName, funit: string;
  i, j: Integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\生产指示单剪样.rmf';

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select *, ');
    sql.Add(' RollSum=(select sum(PrtRollNum) from JYOrder_Sub X where X.mainID=A.mainID),');
    sql.Add(' QtySum=(select sum(PrtOrderQty) from JYOrder_Sub X where X.mainID=A.mainID), ');
    sql.Add(' C_CodeNameZW=(select Top 1 defnote3 from KH_Zdy_Attachment X where X.ZdyName=A.prtCodeName and Type=''CP'') ');
    sql.Add(',C_colorName=(select Top 1 DEFstr6 from KH_Zdy_Attachment X where X.ZdyName=A.prtCodeName and X.DEFstr3=A.PrtColor and Type=''CP'') ');
    sql.Add('from  JYOrder_Sub A ');
    sql.Add('inner join JYOrder_Main  B on B.mainID=A.MainID ');
    sql.Add('where A.mainID=' + quotedstr(trim(Order_Main.fieldbyname('MainID').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryPrint, CDS_Print);
  SInitCDSData20(ADOQueryPrint, CDS_Print);
  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);
    Order_Main.EnableControls;
    exit;
  end;

  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RMVariables['customerNoName'] := Trim(Order_Main.fieldbyname('customerNoName').AsString);
    RMVariables['OrderNo'] := Trim(Order_Main.fieldbyname('OrderNo').AsString);
    RMVariables['Note'] := Trim(Order_Main.fieldbyname('Note').AsString);
    RMVariables['FHAddress'] := Trim(Order_Main.fieldbyname('FHAddress').AsString);
    RMVariables['LXFS'] := Trim(Order_Main.fieldbyname('LXFS').AsString);
    RMVariables['OrdDate'] := Order_Main.fieldbyname('OrdDate').Value;
    RMVariables['OrdPerson1'] := Order_Main.fieldbyname('OrdPerson1').Value;
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\生产指示单剪样.rmf'), '提示', 0);
    exit;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update JYOrder_Main Set PrintInt=PrintInt+1,OrdFlag1=1 ');
    sql.Add('where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    ExecSQL;
  end;
end;

procedure TfrmProductOrderNewList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  if AViewInfo.GridRecord.Values[v1Column7.Index] <> '正常' then
  begin
    ACanvas.Brush.Color := clSkyBlue;
  end;
end;

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

procedure TfrmProductOrderNewList.ToolButton4Click(Sender: TObject);
var
  filepath, fOrderNo: string;
  i: integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if Order_Main.IsEmpty then
    exit;

//  IF Order_Main.FieldByName('OrderType').AsString='剪样单' then
//  begin
//    with AdoPrint do
//    begin
//    close;
//    sql.Clear;
//    sql.Add('select A.mainID,A.subID,A.SYRName,A.cust,A.P_CodeName,A.P_Color,A.QtyUnit,B.Sorddefnote1,C.conNo,c.note,C.orderNo,C.customerNoname,C.orddefnote1,C.FHAddress,C.LXFS,C.Filler as xsyg,SUM(A.Qty) as Qty,AVG(A.Price) as Price,SUM(A.money) as Money,  ');
//    sql.Add('from BP_INout A                   ');
//    sql.Add('left join JYOrder_sub B on B.mainID=A.mainID and B.subID=A.subID ');
//    sql.Add('left join JYOrder_Main C on C.mainID=A.mainID ');
//    sql.Add('where A.MainID='+quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
//    sql.Add('group by  A.mainID,A.subID,A.SYRName,A.cust,A.P_CodeName,A.P_Color,A.QtyUnit,B.Sorddefnote1,C.conNo,c.note,C.orderNo,C.customerNoname,C.orddefnote1,C.FHAddress,C.LXFS,C.Filler');
//    open;
//    end;
//    filepath:=ExtractFilePath(Application.ExeName) + 'report\出库码单样品.rmf';
//
//    if not FileExists(Pchar(filepath))  then
//    begin
//      application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
//      exit;
//    end;
//        try
//          Moudle:=LoadLibrary('MakeQRBarcode.dll');
//          @Makebar:=GetProcAddress(Moudle,'Make');
//          @Mixtext:=GetProcAddress(Moudle,'MixText');
//          Txt:=Trim(AdoPrint.fieldbyname('orderNo').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;
//    RMVariables['QRBARCODE']:=fImagePath;
//    RMVariables['dtxz'] :=FormatDateTime('yyyy-mm-dd',date());
//    RMVariables['zdr'] :=trim(DName);
//    RMVariables['Filler'] :=trim(Order_Main.fieldbyname('Filler').AsString);
//    RM1.LoadFromFile(filepath);
//    RM1.ShowReport;
//  end
//  else
//  begin
//    with AdoPrint do
//    begin
//    close;
//    sql.Clear;
//    sql.Add('exec P_Do_PrintMd10 ');
//    sql.Add('@mainID='+quotedstr(trim(Order_Main.fieldbyname('maiNID').AsString)));
//    sql.Add(',@TblCprk='+quotedstr(trim(fSYRName)));
//    sql.Add(',@flag='+quotedstr(trim('财务码单')));
//    open;
//    end;
//
//    filepath:=ExtractFilePath(Application.ExeName) + 'report\出库码单.rmf';
//    if not FileExists(Pchar(filepath))  then
//    begin
//      application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
//      exit;
//    end;
//        try
//          Moudle:=LoadLibrary('MakeQRBarcode.dll');
//          @Makebar:=GetProcAddress(Moudle,'Make');
//          @Mixtext:=GetProcAddress(Moudle,'MixText');
//          Txt:=Trim(AdoPrint.fieldbyname('orderNo').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;
//    RMVariables['QRBARCODE']:=fImagePath;
//    RMVariables['dtxz'] :=FormatDateTime('yyyy-mm-dd',date());
//    RMVariables['zdr'] :=trim(DName);
//    RMVariables['Filler'] :=trim(Order_Main.fieldbyname('Filler').AsString);
//    RM1.LoadFromFile(filepath);
//    RM1.ShowReport;
//  end;

end;

procedure TfrmProductOrderNewList.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''0'' ');
      sql.Add('where MainId=' + quotedstr(trim(Order_Main.fieldbyname('MainId').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('大货单提交')));
      sql.Add(',' + quotedstr(trim('申请单号：' + trim(Order_Main.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('提交成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('提交成功！', '提示信息');
    tchk.Click;
    TBRafresh.Click;
  except
    application.MessageBox('提交失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderNewList.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''-1'' ');
      sql.Add('where MainId=' + quotedstr(trim(Order_Main.fieldbyname('MainId').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('大货单撤销提交')));
      sql.Add(',' + quotedstr(trim('申请单号：' + trim(Order_Main.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('撤销成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('撤销提交成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('撤销提交失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderNewList.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''2'' ');
      sql.Add('where MainId=' + quotedstr(trim(Order_Main.fieldbyname('MainId').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('大货单出库')));
      sql.Add(',' + quotedstr(trim('申请单号：' + trim(Order_Main.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('出库成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('出库成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('出库失败！', '提示信息', 0);
  end;
end;

procedure TfrmProductOrderNewList.ToolButton7Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrder_Main SET status=''1'' ');
      sql.Add('where MainId=' + quotedstr(trim(Order_Main.fieldbyname('MainId').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('大货单撤销出库')));
      sql.Add(',' + quotedstr(trim('申请单号：' + trim(Order_Main.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('撤销出库成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('撤销出库成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('撤销出库失败！', '提示信息', 0);
  end;
end;

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

procedure TfrmProductOrderNewList.TV2CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  InitImage();
end;

end.

