unit U_DJBRKList_JTHZ;

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;

type
  TfrmDJBRKList_JTHZ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    TBDel: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    Label12: TLabel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1SCPerson: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v2BTMoney: TcxGridDBColumn;
    v1YGMoney: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    SCPerson: TEdit;
    TCX: TToolButton;
    v1KKMoney: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure BTNoteChange(Sender: TObject);
    procedure TCXClick(Sender: TObject);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDJBRKList_JTHZ: TfrmDJBRKList_JTHZ;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut,U_DJBCKInPut_JTZS;

{$R *.dfm}

procedure TfrmDJBRKList_JTHZ.FormDestroy(Sender: TObject);
begin
  frmDJBRKList_JTHZ:=nil;
end;

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

procedure TfrmDJBRKList_JTHZ.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-30;
end;

procedure TfrmDJBRKList_JTHZ.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.SCPerson,Sum(A.Qty) Qty,Sum(BTMoney) BTMoney,Sum(KKMoney) KKMoney,Sum(YGMoney) YGMoney');
      sql.Add(' from Cloth_JiTaiZShu A');
      sql.add(' where A.WCDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
      sql.Add(' and A.WCDate<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''');
      SQL.Add(' group by A.SCPerson');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmDJBRKList_JTHZ.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

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

procedure TfrmDJBRKList_JTHZ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('坯布转数列表',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDJBRKList_JTHZ.FormShow(Sender: TObject);
begin
  if Trim(canshu1)<>'高权限' then
  begin
    TBAdd.Visible:=False;
    TBDel.Visible:=False;
    TBEdit.Visible:=False;
  end;{else
  begin
    TBAdd.Visible:=True;
    TBDel.Visible:=True;
    TBEdit.Visible:=True;
  end;}
  ReadCxGrid('坯布转数列表',Tv1,'待检布仓库');
end;

procedure TfrmDJBRKList_JTHZ.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('坯布转数列表',cxGrid2);
end;

procedure TfrmDJBRKList_JTHZ.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmDJBRKList_JTHZ.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmDJBRKList_JTHZ.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;

procedure TfrmDJBRKList_JTHZ.TBDelClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    try
      ADOQueryCmd.Connection.BeginTrans;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' delete from Cloth_JiTaiZShu where ZSID='''+Trim(CDS_Main.fieldbyname('ZSID').AsString)+'''');
        ExecSQL;
      end;
      ADOQueryCmd.Connection.CommitTrans;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('删除异常!','提示',0);
    end;
  CDS_Main.Delete;
end;

procedure TfrmDJBRKList_JTHZ.TBAddClick(Sender: TObject);
begin
  try
    frmDJBCKInPut_JTZS:=TfrmDJBCKInPut_JTZS.Create(Application);
    with frmDJBCKInPut_JTZS do
    begin
      FZSid:='';
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmDJBCKInPut_JTZS.Free;
  end;
end;

procedure TfrmDJBRKList_JTHZ.TBEditClick(Sender: TObject);
begin
  try
    frmDJBCKInPut_JTZS:=TfrmDJBCKInPut_JTZS.Create(Application);
    with frmDJBCKInPut_JTZS do
    begin
      FZSid:=Trim(CDS_Main.fieldbyname('ZSID').AsString);
      TBAdd.Visible:=False;
      TBDel.Visible:=False;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmDJBCKInPut_JTZS.Free;
  end;
end;

procedure TfrmDJBRKList_JTHZ.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    
  end;
end;

procedure TfrmDJBRKList_JTHZ.ConNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList_JTHZ.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList_JTHZ.BTNoteChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList_JTHZ.TCXClick(Sender: TObject);
begin
  try
    frmDJBCKInPut_JTZS:=TfrmDJBCKInPut_JTZS.Create(Application);
    with frmDJBCKInPut_JTZS do
    begin
      FZSid:=Trim(CDS_Main.fieldbyname('ZSID').AsString);
      ToolBar1.Visible:=False;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmDJBCKInPut_JTZS.Free;
  end;
end;

end.
