unit U_MLOrderMXSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxCurrencyEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxDropDownEdit,
  cxGroupBox, cxCheckBox, ImgList, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, Menus, ShellAPI, cxSplitter;

type
  TfrmMLOrderMXSel = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1ConColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1Qty: TcxGridDBColumn;
    Label10: TLabel;
    v1XHNo: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1ConHX: TcxGridDBColumn;
    Label3: TLabel;
    Label14: TLabel;
    OrdDate: TDateTimePicker;
    KHName: TBtnEditC;
    v1ConNote: TcxGridDBColumn;
    CDS_CON: TClientDataSet;
    DSCON: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1ConCode: TcxGridDBColumn;
    v1ConCodeName: TcxGridDBColumn;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuery2: TADOQuery;
    v1ConGY: TcxGridDBColumn;
    Label2: TLabel;
    SYRName: TBtnEditC;
    v1Column3: TcxGridDBColumn;
    v1ConType: TcxGridDBColumn;
    YWConNO: TEdit;
    v1ConColNo: TcxGridDBColumn;
    v1ConKHColNo: TcxGridDBColumn;
    Label52: TLabel;
    KHConNo: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    ToolButton1: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column4: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitData();
   
    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo: string;
    FXS: Integer;
    canshu1, canshu2: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmMLOrderMXSel: TfrmMLOrderMXSel;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_RTFun;

{$R *.dfm}

procedure TfrmMLOrderMXSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption, Tv1, '生产指示单管理');
end;

procedure TfrmMLOrderMXSel.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select *');
    sql.Add(',IFFZ=(select count(B.WBID) from TP_File B where B.WBID=A.CSID and B.TFType=''合同明细'')');
    sql.Add(',Case when ISPD=1 then ''已排单'' else '''' end as ISPDStr ');
    SQL.Add(' from ML_ConSub A where   ');
    sql.Add(' MLConID=''' + Trim(FMainId) + '''');

    Open;
  end;
  SCreateCDS20(ADOQuery1, Order_Sub);
  SInitCDSData20(ADOQuery1, Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from ML_ConMain where MLConID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOQuery1, ScrollBox1, 2);

end;

procedure TfrmMLOrderMXSel.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption, Tv1, '生产指示单管理');
  InitData();
end;

procedure TfrmMLOrderMXSel.Tv1DblClick(Sender: TObject);
var
  fsj:string;
begin
  {if Order_Sub.IsEmpty then exit;

  if Order_Sub.FieldByName('ISPD').AsBoolean=true then Exit;

  fsj:=Trim(Order_Sub.fieldbyname('CSID').AsString);
  SelOKNo(Order_Sub,False);
  Order_Sub.Locate('CSID',fsj,[]);
  with Order_Sub do
  begin
    Edit;
    FieldByName('SSel').Value:=True;
    Post;
  end;
  ModalResult := 1;   }
end;

procedure TfrmMLOrderMXSel.N1Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  Order_Sub.DisableControls;
  with Order_Sub do
  begin
    First;
    while not Eof do
    begin
      if Trim(fieldbyname('ISPDStr').AsString)='' then
      begin
        Edit;
        FieldByName('SSel').Value:=True;
        Post;
      end;
      Next;
    end;
  end;
  Order_Sub.EnableControls;
end;

procedure TfrmMLOrderMXSel.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Sub,False);
end;

procedure TfrmMLOrderMXSel.Tv1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(Order_Sub.fieldbyname('ISPDStr').AsString)<>'' then
  begin
    v1Column2.Options.Focusing:=False;
  end else
  begin
    v1Column2.Options.Focusing:=True;
  end;
end;

procedure TfrmMLOrderMXSel.ToolButton1Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Order_Sub.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据！','提示',0);
    Exit;
  end;
  ModalResult:=1;
end;

end.

