有一段时间没正经的用delphi了,前两天下载了Delphi2010,用它来找找Delphi的感觉,把写的一些东西共享出来,大家共同学习一下,呵呵。

我想做一个双色球的分析软件,以下是其中实现的部分类的单元文件,其他文件后续一点一点的补齐,有不妥的地方,希望大家指正,谢谢啦!

在使用Delphi2010是,发现个问题,在用show函数调用窗体时,主窗口总是在子窗口的下面。

{工具类单元,包括一些用到的辅助类定义}

unit uCustomUtils;

interface

uses
  Classes;

type
  TLottery = packed record
   {红球集合}
    RedBalls: TStringList;
    {篮球}
    BlueBall: string;
    {开奖期号}
    Period: string;
    {开奖时间}
    Time: string;
    {奇偶数比}
    OddEvenCompare: string;
    {大小比}
    BigSmallCompare: string;
    {和值}
    Sum: string;
  end;
  pLottery = ^TLottery;

implementation

end.

{数据库辅助单元,通过这个类去与数据库打交道,因为当前用到的是Access数据库,}

{所以继承了一个Access的类,其他数据库,可以再另行实现}

unit uDBHelper;

interface

uses
  Classes, ADODB, SysUtils, Windows,

uCustomUtils;

const
  CONNECTION_STRING_ACCESS = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False';

type
  TDBHelper = class
  private
    FDBFilePath: string;
    FCommandText: string;
    FConnection: TADOConnection;
  public
    {执行Insert,Delete,Update操作}
    procedure Execute; virtual; abstract;
    {执行select操作}
    procedure SelectExecute; virtual; abstract;
    {打开数据库连接}
    procedure Open; virtual; abstract;
    {关闭数据库连接}
    procedure Close; virtual; abstract;

{构造函数}
    constructor Create(dbfilePath: string); virtual;
    {析构函数}
    destructor Destory; virtual;

public
    property DBFilePath: string read FDBFilePath;
    property CommandText: string read FCommandText write FCommandText;
  end;

TAccessHelper = class(TDBHelper)
  private
    FLotterys: TList;
  public
    procedure Execute; override;
    procedure SelectExecute; override;
    procedure Open; override;
    procedure Close; override;

constructor Create(dbfilePath: string); override;
    destructor Destroy; override;
  end;

implementation

{ TDBHelper }

constructor TDBHelper.Create(dbfilePath: string);
begin
  FConnection := TADOConnection.Create(nil);
  FDBFilePath := dbfilePath;
end;

destructor TDBHelper.Destory;
begin
  FreeAndNil(FConnection);
end;

{ TAccessHelper }

procedure TAccessHelper.Close;
begin
  if FConnection.Connected then
    FConnection.Close;
end;

constructor TAccessHelper.Create(dbfilePath: string);
var
  dbfile: string;
begin
  inherited;
  FLotterys := TList.Create;
  try
    dbfile := Format(CONNECTION_STRING_ACCESS, [FDBFilePath]);
    FConnection.ConnectionString := dbfile;
    FConnection.LoginPrompt := False;
    FConnection.Open;
  except
    on E:Exception do
      MessageBox(0, Pchar('Open Database error.'), Pchar(''), MB_OK+MB_ICONINFORMATION)
  end;
end;

destructor TAccessHelper.Destroy;
begin
  FConnection.Close;
  FreeAndNil(FLotterys);
  inherited;
end;

procedure TAccessHelper.Execute;
var
  qry: TADOQuery;
begin
  qry := TADOQuery.Create(nil);
  try
    with qry do
    begin
      Connection := FConnection;
      SQL.Clear;
      SQL.Add(FCommandText);
      ExecSQL;
    end;
  finally
    qry.Free;
  end;
end;

procedure TAccessHelper.Open;
begin
  FConnection.Open;
end;

procedure TAccessHelper.SelectExecute;
var
  qry: TADOQuery;
  item: TLottery;
  i: Integer;
  strRed: string;
begin
  qry := TADOQuery.Create(nil);
  try
    with qry do
    begin
      Connection := FConnection;
      SQL.Clear;
      SQL.Add(FCommandText);
      Open;

