unit U_TradeClothTotalStkList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Vcl.Printers, 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,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, dxScrollbarAnnotations, cxContainer,
  cxProgressBar, cxButtons, cxMaskEdit, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmTradeClothTotalStkList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    GPM_1: TcxGridPopupMenu;
    CDS_1: TClientDataSet;
    PopupMenu1: TPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label2: TLabel;
    C_name: TcxTextEdit;
    FromCoName: TcxTextEdit;
    C_spec: TcxTextEdit;
    BatchNo: TcxTextEdit;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1Column13: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column20: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Tv1Column19: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column21: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column17: TcxGridDBColumn;
    Tv1Column18: TcxGridDBColumn;
    Tv1Column22: TcxGridDBColumn;
    Tv1Column25: TcxGridDBColumn;
    Tv1Column24: TcxGridDBColumn;
    Tv1Column26: TcxGridDBColumn;
    Tv1Column23: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Tv1Column7: TcxGridDBColumn;
    Label1: TLabel;
    Label5: TLabel;
    GC_Name: TcxTextEdit;
    CraftCode: TcxTextEdit;
    Tv1Column27: TcxGridDBColumn;
    Tv1Column28: TcxGridDBColumn;
    Tv1Column29: TcxGridDBColumn;
    Tv1Column30: TcxGridDBColumn;
    Tv1Column31: TcxGridDBColumn;
    Tv1Column32: TcxGridDBColumn;
    Label6: TLabel;
    Label7: TLabel;
    FtyPCId: TcxTextEdit;
    FromConNo: TcxTextEdit;
    Panel5: TPanel;
    ComboBox_Print: TcxComboBox;
    LabVolume: TcxTextEdit;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    ADOQueryPrint: TADOQuery;
    Tv1Column33: TcxGridDBColumn;
    N1: TMenuItem;
    N2: TMenuItem;
    Tv1Column34: TcxGridDBColumn;
    Tv1Column35: TcxGridDBColumn;
    Tv1Column36: TcxGridDBColumn;
    Tv1Column37: TcxGridDBColumn;
    Tv1Column38: TcxGridDBColumn;
    Tv1Column39: TcxGridDBColumn;
    Label28: TLabel;
    cxCbqfs: TcxComboBox;
    Tv1Column40: TcxGridDBColumn;
    ToolButton1: TToolButton;
    ToolButton3: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton2Click(Sender: TObject);
    procedure FromCoNamePropertiesChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure FromCoNameKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FstkName, FC_Degree, FC_Pack, canshu4: string;
    { Public declarations }
  end;

var
  frmTradeClothTotalStkList: TfrmTradeClothTotalStkList;

implementation

uses
  U_DataLink, U_RTFun, U_PrintLabFun, U_dynamicsDll, U_printPdf,
  U_TradeClothSplit, U_LabelPrint;

{$R *.dfm}

procedure TfrmTradeClothTotalStkList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradeClothTotalStkList := nil;
end;

procedure TfrmTradeClothTotalStkList.cxButton1Click(Sender: TObject);
var
  mrecid: Integer;
  MaxBLCLID: string;
begin
  mrecid := showFr3LableForm(DCode, DName, DConString, '标签选择');
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select top 1 * from Trade_Label');
    sql.Add('where recid=' + trim(IntToStr(mrecid)));
    Open;
  end;
  LabVolume.Text := Trim(ADOQueryTemp.fieldbyname('LabelCaption').AsString);
end;

procedure TfrmTradeClothTotalStkList.cxButton2Click(Sender: TObject);
begin
  PrintServerLabel1(ADOQueryPrint, StrToIntDef(cxCbqfs.Text, 1), 0, ComboBox_Print.ItemIndex, SelCDSKey(CDS_1, ['BCIOID'])[0], LabVolume.text);
  InitGrid();
end;

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

procedure TfrmTradeClothTotalStkList.FormCreate(Sender: TObject);
begin
  inherited;
  FC_Degree := Trim(Self.fParameters2);
  FC_Pack := Trim(Self.fParameters3);
end;

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

  SqlStr := ' select A.*,StkPieceint=CEILING(A.StkPiece) ';
  SqlStr := SqlStr + ' from BS_Cloth_IO A    ';
  SqlStr := SqlStr + ' where A.IOFlag=''入库'' and (isnull(StkQty,0)>0 or isnull(StkPiece,0)>0) ';
  SqlStr := SqlStr + ' and isnull(stkName,'''')=''' + Trim(FstkName) + '''';

  if FC_Degree <> '' then
    SqlStr := SqlStr + ' and isnull(C_Degree,'''')=''' + Trim(FC_Degree) + '''';
  if FC_Pack <> '' then
    SqlStr := SqlStr + ' and isnull(C_Pack,'''')=''' + Trim(FC_Pack) + '''';
  SqlStr := SqlStr + ' order by IOTime desc';
  if Trim(canshu4) <> '' then
    SqlStr := SqlStr + ' and isnull(StkCoName,'''')=''' + Trim(canshu4) + '''';
  InitCDSData(ADOQueryMain, CDS_1, Tv1, SqlStr, SGetFilters(Panel1, 1, 2), 'BCIOID');

end;

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

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

procedure TfrmTradeClothTotalStkList.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmTradeClothTotalStkList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '贸易汇总仓库');
  ComboBox_Print.Properties.Items.Assign(printer.Printers);
  canshu4 := Trim(self.fParameters4);
  InitGrid();
end;

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

procedure TfrmTradeClothTotalStkList.FromCoNamePropertiesChange(Sender: TObject);
begin
  if Length(Trim(TcxTextEdit(Sender).Text)) < 4 then
    Exit;
  TBFind.Click;
end;

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

procedure TfrmTradeClothTotalStkList.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTradeClothTotalStkList.N1Click(Sender: TObject);
begin
  inherited;
  SelOKNo(CDS_1, True);
end;

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

procedure TfrmTradeClothTotalStkList.ToolButton1Click(Sender: TObject);
begin
  if trim(self.CDS_1.FieldByName('IOType').AsString) = '拆匹入库' then
  begin
    Application.MessageBox('拆匹入库数据无法拆分!', '提示', 0);
    exit;
  end;

  try
    frmTradeClothSplit := TfrmTradeClothSplit.Create(Application);
    with frmTradeClothSplit do
    begin
      FStkID := trim(self.CDS_1.FieldByName('StkID').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTradeClothSplit.Free;
  end;
end;

procedure TfrmTradeClothTotalStkList.ToolButton2Click(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption), Tv1, '贸易汇总仓库');
end;

procedure TfrmTradeClothTotalStkList.ToolButton3Click(Sender: TObject);
begin
  if CDS_1.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'TradeLabVolume1';
      FFiltration1 := Trim(SelCDSKey(self.CDS_1, ['BCIOID'])[0]);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmLabelPrint.Free;
  end;
end;

procedure TfrmTradeClothTotalStkList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ModalResult := 1;
end;

end.

