unit U_YuDingHS_FZ;

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, Mask, DBCtrls, cxContainer, cxTextEdit,
  cxDBEdit, cxButtonEdit;

type
  TfrmYuDingHS_FZ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Label2: TLabel;
    Label11: TLabel;
    OrdDefStr1: TEdit;
    Label6: TLabel;
    ISPH: TComboBox;
    PrtColor: TEdit;
    Label7: TLabel;
    orderType: TComboBox;
    Label24: TLabel;
    khConNo: TEdit;
    Label10: TLabel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Label14: TLabel;
    Panel2: TPanel;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    Order_Print: TClientDataSet;
    cxStyle3: TcxStyle;
    ToolButton2: TToolButton;
    ADOQueryTemp: TADOQuery;
    Label1: TLabel;
    OrderNo: TEdit;
    Label3: TLabel;
    HWName: TEdit;
    cxTabControl1: TcxTabControl;
    Label4: TLabel;
    SJOrderNo: TEdit;
    cxGrid3: TcxGrid;
    TV1: TcxGridDBTableView;
    V3FPNo: TcxGridDBColumn;
    V1OrderNo: TcxGridDBColumn;
    V1HWName: TcxGridDBColumn;
    V1CHDate: TcxGridDBColumn;
    V1Qty: TcxGridDBColumn;
    V1QtyUnit: TcxGridDBColumn;
    V1BZType: TcxGridDBColumn;
    V1KDMoney: TcxGridDBColumn;
    V1KDXS: TcxGridDBColumn;
    V1ZXBMoney: TcxGridDBColumn;
    V1ZXXS: TcxGridDBColumn;
    V1CDYSMoney: TcxGridDBColumn;
    V1CDYSXS: TcxGridDBColumn;
    V1BZMoney: TcxGridDBColumn;
    V1BZXS: TcxGridDBColumn;
    V1ZBMoney: TcxGridDBColumn;
    V1ZBXS: TcxGridDBColumn;
    V1BXZCMoney: TcxGridDBColumn;
    V1XJBXXS: TcxGridDBColumn;
    V1WYZFMoney: TcxGridDBColumn;
    V1WYZFXS: TcxGridDBColumn;
    V1FZZMoney: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    V1Price: TcxGridDBColumn;
    V1YSMoney: TcxGridDBColumn;
    cxTabControl2: TcxTabControl;
    Label9: TLabel;
    Label5: TLabel;
    FPNo: TEdit;
    ZFPNo: TEdit;
    ADOTemp: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure ThanChange(Sender: TObject);
    procedure FPNoChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure SJOrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure FPNoKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl2Change(Sender: TObject);
  private
    DQdate:TDateTime;
    procedure InitGrid();
    procedure InitForm();
    procedure setstatus();
        { Private declarations }
  public

    canshu1:string;
    { Public declarations }
  end;

var
  frmYuDingHS_FZ: TfrmYuDingHS_FZ;

implementation
uses
  U_DataLink,U_Fun,U_ConInPutXF,U_ProductOrderMoneyList_CX,U_ProductOrderMoneyList_GXCX,U_ContractCGJGViewList_CX
  ,U_WJGMDList_CX,U_CPRKList_CX,U_YuDingFPLR,U_YuDingHS_SCLR,U_YuDingHS_DZLR,U_YuDingHS_FZLR;

{$R *.dfm}
procedure TfrmYuDingHS_FZ.setstatus();
begin
  ToolButton2.Visible:=False;
  if cxTabControl1.TabIndex=0 then
  begin
    ToolButton2.Visible:=true;
  end;
end;

procedure TfrmYuDingHS_FZ.FormDestroy(Sender: TObject);
begin
  frmYuDingHS_FZ:=nil;
end;

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

procedure TfrmYuDingHS_FZ.FormCreate(Sender: TObject);
begin
  canshu1:=trim(DParameters1);
  DQdate:=SGetServerDate(ADOQueryCmd);
end;

procedure TfrmYuDingHS_FZ.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption+tv1.Name+'1',Tv1,'业务核算管理');
end;

procedure TfrmYuDingHS_FZ.InitGrid();
var
  strwhere,Tthan:string;