//遍历记录部分
      First;
      while not Eof do
      begin
        item.Period := FieldByName('period').AsString;
        item.BlueBall := FieldByName('blue').AsString;
        item.Time := FieldByName('time').AsString;
        item.OddEvenCompare := FieldByName('oddeven').AsString;
        item.BigSmallCompare := FieldByName('bigsmall').AsString;
        item.Sum := FieldByName('sum').AsString;
        item.RedBalls := TStringList.Create;
        for i := 1 to 6 do
        begin
          strRed := 'red'+IntToStr(i);
          item.RedBalls.Add(FieldByName(strRed).AsString);
        end;
        FLotterys.Add(@item);
        Next;
      end;
    end;
  finally
    qry.Free;
  end;
end;

end.

{彩票的处理单元,包括录入,查询}

unit uLotterys;

interface

uses
  Classes, SysUtils,

uCustomUtils, uDBHelper;

type
  TLotteryManager = class
  private
    FLotterys: TList;
    FDBHelper: TAccessHelper;

{格式化TLottery类型为字符串}
    {%s,%s,%s…}
    {期号,时间,红球,蓝球,奇偶比,大小比,和值}
    function FormatLottery(const lottery: TLottery): string;
  public
    constructor Create(DBFilePath: string);
    destructor Destory;

{添加单独一个中奖记录}
    procedure ImportSingle(const lottery: TLottery; const tableName: string);
    {批量添加中奖纪录}
    {filePath: 要批量导入的数据文件}
    procedure ImportMultiple(const items: TList; const tabelName: string);
    {查询一定数量的中奖记录, 默认搜索全部s}
    procedure Search( const tableName: string; const count: Integer = 0);

{现在只用于在查询返回结果时使用}
    property Lotterys: TList read FLotterys;
  end;

implementation

{ TLotteryManager }

constructor TLotteryManager.Create(DBFilePath: string);
begin
  FLotterys := TList.Create;
  FDBHelper := TAccessHelper.Create(DBFilePath);
end;

destructor TLotteryManager.Destory;
begin
  FreeAndNil(FDBHelper);
  FreeAndNil(FLotterys);
end;

function TLotteryManager.FormatLottery(const lottery: TLottery): string;
const
  FORMAT_STR = '%s,%s';
var
  msg: string;
  i: Integer;
begin
  msg := lottery.Period;
  msg := Format(FORMAT_STR, [msg, lottery.Time]);
  for i := 0 to 5 do
  begin
    msg := Format(FORMAT_STR, [msg, lottery.RedBalls[i]]);
  end;
  msg := Format(FORMAT_STR, [msg, lottery.BlueBall]);
  msg := Format(FORMAT_STR, [msg, lottery.OddEvenCompare]);
  msg := Format(FORMAT_STR, [msg, lottery.BigSmallCompare]);
  msg := Format(FORMAT_STR, [msg, lottery.Sum]);
end;

procedure TLotteryManager.ImportMultiple(const items: TList; const tabelName: string);
var
  item: pLottery;
  i: Integer;
begin
  for i := 0 to items.Count - 1 do
  begin
    item := pLottery(items.Items[i]);
    ImportSingle(item^, tabelName);
  end;
end;

procedure TLotteryManager.ImportSingle(const lottery: TLottery; const tableName: string);
const
  INSERT_STR = 'insert into [%s] values(%s)';
var
  cmdText: string; 
begin
  cmdText := Format(INSERT_STR, [tableName, FormatLottery(lottery)]);
  FDBHelper.CommandText := cmdText;
  FDBHelper.Execute;
end;

procedure TLotteryManager.Search(const tableName: string; const count: Integer);
const
  SELECT_STR = 'select %s * from [%s]';
var
  cmdText: string; 
begin
  if count = 0 then
  begin
    cmdText := Format(SELECT_STR, ['',tableName]);
  end
  else begin
    cmdText := Format(SELECT_STR, [IntToStr(count), tableName]);
  end;
  FDBHelper.CommandText := cmdText;
  FDBHelper.Open;
end;

end.

