unit U_FinPurchasePlanSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  System.ImageList, U_BaseInput, cxCheckBox, cxCalendar, dxSkinsCore,
  dxSkinsDefaultPainters, dxScrollbarAnnotations, cxPC;

type
  TfrmFinPurchasePlanSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    Tv1CPConNo: TcxGridDBColumn;
    Tv1ConNo: TcxGridDBColumn;
    Tv1PurNo: TcxGridDBColumn;
    Tv1Y_Code: TcxGridDBColumn;
    Tv1Y_Name: TcxGridDBColumn;
    Tv1Y_Composition: TcxGridDBColumn;
    Tv1Denier: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    Tv1Y_Color: TcxGridDBColumn;
    Tv1ZS: TcxGridDBColumn;
    Tv1FF: TcxGridDBColumn;
    Tv1Qty: TcxGridDBColumn;
    Tv1Piece: TcxGridDBColumn;
    Tv1QtyUnit: TcxGridDBColumn;
    Tv1SNote: TcxGridDBColumn;
    Tv1C_Degree: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    OrderNo: TEdit;
    C_Name: TEdit;
    C_Color: TEdit;
    C_ColorNo: TEdit;
    C_Pattern: TEdit;
    C_Code: TEdit;
    ConNo: TEdit;
    Tv1Price: TcxGridDBColumn;
    Tv1Amount: TcxGridDBColumn;
    Tv1TaxRate: TcxGridDBColumn;
    Tv1Tax: TcxGridDBColumn;
    Tv1TaxInclude: TcxGridDBColumn;
    Tv1currency: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority: string;
    { Public declarations }
  end;

var
  frmFinPurchasePlanSel: TfrmFinPurchasePlanSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmFinPurchasePlanSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmFinPurchasePlanSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmFinPurchasePlanSel := nil;
end;

procedure TfrmFinPurchasePlanSel.cxTabControl1Change(Sender: TObject);
begin
//  SetStatus();
  InitGrid();
end;

procedure TfrmFinPurchasePlanSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  Action := cahide;
end;

procedure TfrmFinPurchasePlanSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.PurNo,B.SellName,B.SellNo,C.FROMCPSID,C.FROMCPMID,D.shuiNo from Pur_YarnPlan_Sub A ');
      SQL.Add(' left join Pur_YarnPlan_Main B on A.PurMId=B.PurMId ');
      sql.Add(' left join BS_Contract_Sub C on  A.fromConSId=C.ConMId ');
      SQL.Add(' left join BS_Company D on D.CoCode = B.SellNo ');
      sql.Add(' where 1=1 ');
//      ShowMessage(sql.Text);
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and isnull(B.status,''0'')=''9'' ');
          end;
        1:
          begin
            sql.Add(' and isnull(B.status,''0'')=''10'' ');
          end;
      end;
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmFinPurchasePlanSel.OrderNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;
end;

procedure TfrmFinPurchasePlanSel.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), TV1, '采购单选择');

  InitGrid();
end;

procedure TfrmFinPurchasePlanSel.TBCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmFinPurchasePlanSel.TBSaveClick(Sender: TObject);
begin

  WriteCxGrid(trim(Self.Caption), Tv1, '采购单选择');
end;

procedure TfrmFinPurchasePlanSel.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmFinPurchasePlanSel.Tv1DblClick(Sender: TObject);
begin
  ModalResult := 1;

end;

end.

