unit U_YMTStockSel;

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, cxImage, cxDBEdit, Menus, RM_Common, RM_Class, RM_e_Xls,
  RM_Dataset, RM_System, RM_GridReport, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxPC, cxSplitter, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, ShellAPI, cxCheckBox, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue,
  dxSkinscxPCPainter, cxDropDownEdit;

type
  TfrmStockSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    Label4: TLabel;
    CustomerNoName: TEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    Label12: TLabel;
    MPRTKZ: TEdit;
    cxSplitter1: TcxSplitter;
    SPName: TEdit;
    Label5: TLabel;
    N1: TMenuItem;
    Label7: TLabel;
    status: TComboBox;
    N3: TMenuItem;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1SSel: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label2: TLabel;
    CRType: TComboBox;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPNameKeyPress(Sender: TObject; var Key: Char);
    procedure MLConNoKeyPress(Sender: TObject; var Key: Char);
    procedure MLOrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();

    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1, canshu2, canshu3: string;
    fFlileFlag: string;
    FKHNo, FTT: string;
    { Public declarations }
  end;

var
  frmStockSel: TfrmStockSel;

implementation

uses
  U_DataLink, U_Fun;
{$R *.dfm}

procedure TfrmStockSel.FormDestroy(Sender: TObject);
begin
  frmStockSel := nil;
end;

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

procedure TfrmStockSel.FormCreate(Sender: TObject);
begin
  DQdate := SGetServerDate(ADOQueryTemp);
  canshu1 := trim(DParameters1);
  canshu2 := trim(DdataBase);
end;

procedure TfrmStockSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('生产指示单新YX', Tv1, '生产指示单管理');
end;

procedure TfrmStockSel.InitGrid();
var
  fwhere, Pwhere: string;
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from YMT_CK_CR A');
      sql.add(' where A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.CRTime<=''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      sql.Add(' and isnull(CKName,'''')=''面料''');
      SQL.Add(' and CRFlag=''入库''  ');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmStockSel.InitForm();
begin
  ReadCxGrid('生产指示单新YX', Tv1, '生产指示单管理');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  InitGrid();

end;

procedure TfrmStockSel.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '面料染色计划单');
end;

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

procedure TfrmStockSel.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmStockSel.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmStockSel.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmStockSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, false);
end;

procedure TfrmStockSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

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

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

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

procedure TfrmStockSel.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, CDS_Main);
  SInitCDSData20(ADOQueryMain, CDS_Main);
end;

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

end.

