unit U_DBMLJCList;

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,
  cxCalendar;

type
  TfrmPBMLJCList = 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;
    v1Column1: TcxGridDBColumn;
    Label7: TLabel;
    v1Column5: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    ADOQueryMain: TADOQuery;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton2: TToolButton;
    v1Column2: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Label2: TLabel;
    BatchNo: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Label4: TLabel;
    CPColor: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Label1: TLabel;
    Label5: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1Column6: TcxGridDBColumn;
    Label6: TLabel;
    fromFactoryName: 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 TOkClick(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 ToolButton1Click(Sender: TObject);
    procedure kuweiBtnClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    fType: integer;
    fCKName, FZZType: string;
    
    { Public declarations }
  end;

//var
//  frmPBKcList: TfrmPBKcList;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;
{$R *.dfm}

procedure TfrmPBMLJCList.SetStatus();
begin

end;

procedure TfrmPBMLJCList.InitGrid();
begin
  try
    with adoqueryMain do
    begin
      close;
      sql.Clear;
      sql.Add(' SELECT * FROM  V_MLJCLIST A');
      sql.Add('where A.CRTime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
      sql.Add('and  A.CRTime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');

      open;
    end;
    SCreateCDS20(adoqueryMain, CDS_Main);
    SInitCDSData20(adoqueryMain, CDS_Main);
  finally
  end;
end;

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

procedure TfrmPBMLJCList.FormDestroy(Sender: TObject);
begin
//  frmPBKcList:=nil;
end;

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

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

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

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

procedure TfrmPBMLJCList.TOkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  ModalResult := 1;
end;

procedure TfrmPBMLJCList.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 TfrmPBMLJCList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

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

end;

procedure TfrmPBMLJCList.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 TfrmPBMLJCList.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 TfrmPBMLJCList.ToolButton1Click(Sender: TObject);
begin
  if Application.MessageBox('确定删除现有库存后重新生成库存么？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('exec P_Up_FlKcAll ');
      ExecSQL;
    end;
    Application.MessageBox('重新生成库存成功！', '提示信息', 0);
  except
    Application.MessageBox('重新生成库存失败！', '提示信息', 0);
  end;
end;

procedure TfrmPBMLJCList.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;

procedure TfrmPBMLJCList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmPBMLJCList.FormCreate(Sender: TObject);
begin
  EndDate.Date := SGetServerDate10(ADOQueryTmp);
  BegDate.Date := EndDate.Date - 30;
end;

end.

