unit U_OrderInPut_HYWT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxGridCustomPopupMenu, cxGridPopupMenu, cxPC,
  ExtCtrls, StdCtrls, ADODB, DBClient, RM_Common, RM_Class, RM_GridReport,
  RM_System, RM_Dataset, cxCalendar;

type
  TfrmorderInput_HYWT = class(TForm)
    ToolBar2: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    Tsel: TToolButton;
    TChk: TToolButton;
    TNOChk: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    V1WTNo: TcxGridDBColumn;
    V1Conno: TcxGridDBColumn;
    V1CustomerNoName: TcxGridDBColumn;
    V1shiptime: TcxGridDBColumn;
    V1orddefstr1: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    Panel1: TPanel;
    Label1: TLabel;
    begdate: TDateTimePicker;
    enddate: TDateTimePicker;
    Label2: TLabel;
    Label3: TLabel;
    WTNo: TEdit;
    CustomerNoName: TEdit;
    Label4: TLabel;
    conNo: TEdit;
    Label5: TLabel;
    KHConNo: TEdit;
    order_Main: TClientDataSet;
    ADOQueryTMP: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    RMDBMain: TRMDBDataSet;
    RMPrint: TRMGridReport;
    V1khconNo: TcxGridDBColumn;
    V1BLNO: TcxGridDBColumn;
    V1vessel: TcxGridDBColumn;
    V1voy: TcxGridDBColumn;
    V1ConPerson1: TcxGridDBColumn;
    V1XYNO: TcxGridDBColumn;
    V1EXPORT: TcxGridDBColumn;
    V1TDNUM: TcxGridDBColumn;
    V1payaddress: TcxGridDBColumn;
    V1POD: TcxGridDBColumn;
    V1DLYDate: TcxGridDBColumn;
    V1DLYaddress: TcxGridDBColumn;
    V1BJNO: TcxGridDBColumn;
    V1BGTYPE: TcxGridDBColumn;
    V1PRTspec: TcxGridDBColumn;
    V1SordQty1: TcxGridDBColumn;
    V1PRTCodeName: TcxGridDBColumn;
    V1PRTCode: TcxGridDBColumn;
    V1SordQty3: TcxGridDBColumn;
    V1OrderUnit: TcxGridDBColumn;
    V1PrtPrice: TcxGridDBColumn;
    procedure TBRafreshClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TselClick(Sender: TObject);
    procedure TChkClick(Sender: TObject);
    procedure TNOChkClick(Sender: TObject);
    procedure WTNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure initGrid();
    procedure SetStatus();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmorderInput_HYWT: TfrmorderInput_HYWT;

implementation

uses U_Fun,U_datalink, U_orderInPut_HYWT_Sub;

{$R *.dfm}

procedure TfrmorderInput_HYWT.initGrid();
begin
  with ADOQueryTMP do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,B.* from JYOrderWT_Main A ');
    SQL.Add('inner join JYOrderWT_Sub B on B.Mainid=A.Mainid ');
    SQL.Add('where A.filltime>='''+FormatDateTime('yyyy-MM-dd',BegDate.DateTime)+''' ');
    SQL.Add('and A.filltime<'''+FormatDateTime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
    if cxTabControl1.TabIndex=0 then
    sql.Add('and status=''''');
    if cxTabControl1.TabIndex=1 then
    sql.Add('and status=''1''');
    Open;
  end;
  SCreateCDS20(ADOQueryTMP,Order_Main);
  SInitCDSData20(ADOQueryTMP,Order_Main);
end;

procedure TfrmorderInput_HYWT.SetStatus();
begin
  tchk.Visible:=false;
  tnochk.Visible:=false;
  tbedit.Visible:=false;
  tbdel.Visible:=false;
  if Trim(DParameters1)<>'高权限'  then
  begin
    case cxTabControl1.TabIndex of
    0:begin
       tbedit.Visible:=true;
       tbdel.Visible:=true;
      end;
    1:begin
      end;
    2:begin
      end;
    end;
  end
  else
  begin
    case cxTabControl1.TabIndex of
    0:begin
       tchk.Visible:=true;
       tbedit.Visible:=true;
       tbdel.Visible:=true;
      end;
    1:begin
       tnochk.Visible:=true;
      end;
    2:begin
      end;
    end;
  end;
end;

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

procedure TfrmorderInput_HYWT.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alclient;
  cxTabControl1.TabIndex:=0;
end;

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

procedure TfrmorderInput_HYWT.FormDestroy(Sender: TObject);
begin
  frmorderInput_HYWT:=nil;
end;

procedure TfrmorderInput_HYWT.FormShow(Sender: TObject);
begin
  SetStatus();
  ReadCxGrid(self.Caption+tv1.Name,Tv1);
  BegDate.DateTime:=SGetServerDate10(ADOQueryTmp)-7;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTmp);
  InitGrid();
