unit U_ContractListPBKFSH;

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;

type
  TfrmContractListPBKFSH = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBEdit: 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;
    v1Column1: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    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;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DataSource2: TDataSource;
    v1Column8: TcxGridDBColumn;
    Label2: TLabel;
    KHConNO: TEdit;
    Label3: TLabel;
    ToolButton5: TToolButton;
    v1Column10: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    CDS_Note: TClientDataSet;
    RM1: TRMGridReport;
    v1Column22: TcxGridDBColumn;
    Label6: TLabel;
    XSType: TComboBox;
    RMDBDataSet2: TRMDBDataSet;
    v1Column3: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Label7: TLabel;
    Label10: TLabel;
    PrtCode: TEdit;
    PrtCodeName: TEdit;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    tnochkkf: TToolButton;
    tchkkf: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1XHNo: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    v1Column11: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    ToolButton1: TToolButton;
    //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 TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure tchkkfClick(Sender: TObject);
    procedure tnochkkfClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  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_ConInPutNXKFSH,U_Fun,U_ZDYHelp, U_FjList_RZ;

{$R *.dfm}

procedure TfrmContractListPBKFSH.SetStatus();
begin

  tchkkf.Visible:=false;
  tnochkkf.Visible:=false;
  TBEdit.Visible:=false;
  TBPrint.Visible:=false;
  ToolButton1.Visible:=false;
  if Trim(canshu1)='开发审核'  then
  begin
    case cxTabControl1.TabIndex of
    0:begin
        tchkkf.Visible:=true;
        TBEdit.Visible:=true;
        ToolButton1.Visible:=true;
      end;
    1:begin
        tnochkkf.Visible:=true;
      end;
    end;
  end;

end;


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

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

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

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

procedure TfrmContractListPBKFSH.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.*  ');
      sql.Add(',FHPS=(select sum(X.FHPSHZ)  from FHSQ_Main X where X.ConMainId=A.MainId ) ');
      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=cast((select distinct '' ''+JCS.PrtCode from JYOrderCon_Sub_PB JCS where JCS.MainId=A.MainId for xml path('''')) as varchar(150))');
      sql.Add(',PrtCodeName=cast((select distinct '' ''+JCS.PrtCodeName from JYOrderCon_Sub_PB JCS where JCS.MainId=A.MainId for xml path('''')) as varchar(150))');
      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(',Operor=(select top 1 Operor from SY_SysLog where Acction=''开发内销合同审核''   and OPEvent=''合同号：''+A.ConNo order by OperTime desc)');
      sql.Add(',OperTime=(select top 1 OperTime from SY_SysLog where Acction=''开发内销合同审核''   and OPEvent=''合同号：''+A.ConNo order by OperTime desc)');


      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))+'''');
     
      case cxTabControl1.TabIndex of
      0:begin
          SQL.Add(' and  isnull(A.status,''0'')=''1''');
        end;
      1:begin
          SQL.Add(' and  isnull(A.status,''0'') in (''4'',''3'')');
        end;

      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;



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


  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-60;

  
end;

procedure TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;

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

      end;
    end;
  finally
    frmConInPutNXKFSH.Free;
  end;
end;

function TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv1,ADOQueryMain,'生产指示单列表');
end;

procedure TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  TBFind.Click;
end;

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

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

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

procedure TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  TBRafresh.Click;

end;

procedure TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.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 TfrmContractListPBKFSH.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
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;

procedure TfrmContractListPBKFSH.tchkkfClick(Sender: TObject);
begin
 if Order_Main.IsEmpty then exit;

  if ClientDataSet2.Locate('ZhenZhiNote','',[])=True then
  begin
    Application.MessageBox('针织要求不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('ZhenZhiNote',null,[])=True then
  begin
    Application.MessageBox('针织要求不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('ZZSunHao','',[])=True then
  begin
    Application.MessageBox('织造损耗不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('ZZSunHao',null,[])=True then
  begin
    Application.MessageBox('织造损耗不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('MeiFenZhuanSu',null,[])=True then
  begin
    Application.MessageBox('转速/分不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('MeiFenZhuanSu',0,[])=True then
  begin
    Application.MessageBox('转速/分不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('ZongJieNote',null,[])=True then
  begin
    Application.MessageBox('批量风险总结不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet2.Locate('ZongJieNote',null,[])=True then
  begin
    Application.MessageBox('批量风险总结不能为空！','提示',0);
    Exit;
  end;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  JYOrderCon_Main_PB SET status=''4'' ');
      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 TfrmContractListPBKFSH.tnochkkfClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  if   Order_Main.FieldByName('status').AsString<>'4' 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 TfrmContractListPBKFSH.ToolButton1Click(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_PB 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;

end.