begin
  Panel2.Visible:=true;
  Panel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YWHS_Main ');
      sql.add('where CHDate>='''+trim(FormatDateTime('yyyy-MM-dd',Begdate.Date))+'''');
      sql.add(' and CHDate<'''+trim(FormatDateTime('yyyy-MM-dd',Enddate.Date+1))+'''');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''''');
      end;
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''1''');
      end;
      if cxTabControl2.TabIndex=0 then
      begin
        sql.Add(' and isnull(OrdType,'''')=''宇玎''');
        if (Length(FPNo.Text)>4) and (Length(ZFPNo.Text)>4) then
        begin
          sql.Add(' and FPNO>='''+trim(FPNo.Text)+'''');
          sql.Add(' and FPNO<='''+trim(ZFPNo.Text)+'''');
        end;
      end;
      if cxTabControl2.TabIndex=1 then
      begin
        sql.Add(' and isnull(OrdType,'''')=''锦凤''');
        if (Length(FPNo.Text)>4) and (Length(ZFPNo.Text)>4) then
        begin
          sql.Add(' and FPNO>='''+trim(FPNo.Text)+'''');
          sql.Add(' and FPNO<='''+trim(ZFPNo.Text)+'''');
        end;
      end;
      if cxTabControl2.TabIndex=2 then
      begin
        sql.Add(' and isnull(OrdType,'''')=''国内RMB''');
      end;
      if cxTabControl2.TabIndex=3 then
      begin
        sql.Add(' and isnull(OrdType,'''')=''国内USD''');
      end;
      SQL.Add(' Order by CHDate,OrderNo');
      open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel2.Visible:=false;
end;

procedure TfrmYuDingHS_FZ.InitForm();
begin
  readCxGrid(self.Caption+tv1.Name+'1',Tv1,'业务核算管理');
  BegDate.DateTime:=StrToDate(Formatdatetime('yyyy',SGetServerDate10(ADOQueryCmd))+'-01'+'-01');
  EndDate.DateTime:=SGetServerDate10(ADOQueryCmd);
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('Update YWHS_Main set DZZMoney=(select Sum(B.JFMoney) ');
    sql.Add('from JYOrder_Fee_Sub B ');
    sql.Add('inner join JYOrder_Main C on C.OrderNo=B.OrderNo ');
    sql.Add('where B.FPNo=YWHS_Main.FPNO ');
    sql.Add('and B.OrderNo=YWHS_Main.OrderNo ');
    sql.Add('and C.MPRTCodeName=YWHS_Main.HWName)');
    sql.add(' where CHDate>='''+trim(FormatDateTime('yyyy-MM-dd',Begdate.Date))+'''');
    sql.add(' and CHDate<'''+trim(FormatDateTime('yyyy-MM-dd',Enddate.Date+1))+'''');
    execsql;
  end;
 // InitGrid();
end;

procedure TfrmYuDingHS_FZ.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 TfrmYuDingHS_FZ.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv1,ADOQueryMain,'业务核算列表');
end;

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

procedure TfrmYuDingHS_FZ.OrderNoChange(Sender: TObject);
begin
 TBFind.Click;
end;

procedure TfrmYuDingHS_FZ.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmYuDingHS_FZ.CheckBox1Click(Sender: TObject);
begin
   TBFind.Click;
end;

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

procedure TfrmYuDingHS_FZ.ComboBox2Change(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmYuDingHS_FZ.ThanChange(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmYuDingHS_FZ.FPNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmYuDingHS_FZ.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  frmYuDingHSFZLR:=TfrmYuDingHSFZLR.create(self);
  with frmYuDingHSFZLR do
  begin
    FHSID:=trim(Order_Main.fieldbyname('HSID').asstring);
    if ShowModal=1 then
    begin
      InitGrid();
    end;
    free;
  end;
end;

procedure TfrmYuDingHS_FZ.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  initgrid();
end;

procedure TfrmYuDingHS_FZ.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  IF Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YWHS_Main ');
      sql.add('where OrderNo='''+'%'+trim(OrderNo.Text)+'%'+'''');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''''');
      end;
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''1''');
      end;
      open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  end;
end;

procedure TfrmYuDingHS_FZ.SJOrderNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  IF Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YWHS_Main ');
      sql.add('where SJOrderNo='''+'%'+trim(SJOrderNo.Text)+'%'+'''');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''''');
      end;
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''1''');
      end;
      open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  end;
end;

procedure TfrmYuDingHS_FZ.FPNoKeyPress(Sender: TObject; var Key: Char);
begin
  IF Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YWHS_Main ');
      sql.add('where FPNo='''+'%'+trim(FPNo.Text)+'%'+'''');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''''');
      end;
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(Chkstatus,'''')=''1''');
      end;
      open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  end;
end;

procedure TfrmYuDingHS_FZ.cxTabControl2Change(Sender: TObject);
begin
  InitGrid();
end;

end.
