unit U_frmFabList_sel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, ComCtrls, ToolWin, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, cxPC, ExtCtrls, StdCtrls, DBClient, cxCalendar,
  RM_Dataset, RM_Common, RM_Class, RM_e_Xls, RM_System, RM_GridReport,
  cxLookAndFeels, cxLookAndFeelPainters, 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,
  cxNavigator, dxBarBuiltInMenu;

type
  TFrmFabList_sel = class(TForm)
    ToolBar1: TToolBar;
    TClose: TToolButton;
    TINIT: TToolButton;
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    TVSQNo: TcxGridDBColumn;
    TVSQDate: TcxGridDBColumn;
    TVSQName: TcxGridDBColumn;
    TVNote: TcxGridDBColumn;
    TVC_CodeName: TcxGridDBColumn;
    TVC_Spec: TcxGridDBColumn;
    TVMFQty: TcxGridDBColumn;
    TVKZQty: TcxGridDBColumn;
    TVC_Qty: TcxGridDBColumn;
    TVC_Unit: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource1: TDataSource;
    ADOQueryTmp: TADOQuery;
    ADOQueryDel: TADOQuery;
    Panel1: TPanel;
    cxTabControl1: TcxTabControl;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cds_Main: TClientDataSet;
    Label2: TLabel;
    PONo: TEdit;
    Label3: TLabel;
    ConNo: TEdit;
    Label4: TLabel;
    P_CodeName: TEdit;
    Label5: TLabel;
    P_Spec: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    Tglv: TToolButton;
    TVchktime: TcxGridDBColumn;
    TVchker: TcxGridDBColumn;
    P_MF: TEdit;
    P_KZ: TEdit;
    V1ConNo: TcxGridDBColumn;
    V1PONo: TcxGridDBColumn;
    V1Column1: TcxGridDBColumn;
    TPrint: TToolButton;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    RMDBMain: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    RMDBsub: TRMDBDataSet;
    V1Column2: TcxGridDBColumn;
    V1Column3: TcxGridDBColumn;
    V1Column4: TcxGridDBColumn;
    TOK: TToolButton;
    TV1Column1: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure TCloseClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure TINITClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure PONoChange(Sender: TObject);
    procedure TglvClick(Sender: TObject);
    procedure TPrintClick(Sender: TObject);
    procedure TOKClick(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    procedure initData();
    procedure setStatus();
    { Private declarations }
  public
    Ftype: string;
    { Public declarations }
  end;

var
  FrmFabList_sel: TFrmFabList_sel;

implementation

uses U_DataLink,U_Fun,U_frmFabSQ;

{$R *.dfm}

procedure TFrmFabList_sel.setStatus();
begin

 { if trim(Ftype)='高权限' then
  begin
    if cxTabControl1.TabIndex=0 then
    begin
      Tupdate.Enabled:=true;
      Tdel.Enabled:=true;
      Tchk.Visible:=true;
    end;
    if cxTabControl1.TabIndex=1 then
    begin
      Tnochk.Visible:=true;
    end;
  end
  else
  begin
    if cxTabControl1.TabIndex=0 then
    begin
      Tupdate.Enabled:=true;
      Tdel.Enabled:=true;
    end;
  end; }
end;

procedure TFrmFabList_sel.initData();
begin
  with ADOQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select a.*,b.*, ');
    sql.Add('Z_Qty=(select sum(X.C_Qty) from contract_Sub_Sh X where X.maiNID=A.MainID) ');
    sql.add('from contract_main_Sh A ');
    sql.Add('inner join contract_Sub_Sh B on B.Mainid=A.Mainid ');
    sql.Add('where A.SQDate>='''+formatdatetime('yyyy-MM-dd',begdate.datetime)+''' ' );
    sql.Add('and A.SQDate<'''+formatdatetime('yyyy-MM-dd',Enddate.datetime+1)+''' ' );
    if cxtabControl1.TabIndex=0 then
    sql.Add('and A.ChkStatus=''0'' ');
    if CxtabControl1.TabIndex=1 then
    sql.Add('and A.ChkStatus=''1'' ');
    open;
  end;
  SCreateCDS20(ADOQueryTmp,cds_Main);
  SInitCDSData20(ADOQueryTmp,cds_Main);
end;

procedure TFrmFabList_sel.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alclient;
end;

procedure TFrmFabList_sel.TCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TFrmFabList_sel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption+tv1.Name,Tv1);
  action:=cafree;
end;

procedure TFrmFabList_sel.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv1.Name,Tv1);
  begdate.datetime:=SGetServerDateTime(ADOQueryTmp)-7;
  enddate.datetime:=SGetServerDateTime(ADOQueryTmp);
  setStatus();
  initdata();
end;

procedure TFrmFabList_sel.TINITClick(Sender: TObject);
begin
  initData();
end;

procedure TFrmFabList_sel.TV1DblClick(Sender: TObject);
begin
  TOK.Click;
end;

procedure TFrmFabList_sel.FormDestroy(Sender: TObject);
begin
  FrmFabList_sel:=nil;
end;

procedure TFrmFabList_sel.cxTabControl1Change(Sender: TObject);
begin
  setStatus();
  initData();
end;

procedure TFrmFabList_sel.PONoChange(Sender: TObject);
begin
  SDofilter(AdoQueryTmp,SGetFilters(Panel1,1,0));
  SCreateCDS20(AdoQueryTmp,cds_Main);
  SInitCDSData20(AdoQueryTmp,cds_Main);
end;

procedure TFrmFabList_sel.TglvClick(Sender: TObject);
begin
  SDofilter(AdoQueryTmp,SGetFilters(Panel1,1,0));
  SCreateCDS20(AdoQueryTmp,cds_Main);
  SInitCDSData20(AdoQueryTmp,cds_Main);
end;

procedure TFrmFabList_sel.TPrintClick(Sender: TObject);
var
  fPrintFile:string;
begin
  if cds_Main.IsEmpty then exit;
  with ADOQueryPrint do
  begin
    close;
    sql.clear;
    sql.Add('select a.*,b.*, ');
    sql.Add('C.MPrtCodeName as FYName,C.Mprtspec as FYSpec,C.MprtCF as FYCF,C.MPRTMF as FYMF,C.MPRTKZ as FYKZ,C.PBfactory,C.Note as FYNote ');
    sql.add('from contract_main_Sh A ');
    sql.Add('inner join contract_Sub_Sh B on B.Mainid=A.Mainid ');
    sql.Add('left join JYOrderFy_Other C on C.OrderNo=A.FYNO ');
    sql.Add('where A.Mainid='''+trim(cds_Main.fieldbyname('Mainid').asstring)+''' ');
    open;
  end;
  fPrintFile:=ExtractFilePath(Application.ExeName)+'Report\坯布申请合同.rmf' ;
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+trim(fPrintFile)),'提示',0);
  end;
end;

procedure TFrmFabList_sel.TOKClick(Sender: TObject);
begin
  IF cds_Main.IsEmpty then exit;
  self.ModalResult:=1;
end;

procedure TFrmFabList_sel.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TOK.Click;
end;

end.
