unit U_FinishedCloth_ZKCL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, MovePanel, cxTextEdit,
  cxContainer, cxCurrencyEdit, BtnEdit, RM_e_main, RM_e_htm, RM_e_Graphic,
  RM_e_Jpeg, RM_e_txt, RM_e_csv, RM_E_llPDF, Math, Clipbrd, cxPC, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TfrmFinishedCloth_ZKCL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_Main: TDataSource;
    v1Column4: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    RM2: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    MovePanel2: TMovePanel;
    RMXLSExport1: TRMXLSExport;
    N3: TMenuItem;
    X1: TMenuItem;
    Order_Main: TClientDataSet;
    v1Column1: TcxGridDBColumn;
    Panel1: TPanel;
    Label7: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    USERNAME: TEdit;
    ToolButton1: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label1: TLabel;
    edtKaNo: TEdit;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    IsJYTime: TCheckBox;
    Tv1Column5: TcxGridDBColumn;
    Label2: TLabel;
    CarNo: TEdit;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Label3: TLabel;
    gytype: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure MJIDKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure MJStr2Change(Sender: TObject);
    procedure KHConNOKeyPress(Sender: TObject; var Key: Char);
    procedure RKOrdIDKeyPress(Sender: TObject; var Key: Char);
    procedure TCBNORChange(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure APIDKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure USERNAMEChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    DQdate: TDateTime;
    FLeft, FTop: Integer;
    FDCheG, FPCode, FTabInt: string;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure InitForm();
    function Savedata(): Boolean;
    { Private declarations }
  public
    FFInt: Integer;
    canshu1: string;
    procedure SetStatus();
    { Public declarations }
  end;

var
  frmFinishedCloth_ZKCL: TfrmFinishedCloth_ZKCL;

implementation

uses
  U_DataLink, U_Fun, U_MJEdit, U_ZDYHelp, U_SysLogHelp,
  U_FinishedClothStatistical;

{$R *.dfm}

procedure TfrmFinishedCloth_ZKCL.SetStatus();
begin

end;

procedure TfrmFinishedCloth_ZKCL.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmFinishedCloth_ZKCL.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  DQdate := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmFinishedCloth_ZKCL.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption, Tv1, '检验管理');
  Close;
end;

procedure TfrmFinishedCloth_ZKCL.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      //Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_CK_Cloth_zkclTJ ');
      if IsJYTime.Checked then
      begin
        sql.add('@FBegTime=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime))));
        sql.Add(',@FEndTime=' + QuotedStr(Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1))));
      end
      else
      begin
        sql.add('@FBegTime=' + QuotedStr(Trim(FormatDateTime('2000-01-01', BegDate.DateTime))));
        sql.Add(',@FEndTime=' + QuotedStr(Trim(FormatDateTime('2099-12-12', enddate.DateTime + 1))));
      end;

//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);

    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;
end;

procedure TfrmFinishedCloth_ZKCL.InitForm();
var
  fsj: string;
begin
  ReadCxGrid(self.Caption, Tv1, '检验管理');
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime;
  InitGrid();
end;

procedure TfrmFinishedCloth_ZKCL.TBFindClick(Sender: TObject);
var
  fsj, fwhere: string;
begin

end;

procedure TfrmFinishedCloth_ZKCL.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  SetStatus();
  InitGrid();

end;

procedure TfrmFinishedCloth_ZKCL.FormShow(Sender: TObject);
begin
  CurrentPage := 1;
  RecordsNumber := 500;
  SetStatus();
  InitForm();
end;

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

procedure TfrmFinishedCloth_ZKCL.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmFinishedCloth_ZKCL.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, False);
end;

function TfrmFinishedCloth_ZKCL.Savedata(): Boolean;
begin

end;

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

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

procedure TfrmFinishedCloth_ZKCL.MJStr2Change(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

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

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

procedure TfrmFinishedCloth_ZKCL.TCBNORChange(Sender: TObject);
begin

  InitGrid();
end;

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

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

procedure TfrmFinishedCloth_ZKCL.APIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if ADOQueryMain.Active = False then
      Exit;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  end;
end;

procedure TfrmFinishedCloth_ZKCL.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '轴卡产量统计');
end;

procedure TfrmFinishedCloth_ZKCL.USERNAMEChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  end;
end;

procedure TfrmFinishedCloth_ZKCL.ToolButton2Click(Sender: TObject);
begin
  try
    frmFinishedClothStatistical := TfrmFinishedClothStatistical.Create(self);
    with frmFinishedClothStatistical do
    begin

      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFinishedClothStatistical.Free;
  end;
end;

end.

