⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u_zhongbiaotzs.pas

📁 招投标软件代码,很有应用价值,请大家参考下哦,不明白的地方给我留言
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit U_ZhongBiaotzs;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ToolWin, ComCtrls, OleCtrls,
  CELL50Lib_TLB,Unit_TopParentForm,adodb,ComObj;

type
  Tf_zhongbiaotzs = class(Tfrm_TopParentForm)
    listview1: TListView;
    Label1: TLabel;
    Label6: TLabel;
    ListView2: TListView;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    bb_Save: TBitBtn;
    btn_priview: TBitBtn;
    Memo1: TMemo;
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure Com_xmnameChange(sender:Tobject);
    procedure Com_zhaoBiaoChange(Sender:Tobject);
    procedure Com_GclxnameChange(Sender: TObject);
    procedure LoadSource;
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure bb_SaveClick(Sender: TObject);
    procedure btn_priviewClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
    Word,Doc : variant;
    IsPrint:boolean;
    CanSave:boolean;//判断文件关闭的时候是否要进行保存
    FileName:string;//用于存储释放程序中打开的文件
  public
    { Public declarations }
  end;

var
  f_zhongbiaotzs: Tf_zhongbiaotzs;

implementation

uses
  Unit_Public,SystemObject,DataModule,DataAccessCommonShell;

{$R *.dfm}

procedure Tf_zhongbiaotzs.LoadSource;
var
  adoquery:tadoquery;
  i:Integer;
  alistitem:tlistitem;
