unit U_YarnOutReturnList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters,
  cxNavigator, dxDateRanges, dxBarBuiltInMenu, U_BaseHelp, dxSkinWXI,
  cxContainer, dxScrollbarAnnotations, cxMaskEdit, FrameDateSel, U_BaseList,
  System.ImageList, Vcl.ImgList, dxSkinBasic, 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, dxSkinOffice2016Colorful, dxSkinOffice2016Dark,
  dxSkinOffice2019Black, dxSkinOffice2019Colorful, dxSkinOffice2019DarkGray,
  dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringtime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinTheBezier, dxSkinValentine,
  dxSkinVisualStudio2013Blue, dxSkinVisualStudio2013Dark,
  dxSkinVisualStudio2013Light, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TfrmYarnOutReturnList = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label12: TLabel;
    Y_Name: TcxTextEdit;
    BYIOID: TcxTextEdit;
    Y_spec: TcxTextEdit;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    frmFrameDateSel1: TfrmFrameDateSel;
    IOType: TcxComboBox;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    Tv1Column14: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure SPNameChange(Sender: TObject);
    procedure BYIOIDChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Y_specChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    canshu1, FStkName, canshu3: string;
    { Public declarations }
  end;

var
  frmYarnOutReturnList: TfrmYarnOutReturnList;

implementation

uses
  U_DataLink, U_RTFun, U_YarnPurOutReturn;

{$R *.dfm}

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

procedure TfrmYarnOutReturnList.FormCreate(Sender: TObject);
begin
  inherited;

  frmFrameDateSel1.EndDate.Date := SGetServerDate(ADOQueryTemp);
  frmFrameDateSel1.BegDate.Date := frmFrameDateSel1.EndDate.Date - 90;
end;

procedure TfrmYarnOutReturnList.InitGrid();
var
  SqlStr: string;
begin

  SqlStr := ' select A.* ';
  SqlStr := SqlStr + ',LJHCPiece= (select SUM(X.Piece) from BS_Yarn_IO X where X.FromBYIOID = A.BYIOID)';
  SqlStr := SqlStr + ',LJHCQty= (select SUM(X.Qty)   from BS_Yarn_IO X where X.FromBYIOID = A.BYIOID)';
  SqlStr := SqlStr + ',BCHCPiece= 0.00 ,BCHCQty= 0.00';
  SqlStr := SqlStr + ' from BS_Yarn_IO A';
  SqlStr := SqlStr + ' where ioFlag=''出库'' and IOType in (''染色出库'',''拼纱出库'',''加捻出库'') ';
  SqlStr := SqlStr + '  and isnull(stkName,'''')=''' + Trim(FstkName) + '''';

  if cxTabControl1.TabIndex = 0 then
  begin
    SqlStr := SqlStr + ' and not exists (select X.FromBYIOID from BS_Yarn_IO X where X.FromBYIOID = A.BYIOID)';
  end
  else if cxTabControl1.TabIndex = 1 then
  begin
    SqlStr := SqlStr + ' and   exists (select X.FromBYIOID from BS_Yarn_IO X where X.FromBYIOID = A.BYIOID)';
    SqlStr := SqlStr + ' and  A.IOTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date)) + '''';
    SqlStr := SqlStr + ' and A.IOTime<''' + Trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date + 1)) + '''';
  end;
  InitCDSData(ADOQueryMain, CDS_Main, Tv1, SqlStr, SGetFilters(Panel1, 1, 2), 'BYIOID');

end;

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

procedure TfrmYarnOutReturnList.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption), Tv1, '纱线仓库');

end;

procedure TfrmYarnOutReturnList.ToolButton3Click(Sender: TObject);
begin

  try
    frmYarnPurOutReturn := TfrmYarnPurOutReturn.Create(Application);
    with frmYarnPurOutReturn do
    begin
      FBYIOID := Trim(self.CDS_Main.fieldbyname('BYIOID').AsString);
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmYarnPurOutReturn.Free;
  end;
end;

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

procedure TfrmYarnOutReturnList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmYarnOutReturnList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmYarnOutReturnList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '纱线仓库');
  InitGrid();
end;

procedure TfrmYarnOutReturnList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmYarnOutReturnList.SPNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmYarnOutReturnList.BYIOIDChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmYarnOutReturnList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmYarnOutReturnList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmYarnOutReturnList.Y_specChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmYarnOutReturnList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

