unit U_ContractListPB;

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, cxPC, cxButtonEdit, RM_E_llPDF, cxDropDownEdit, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu;

type
  TfrmContractListPB = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1OrdPerson1: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1MPRTCF: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RMDBDataSet1: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1CustomerNoName: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ToolButton3: TToolButton;
    v1Column4: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CustomerNoName: TEdit;
    ConPerson1: TEdit;
    MPRTCodeName: TEdit;
    ConNo: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    v1Column2: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    tchk: TToolButton;
    Tnochk: TToolButton;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    v1Column8: TcxGridDBColumn;
    Label2: TLabel;
    KHConNO: TEdit;
    Label3: TLabel;
    Tqx: TToolButton;
    Tnoqx: TToolButton;
    ToolButton5: TToolButton;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    //RMllPDFExport1: TRMllPDFExport;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v2Column1: TcxGridDBColumn;
    CDS_Note: TClientDataSet;
    v2Column2: TcxGridDBColumn;
    RM1: TRMGridReport;
    v1Column22: TcxGridDBColumn;
    Label6: TLabel;
    XSType: TComboBox;
    RMDBDataSet2: TRMDBDataSet;
    v2Column3: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label7: TLabel;
    Label10: TLabel;
    PrtCode: TEdit;
    PrtCodeName: TEdit;
    v1Column14: TcxGridDBColumn;
    //RMllPDFExport1: TRMllPDFExport;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure tchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TqxClick(Sender: TObject);
    procedure TnoqxClick(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    DQdate:TDateTime;
    fuserName,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure SetStatus();
    { Private declarations }
  public
    FFInt,FCloth:Integer;
    canshu1:string;
    { Public declarations }
  end;

//var
  //frmContractListNX: TfrmContractListNX;

implementation
uses
  U_DataLink,U_ConInPutNX,U_Fun,U_ZDYHelp, U_FjList_RZ;

{$R *.dfm}

procedure TfrmContractListPB.SetStatus();
begin
  tchk.Visible:=false;
  tnochk.Visible:=false;
 // tbedit.Visible:=false;
 // tbdel.Visible:=false;
  Tqx.Visible:=false;
  TNoqx.Visible:=false;
  if Trim(canshu1)<>'高权限'  then
  begin
  end
  else
  begin
    case cxTabControl1.TabIndex of
    0:begin

       tchk.Visible:=true;
       tbedit.Visible:=true;
       tbdel.Visible:=true;
       Tqx.Visible:=true;
      end;
    1:begin
       tnochk.Visible:=true;
       Tqx.Visible:=true;
      end;
    2:begin
        TNOqx.Visible:=true;
      end;
    3:begin
      end;
    end;
  end;
end;


procedure TfrmContractListPB.FormDestroy(Sender: TObject);
begin
  //frmContractListNX:=nil;
end;

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

procedure TfrmContractListPB.FormCreate(Sender: TObject);
begin
  //canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  cxgrid1.Align:=alClient;
  DQdate:=SGetServerDate(ADOQueryTemp);
end;

procedure TfrmContractListPB.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('内销合同',Tv1,'生产指示单管理');
  WriteCxGrid('内销合同11',Tv2,'生产指示单管理');
end;

procedure TfrmContractListPB.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.*  ');
      sql.Add(',Case when isnull((select count(*) from TP_File where WBID=A.MainID and TFType=''合同'' ),0)>0 ');
      sql.Add('then Cast(1 as bit) else Cast(0 as bit) end as FJFlag');
      sql.Add(',PrtCode=(select Top 1 PrtCode from JYOrderCon_Sub_PB JCS where JCS.MainId=A.MainId)');
      sql.Add(',PrtCodeName=(select Top 1 PrtCodeName from JYOrderCon_Sub_PB JCS where JCS.MainId=A.MainId)');
      sql.Add(',Case when isnull((select count(*) from Cloth_Main where ConMainId=A.MainID ),0)>0 ');
      sql.Add('then Cast(1 as bit) else Cast(0 as bit) end as JHDFlag');
      sql.Add(' from JYOrderCon_Main_PB A where 1=1');
      sql.Add(' and A.FillTIme>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
      sql.Add(' and A.FillTIme<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''');
     { if Trim(canshu1)<>'高权限'  then
      begin
        SQL.Add(' and A.FillerCode='''+Trim(DCode)+'''');
      end; }
      IF cxTabControl1.TabIndex<3 then
      begin
        SQL.Add(' and  isnull(A.status,''0'')='''+inttostr(cxTabControl1.TabIndex)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;



procedure TfrmContractListPB.InitForm();
begin
  ReadCxGrid('内销合同',Tv1,'生产指示单管理');
  ReadCxGrid('内销合同11',Tv2,'生产指示单管理');


  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime;
  //InitGrid();
  
end;

procedure TfrmContractListPB.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmContractListPB.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Trim(canshu1)<>'高权限' then
  begin
    if Trim(Order_Main.fieldbyname('Filler').AsString)<>Trim(DName) then
    begin
      Application.MessageBox('不能操作他人的数据!','提示',0);
      Exit;
    end;
  end;
  if Trim(canshu1)<>'高权限' then
  begin
    if cxTabControl1.TabIndex<>0 then Exit;
  end;

  try
    frmConInPutNX:=TfrmConInPutNX.Create(Application);
    with frmConInPutNX do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmConInPutNX.Free;
  end;
end;

procedure TfrmContractListPB.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if cxTabControl1.TabIndex<>0 then Exit;
//  if Trim(Order_Main.fieldbyname('Filler').AsString)<>Trim(DName) then
//  begin
//    Application.MessageBox('不能操作他人的数据!','提示',0);
//    Exit;
//  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_Main where ConMainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False  then
  begin
    Application.MessageBox('已做计划单，不能删除数据！','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from FHSQ_Main where ConMainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False  then
  begin
    Application.MessageBox('已做发货申请，不能删除数据！','提示',0);
    Exit;
  end;

  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmContractListPB.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_Sub_PB where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_Main_PB where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result:=False;
    Application.MessageBox('数据删除异常！','提示',0);
  end;
end;

procedure TfrmContractListPB.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv1,ADOQueryMain,'生产指示单列表');
end;

procedure TfrmContractListPB.TBPrintClick(Sender: TObject);
var
   fPrintFile,FeeStr:string;
   EngMoney:string;
   Fint,i,j:Integer;
begin
  if Order_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\内销合同.rmf' ;
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.* ');
    sql.Add(' from JYOrderCon_Main_PB A inner join JYOrderCon_Sub_PB B on A.MainId=B.MainId ');
    sql.Add(' where A.MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryPrint,CDS_Print);
  SInitCDSData20(ADOQueryPrint,CDS_Print);
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select MNote=RTrim(B.MNote),XHInt=Cast(XHNo as int),XHStr=Cast(Null as varchar(20)),B.MNID ');
    sql.Add(',A.SYRAddress,A.TelNo,A.FaxNo,A.BankName,A.BankNo,A.CTMAddress,A.CTMTelNo,A.CTMFaxNo');
    sql.Add(' from JYOrderCon_Main_PB A left join JYOrderCon_Main_Note_PB B on A.MainId=B.MainId ');
    sql.Add(' where A.MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryPrint,CDS_Note);
  SInitCDSData20(ADOQueryPrint,CDS_Note);
  if (CDS_Note.RecordCount=1) and (Trim(CDS_Note.fieldbyname('MNID').AsString)='') then
  begin
    begin
      with CDS_Note do
      begin
        Edit;
        FieldByName('XHInt').Value:=Null;
        FieldByName('XHStr').Value:=Null;
        FieldByName('MNote').Value:='解决合同纠纷方式：双方友好协商，协商不成由绍兴当地法院管辖；如因不可抗力造成合同不能履行，违约责任另行协商；';
        Post;
      end;
      CopyAddRowCDS(CDS_Note);
      with CDS_Note do
      begin
        Edit;
        FieldByName('XHInt').Value:=Null;
        FieldByName('XHStr').Value:=Null;
        FieldByName('MNote').Value:='本合同一式两份,双方各执一份,合同传真件、邮件形式同为有效,双方签订之日起成立。';
        Post;
      end;
    end;
  end else
  begin
    CopyAddRowCDS(CDS_Note);

    with CDS_Note do
    begin
      Edit;
      FieldByName('XHInt').Value:=Null;
      FieldByName('XHStr').Value:=Null;
      FieldByName('MNote').Value:='解决合同纠纷方式：双方友好协商，协商不成由绍兴柯桥当地法院管辖；如因不可抗力造成合同不能履行，违约责任另行协商；';
      Post;
    end;
    CopyAddRowCDS(CDS_Note);
    with CDS_Note do
    begin
      Edit;
      FieldByName('XHInt').Value:=Null;
      FieldByName('XHStr').Value:=Null;
      FieldByName('MNote').Value:='本合同一式两份,双方各执一份,合同传真件、邮件形式同为有效,双方签订之日起成立。';
      Post;
    end;
  end;
  Fint:=CDS_Note.RecordCount;
  i:=7;
  if Fint=2 then
  begin
    with CDS_Note do
    begin
      First;
      while not Eof do
      begin
        i:=i+1;
        Edit;
        if i=8 then
        begin
          FieldByName('XHStr').Value:='八、';
        end else
        begin
          FieldByName('XHStr').Value:='九、';
        end;
        Post;
        Next;
      end;
    end;
  end else
  begin
    with CDS_Note do
    begin
      First;
      while not Eof do
      begin
        i:=i+1;
        Edit;
        if i=8 then
        begin
          FieldByName('XHStr').Value:='八、';
        end else
        if i=9 then
        begin
          FieldByName('XHStr').Value:='九、';
        end else
        if i=10 then
        begin
          FieldByName('XHStr').Value:='十、';
        end else
        if i=11 then
        begin
          FieldByName('XHStr').Value:='十一、';
        end else
        if i=12 then
        begin
          FieldByName('XHStr').Value:='十二、';
        end else
        if i=13 then
        begin
          FieldByName('XHStr').Value:='十三、';
        end else
        if i=14 then
        begin
          FieldByName('XHStr').Value:='十四、';
        end else
        if i=15 then
        begin
          FieldByName('XHStr').Value:='十五、';
        end else
        if i=16 then
        begin
          FieldByName('XHStr').Value:='十六、';
        end;
        Post;
        Next;
      end;
    end;
  end;
  if FileExists(fPrintFile) then
  begin
    RMVariables['EngMoney']:=EngMoney;
    //RMVariables['FeeStr']:=FeeStr;
    //RMVariables['printtime']:=Now;
    //RMVariables['printer']:=Trim(gUserName);
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\内销合同.rmf'),'提示',0);
  end;
end;

procedure TfrmContractListPB.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  TBFind.Click;
end;

procedure TfrmContractListPB.TBAddClick(Sender: TObject);
var
  maxno:string;
begin
  try
    frmConInPutNX:=TfrmConInPutNX.Create(Application);
    with frmConInPutNX do
    begin
      PState:=0;
      FMainId:='';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmConInPutNX.Free;
  end;
end;

procedure TfrmContractListPB.FormShow(Sender: TObject);
begin
  fuserName:=DCode;
  InitForm();
  SetStatus();
end;

procedure TfrmContractListPB.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmContractListPB.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmContractListPB.N1Click(Sender: TObject);
var
   fPrintFile:string;
   Porderno:string;
begin
  if Order_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\生产指示单10.rmf' ;
  SDofilter(ADOQueryMain,' OrderNoM='''+Trim(Order_Main.fieldbyname('OrderNoM').AsString)+'''');
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
  Porderno:=Trim(Order_Main.fieldbyname('OrderNoM').AsString);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['begindate']:=begindate.DateTime;
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    //RMVariables['printer']:=Trim(gUserName);
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\生产指示单10.rmf'),'提示',0);
  end;
  SDofilter(ADOQueryMain,'');
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
  Order_Main.Locate('ordernoM',Porderno,[]);
end;

procedure TfrmContractListPB.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmConInPutNX:=TfrmConInPutNX.Create(Application);
    with frmConInPutNX do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      ToolBar2.Visible:=False;
      TBSave.Visible:=False;
      ScrollBox1.Enabled:=False;
      Tv1.OptionsSelection.CellSelect:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmConInPutNX.Free;
  end;
end;

procedure TfrmContractListPB.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmConInPutNX:=TfrmConInPutNX.Create(Application);
    with frmConInPutNX do
    begin
      PState:=1;
      CopyInt:=99;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmConInPutNX.Free;
  end;
end;

procedure TfrmContractListPB.ToolButton3Click(Sender: TObject);
begin
  ModalResult:=1;
end;

procedure TfrmContractListPB.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmContractListPB.tchkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrderCon_Main_PB SET status=''1'' ');
      sql.Add('where mainID='+quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' '+quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(','+quotedstr(trim(self.Caption)));
      sql.Add(','+quotedstr(trim('内销合同审核')));
      sql.Add(','+quotedstr(trim('合同号：'+trim(Order_Main.FieldByName('conNo').AsString))));
      sql.Add(','+quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('审核成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('审核失败！','提示信息',0);
  end;
end;

procedure TfrmContractListPB.TnochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrderCon_Main_PB SET status=''0'' ');
      sql.Add('where mainID='+quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' '+quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(','+quotedstr(trim(self.Caption)));
      sql.Add(','+quotedstr(trim('内销合同撤销审核')));
      sql.Add(','+quotedstr(trim('合同号：'+trim(Order_Main.FieldByName('conNo').AsString))));
      sql.Add(','+quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('撤销审核成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('撤销审核失败！','提示信息',0);
  end;
end;

procedure TfrmContractListPB.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  TBRafresh.Click;

end;

procedure TfrmContractListPB.TqxClick(Sender: TObject);
begin
 if Order_Main.IsEmpty then exit;
 if Application.MessageBox('确定要取消合同吗？','提示',32+4)<>IDYES then Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrdercon_Main SET status=''2'' ');
      sql.Add('where mainID='+quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' '+quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(','+quotedstr(trim(self.Caption)));
      sql.Add(','+quotedstr(trim('内销合同取消')));
      sql.Add(','+quotedstr(trim('合同号：'+trim(Order_Main.FieldByName('conNo').AsString))));
      sql.Add(','+quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('合同取消成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('合同取消失败！','提示信息',0);
  end;
end;

procedure TfrmContractListPB.TnoqxClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrdercon_Main SET status=''0'' ');
      sql.Add('where mainID='+quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' '+quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(','+quotedstr(trim(self.Caption)));
      sql.Add(','+quotedstr(trim('内销合同撤销取消')));
      sql.Add(','+quotedstr(trim('合同号：'+trim(Order_Main.FieldByName('conNo').AsString))));
      sql.Add(','+quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('撤销合同取消成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('撤销合同取消失败！','提示信息',0);
  end;
end;

procedure TfrmContractListPB.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmFjList_RZ:=TfrmFjList_RZ.Create(Application);
    with frmFjList_RZ do
    begin
    //  PState:=1;
      //if Trim(DParameters1)<>'高权限'  then cxButton1.Visible:=false;
      if Self.cxTabControl1.TabIndex<>0 then  cxButton1.Visible:=false;
      fkeyNO:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      fType:='合同';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmFjList_RZ.Free;
  end;
end;

procedure TfrmContractListPB.Tv1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  IF AViewInfo.GridRecord.Values[tv1.GetColumnByFieldName('status').Index]='2' then
    ACanvas.Brush.Color:=clLime;
end;

procedure TfrmContractListPB.Tv1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    if Order_Main.IsEmpty=False then
      sql.Add('select * from JYOrderCon_Sub_PB A where A.MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''')
    else
      sql.Add('select * from JYOrderCon_Sub_PB A where 1=2');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
end;

end.
