addupdatefile.pas

来自「delphi框架可以学习, 写的很好的」· PAS 代码 · 共 117 行

PAS
117
字号
unit AddUpdateFile;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzButton, StdCtrls, Mask, RzEdit, ComCtrls, RzListVw;

type
  TfrmAddUpdateFile = class(TForm)
    Label1: TLabel;
    edtFileName: TRzEdit;
    RzButton2: TRzButton;
    btnAddFile: TRzBitBtn;
    RzBitBtn1: TRzBitBtn;
    btnCancel: TRzBitBtn;
    RzListView1: TRzListView;
    OpenDialog1: TOpenDialog;
    Label2: TLabel;
    Label3: TLabel;
    mmNote: TRzMemo;
    btnDelAdd: TRzBitBtn;
    procedure RzButton2Click(Sender: TObject);
    procedure btnAddFileClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure btnDelAddClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmAddUpdateFile: TfrmAddUpdateFile;

implementation

uses MyPublic;

{$R *.dfm}

procedure TfrmAddUpdateFile.RzButton2Click(Sender: TObject);
begin
  with OpenDialog1 do
  if Execute then
    edtFileName.Text := FileName;
end;

procedure TfrmAddUpdateFile.btnAddFileClick(Sender: TObject);
var lv_tmp: TListItem;
    hd_file: THandle;
    li_time: Integer;
begin
  if not FileExists(edtFileName.Text) then Exit;
  if mmNote.Lines.Text = '' then
  begin
    ShowMess('提示','请适当输入一些升级描述,以便客户端用户使用!', MB_OK);
    Exit;
  end;

  lv_tmp := RzListView1.Items.Add;
  lv_tmp.Caption := ExtractFileName(edtFileName.Text);
  lv_tmp.SubItems.Add(GetVersionInfo(edtFileName.Text));
  try
    hd_file := FileOpen(edtFileName.Text, fmOpenRead);
    li_time := FileGetDate(hd_file);
    if li_time <> -1 then
      lv_tmp.SubItems.Add(FormatDateTime('yyyy-mm-dd HH:nn:ss', FileDateToDateTime(li_time)))
    else
      lv_tmp.SubItems.Add(FormatDateTime('yyyy-mm-dd HH:nn:ss', now));
    lv_tmp.SubItems.Add(mmNote.Lines.Text);
  finally
    FileClose(hd_File);
  end;
end;

procedure TfrmAddUpdateFile.btnCancelClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmAddUpdateFile.RzBitBtn1Click(Sender: TObject);
var ls_err: String;
    SQLs: TStrings;
    li_Count: Integer;
begin
  //将资料写入数据库
  SQLs := TStringList.Create;
  try
    SQLs.Add('DELETE FROM UPDATEINFO');
    for li_Count:=0 to RzListView1.Items.Count-1 do
      SQLs.Add('INSERT INTO UPDATEINFO (FileName, FileVer, FileTime, Note) VALUES ('+
               ''''+ RzListView1.Items.Item[li_Count].Caption+''','+
               ''''+ RzListView1.Items.Item[li_Count].SubItems.Strings[0]+''','+
               ''''+ RzListView1.Items.Item[li_Count].SubItems.Strings[1]+''','+
               ''''+ RzListView1.Items.Item[li_Count].SubItems.Strings[2]+''')');
    ls_Err := doBatchSQL(SQLs);
    if ls_Err <> '' then
      ShowMess('系统错误','将需更新文件的资料提交至服务器失败,具体为:'+ls_Err, MB_ICONERROR)
    else
      ShowMess('提示','已经成功将需更新文件的资料提交至服务器!', MB_OK);
  finally
    SQLs.Free;
  end;
end;

procedure TfrmAddUpdateFile.btnDelAddClick(Sender: TObject);
begin
  //取消选中的文件
  if not ShowMess('提示','确实要取消下面选中的文件吗?', MB_OKCANCEL) then Exit;

  RzListView1.DeleteSelected;
end;

end.

⌨️ 快捷键说明

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