Delphi-双色球分析软件(1)相关推荐

  1. 【原创】C#玩高频数字彩快3的一点体会

    购彩风险非常高,本人纯属很久以前对数字高频彩的一点研究.目前已经远离数字彩,重点研究足球篮球比赛资料库和赛果预测. 这是一篇在草稿箱保存了1年多的文章,一直没发现,顺便修改修改分享给大家.以后会有更多 ...

  2. 弦箭彩票分析软件 v4.03 双色球完全版 官方

    Welcome to my blog! <script language="javascript" src="http://avss.b15.cnwg.cn/cou ...

  3. delphi 软件在线人数统计_8款值得学习的科研论文作图软件

    写在前面 科研绘图在国外已经非常流行,且被高度重视,国内科研人员也越来越重视科研方面的绘图. 不少科研工作者,包括在读的博士生.研究生等可能都有这样的体会:千辛万苦得来的实验结果,不知道该如何展现给别 ...

  4. delphi 演示数据路径

    链接里默认的--------------------------- Error --------------------------- I/O error for file "C:\Prog ...

  5. HS4、HS6 USB示波器,USB虚拟示波器,多通道数据分析软件功能图解

    HS3.HS4.HS5.HS6 USB高速USB虚拟示波器不但具有采集卡的全部功能,还包括二次开发,Labview,Matlab调用,最主要的是 配有一套强大的多功能仪器分析软件包括(数字存储示波器, ...

  6. 常用统计分析软件介绍

    一. SAS统计软件 SAS 是英文Statistical Analysis System的缩写,翻译成汉语是统计分析系统,最初由美国北卡罗来纳州立大学两名研究生开始研制,1976 年创立SAS公司, ...

  7. Scientific Toolworks Understand(代码分析软件) v5.1.1001免费版

    Scientific Toolworks Understand(代码分析软件)是一款支持多平台代码分析软件,使用这款Scientific Toolworks Understand(代码分析软件)可以让 ...

  8. Delphi 之Copyrect的使用

    http://cqujsjcyj.iteye.com/blog/380970 Copyrect的使用(图片复制.放大.以及做图片放大镜等) 一.从一个选取一个区域中的图象到另一个图象组件中的固定区域 ...

  9. delphi 10 seattle 中 解决IOS 9 限制使用HTTP 服务问题

    IOS 9 于17号早上正式开始推送,早上起来立马安装,这次升级包只有1G, 安装空间也大大降低(想起IOS 8 升级时,几乎把手机里面的东西删光了,满眼都是泪). 虽然安装后,网上几乎是铺天盖地的吐 ...

最新文章

  1. quickpcb添加pcb库_quickpcb使用说明
  2. 阿里巴巴为什么能抗住90秒100亿?看完这篇你就明白了!
  3. 【面试经验分享】大厂HR在面试时,都想听你说些啥?
  4. |NOIOJ|动态规划|3532:最大上升子序列和
  5. s5pv210——按键
  6. 文本检测算法新思路:基于区域重组的文本检测
  7. Visual Studio .NET已检测到指定的Web服务器运行的不是ASP.NET 1.1 版...的解决办法
  8. 设计模式-01-设计模式简介及分类
  9. python重写和装饰器_Python | 老司机教你 5 分钟读懂 Python 装饰器
  10. linux 怎么格式化u盘写保护,u盘怎样去掉写保护状态手机怎么加密软件
  11. 精美教师说课试讲教学通用PPT模板
  12. 根据条件对Excel表中数据进行计数
  13. 使用Excel 提取文本中的数字
  14. dpg learning 和q_【强化学习】DPG, DQN与DDPG
  15. Python实现极大似然估计
  16. ios 13 全局修改 present 卡片式
  17. 检测特殊字符的正则表达式
  18. XToDoList 助你一臂之力
  19. Android (嘤)英语语音识别 简单概况
  20. 《流星》·序章至完结 SK-CP:Yoh X Hao

热门文章

  1. 3D打印机(Prusa I2)DIY经验分享(Part II)
  2. asp.net mvc + mongodb 实践
  3. 关于反向传播算法中的残差推导理解
  4. VMware16的安装以及VMware安装Linux(CentOS7)虚拟机教程(超详细)
  5. 轻量级3d模型查看器_NVIDIA这是要统领3D软件了么?感觉一股强大冲击波~
  6. C++ 二叉树的层次建树及其遍历
  7. c语言从键盘输入asdfg输出asdfg,C语言编程问题 C语言编程问题:题目计算圆的面积。...
  8. 英语六级高频词汇速记 + 2020-9听力 Day10
  9. 剑指offer 有人相爱,有人夜里开车看海,有人leetcode第一题都做不出来(leetcode有空就刷系列之找出数组中重复的数字)
  10. 7-14 英文单词排序