unit U_ShaWDHList;

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, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmShaWDHList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column10: TcxGridDBColumn;
    Panel1: TPanel;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Tv1Column1: TcxGridDBColumn;
    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 Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure Tv1Column1PropertiesEditValueChanged(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FDYFlag: string;
    { Public declarations }
  end;

var
  frmShaWDHList: TfrmShaWDHList;

implementation

uses
  U_DataLink, U_RTFun,U_ShaWDHMXList;

{$R *.dfm}

procedure TfrmShaWDHList.FormDestroy(Sender: TObject);
begin
  frmShaWDHList := nil;
end;

procedure TfrmShaWDHList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action :=cafree ;
end;

procedure TfrmShaWDHList.InitGrid();
begin
  ToolBar1.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_SXYLDH :begdate,:enddate   ');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',enddate.Date+1));
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

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

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

procedure TfrmShaWDHList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('原料未到货', Tv1, '原料仓库');
  Close;
end;

procedure TfrmShaWDHList.FormShow(Sender: TObject);
begin
  ReadCxGrid('原料未到货', Tv1, '原料仓库');
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-30;
end;

procedure TfrmShaWDHList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmShaWDHMXList:=TfrmShaWDHMXList.Create(Application);
    with frmShaWDHMXList do
    begin
      frmShaWDHMXList.BegDate.Date:=Self.BegDate.Date;
      frmShaWDHMXList.EndDate.Date:=Self.EndDate.Date;
      frmShaWDHMXList.FactoryName1:=Trim(Self.CDS_Main.fieldbyname('FactoryName').AsString);
      frmShaWDHMXList.Y_CodeName1:=Trim(Self.CDS_Main.fieldbyname('Y_CodeName').AsString);
      frmShaWDHMXList.Y_Spec1:=Trim(Self.CDS_Main.fieldbyname('Y_Spec').AsString);
      frmShaWDHMXList.BatchNo1:=Trim(Self.CDS_Main.fieldbyname('BatchNo').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmShaWDHMXList.Free;
  end;
end;

procedure TfrmShaWDHList.Tv1Column1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditingValue;
  if mvalue=True then
  begin
    with CDS_Main do
    begin
      Edit;
      FieldByName('YCFlag').Value:=True;
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update Yarn_YC Set YCFlag=1,EditTime=getdate(),Editer='''+Trim(DName)+'''');
      sql.Add('where isnull(FactoryName,'''')='''+Trim(CDS_Main.fieldbyname('FactoryName').AsString)+'''');
      sql.Add('and isnull(Y_CodeName,'''')='''+Trim(CDS_Main.fieldbyname('Y_CodeName').AsString)+'''');
      sql.Add('and isnull(Y_Spec,'''')='''+Trim(CDS_Main.fieldbyname('Y_Spec').AsString)+'''');
      sql.Add('and isnull(BatchNo,'''')='''+Trim(CDS_Main.fieldbyname('BatchNo').AsString)+'''');
      ExecSQL;
    end;
  end else
  begin
    with CDS_Main do
    begin
      Edit;
      FieldByName('YCFlag').Value:=False;
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update Yarn_YC Set YCFlag=0,EditTime=getdate(),Editer='''+Trim(DName)+'''');
      sql.Add('where isnull(FactoryName,'''')='''+Trim(CDS_Main.fieldbyname('FactoryName').AsString)+'''');
      sql.Add('and isnull(Y_CodeName,'''')='''+Trim(CDS_Main.fieldbyname('Y_CodeName').AsString)+'''');
      sql.Add('and isnull(Y_Spec,'''')='''+Trim(CDS_Main.fieldbyname('Y_Spec').AsString)+'''');
      sql.Add('and isnull(BatchNo,'''')='''+Trim(CDS_Main.fieldbyname('BatchNo').AsString)+'''');
      ExecSQL;
    end;
  end;
end;

end.

