unit U_ProductOrderListSel;

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, cxContainer, cxImage,
  cxDBEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmProductOrderListSel = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNoM: TEdit;
    v1OrderNo: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    v1MPRTKZ: TcxGridDBColumn;
    v1OrdDefStr1: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ToolButton3: TToolButton;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1KHConNO: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Label1: TLabel;
    MPRTCodeName: TEdit;
    PRTColor: TEdit;
    Label2: TLabel;
    PRTColorNo: TEdit;
    Label4: TLabel;
    PRTHX: TEdit;
    Label5: TLabel;
    Panel2: TPanel;
    Picture4: TcxDBImage;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    v1Column4: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    PopupMenu2: TPopupMenu;
    N1: TMenuItem;
    MenuItem1: TMenuItem;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure OrderNoMKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure N1Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    procedure InitImage(fsubID: string);
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmProductOrderListSel: TfrmProductOrderListSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}
procedure TfrmProductOrderListSel.InitImage(fsubID: string);
begin
  ADOQueryImage.close;
 // IF fwbid='' then exit;
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('inner join JYOrder_Sub B on B.HXFile=A.WBID');
    sql.Add('where B.SubID=' + quotedstr(trim(fsubID)));
    open;
  end;
end;

procedure TfrmProductOrderListSel.FormDestroy(Sender: TObject);
begin
  frmProductOrderListSel := nil;
end;

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

procedure TfrmProductOrderListSel.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
end;

procedure TfrmProductOrderListSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单列表选择坯布仓库', Tv1, '生产指示单管理');
end;

procedure TfrmProductOrderListSel.InitGrid();
begin
//  if Length(Trim(OrderNoM.Text)) < 3 then
//    Exit;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select B.*,A.*  ');
      SQL.add(',RKPiQty=(select sum(PiQty) from CK_SXPB_CR x where CKName=''待检布'' and x.ORDMainIdRK=A.Mainid and x.ORDSubIdRK=A.Subid and x.SPColor=A.PRTColor and x.SPHX=A.PRTHX)');
      SQL.add(',RKQty=(select sum(Qty) from CK_SXPB_CR x where CKName=''待检布'' and x.ORDMainIdRK=A.Mainid and x.ORDSubIdRK=A.Subid and x.SPColor=A.PRTColor and x.SPHX=A.PRTHX)');
      sql.add('from JYOrder_sub A');
      sql.Add('inner join  JYOrder_Main B on B.mainID=A.mainID ');
      sQL.Add('where isnull(B.status,''0'')=''1'' ');
      if Trim(OrderNoM.Text) <> '' then
        SQL.Add(' and B.OrderNo like ''' + '%' + Trim(OrderNoM.Text) + '%' + '''');
      if Trim(MPRTCodeName.Text) <> '' then
        SQL.Add(' and B.MPRTCodeName like ''' + '%' + Trim(MPRTCodeName.Text) + '%' + '''');
      if Trim(PRTColor.Text) <> '' then
        SQL.Add(' and A.PRTColor like ''' + '%' + Trim(PRTColor.Text) + '%' + '''');
      if Trim(PRTColorNo.Text) <> '' then
        SQL.Add(' and A.PRTColorNo like ''' + '%' + Trim(PRTColorNo.Text) + '%' + '''');
      if Trim(PRTHX.Text) <> '' then
        SQL.Add(' and A.PRTHX like ''' + '%' + Trim(PRTHX.Text) + '%' + '''');

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderListSel.InitForm();
begin
  ReadCxGrid('指示单列表选择坯布仓库', Tv1, '生产指示单管理');
//  InitGrid();

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select B.*,A.* ');
      SQL.add(',RKPiQty=(select sum(PiQty) from CK_SXPB_CR x where CKName=''待检布'' and x.ORDMainIdRK=A.Mainid and x.ORDSubIdRK=A.Subid and x.SPColor=A.PRTColor and x.SPHX=A.PRTHX)');
      SQL.add(',RKQty=(select sum(Qty) from CK_SXPB_CR x where CKName=''待检布'' and x.ORDMainIdRK=A.Mainid and x.ORDSubIdRK=A.Subid and x.SPColor=A.PRTColor and x.SPHX=A.PRTHX)');
      sql.add('from JYOrder_sub A');
      sql.Add('inner join  JYOrder_Main B on B.mainID=A.mainID ');
      sQL.Add('where   B.filltime>getdate()-30 ');
//    isnull(B.status,''0'')=''1''

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderListSel.FormShow(Sender: TObject);
begin
  InitForm();

end;

procedure TfrmProductOrderListSel.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  ModalResult := 1;
end;

procedure TfrmProductOrderListSel.OrderNoMKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

procedure TfrmProductOrderListSel.Tv1DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

procedure TfrmProductOrderListSel.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ADOQueryImage.Close;
  if Order_Main.IsEmpty then
    exit;
  InitImage(Order_Main.fieldbyname('subID').AsString);
end;

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

procedure TfrmProductOrderListSel.MenuItem1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  Order_Main.DisableControls;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      Edit;
      FieldByName('SSel').Value := false;
      Post;
      Next;
    end;
  end;
  Order_Main.EnableControls;
end;

end.

