unit U_CKProductBCPKCListSel;

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, MovePanel, cxCheckBox, Menus, cxCalendar, RM_Common, RM_Class,
  RM_GridReport, RM_System, RM_Dataset, BtnEdit, Math, Clipbrd,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmCKProductBCPKCListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    RM2: TRMGridReport;
    v1Column16: TcxGridDBColumn;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    RM3: TRMGridReport;
    RMDBHZ: TRMDBDataSet;
    RMDBPRT: TRMDBDataSet;
    Panel6: TPanel;
    Label31: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    v1Column18: TcxGridDBColumn;
    Panel1: TPanel;
    Label3: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label7: TLabel;
    Label4: TLabel;
    Label10: TLabel;
    Label15: TLabel;
    MPRTCodeName: TEdit;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    orderNo: TEdit;
    MJID: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    CPType: TComboBox;
    RKplace: TEdit;
    PRTColor: TEdit;
    v1Column5: TcxGridDBColumn;
    MPRTSpec: TEdit;
    v1Column10: TcxGridDBColumn;
    Label11: TLabel;
    ConNo: TEdit;
    Label12: TLabel;
    RKOrdID: TEdit;
    Label13: TLabel;
    KuangHao: TEdit;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    Label14: TLabel;
    CustomerNoName: TEdit;
    ToolButton1: TToolButton;
    N3: TMenuItem;
    X1: TMenuItem;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    v1Column15: TcxGridDBColumn;
    Label19: TLabel;
    APID: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    procedure FormDestroy(Sender: TObject);
    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 Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure MPRTCodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure CPTypeKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure X1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure GetQty();
    procedure v1Column12PropertiesEditValueChanged(Sender: TObject);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
 
    { Private declarations }
  public
    issel: integer;
    { Public declarations }
  end;

var
  frmCKProductBCPKCListSel: TfrmCKProductBCPKCListSel;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}
procedure TfrmCKProductBCPKCListSel.GetQty();
var
  sumP, sumnum, summoney: double;
  id: string;
begin
  if CDS_Main.IsEmpty then
    exit;
  id := CDS_Main.fieldbyname('mjid').asstring;
  try
    sumP := 0;
    sumnum := 0;
    summoney := 0;
    with CDS_Main do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        if Fieldbyname('ssel').AsBoolean then
        begin
          sumP := sumP + 1;
          sumnum := sumnum + CDS_Main.fieldbyname('KGQty').AsFloat;
          summoney := summoney + CDS_Main.fieldbyname('Qty').AsFloat;
        end;

        next;
      end;
      EnableControls;
    end;

    label16.Caption := '匹数:' + floattostr(sumP);
    label17.Caption := '重量:' + floattostr(sumnum);
    label18.Caption := '数量:' + floattostr(summoney);
    CDS_Main.Locate('mjid', id, []);
  except
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmCKProductBCPKCListSel.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPKCListSel := nil;
end;

procedure TfrmCKProductBCPKCListSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

procedure TfrmCKProductBCPKCListSel.FormCreate(Sender: TObject);
begin
  BegDate.DateTime := SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime := SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCKProductBCPKCListSel.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  Pwhere := SGetFilters(Panel1, 1, 2);
  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' where ' + trim(Pwhere);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_Page_FinishClothKC ');
      sql.Add('@pageIndex=' + inttostr(CurrentPage));
      sql.Add(',@pageSize=' + inttostr(RecordsNumber));
      sql.Add(',@criteria= ' + quotedstr(fwhere));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
    LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber));
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmCKProductBCPKCListSel.TBRafreshClick(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();

end;

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

procedure TfrmCKProductBCPKCListSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv1, '成品仓库');
  Close;
end;

procedure TfrmCKProductBCPKCListSel.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
//  ReadCxGrid(trim(self.Caption), Tv1, '成品仓库');

end;

procedure TfrmCKProductBCPKCListSel.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmCKProductBCPKCListSel.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

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

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

procedure TfrmCKProductBCPKCListSel.BTNPClick(Sender: TObject);
begin
  if CurrentPage < CDS_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmCKProductBCPKCListSel.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmCKProductBCPKCListSel.TCBNORChange(Sender: TObject);
begin
  RecordsNumber := StrToInt(TCBNOR.Text);
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPKCListSel.MPRTCodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmCKProductBCPKCListSel.CPTypeKeyPress(Sender: TObject; var Key: Char);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPKCListSel.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  ModalResult := 1;
end;

procedure TfrmCKProductBCPKCListSel.X1Click(Sender: TObject);
var
  str, SSubId, SGangNo: string;
  ZChiShu, DQChiShu: integer;
  ISSel: boolean;
begin
  ISSel := true;
  SSubId := trim(CDS_Main.FieldByName('SubId').AsString);
  str := '';
  if InputQuery('选择', '请输入数字', str) then
  begin
    ZChiShu := strtointdef(str, 0);
    if ZChiShu <= 0 then
      exit;

    with CDS_Main do
    begin

      CDS_Main.DisableControls;
      first;
      DQChiShu := 0;
      while not eof do
      begin

        if ((SSubId = trim(FieldByName('SubId').AsString))  ) then
        begin
          edit;
          FieldByName('SSel').value := ISSel;
          DQChiShu := DQChiShu + 1;
          Post;
        end
        else
        begin
          edit;
          FieldByName('SSel').value := false;
          Post;
        end;
        if DQChiShu = ZChiShu then
          ISSel := false;
        Next;
      end;
      CDS_Main.Locate('SubId',  SSubId , []);
      CDS_Main.EnableControls;
    end;
  end;
  GetQty();
end;

procedure TfrmCKProductBCPKCListSel.N3Click(Sender: TObject);
var
  SSubId, SGangNo: string;
begin
  with CDS_Main do
  begin
    SSubId := trim(FieldByName('SubId').AsString);
//    SGangNo := trim(FieldByName('Mjstr4').AsString);
    CDS_Main.DisableControls;
    first;
    while not eof do
    begin
      if ((SSubId = trim(FieldByName('SubId').AsString))) then
      begin
        edit;
        FieldByName('SSel').value := true;
        Post;
      end
      else
      begin
        edit;
        FieldByName('SSel').value := false;
        Post;
      end;
      Next;
    end;
    CDS_Main.Locate('SubId', SSubId, []);
    CDS_Main.EnableControls;
  end;
  GetQty();
end;

procedure TfrmCKProductBCPKCListSel.v1Column12PropertiesEditValueChanged(Sender: TObject);
begin
  GetQty();
end;

end.

