unit U_SalesContractCPSel;

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, cxButtonEdit, cxDropDownEdit, cxCheckBox,
  Vcl.Menus, dxSkinsCore, dxSkinsDefaultPainters, dxScrollbarAnnotations;

type
  TfrmSalesContractCPSel = 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;
    Label1: TLabel;
    ConNo: TEdit;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    VC_SCSCode: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TV1Column1: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    TV1Column3: TcxGridDBColumn;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    TV1Column7: TcxGridDBColumn;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label2: TLabel;
    C_Name: TEdit;
    Label3: TLabel;
    BuyName: TEdit;
    TV1C_FinishLatitudeDensity: TcxGridDBColumn;
    TV1C_FinishLongitudeDensity: TcxGridDBColumn;
    TV1InspStandard: TcxGridDBColumn;
    TV1InspScore: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoType, FAuthority: string;
    { Public declarations }
  end;

var
  frmSalesContractCPSel: TfrmSalesContractCPSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmSalesContractCPSel.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 TfrmSalesContractCPSel.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);

end;

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

  ConNo.SetFocus;

  Action := cahide;
end;

procedure TfrmSalesContractCPSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* ');
//      SQL.Add(' ,B.ConMId,B.ConSId,B.FromConNo,B.FromConMId,B.FromConSId ');
//      SQL.Add(' ,B.SerialNo,B.BCIID,B.ConQty,B.ConUnit,B.ConPrice,B.ConTotalAmount');
//      SQL.Add(' ,B.JHDate,B.YDZ,B.ConSNote,B.CP_CODE,B.CP_NAME ');
//      SQL.Add(' ,C.C_Code,C.C_Name,C.C_Spec,C.C_Composition,C.C_Color,C.C_ColorNo,C.C_Pattern ');
//      SQL.Add(' ,C.C_StyleNo,C.C_FinishLongitudeDensity,C.C_FinishLatitudeDensity');
//      SQL.Add(' ,C.C_Width,C.C_GramWeight');
//      SQL.Add(' ,AttName=(select top 1 FileName from TP_File X where X.WBID = B.BCIID ORDER BY FillTime )');
      sql.Add(' from CP_Contract_Main A inner join CP_Contract_SUB B on (A.ConMId=B.ConMId and  isnull(A.status,''0'')=''9'') ');
//      sql.Add(' left join Bs_Cloth_Info C on B.BCIID=C.BCIID  ');
      Open;
    end;
//    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
//    showmessage(IntToStr(ADOQueryMain.RecordCount));
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSalesContractCPSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);

end;

procedure TfrmSalesContractCPSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);
end;

procedure TfrmSalesContractCPSel.FormShow(Sender: TObject);
begin
  inherited;

  InitGrid();

  ReadCxGrid(Trim(self.Caption), TV1, '自定义数据');

end;

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

procedure TfrmSalesContractCPSel.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption), TV1, '自定义数据');

end;

procedure TfrmSalesContractCPSel.ToolButton1Click(Sender: TObject);
begin
  ConNo.SetFocus;
  ModalResult := 1;
end;

procedure TfrmSalesContractCPSel.TV1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmSalesContractCPSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmSalesContractCPSel := nil;
end;

end.

