unit U_MLKcHzList;

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;

type
  TfrmMLKcHzList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    P_CodeName: TEdit;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1MJID: TcxGridDBColumn;
    v1MJXH: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label7: TLabel;
    P_Color: TEdit;
    Label8: TLabel;
    Label9: TLabel;
    kuwei: TEdit;
    v1Column2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    v1Column8: TcxGridDBColumn;
    ADOQueryMain: TADOQuery;
    Label13: TLabel;
    P_Code: TEdit;
    Label18: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Label11: TLabel;
    KuweiName: TEdit;
    ToolButton1: TToolButton;
    Label10: TLabel;
    Label12: TLabel;
    P_SPEC: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure P_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 ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetStatus();
    procedure SetComboBox();
    { Private declarations }
  public
    fType:integer;
    fCKName:string;
    
    { Public declarations }
  end;

var
  frmMLKcHzList: TfrmMLKcHzList;

implementation
uses
  U_DataLink,U_Fun10,U_ZDYHelp;
{$R *.dfm}
procedure TfrmMLKcHzList.SetStatus();
begin
 
end;
procedure TfrmMLKcHzList.SetComboBox();
begin
 
end;
procedure TfrmMLKcHzList.InitGrid();
begin
  try
    with adoqueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('  select A.P_Code,A.P_CodeName,A.P_spec,A.P_MF,A.P_KZ,A.P_Color,A.kuwei,C.DEFstr1 KuweiName ');
      SQL.Add(' ,COUNT(A.MJID) PS,SUM(A.Qty) Qty,A.QtyUnit');
      SQL.Add(' from CK_ML_KC A left join KH_Zdy_Attachment C on A.Kuwei=C.ZdyCode and C.Type=''CPKW'' ');
      sql.Add(' where A.Qty<>0 ');
      sql.ADD(' and exists(select * from CK_ML_CR X where X.Valid=''Y'' and X.CRFlag=''入库'' and X.MJID=A.MJID )');
      sql.Add('group by A.P_Code,A.P_CodeName,A.P_spec,A.P_MF,A.P_KZ,A.P_Color,A.QtyUnit,A.kuwei,C.DEFstr1');
      sql.Add(' order by A.P_Code ');
      open;
    end;
    SCreateCDS20(adoqueryMain,CDS_Main);
    SInitCDSData20(adoqueryMain,CDS_Main);
  finally
  end;
end;

procedure TfrmMLKcHzList.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  writeCxGrid(self.Caption+tv1.Name,Tv1,'面料仓库');
  Action:=cafree;
end;

procedure TfrmMLKcHzList.FormDestroy(Sender: TObject);
begin
  frmMLKcHzList:=nil;
end;

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

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

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

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

procedure TfrmMLKcHzList.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 TfrmMLKcHzList.ToolButton1Click(Sender: TObject);
begin
  if adoqueryMain.Active=False then Exit;
  SDofilter(adoqueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(adoqueryMain,CDS_Main);
  SInitCDSData20(adoqueryMain,CDS_Main);
end;

end.