begin
  listview1.Items.Clear;
  listview2.Items.Clear;
  listview1.Columns[2].Width:=100;
  listview2.Columns[2].Width:=100;
  if com_zhaobiao.Text='施工' then
  begin
    if IsFileInUse(FileName+'zhongbiao.Doc') then
    begin
      if IsPrint then
      begin
        if application.MessageBox('通知书调用该文件,是否结束','请确定',MB_YESNO)<>Idyes then
          exit;
      end;
      try
      try
        if CanSave then
          Doc.save
        else
          Doc.saved:=True;
        Word.Quit;
        Word:=Unassigned;
      except
        showmessage('文件在程序外打开,请先关闭!');
        exit;
      end;
      except
      end;
      if IsFileInUse(FileName+'zhongbiao.Doc') then
      begin
        showmessage('文件在程序外打开,请先关闭!');
        exit;
      end;
    end;
    if not DirectoryExists(GetFilePath) then
      CreateDir(GetFilePath);
    if not fileexists(GetFilePath+'zhongbiao.Doc') or IsFileInUse(GetFilePath+'zhongbiao.Doc') then
    begin
       CopyFile(Pchar(sPath+'report\tongzhi\zhongbiao.doc'),Pchar(GetFilePath+'zhongbiao.Doc'),false);
    end;
    try
      word:=CreateOleObject('word.application');
      Word.visible:=False;
      Doc:=word.documents.open(GetFilePath+'zhongbiao.Doc');
    except
      showmessage('打开模板错误!');
      Word.quit;
      WOrd:=UnAssigned;
      exit;
    end;


    adoquery:=tadoquery.Create(nil);
    try
      adoquery.Close;
      adoquery.Connection:=datamodule1.ADOMainConn;
      adoquery.SQL.Text:='select bd_name,dw_NAME,pb_pingbiaoj  from bid_danwei_xinxi a,bid_biaoduan_xinxi b,bid_pingbiao c '
        +' where a.dw_id=c.dw_id and b.bd_isbn=c.bd_isbn and c.pb_zhongbiao=1 and b.xmgczb_id in  (select xmgczb_id from bid_xmgczb '
        +' where xm_isbn='''+trim(xmbdgc.XM_ISBn)+''' and gclx_id='+xmbdgc.gCLX_ID
        +' and zblx_id='+xmbdgc.BDLX_ID+') order by b.bd_bianhao ';
      adoquery.Open;
      adoquery.First;
      for I:=0 to adoquery.RecordCount-1 do
      begin
        alistitem:=listview1.Items.Add;
        alistitem.Caption:=adoquery.fieldbyname('dw_name').AsString;
        alistitem.SubItems.Add(adoquery.fieldbyname('bd_name').AsString);
        alistitem.SubItems.Add(adoquery.fieldbyname('pb_pingbiaoj').AsString);
        adoquery.Next;
      end;
    finally
      freeandnil(adoquery);
    end;
  end
  else if com_zhaobiao.Text='监理' then
  begin
    if IsFileInUse(FileName+'zhongbiao.Doc') then
    begin
      if IsPrint then
      begin
        if application.MessageBox('通知书调用该文件,是否结束','请确定',MB_YESNO)<>Idyes then
          exit;
      end;
      try
        if CanSave then
          Doc.save
        else
          Doc.saved:=True;
        Word.Quit;
        Word:=Unassigned;
      except
        showmessage('文件在程序外打开,请先关闭!');
        exit;
      end;
    end;
    if not DirectoryExists(GetFilePath) then
      CreateDir(GetFilePath);
    if not fileexists(GetFilePath+'zhongbiao.Doc') or IsFileInUse(GetFilePath+'zhongbiao.Doc') then
    begin
       CopyFile(Pchar(sPath+'report\tongzhi\zhongbiao.doc'),Pchar(GetFilePath+'zhongbiao.Doc'),false);
    end;
    try
      word:=CreateOleObject('word.application');
      Word.visible:=False;
      Doc:=word.documents.open(GetFilePath+'zhongbiao.Doc');
    except
      showmessage('打开模板错误!');
      Word.quit;
      WOrd:=UnAssigned;
      exit;
    end;

    adoquery:=tadoquery.Create(nil);
    try
      adoquery.Close;
      adoquery.Connection:=datamodule1.ADOMainConn;
      adoquery.SQL.Text:='select bd_name,dw_NAME,pb_suanshubj  from bid_danwei_xinxi a,bid_biaoduan_xinxi b,bid_pingbiao c '
        +' where a.dw_id=c.dw_id and b.bd_isbn=c.bd_isbn and c.pb_zhongbiao=1 and b.xmgczb_id in  (select xmgczb_id from bid_xmgczb '
        +' where xm_isbn='''+trim(xmbdgc.XM_ISBn)+''' and gclx_id='+xmbdgc.gCLX_ID
        +' and zblx_id='+xmbdgc.BDLX_ID+') order by b.bd_bianhao ';
      adoquery.Open;
      adoquery.First;
      for I:=0 to adoquery.RecordCount-1 do
      begin
        alistitem:=listview1.Items.Add;
        alistitem.Caption:=adoquery.fieldbyname('dw_name').AsString;
        alistitem.SubItems.Add(adoquery.fieldbyname('bd_name').AsString);
        alistitem.SubItems.Add(adoquery.fieldbyname('pb_suanshubj').AsString);
        adoquery.Next;
      end;
    finally
      freeandnil(adoquery);
    end;
  end
  else if com_zhaobiao.Text='设计' then
  begin
    listview1.Columns[2].Width:=0;
    listview2.Columns[2].Width:=0;
    if IsFileInUse(FileName+'zhongbiao.Doc') then
    begin
      if IsPrint then
      begin
        if application.MessageBox('通知书调用该文件,是否结束','请确定',MB_YESNO)<>Idyes then
          exit;
      end;
      try
        if CanSave then
          Doc.save
        else
          Doc.saved:=True;
        Word.Quit;
        Word:=Unassigned;
      except
        showmessage('文件在程序外打开,请先关闭!');
        exit;
      end;
    end;
    if not DirectoryExists(GetFilePath) then
      CreateDir(GetFilePath);
    if not fileexists(GetFilePath+'zhongbiao.Doc') or IsFileInUse(GetFilePath+'zhongbiao.Doc') then
    begin
       CopyFile(Pchar(sPath+'report\tongzhi\zhongbiao.doc'),Pchar(GetFilePath+'zhongbiao.Doc'),false);
    end;
    try
      word:=CreateOleObject('word.application');
      Word.visible:=False;
      Doc:=word.documents.open(GetFilePath+'zhongbiao.Doc');
    except
      showmessage('打开模板错误!');
      Word.quit;
      WOrd:=UnAssigned;
      exit;
    end;

    adoquery:=tadoquery.Create(nil);
    try
      adoquery.Close;
      adoquery.Connection:=datamodule1.ADOMainConn;
      adoquery.SQL.Text:='select dw_name,bd_name from bid_sj_qingbiao a,bid_biaoduan_xinxi b'
          +' where sj_zhongbiao=1 and a.bd_isbn=b.bd_isbn and xmgczb_Id in'
          +' (select xmgczb_id from bid_xmgczb '+' where xm_isbn='''
          +trim(xmbdgc.XM_ISBn)+''' and gclx_id='+xmbdgc.gCLX_ID+' and zblx_id='
          +xmbdgc.BDLX_ID+')';
      adoquery.Open;
      adoquery.First;
      for I:=0 to adoquery.RecordCount-1 do
      begin
        alistitem:=listview1.Items.Add;
        alistitem.Caption:=adoquery.fieldbyname('dw_name').AsString;
        alistitem.SubItems.Add(adoquery.fieldbyname('bd_name').AsString);
        //alistitem.SubItems.Add(adoquery.fieldbyname('pb_suanshubj').AsString);
        adoquery.Next;
      end;
    finally
      freeandnil(adoquery);
    end;
  end;
end;

procedure Tf_zhongbiaotzs.FormCreate(Sender: TObject);
begin
  GetItems(com_xmname,com_zhaobiao,com_gclxname,2);
  inherited;
  IsPrint:=false;
  CanSave:=False;
  panel2.Caption:='中标通知书';
  if (com_xmname.Items.IndexOf(com_xmname.text)<0)
    or (Com_Gclxname.Items.IndexOf(Com_Gclxname.text)<0)
    or (com_zhaobiao.items.IndexOf(com_zhaobiao.text)<0) then
  else
  begin
    FileName:=GetFilePath;
    LoadSource;
  end;
end;

procedure Tf_zhongbiaotzs.Com_xmnameChange(sender:Tobject);
begin
  inherited;
  if (com_xmname.Items.IndexOf(com_xmname.text)<0)
      or (Com_Gclxname.Items.IndexOf(Com_Gclxname.text)<0)
      or (com_zhaobiao.items.IndexOf(com_zhaobiao.text)<0) then exit;
  LoadSource;
  FileName:=GetFilePath;
end;

procedure Tf_zhongbiaotzs.Com_zhaoBiaoChange(Sender:Tobject);
begin
  inherited;
  if (com_xmname.Items.IndexOf(com_xmname.text)<0)
      or (Com_Gclxname.Items.IndexOf(Com_Gclxname.text)<0)
      or (com_zhaobiao.items.IndexOf(com_zhaobiao.text)<0) then exit;
  LoadSource;
  FileName:=GetFilePath;
end;

procedure Tf_zhongbiaotzs.Com_GclxnameChange(Sender: TObject);
begin
  inherited;
  if (com_xmname.Items.IndexOf(com_xmname.text)<0)
      or (Com_Gclxname.Items.IndexOf(Com_Gclxname.text)<0)
      or (com_zhaobiao.items.IndexOf(com_zhaobiao.text)<0) then exit;
  LoadSource;
  FileName:=GetFilePath;
end;

procedure Tf_zhongbiaotzs.SpeedButton2Click(Sender: TObject);
var
  listitem:tlistitem;
begin
  inherited;
  if listview1.Selected=nil then exit;
  listitem:=listview2.Items.Add;
  listitem.Caption:=listview1.Selected.Caption;
  listitem.SubItems.Add(listview1.Selected.SubItems[0]);
  listitem.SubItems.Add(listview1.Selected.SubItems[1]);
  listview1.DeleteSelected;
end;

procedure Tf_zhongbiaotzs.SpeedButton3Click(Sender: TObject);
var
  listitem:tlistitem;
begin
  inherited;
  if listview2.Selected=nil then exit;
  listitem:=listview1.Items.Add;
  listitem.Caption:=listview2.Selected.Caption;
  listitem.SubItems.Add(listview2.Selected.SubItems[0]);
  listitem.SubItems.Add(listview2.Selected.SubItems[1]);
  listview2.DeleteSelected;
end;

procedure Tf_zhongbiaotzs.bb_SaveClick(Sender: TObject);
var
  FileHandle:integer;
  i:Integer;
begin
  inherited;
  if not IsExistsPath then exit;
  if com_zhaobiao.text='施工' then
  begin
    if IsFileInUse(GetFilePath+'zhongbiao.Doc') then
    begin
      if IsPrint then
      begin
        if application.MessageBox('通知书调用该文件,是否结束','请确定',MB_YESNO)<>Idyes then
          exit;
      end;
      try
        if CanSave then
          Doc.save
        else
          Doc.saved:=True;
        Word.Quit;
        Word:=Unassigned;
      except
        showmessage('文件在程序外打开,请先关闭!');
        exit;
      end;
    end;
    try
      word:=CreateOleObject('word.application');
      Doc:=Word.Documents.open(getFilePath+'zhongbiao.doc');
    except
      showmessage('打开模板错误');
      word.quit;
      word:=UnAssigned;
      exit;
    end;

    if not fileexists(GetFilePath+'dingbiao.txt') then
    begin
      FileHandle:=filecreate(GetFilePath+'dingbiao.txt');
      fileclose(FileHandle);
    end;
    memo1.Lines.LoadFromFile(GetFilePath+'dingbiao.txt');
    for i:=0 to listview1.Items.Count-1 do
    begin
      Doc.FormFields.Item(1).Result := ListView1.Items[i].Caption;
      Doc.FormFields.Item(2).Result := xmbdgc.GCLX_NAME;
      Doc.FormFields.Item(3).Result := ListView1.Items[i].SubItems[0];
      Doc.FormFields.Item(4).Result := NumToWstr(StrToFloat(ListView1.Items[i].SubItems[1]));
      Doc.FormFields.Item(5).Result := ListView1.Items[i].SubItems[1];
      //word.visible:=False;
      Doc.PrintOut;

      memo1.Lines.Add('发送单位:'+listview1.Items[i].Caption);
      memo1.lines.Add('中标标段:'+(listview1.Items[i].SubItems[0]));
    end;

    memo1.Lines.SaveToFile(GetFilePath+'dingbiao.txt');

    IsPrint:=True;
    CanSave:=False;
  end
  else if com_zhaobiao.text='监理' then
  begin
    if IsFileInUse(GetFilePath+'zhongbiao.Doc') then
    begin
      if IsPrint then
      begin
        if application.MessageBox('通知书调用该文件,是否结束','请确定',MB_YESNO)<>Idyes then
          exit;
      end;
      try
        if CanSave then
          Doc.save
        else
          Doc.saved:=True;
        Word.Quit;
        Word:=Unassigned;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -