unit U_PBKcAllList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, cxGridCustomPopupMenu,
  cxGridPopupMenu, cxCheckBox, RM_Common, RM_Class, RM_GridReport,
  RM_System, RM_Dataset ,MMSystem, Menus, BtnEdit, RM_e_Xls,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmPBKcAllList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    CodeName: TEdit;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1Ssel: TcxGridDBColumn;
    v1MJXH: TcxGridDBColumn;
    Label7: TLabel;
    v1Column5: TcxGridDBColumn;
    TBPrint1: TToolButton;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    v1Column8: TcxGridDBColumn;
    Code: TEdit;
    Label18: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton2: TToolButton;
    RMXLSExport1: TRMXLSExport;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    Label1: TLabel;
    BatchNo: TEdit;
    ADOQueryMain: TADOQuery;
    Tv1Column1: TcxGridDBColumn;
    Label2: TLabel;
    C_SPec: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Label4: TLabel;
    KHName: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure CodeNameChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure edtKuWeiBtnClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBPrint1Click(Sender: TObject);
    procedure kuweiBtnClick(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    fType:integer;
    fCKName,FZZType:string;
    
    { Public declarations }
  end;

var
  frmPBKcAllList: TfrmPBKcAllList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;
{$R *.dfm}
procedure TfrmPBKcAllList.SetStatus();
begin

end;

procedure TfrmPBKcAllList.InitGrid();
begin
  try
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      SQL.Add('exec P_View_PbAllList ');
      open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
  end;
end;

procedure TfrmPBKcAllList.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  writeCxGrid(self.Caption+tv1.Name,Tv1,'面料仓库');
  if fType=10 then
    Action:=cahide
  else
    Action:=cafree;
end;

procedure TfrmPBKcAllList.FormDestroy(Sender: TObject);
begin
  frmPBKcAllList:=nil;
end;

procedure TfrmPBKcAllList.CodeNameChange(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 TfrmPBKcAllList.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption+tv1.Name,Tv1,'面料仓库');
  SetStatus();
  InitGrid();
end;

procedure TfrmPBKcAllList.TBCloseClick(Sender: TObject);
begin
    close;
end;

procedure TfrmPBKcAllList.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmPBKcAllList.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel(self.Caption,cxgrid1);
end;

procedure TfrmPBKcAllList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView;
  ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
  var ADone: Boolean);
begin
  IF  AViewInfo.GridRecord.Values[tv1.GetColumnByFieldName('isph').index]='1' then
  ACanvas.Brush.Color:=clred;
end;

procedure TfrmPBKcAllList.N1Click(Sender: TObject);
begin
 SelOKNo(CDS_Main,true);
end;

procedure TfrmPBKcAllList.N2Click(Sender: TObject);
begin
 SelOKNo(CDS_Main,false);
 
end;

procedure TfrmPBKcAllList.edtKuWeiBtnClick(Sender: TObject);
begin
//  try
//    frmCPKWList:=TfrmCPKWList.Create(Application);
//    with frmCPKWList do
//    begin
//      if ShowModal=1 then
//      begin
//        edtKuWei.Text:=Trim(CDS_HZ.fieldbyname('ZdyCode').AsString);
//        edtKuweiName.Text:=Trim(CDS_HZ.fieldbyname('DEFstr1').AsString);
//      end;
//    end;
//  finally
//    frmCPKWList.Free;
//  end;
end;

procedure TfrmPBKcAllList.ToolButton2Click(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 TfrmPBKcAllList.TBPrint1Click(Sender: TObject);
var
  filepath:string;
begin
//   with ADOQueryPrint do
//  begin
//    Close;
//    SQL.Clear;
//    SQL.Add('exec P_View_JCCWFJGY @enddate='+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime))));
//    SQL.Add(', @KuWei= '+quotedstr(Trim(kuwei.Text)));
//    SQL.Add(', @ReportFlag=''日'' ');
//    Open;
//  end;
//  try
//    filepath:=ExtractFilePath(Application.ExeName) + 'report\外加工库存日报表.rmf';
//    if not FileExists(Pchar(filepath))  then
//    begin
//      application.MessageBox(pchar('文件['+filepath+']不存在！'),'提示信息',MB_IConError);
//      exit;
//    end;
//    RM1.LoadFromFile(filepath);
//    RM1.ShowReport;
//  finally
//
//  end;
end;



procedure TfrmPBKcAllList.kuweiBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='kuwei';
      flagname:='库位';
      if ShowModal=1 then
      begin
        TEdit(Sender).Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        ToolButton2.Click;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
