unit U_CP_YDang_BJDJ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, ExtCtrls, StdCtrls, DBClient, DB, ADODB,
  cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxPC, cxCalendar, cxButtonEdit,
  RM_System, RM_Common, RM_Class, RM_GridReport, RM_Dataset;

type
  TfrmCP_YDang_BJDJ = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    contract_Main: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    ToolBar1: TToolBar;
    TINIT: TToolButton;
    Tglv: TToolButton;
    Tadd: TToolButton;
    Tupdate: TToolButton;
    TSel: TToolButton;
    TClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label2: TLabel;
    CustomerNoName: TEdit;
    Label4: TLabel;
    ConPerson1: TEdit;
    V1PRTCodeName: TcxGridDBColumn;
    V1PRTSpec: TcxGridDBColumn;
    V1MFQty: TcxGridDBColumn;
    V1KZQty: TcxGridDBColumn;
    V1PRTOrderQty: TcxGridDBColumn;
    V1OrderUnit: TcxGridDBColumn;
    V1Note: TcxGridDBColumn;
    RMReport: TRMGridReport;
    RMDBMAIN: TRMDBDataSet;
    order_print: TClientDataSet;
    Label3: TLabel;
    Label5: TLabel;
    PRTCodeName: TEdit;
    PRTSpec: TEdit;
    V1CustomerNoName: TcxGridDBColumn;
    V1ConPerson1: TcxGridDBColumn;
    V1PRTCF: TcxGridDBColumn;
    V1SOrdQty1: TcxGridDBColumn;
    V1BJtime: TcxGridDBColumn;
    V1SOrdQty5: TcxGridDBColumn;
    V1SOrdQty6: TcxGridDBColumn;
    V1SOrdQty7: TcxGridDBColumn;
    V1SOrdQty8: TcxGridDBColumn;
    V1SOrdQty9: TcxGridDBColumn;
    V1SOrdQty10: TcxGridDBColumn;
    V1SOrdQty11: TcxGridDBColumn;
    V1SOrdQty12: TcxGridDBColumn;
    V1SOrdQty13: TcxGridDBColumn;
    V1SOrdQty2: TcxGridDBColumn;
    V1BJPrice: TcxGridDBColumn;
    V1PriceUnit: TcxGridDBColumn;
    V1BJXS: TcxGridDBColumn;
    V1CBPrice: TcxGridDBColumn;
    V1PBMF: TcxGridDBColumn;
    V1PBKZ: TcxGridDBColumn;
    V1PBSPEC: TcxGridDBColumn;
    V1PRTCode: TcxGridDBColumn;
    V1CustomerNo: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    V1QDLQty: TcxGridDBColumn;
    Label6: TLabel;
    PRTCode: TEdit;
    procedure TSelClick(Sender: TObject);
    procedure TCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TaddClick(Sender: TObject);
    procedure TupdateClick(Sender: TObject);
    procedure TglvClick(Sender: TObject);
    procedure TINITClick(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure TNochkClick(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
    procedure PRTCodeKeyPress(Sender: TObject; var Key: Char);
    procedure CustomerNoNameKeyPress(Sender: TObject; var Key: Char);
    procedure PRTCodeNameKeyPress(Sender: TObject; var Key: Char);
  private
    procedure INITDATa();
    procedure SetStatus();
    { Private declarations }
  public
    ftype,fDParameters1:string;
    { Public declarations }
  end;

var
  frmCP_YDang_BJDJ: TfrmCP_YDang_BJDJ;

implementation

uses U_frmcontract_OutProce_sub,U_Fun,U_DataLink, U_ZDYHelp,
  U_CP_YDang_BJ_Sub;

{$R *.dfm}
procedure TfrmCP_YDang_BJDJ.SetStatus();
begin
  Tupdate.Visible:=False;
  case cxTabControl1.TabIndex of
  0:begin
     Tupdate.Visible:=true;
    end;
  1:begin
    end;
  2:begin
    end;
  3:begin
    end;
  end;
end;

procedure TfrmCP_YDang_BJDJ.INITDATa();
begin
  with ADOQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select a.*,b.* from CP_YDang_BJ_Main a ');
    sql.Add('inner join CP_YDang_BJ_Sub b on b.Mainid=a.Mainid ');
    sql.Add('where a.filltime>='''+formatdatetime('yyyy-MM-dd',begdate.datetime)+'''' );
    sql.Add('and a.filltime<'''+formatdatetime('yyyy-MM-dd',Enddate.datetime+1)+'''' );
    if cxTabControl1.TabIndex=0 then
    sql.Add('and isnull(a.status,0)=0 ');
    if cxTabControl1.TabIndex=1 then
    sql.Add('and a.status=1 ');
    if cxTabControl1.TabIndex=2 then
    sql.Add('and a.status=2 ');
    open;
  end;
  SCreateCDS20(ADOQueryTmp,contract_Main);
  SInitCDSData20(ADOQueryTmp,contract_Main);
end;

procedure TfrmCP_YDang_BJDJ.TSelClick(Sender: TObject);
begin
  if contract_Main.IsEmpty then exit;
  try
    frmCP_YDang_BJ_Sub:=TfrmCP_YDang_BJ_Sub.create(self);
    with frmCP_YDang_BJ_Sub do
    begin
      Formid:=99;
      caption:='报价信息登记';
      FMainid:=trim(self.contract_Main.fieldbyname('Mainid').asstring);
      Tsave.Visible:=False;
      ToolBar2.Visible:=False;
      Panel1.Enabled:=False;
      TV1.OptionsData.Editing:=False;
      TV1.OptionsData.Deleting:=False;
      if showmodal=1 then
      begin
        INITDATa();
      end;
    end;
  finally
    frmCP_YDang_BJ_Sub.Free;
  end;
end;

procedure TfrmCP_YDang_BJDJ.TCloseClick(Sender: TObject);
begin
  close;
  WriteCxGrid(self.Caption+tv1.Name,Tv1);
end;

procedure TfrmCP_YDang_BJDJ.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alclient;
end;

procedure TfrmCP_YDang_BJDJ.FormDestroy(Sender: TObject);
begin
  frmCP_YDang_BJDJ:=nil;
end;

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

procedure TfrmCP_YDang_BJDJ.TaddClick(Sender: TObject);
begin
  try
    frmCP_YDang_BJ_Sub:=TfrmCP_YDang_BJ_Sub.create(self);
    with frmCP_YDang_BJ_Sub do
    begin
      formid:=0;
      FMainid:='';
      if showmodal=1 then
      begin
        INITDATa();
      end;
    end;
  finally
    frmCP_YDang_BJ_Sub.Free;
  end;
end;

procedure TfrmCP_YDang_BJDJ.TupdateClick(Sender: TObject);
begin
  if contract_Main.IsEmpty then exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.add('select Status from CP_YDang_BJ_Main ');
    sql.add(' where Mainid='''+trim(contract_Main.fieldbyname('Mainid').asstring)+''' ');
    open;
    if fieldbyname('status').asstring='2' then
    begin
      application.MessageBox('单据已审核','');
      exit;
    end;
  end;
  try
    frmCP_YDang_BJ_Sub:=TfrmCP_YDang_BJ_Sub.create(self);
    with frmCP_YDang_BJ_Sub do
    begin
      Formid:=99;
      caption:='报价信息登记';
      FMainid:=trim(self.contract_Main.fieldbyname('Mainid').asstring);
      if showmodal=1 then
      begin
        INITDATa();
      end;
    end;
  finally
    frmCP_YDang_BJ_Sub.Free;
  end;
end;

procedure TfrmCP_YDang_BJDJ.TglvClick(Sender: TObject);
begin
  SDofilter(ADOQueryTMP,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryTMP,CONTRACT_Main);
  SInitCDSData20(ADOQueryTMP,contract_Main);
end;

procedure TfrmCP_YDang_BJDJ.TINITClick(Sender: TObject);
begin
  INITDATa();
end;

procedure TfrmCP_YDang_BJDJ.TchkClick(Sender: TObject);
begin
  if contract_Main.IsEmpty then exit;
  try
    with ADOQueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('update CP_YDang_BJ_Main set status=''1'',chktime=getdate(),chker='+quotedstr(trim(Dname)) );
      sql.Add(' where Mainid='''+trim(contract_Main.fieldbyname('Mainid').asstring)+'''');
      execsql;
    end;
    application.MessageBox('审核成功','提示');
    initdata();
  except
    application.messagebox('审核失败','提示');
  end;
end;

procedure TfrmCP_YDang_BJDJ.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv1.Name,Tv1);
  enddate.datetime:=SGetServerDateTime(ADOQueryTmp);
  begdate.datetime:=enddate.datetime-1;
  SetStatus();
  initdata();
end;

procedure TfrmCP_YDang_BJDJ.CustomerNoNameChange(Sender: TObject);
begin
  SDofilter(ADOQueryTMP,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryTMP,CONTRACT_Main);
  SInitCDSData20(ADOQueryTMP,contract_Main);
end;

procedure TfrmCP_YDang_BJDJ.TNochkClick(Sender: TObject);
begin
  if contract_Main.IsEmpty then exit;
  try
    with ADOQueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('update CP_YDang_BJ_Main set status=''0'',chktime=null,chker=null ');
      sql.Add(' where Mainid='''+trim(contract_Main.fieldbyname('Mainid').asstring)+'''');
      execsql;
    end;
    application.MessageBox('撤销成功','提示');
    initdata();
  except
    application.messagebox('撤销失败','提示');
  end;
end;

procedure TfrmCP_YDang_BJDJ.TV1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TSel.Click;
end;

procedure TfrmCP_YDang_BJDJ.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  initdata();
end;

procedure TfrmCP_YDang_BJDJ.PRTCodeKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then
  begin
    with ADOQueryTmp do
    begin
    close;
    sql.Clear;
    sql.Add('select a.*,b.* from CP_YDang_BJ_Main A ');
    sql.Add('inner join CP_YDang_BJ_Sub B on B.Mainid=A.Mainid ');
    sql.Add('where B.PRTCode like '''+'%'+trim(PRTCode.Text)+'%'+''' ');
    if cxTabControl1.TabIndex=0 then
    sql.Add('and a.status<>2 ');
    if cxTabControl1.TabIndex=1 then
    sql.Add('and a.status=2 ');
    open;
    end;
    SCreateCDS20(ADOQueryTmp,contract_Main);
    SInitCDSData20(ADOQueryTmp,contract_Main);
  end;
end;

procedure TfrmCP_YDang_BJDJ.CustomerNoNameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then
  begin
    with ADOQueryTmp do
    begin
    close;
    sql.Clear;
    sql.Add('select a.*,b.* from CP_YDang_BJ_Main A ');
    sql.Add('inner join CP_YDang_BJ_Sub B on B.Mainid=A.Mainid ');
    sql.Add('where A.CustomerNoName like '''+'%'+trim(CustomerNoName.Text)+'%'+''' ');
    if cxTabControl1.TabIndex=0 then
    sql.Add('and a.status<>2 ');
    if cxTabControl1.TabIndex=1 then
    sql.Add('and a.status=2 ');
    open;
    end;
    SCreateCDS20(ADOQueryTmp,contract_Main);
    SInitCDSData20(ADOQueryTmp,contract_Main);
  end;
end;

procedure TfrmCP_YDang_BJDJ.PRTCodeNameKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then
  begin
    with ADOQueryTmp do
    begin
    close;
    sql.Clear;
    sql.Add('select a.*,b.* from CP_YDang_BJ_Main A ');
    sql.Add('inner join CP_YDang_BJ_Sub B on B.Mainid=A.Mainid ');
    sql.Add('where B.PRTCodeName like '''+'%'+trim(PRTCodeName.Text)+'%'+''' ');
    if cxTabControl1.TabIndex=0 then
    sql.Add('and a.status<>2 ');
    if cxTabControl1.TabIndex=1 then
    sql.Add('and a.status=2 ');
    open;
    end;
    SCreateCDS20(ADOQueryTmp,contract_Main);
    SInitCDSData20(ADOQueryTmp,contract_Main);
  end;
end;

end.