end;

procedure TfrmorderInput_HYWT.TBCloseClick(Sender: TObject);
begin
  close;
  WriteCxGrid(self.Caption+tv1.Name,Tv1);
end;

procedure TfrmorderInput_HYWT.TV1DblClick(Sender: TObject);
begin
  Tsel.Click;
end;

procedure TfrmorderInput_HYWT.TBFindClick(Sender: TObject);
begin
  SDofilter(ADOQueryTmp,SGetFilters(Panel1,1,0));
  SCreateCDS20(ADOQueryTmp,Order_Main);
  SInitCDSData20(ADOQueryTmp,Order_Main);
end;

procedure TfrmorderInput_HYWT.TBPrintClick(Sender: TObject);
var
   FPrintFile:string;
begin
  if Order_Main.IsEmpty then Exit;
  FPrintFile:=ExtractFilePath(Application.ExeName)+'Report\货运委托书.rmf';
  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,B.* from JYOrderWT_Main A ');
    SQL.Add('inner join JYOrderWT_Sub B on B.Mainid=A.Mainid ');
    SQL.Add('where A.Mainid='''+trim(order_Main.fieldbyname('Mainid').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTmp,order_Main);
  SInitCDSData20(ADOQueryTmp,order_Main);
  if FileExists(fPrintFile) then
  begin
    RMPrint.LoadFromFile(fPrintFile);
    RMPrint.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\货运委托书.rmf'),'提示');
  end;
  InitGrid();
end;

procedure TfrmorderInput_HYWT.TBAddClick(Sender: TObject);
begin
  try
    FrmOrderInPut_HYWT_Sub:=TFrmOrderInPut_HYWT_Sub.create(self);
    with FrmOrderInPut_HYWT_Sub do
    begin
      FMainId:='';
      if showmodal=1 then
      begin
        InitGrid();
      end;
    end;
  finally
    FrmOrderInPut_HYWT_Sub.Free;
  end;
end;

procedure TfrmorderInput_HYWT.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    FrmOrderInPut_HYWT_Sub:=TFrmOrderInPut_HYWT_Sub.create(self);
    with FrmOrderInPut_HYWT_Sub do
    begin
      FMainid:=trim(self.order_Main.fieldbyname('Mainid').AsString);
      if showmodal=1 then
      begin
        initGrid();
      end;
    end;
  finally
    FrmOrderInPut_HYWT_Sub.Free;
  end;
end;

procedure TfrmorderInput_HYWT.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',1)=2 then Exit;
  with ADOQuerycmd do
  begin
    close;
    sql.Clear;
    sql.Add('delete from JYOrderWT_Main where Mainid='''+trim(order_Main.fieldbyname('Mainid').AsString)+'''');
    execsql;
  end;
  initGrid();
end;

procedure TfrmorderInput_HYWT.TselClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    FrmOrderInPut_HYWT_Sub:=TFrmOrderInPut_HYWT_Sub.create(self);
    with FrmOrderInPut_HYWT_Sub do
    begin
      FMainid:=trim(self.order_Main.fieldbyname('Mainid').AsString);
      ToolBar2.Visible:=False;
      TBSave.Visible:=False;
      Panel1.Enabled:=False;
      Tv1.OptionsSelection.CellSelect:=False;
      if showmodal=1 then
      begin
        initGrid();
      end;
    end;
  finally
    FrmOrderInPut_HYWT_Sub.Free;
  end;
end;

procedure TfrmorderInput_HYWT.TChkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    with ADOQueryTMP do
    begin
      close;
      sql.Clear;
      sql.Add('update JYOrderWT_Main set status=''1'',chktime=getdate(),chker='+quotedstr(trim(Dname)));
      sql.Add(' where Mainid='''+trim(Order_Main.fieldbyname('Mainid').asstring)+'''');
      execsql;
    end;
    application.MessageBox('审核成功','提示');
    initGrid();
  except
    application.messagebox('审核失败','提示');
  end;
end;

procedure TfrmorderInput_HYWT.TNOChkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    with ADOQueryTMP do
    begin
      close;
      SQL.Clear;
      sql.Add('update JYOrderWT_Main set chker=null,chktime=Null,status='''' ');
      sql.Add('where Mainid='+quotedstr(trim(order_Main.fieldbyname('Mainid').asstring)));
      ExecSQL;
    end;
    Application.MessageBox('撤销成功','提示');
    initGrid();
  except;
    Application.MessageBox('撤销失败','提示');
  end;
end;

procedure TfrmorderInput_HYWT.WTNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmorderInput_HYWT.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  TBRafresh.Click;
end;

end.
