unit U_DJBRKList_JTZS;

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, cxContainer, cxMaskEdit,
  cxSpinEdit, cxTimeEdit;

type
  TfrmDJBRKList_JTZS = 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;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    CarNo: TEdit;
    BTNote: TEdit;
    ConNo: TEdit;
    Label12: TLabel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1ConNo: TcxGridDBColumn;
    v1ZSDate: TcxGridDBColumn;
    v1SCPerson: TcxGridDBColumn;
    v1CarNo: TcxGridDBColumn;
    v1JBQty: TcxGridDBColumn;
    v1BegQty: TcxGridDBColumn;
    v1EndQty: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1GJPrice: TcxGridDBColumn;
    v1BTNote: TcxGridDBColumn;
    v2BTMoney: TcxGridDBColumn;
    v1YGMoney: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    SCPerson: TEdit;
    TCX: TToolButton;
    v1C_CodeName: TcxGridDBColumn;
    Label6: TLabel;
    C_CodeName: TEdit;
    v1MPZQty: TcxGridDBColumn;
    v1PS: TcxGridDBColumn;
    v1JYDate: TcxGridDBColumn;
    v1WCDate: TcxGridDBColumn;
    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);
    procedure Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView;
      ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
      out AStyle: TcxStyle);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDJBRKList_JTZS: TfrmDJBRKList_JTZS;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut,U_DJBCKInPut_JTZS;

{$R *.dfm}

procedure TfrmDJBRKList_JTZS.FormDestroy(Sender: TObject);
begin
  frmDJBRKList_JTZS:=nil;
end;

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

procedure TfrmDJBRKList_JTZS.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_JTZS.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.add(',C_CodeName=(select Top 1 C_CodeName from Cloth_Sub B where B.Subid=A.Subid)');
      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(' order by A.WCDate desc');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

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

procedure TfrmDJBRKList_JTZS.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_JTZS.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('坯布转数列表',cxGrid2);
end;

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

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

procedure TfrmDJBRKList_JTZS.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_JTZS.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_JTZS.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_JTZS.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(Trim(ConNO.Text))<3 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(' from Cloth_JiTaiZShu A');
        sql.add(' where ConNO like '''+'%'+trim(ConNO.Text)+'%'+'''');
        SQL.Add(' order by A.ZSDate desc');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

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

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

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

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

procedure TfrmDJBRKList_JTZS.Tv1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id,id10:Integer;
begin
  Id:=Tv1.GetColumnByFieldName('KKMoney').Index;
  if ARecord.Values[id]=NULL then Exit;
  if ARecord.Values[id]<>'0' then
  AStyle:=DataLink_FMMD.Red;
end;

end.
