unit U_BGManage; //22

interface

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

type
  TfrmBGManage = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBView: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label8: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    MPRTCodeHZ: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Order_Main: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryPrint: TADOQuery;
    cxTabControl1: TcxTabControl;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    cxTabSheet4: TcxTabSheet;
    cxTabSheet5: TcxTabSheet;
    cxTabSheet6: TcxTabSheet;
    cxTabSheet7: TcxTabSheet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ClientDataSet7: TClientDataSet;
    cxGridPopupMenu7: TcxGridPopupMenu;
    DataSource7: TDataSource;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel6: TPanel;
    Panel5: TPanel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    OrderNo10: TEdit;
    Note: TMemo;
    BGName10: TEdit;
    CangKuQty: TEdit;
    MLenStr: TEdit;
    CangKuPS: TEdit;
    ComTaiTou: TBtnEditA;
    QtyUnit: TEdit;
    Panel7: TPanel;
    Panel3: TPanel;
    cxGrid4: TcxGrid;
    TvZLD: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Label28: TLabel;
    BtnEditA1: TBtnEditA;
    Label30: TLabel;
    Label31: TLabel;
    Edit15: TEdit;
    DateTimePicker1: TDateTimePicker;
    Label29: TLabel;
    BtnEditA2: TBtnEditA;
    cxGrid5: TcxGrid;
    cxGridDBTableView3: TcxGridDBTableView;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    cxGridDBTableView3Column1: TcxGridDBColumn;
    Label32: TLabel;
    DateTimePicker2: TDateTimePicker;
    Label33: TLabel;
    BtnEditA3: TBtnEditA;
    Label34: TLabel;
    BtnEditA4: TBtnEditA;
    Label35: TLabel;
    Edit16: TEdit;
    Label36: TLabel;
    Edit17: TEdit;
    Label38: TLabel;
    BtnEditA5: TBtnEditA;
    Label37: TLabel;
    BtnEditA6: TBtnEditA;
    Label39: TLabel;
    BtnEditA7: TBtnEditA;
    Label40: TLabel;
    Label41: TLabel;
    BtnEditA9: TBtnEditA;
    Label42: TLabel;
    BtnEditA10: TBtnEditA;
    Edit18: TEdit;
    Label43: TLabel;
    BtnEditA8: TBtnEditA;
    Label44: TLabel;
    BtnEditA11: TBtnEditA;
    Label45: TLabel;
    BtnEditA12: TBtnEditA;
    Label46: TLabel;
    BtnEditA13: TBtnEditA;
    Label47: TLabel;
    BtnEditA14: TBtnEditA;
    Label48: TLabel;
    BtnEditA15: TBtnEditA;
    Label49: TLabel;
    BtnEditA16: TBtnEditA;
    Label50: TLabel;
    BtnEditA17: TBtnEditA;
    Label51: TLabel;
    BtnEditA18: TBtnEditA;
    cxGrid7: TcxGrid;
    Tv7: TcxGridDBTableView;
    cxGridDBColumn34: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    v7Column1: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    cxGrid3: TcxGrid;
    cxGridLevel2: TcxGridLevel;
    TvJCK: TcxGridDBBandedTableView;
    vJCKColumn1: TcxGridDBBandedColumn;
    vJCKColumn2: TcxGridDBBandedColumn;
    vJCKColumn3: TcxGridDBBandedColumn;
    vJCKColumn4: TcxGridDBBandedColumn;
    vJCKColumn5: TcxGridDBBandedColumn;
    vJCKColumn6: TcxGridDBBandedColumn;
    vJCKColumn7: TcxGridDBBandedColumn;
    vJCKColumn8: TcxGridDBBandedColumn;
    vJCKColumn9: TcxGridDBBandedColumn;
    vJCKColumn10: TcxGridDBBandedColumn;
    vJCKColumn11: TcxGridDBBandedColumn;
    vJCKColumn12: TcxGridDBBandedColumn;
    vJCKColumn13: TcxGridDBBandedColumn;
    vJCKColumn14: TcxGridDBBandedColumn;
    cxGrid6: TcxGrid;
    TvJCKMX: TcxGridDBTableView;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    CDS_JCKMX: TClientDataSet;
    cxGridPopupMenu6: TcxGridPopupMenu;
    DS_JCKMX: TDataSource;
    CDS_ZLD: TClientDataSet;
    cxGridPopupMenu4: TcxGridPopupMenu;
    DS_ZLD: TDataSource;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ToolButton3Click(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TvJCKFocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public
    { Public declarations }
  end;

var
  frmBGManage: TfrmBGManage;

implementation
uses
  U_DataLink,U_RTFun, U_ZDYHelp, U_ZDYHelpSel,U_ModuleNote,
  U_BGZLInput,U_BGJCKMXInput;

{$R *.dfm}

procedure TfrmBGManage.FormDestroy(Sender: TObject);
begin
  frmBGManage:=nil;
end;

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

procedure TfrmBGManage.ToolButton3Click(Sender: TObject);
begin
  try
    frmModuleNote:=TfrmModuleNote.Create(Application);
    with frmModuleNote do
    begin
      flag:='报关说明';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmModuleNote.Free;
  end;
end;

procedure TfrmBGManage.TBAddClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex=0 then
  begin
    try
      frmBGZLInput:=TfrmBGZLInput.Create(Application);
      with frmBGZLInput do
      begin
        FBGID:='';
        FOrderNo:='';
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGZLInput.Free;
    end;
  end else
  if cxPageControl1.ActivePageIndex=1 then
  begin
    try
      frmBGJCKMXInput:=TfrmBGJCKMXInput.Create(Application);
      with frmBGJCKMXInput do
      begin
        FBGID:='';
        FOrderNo:='';
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGJCKMXInput.Free;
    end;
  end;
end;

procedure TfrmBGManage.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('Tv1',Tv1,'报关管理');
  WriteCxGrid('Tv2',Tv2,'报关管理');
  WriteCxGrid('Tv7',Tv7,'报关管理');
  Close;
end;

procedure TfrmBGManage.FormShow(Sender: TObject);
begin
  EndDate.DateTime:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.DateTime-30;
  cxPageControl1.ActivePageIndex:=0;
  cxTabControl1.TabIndex:=0;
  InitGrid();
  ReadCxGrid('Tv1',Tv1,'报关管理');
  ReadCxGrid('Tv2',Tv2,'报关管理');
  ReadCxGrid('Tv7',Tv7,'报关管理');
end;

procedure TfrmBGManage.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_BG where 1=1');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')<>''审核通过'' ');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and isnull(ChkStatus,'''')=''审核通过'' ');
      end;
      if cxTabControl1.TabIndex<>0 then
      begin
        sql.Add(' and FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
        sql.Add(' and FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmBGManage.TBEditClick(Sender: TObject);
begin
  if cxPageControl1.ActivePageIndex=0 then
  begin
    try
      frmBGZLInput:=TfrmBGZLInput.Create(Application);
      with frmBGZLInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGZLInput.Free;
    end;
  end else
  if cxPageControl1.ActivePageIndex=1 then
  begin
    try
      frmBGJCKMXInput:=TfrmBGJCKMXInput.Create(Application);
      with frmBGJCKMXInput do
      begin
        FBGID:=Trim(Self.Order_Main.fieldbyname('BGID').AsString);
        FOrderNo:=Trim(Self.Order_Main.fieldbyname('OrderNo').AsString);
        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmBGJCKMXInput.Free;
    end;
  end;
end;

procedure TfrmBGManage.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Qty where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from (');
    sql.Add('select PSName=Cast(A.PSXH As Varchar(20))+'' ''+Cast(A.PSName As Varchar(20)),B.FactoryNo,PSName10=A.PSName,B.FactoryName,sum(QtyFlag*PS) MDPS,Sum(QtyFlag*Qty) MDQty,B.QtyUnit');
    sql.Add(' from JYOrder_Process A  ');
    sql.Add(' left join JYOrder_Main_MD B on A.PSID=B.PSID');
    sql.Add(' inner join JYOrder_Main C on A.Mainid=C.MainId');
    sql.Add(' where C.OrderNo='''+Trim(Order_Main.fieldbyname('OrderNo').AsString)+'''');
    sql.Add(' group by A.PSXH,A.PSName,B.FactoryName,B.FactoryNo,B.QtyUnit)AA where MDQty>0 order by PSName');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet7);
  SInitCDSData20(ADOQueryTemp,ClientDataSet7);
end;

procedure TfrmBGManage.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmBGManage.TvJCKFocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_KPFee where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_JCKMX);
  SInitCDSData20(ADOQueryTemp,CDS_JCKMX);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_KPFee where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_JCKMX);
  SInitCDSData20(ADOQueryTemp,CDS_JCKMX);
   with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG_Qty where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_ZLD);
  SInitCDSData20(ADOQueryTemp,CDS_ZLD);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_BG where BGID='''+Trim(Order_Main.fieldbyname('BGID').AsString)+'''');
    Open;
  end;
  SCSHDataNew(ADOQueryTemp,Panel5,2);
  OrderNo10.Text:=Trim(ADOQueryTemp.fieldbyname('OrderNo').AsString);
  BGName10.Text:=Trim(ADOQueryTemp.fieldbyname('BGName').AsString);
end;

end.
